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 query = Wrappers.lambdaQuery(); query.eq(TEquipment::getClientId,clientId); List 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 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 query = Wrappers.lambdaQuery(); query.eq(TEquipment::getClientId,clientId); List list = equipmentService.list(query); TEquipment equipment = list.get(0); if (equipment == null) { // return JsonMessage.error("设备不存在"); return "设备不存在"; } Integer value = equipment.getPayType(); HashMap 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 query = Wrappers.lambdaQuery(); // query.eq(TEquipment::getClientId,clientId); // List 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 filters = pageable.getFilters(); //// filters.add(Filter.eq("equipmentId", id)); //// Page page = productService.findPage(pageable); //// List 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 filters = pageable.getFilters(); // filters.add(Filter.like("clientId", clientId)); // List 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 filters = pageable.getFilters(); // filters.add(Filter.like("clientId", clientId)); // List 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 query = Wrappers.lambdaQuery(); query.eq(TEquipment::getClientId,clientId); List 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 query = Wrappers.lambdaQuery(); // query.eq(TEquipment::getClientId,clientId); // List 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 query = Wrappers.lambdaQuery(); query.eq(TEquipment::getClientId,clientId); List 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 query = Wrappers.lambdaQuery(); query.eq(TEquipment::getClientId,clientId); List 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(); } }