SynchroController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package com.szwl.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.szwl.model.entity.TEquipment;
  6. import com.szwl.service.TAlarmRecordService;
  7. import com.szwl.service.TEquipmentService;
  8. import com.szwl.service.TProductService;
  9. import org.apache.commons.lang.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import javax.annotation.Resource;
  17. import java.util.Date;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. /**
  21. * 用来同步数据
  22. */
  23. @Controller("appsynchroIndexController")
  24. @RequestMapping("/api/app_synchro/synchroIndex")
  25. public class SynchroController {
  26. @Autowired
  27. private TProductService productService;
  28. @Autowired
  29. private TEquipmentService equipmentService;
  30. @Autowired
  31. private TAlarmRecordService alarmRecordService;
  32. // @Autowired
  33. // private TMaintainingHistoryService maintainingHistoryService;
  34. /**
  35. * 同步密码
  36. *
  37. * @param clientId
  38. * @return
  39. */
  40. @RequestMapping(value = "/synPwd", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  41. @ResponseBody
  42. public String synPwd(String clientId) {
  43. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  44. query.eq(TEquipment::getClientId,clientId);
  45. List<TEquipment> list = equipmentService.list(query);
  46. TEquipment equipment = list.get(0);
  47. if (equipment == null) {
  48. // return JsonMessage.error("设备不存在");
  49. return "设备不存在";
  50. }
  51. String adminPwd = equipment.getAdminPwd();
  52. String guestPwd = equipment.getGuestPwd();
  53. HashMap<String, String> map = new HashMap<>();
  54. map.put("adminPwd", adminPwd);
  55. map.put("guestPwd", guestPwd);
  56. JSONObject jsonObject = getJsonObject(map);
  57. return jsonObject.toJSONString();
  58. }
  59. /**
  60. * 同步支付方式
  61. */
  62. @RequestMapping(value = "/synPay", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  63. @ResponseBody
  64. public String synPay(String clientId) {
  65. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  66. query.eq(TEquipment::getClientId,clientId);
  67. List<TEquipment> list = equipmentService.list(query);
  68. TEquipment equipment = list.get(0);
  69. if (equipment == null) {
  70. // return JsonMessage.error("设备不存在");
  71. return "设备不存在";
  72. }
  73. Integer value = equipment.getPayType();
  74. HashMap<String, String> map = new HashMap<>();
  75. map.put("payType", value.toString());
  76. JSONObject jsonObject = getJsonObject(map);
  77. return jsonObject.toJSONString();
  78. }
  79. /**
  80. * 同步商品数据
  81. */
  82. // @RequestMapping(value = "/synProduct", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  83. // @ResponseBody
  84. // public String synProduct(String clientId) {
  85. //
  86. // LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  87. // query.eq(TEquipment::getClientId,clientId);
  88. // List<TEquipment> list = equipmentService.list(query);
  89. // TEquipment equipment = list.get(0);
  90. // if (equipment == null) {
  91. // // return JsonMessage.error("设备不存在");
  92. // return "设备不存在";
  93. // }
  94. // Long id = equipment.getId();
  95. //// Pageable pageable = new Pageable();
  96. //// List<Filter> filters = pageable.getFilters();
  97. //// filters.add(Filter.eq("equipmentId", id));
  98. //// Page<Product> page = productService.findPage(pageable);
  99. //// List<Product> content = page.getContent();
  100. // JSONObject jsonObject = getJsonObject(content);
  101. // return jsonObject.toJSONString();
  102. // }
  103. /**
  104. * 同步报警记录
  105. */
  106. // @RequestMapping(value = "/synAlarmRecord", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  107. // @ResponseBody
  108. // public Object synAlarmRecord(String clientId) {
  109. // Pageable pageable = new Pageable();
  110. // List<Filter> filters = pageable.getFilters();
  111. // filters.add(Filter.like("clientId", clientId));
  112. // List<AlarmRecord> alarmRecords = alarmRecordService.findPage(pageable).getContent();
  113. // JSONObject jsonObject = getJsonObject(alarmRecords);
  114. // return jsonObject.toJSONString();
  115. //
  116. // }
  117. /**
  118. * 维护记录
  119. */
  120. // @RequestMapping(value = "/synMainTain", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  121. // @ResponseBody
  122. // public Object synMainTain(String clientId) {
  123. // Pageable pageable = new Pageable();
  124. // List<Filter> filters = pageable.getFilters();
  125. // filters.add(Filter.like("clientId", clientId));
  126. // List<MaintainingHistory> list = maintainingHistoryService.findPage(pageable).getContent();
  127. // JSONObject jsonObject = getJsonObject(list);
  128. // return jsonObject.toJSONString();
  129. // }
  130. private JSONObject getJsonObject(Object o) {
  131. JSONObject jsonObject = new JSONObject();
  132. jsonObject.put("code", 0);
  133. jsonObject.put("data", jsonObject.toJSONString(o));
  134. jsonObject.put("errmsg", "");
  135. return jsonObject;
  136. }
  137. /**
  138. * 同步广告规则
  139. *
  140. * @param clientId
  141. * @return
  142. */
  143. @GetMapping(value = "/synTimeRule", produces = "text/html;charset=utf-8")
  144. @ResponseBody
  145. public String synTimeRule(String clientId) {
  146. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  147. query.eq(TEquipment::getClientId,clientId);
  148. List<TEquipment> list = equipmentService.list(query);
  149. TEquipment equipment = list.get(0);
  150. if (equipment == null) {
  151. // return JsonMessage.error("该设备不存在");
  152. return "该设备不存在";
  153. }
  154. // return JsonMessage.success(equipment.getTimeRuleId());
  155. return equipment.getTimeRuleId().toString();
  156. }
  157. /**
  158. * 同步开关机时间
  159. *
  160. * @param clientId
  161. * @return
  162. */
  163. // @GetMapping(value = "/timeRule")
  164. // @ResponseBody
  165. // public Object cleanRule(String clientId){
  166. // LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  167. // query.eq(TEquipment::getClientId,clientId);
  168. // List<TEquipment> list = equipmentService.list(query);
  169. // TEquipment equipment = list.get(0);
  170. //// String bootTime = equipment.getBootTime();
  171. //// String offTime = equipment.getOffTime();
  172. // JSONObject jsonObject = new JSONObject();
  173. // if(StringUtils.isEmpty(bootTime)){
  174. // jsonObject.put("bootTime", "尚未设定清洗规则");
  175. // }else {
  176. // jsonObject.put("bootTime", bootTime);
  177. // }
  178. // if(StringUtils.isEmpty(offTime)){
  179. // jsonObject.put("offTime", "尚未设定清洗规则");
  180. // }else {
  181. // jsonObject.put("offTime", offTime);
  182. // }
  183. // return jsonObject;
  184. // }
  185. /**
  186. * 同步plc版本
  187. *
  188. * @param clientId
  189. * @return
  190. */
  191. @GetMapping(value = "/plcVersion", produces = "text/html;charset=utf-8")
  192. @ResponseBody
  193. public String plcVersion(String clientId,String plcVersion){
  194. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  195. query.eq(TEquipment::getClientId,clientId);
  196. List<TEquipment> list = equipmentService.list(query);
  197. TEquipment equipment = list.get(0);
  198. equipment.setPlcVersion(plcVersion);
  199. equipmentService.updateById(equipment);
  200. return "success";
  201. }
  202. /**
  203. * 同步机器到期时间
  204. *
  205. * @param clientId
  206. * @return
  207. */
  208. @GetMapping(value = "/endDate", produces = "text/html;charset=utf-8")
  209. @ResponseBody
  210. public Object endDate(String clientId){
  211. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  212. query.eq(TEquipment::getClientId,clientId);
  213. List<TEquipment> list = equipmentService.list(query);
  214. TEquipment equipment = list.get(0);
  215. Date endDate = equipment.getEndDate();
  216. JSONObject jsonObject = new JSONObject();
  217. String time = null;
  218. if(endDate!=null){
  219. jsonObject.put("endDate", "");
  220. }else {
  221. time = String.valueOf(endDate.getTime());
  222. jsonObject.put("endDate", time);
  223. }
  224. // return JsonMessage.success(time);
  225. // return time;
  226. return jsonObject.toJSONString();
  227. }
  228. }