123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- package com.szwl.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.gexin.fastjson.JSON;
- import com.szwl.model.bo.JsonMessage;
- import com.szwl.model.dto.AdVo;
- import com.szwl.model.dto.TimeRuleVo;
- import com.szwl.model.entity.TAd;
- import com.szwl.model.entity.TEquipment;
- import com.szwl.model.entity.TTimeRule;
- import com.szwl.service.TAdService;
- import com.szwl.service.TEquipmentService;
- import com.szwl.service.TTimeRuleService;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.annotation.Resource;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- @Controller("ADIndexController")
- @RequestMapping("/api/app_ADIndex/ADIndex")
- public class ADIndexController {
- @Autowired
- TAdService aDService;
- @Autowired
- private TTimeRuleService timeRuleService;
- @Autowired
- private TEquipmentService equipmentService;
- @Resource
- private RedisTemplate redisTemplate;
- /**
- * 根据广告id获取广告
- */
- @GetMapping(value = "/getAdById.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getAdById(String id) {
- if(StringUtils.isEmpty(id)){
- // return JsonMessage.error("id为null");
- return "id为null";
- }
- TAd ad = aDService.getById(id);
- ArrayList<AdVo> list = new ArrayList<>();
- AdVo adVo = new AdVo();
- adVo.setAdType(String.valueOf(ad.getAdType()));
- adVo.setLocationType(String.valueOf(ad.getLocationType()));
- adVo.setName(ad.getName());
- adVo.setOrder(ad.getOrders());
- adVo.setUrl(ad.getUrl());
- adVo.setEquipmentType(ad.getEquipmentType());
- adVo.setCreateDate(ad.getCreateDate());
- adVo.setId(ad.getId());
- adVo.setMediaPreview(ad.getMediaPreview());
- adVo.setDuration(ad.getDuration());
- adVo.setScreenType(ad.getScreenType());
- list.add(adVo);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", JSONObject.toJSON(list).toString());
- jsonObject.put("errmsg", "");
- return jsonObject.toJSONString();
- }
- /**
- * 设备获取默认广告
- */
- @GetMapping(value = "/getAd.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getAdNew(String clientId,String equimentType) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> equipmentList = equipmentService.list(query);
- TEquipment equipment = equipmentList.get(0);
- String adminId = String.valueOf(equipment.getAdminId());
- //1,获取
- LambdaQueryWrapper<TAd> query1 = Wrappers.lambdaQuery();
- query1.eq(TAd::getType,"0");
- query1.eq(TAd::getEquipmentType,equimentType);
- List<TAd> ads = aDService.list(query1);
- ArrayList<AdVo> list = new ArrayList<>();
- for (TAd ad : ads) {
- if(adminId.equals(ad.getAdminId())||ad.getAdminId()==null){
- AdVo adVo = new AdVo();
- adVo.setAdType(String.valueOf(ad.getAdType()));
- adVo.setLocationType(String.valueOf(ad.getLocationType()));
- adVo.setName(ad.getName());
- adVo.setOrder(ad.getOrders());
- adVo.setUrl(ad.getUrl());
- adVo.setCreateDate(ad.getCreateDate());
- adVo.setId(ad.getId());
- adVo.setMediaPreview(ad.getMediaPreview());
- adVo.setDuration(ad.getDuration());
- adVo.setScreenType(ad.getScreenType());
- list.add(adVo);
- }
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", JSONObject.toJSON(list).toString());
- jsonObject.put("errmsg", "");
- return jsonObject.toJSONString();
- }
- /**
- * 设备获取广告
- */
- @GetMapping(value = "/getAdByEquipment.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getAdByEquipment(String clientId,String equimentType) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> equipmentList = equipmentService.list(query);
- TEquipment equipment = equipmentList.get(0);
- String adminId = String.valueOf(equipment.getAdminId());
- //1,获取
- LambdaQueryWrapper<TAd> query1 = Wrappers.lambdaQuery();
- query1.eq(TAd::getType,"0");
- query1.eq(TAd::getEquipmentType,equimentType);
- query1.eq(TAd::getAdminId,adminId);
- List<TAd> ads = aDService.list(query1);
- ArrayList<AdVo> list = new ArrayList<>();
- for (TAd ad : ads) {
- if(adminId.equals(ad.getAdminId())||ad.getAdminId()==null){
- AdVo adVo = new AdVo();
- adVo.setAdType(String.valueOf(ad.getAdType()));
- adVo.setLocationType(String.valueOf(ad.getLocationType()));
- adVo.setName(ad.getName());
- adVo.setOrder(ad.getOrders());
- adVo.setUrl(ad.getUrl());
- adVo.setCreateDate(ad.getCreateDate());
- adVo.setId(ad.getId());
- adVo.setMediaPreview(ad.getMediaPreview());
- adVo.setDuration(ad.getDuration());
- adVo.setScreenType(ad.getScreenType());
- list.add(adVo);
- }
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", JSONObject.toJSON(list).toString());
- jsonObject.put("errmsg", "");
- return jsonObject.toJSONString();
- }
- /**
- * 获取时间规则
- *
- * @param id
- * @return
- */
- @GetMapping(value = "/getTimeRule.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getTimeRule(Long id) {
- TTimeRule timeRule = timeRuleService.getById(id);
- if (timeRule == null) {
- // return JsonMessage.error("该规则不存在");
- return "该规则不存在";
- }
- if(StringUtils.isEmpty(timeRule.getType())||timeRule.getType().equals("0")){
- //旧规则
- String rule = null;
- List<TimeRuleVo> timeRuleVos = JSON.parseArray(timeRule.getRule(), TimeRuleVo.class);
- for(TimeRuleVo timeRuleVo:timeRuleVos){
- List<String> ads = timeRuleVo.getAd();
- rule = ads.toString();
- break;
- }
- return rule;
- }else {
- //新规则
- String rule = timeRule.getRule();
- return rule;
- }
- }
- /**
- * 设备下载广告失败则更新设备的推送广告时间
- *
- * @return
- */
- @PostMapping(value = "/pushTimeUpdate.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updatePushTimeUpdate(String clientId, String pushUpdateTime) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> equipmentList = equipmentService.list(query);
- TEquipment equipment = equipmentList.get(0);
- if (equipment == null) {
- // return JsonMessage.error("该设备不存在");
- return "该设备不存在";
- }
- Date date = null;
- try {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- date = format.parse(pushUpdateTime);
- equipment.setPushUpdateTime(date);
- } catch (ParseException e) {
- e.printStackTrace();
- // return JsonMessage.error("修改失败");
- return "修改失败";
- }
- equipmentService.updateById(equipment);
- // return JsonMessage.success("修改成功");
- return "修改成功";
- }
- /**
- *
- *
- * @param
- * @return
- */
- @GetMapping(value = "/checkRedis.htm", produces = "application/json;charset=UTF-8")
- @ResponseBody
- public JsonMessage checkRedis(String str) {
- Boolean hasKey = redisTemplate.hasKey(str);
- return JsonMessage.success(hasKey);
- }
- /**
- *
- *
- * @param
- * @return
- */
- @GetMapping(value = "/checkRedis2.htm", produces = "application/json;charset=UTF-8")
- @ResponseBody
- public JsonMessage checkRedis2(String key,String hashkey) {
- Object o = redisTemplate.boundHashOps(key).get(hashkey);
- return JsonMessage.success(o);
- }
- }
|