123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- 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.szwl.model.entity.TEquipment;
- import com.szwl.service.TAlarmRecordService;
- import com.szwl.service.TEquipmentService;
- import com.szwl.service.TProductService;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.annotation.Resource;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- /**
- * 用来同步数据
- */
- @Controller("appsynchroIndexController")
- @RequestMapping("/api/app_synchro/synchroIndex")
- public class SynchroController {
- @Autowired
- private TProductService productService;
- @Autowired
- private TEquipmentService equipmentService;
- @Autowired
- private TAlarmRecordService alarmRecordService;
- // @Autowired
- // private TMaintainingHistoryService maintainingHistoryService;
- /**
- * 同步密码
- *
- * @param clientId
- * @return
- */
- @RequestMapping(value = "/synPwd", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String synPwd(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- TEquipment equipment = list.get(0);
- if (equipment == null) {
- // return JsonMessage.error("设备不存在");
- return "设备不存在";
- }
- String adminPwd = equipment.getAdminPwd();
- String guestPwd = equipment.getGuestPwd();
- HashMap<String, String> map = new HashMap<>();
- map.put("adminPwd", adminPwd);
- map.put("guestPwd", guestPwd);
- JSONObject jsonObject = getJsonObject(map);
- return jsonObject.toJSONString();
- }
- /**
- * 同步支付方式
- */
- @RequestMapping(value = "/synPay", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String synPay(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- TEquipment equipment = list.get(0);
- if (equipment == null) {
- // return JsonMessage.error("设备不存在");
- return "设备不存在";
- }
- Integer value = equipment.getPayType();
- HashMap<String, String> map = new HashMap<>();
- map.put("payType", value.toString());
- JSONObject jsonObject = getJsonObject(map);
- return jsonObject.toJSONString();
- }
- /**
- * 同步商品数据
- */
- // @RequestMapping(value = "/synProduct", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- // @ResponseBody
- // public String synProduct(String clientId) {
- //
- // LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- // query.eq(TEquipment::getClientId,clientId);
- // List<TEquipment> list = equipmentService.list(query);
- // TEquipment equipment = list.get(0);
- // if (equipment == null) {
- // // return JsonMessage.error("设备不存在");
- // return "设备不存在";
- // }
- // Long id = equipment.getId();
- //// Pageable pageable = new Pageable();
- //// List<Filter> filters = pageable.getFilters();
- //// filters.add(Filter.eq("equipmentId", id));
- //// Page<Product> page = productService.findPage(pageable);
- //// List<Product> content = page.getContent();
- // JSONObject jsonObject = getJsonObject(content);
- // return jsonObject.toJSONString();
- // }
- /**
- * 同步报警记录
- */
- // @RequestMapping(value = "/synAlarmRecord", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- // @ResponseBody
- // public Object synAlarmRecord(String clientId) {
- // Pageable pageable = new Pageable();
- // List<Filter> filters = pageable.getFilters();
- // filters.add(Filter.like("clientId", clientId));
- // List<AlarmRecord> alarmRecords = alarmRecordService.findPage(pageable).getContent();
- // JSONObject jsonObject = getJsonObject(alarmRecords);
- // return jsonObject.toJSONString();
- //
- // }
- /**
- * 维护记录
- */
- // @RequestMapping(value = "/synMainTain", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- // @ResponseBody
- // public Object synMainTain(String clientId) {
- // Pageable pageable = new Pageable();
- // List<Filter> filters = pageable.getFilters();
- // filters.add(Filter.like("clientId", clientId));
- // List<MaintainingHistory> list = maintainingHistoryService.findPage(pageable).getContent();
- // JSONObject jsonObject = getJsonObject(list);
- // return jsonObject.toJSONString();
- // }
- private JSONObject getJsonObject(Object o) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", jsonObject.toJSONString(o));
- jsonObject.put("errmsg", "");
- return jsonObject;
- }
- /**
- * 同步广告规则
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/synTimeRule", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String synTimeRule(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- TEquipment equipment = list.get(0);
- if (equipment == null) {
- // return JsonMessage.error("该设备不存在");
- return "该设备不存在";
- }
- // return JsonMessage.success(equipment.getTimeRuleId());
- return equipment.getTimeRuleId().toString();
- }
- /**
- * 同步开关机时间
- *
- * @param clientId
- * @return
- */
- // @GetMapping(value = "/timeRule")
- // @ResponseBody
- // public Object cleanRule(String clientId){
- // LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- // query.eq(TEquipment::getClientId,clientId);
- // List<TEquipment> list = equipmentService.list(query);
- // TEquipment equipment = list.get(0);
- //// String bootTime = equipment.getBootTime();
- //// String offTime = equipment.getOffTime();
- // JSONObject jsonObject = new JSONObject();
- // if(StringUtils.isEmpty(bootTime)){
- // jsonObject.put("bootTime", "尚未设定清洗规则");
- // }else {
- // jsonObject.put("bootTime", bootTime);
- // }
- // if(StringUtils.isEmpty(offTime)){
- // jsonObject.put("offTime", "尚未设定清洗规则");
- // }else {
- // jsonObject.put("offTime", offTime);
- // }
- // return jsonObject;
- // }
- /**
- * 同步plc版本
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/plcVersion", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String plcVersion(String clientId,String plcVersion){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- TEquipment equipment = list.get(0);
- equipment.setPlcVersion(plcVersion);
- equipmentService.updateById(equipment);
- return "success";
- }
- /**
- * 同步机器到期时间
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/endDate", produces = "text/html;charset=utf-8")
- @ResponseBody
- public Object endDate(String clientId){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- TEquipment equipment = list.get(0);
- Date endDate = equipment.getEndDate();
- JSONObject jsonObject = new JSONObject();
- String time = null;
- if(endDate!=null){
- jsonObject.put("endDate", "");
- }else {
- time = String.valueOf(endDate.getTime());
- jsonObject.put("endDate", time);
- }
- // return JsonMessage.success(time);
- // return time;
- return jsonObject.toJSONString();
- }
- }
|