AlarmRecordIndexController.java 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package com.szwl.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4. import com.szwl.model.dto.AlarmRecordVo;
  5. import com.szwl.model.entity.TAdmin;
  6. import com.szwl.model.entity.TAlarmRecord;
  7. import com.szwl.model.entity.TEquipment;
  8. import com.szwl.model.utils.MailUtil;
  9. import com.szwl.model.utils.YunPianSms;
  10. import com.szwl.service.TAdminService;
  11. import com.szwl.service.TAlarmRecordService;
  12. import com.szwl.service.TEquipmentService;
  13. import org.apache.commons.lang.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.annotation.Resource;
  18. import java.text.SimpleDateFormat;
  19. import java.util.Date;
  20. import java.util.List;
  21. @Controller("appAlarmRecordController")
  22. @RequestMapping("/api/app_alarmRecord/alarmRecodeIndex")
  23. public class AlarmRecordIndexController {
  24. @Autowired
  25. private TAlarmRecordService alarmRecordService;
  26. @Autowired
  27. private TEquipmentService equipmentService;
  28. @Autowired
  29. private TAdminService adminService;
  30. private static final String appid = "07784f5fedb508046c841b391005b7de";
  31. /**
  32. * 添加报警记录
  33. */
  34. @RequestMapping(value = "/addAlarmRecord.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  35. @ResponseBody
  36. public String addAlarmRecord(@RequestBody AlarmRecordVo alarmRecordVo) {
  37. TAlarmRecord alarmRecord = new TAlarmRecord();
  38. String clientId = alarmRecordVo.getClientId();
  39. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  40. query.eq(TEquipment::getClientId,clientId);
  41. List<TEquipment> list = equipmentService.list(query);
  42. TEquipment equipment = list.get(0);
  43. if (equipment == null) {
  44. return "添加报警记录失败";
  45. }
  46. Integer type = equipment.getType();
  47. Long adminId = equipment.getAdminId();
  48. Long equipmentId = equipment.getId();
  49. String name = equipment.getName();
  50. String adminUserName = equipment.getAdminUserName();
  51. alarmRecord.setEquipmentId(equipmentId);
  52. alarmRecord.setName(name);
  53. alarmRecord.setAdminLevel(equipment.getAdminLevel());
  54. alarmRecord.setClientId(clientId);
  55. alarmRecord.setType(type);
  56. alarmRecord.setAdminId(adminId);
  57. alarmRecord.setCreateDate(new Date());
  58. alarmRecord.setModifyDate(new Date());
  59. alarmRecord.setAdminUserName(adminUserName);
  60. String alarmContent = alarmRecordVo.getAlarmContent();
  61. alarmRecord.setAlarmContent(alarmContent);
  62. alarmRecord.setRemark(alarmRecordVo.getRemark());
  63. alarmRecord.setOccurrenceTime(alarmRecordVo.getOccurrenceTime());
  64. alarmRecord.setIsEliminate(0);
  65. alarmRecordService.save(alarmRecord);
  66. TAdmin admin = adminService.getById(adminId);
  67. String email = admin.getEmail();
  68. String ifForeign = admin.getIfForeign();
  69. String companyType = admin.getCompanyType();
  70. String messageReceiver = equipment.getMessageReceiver();
  71. if(ifForeign.equals("1")){
  72. String subject = "Error message from Magic Candy Machine";
  73. StringBuffer contnet = new StringBuffer();
  74. String str1="Dear customer<br>" +
  75. "<br>" +
  76. "This is an automatic-sent mail to inform you that there is an error occurred on one of your Magic Candy machines, please kindly check the detail as below.<br>" +
  77. "<br>" +
  78. " Machine name:";
  79. String str2="<br>" +" Time&Date:";
  80. String str3="<br>"+" Error Message:";
  81. String str4= "<br>" +" <br>You don't have to reply this mail . What you need to do is to follow the instructions on the touch screen to clear the error and recover the machine. If there is any question or more information you need . Please do not be hesitated to contact your distributor.<br>" +
  82. "<br>" +
  83. " Thank you for choosing our machine!<br>" +
  84. "<br>" +
  85. "<br>" +
  86. "Best Regards.<br>" +
  87. "Magic Candy Service Team";
  88. contnet.append(str1).append(name).append(str2).append(alarmRecordVo.getOccurrenceTime()).append(str3).append(alarmContent).append(str4);
  89. if(StringUtils.isNotEmpty(messageReceiver)) {
  90. String[] split = messageReceiver.split(",");
  91. for (String s : split) {
  92. new MailUtil().send(s,subject,contnet.toString());
  93. }
  94. return "报警记录添加成功";
  95. } else {
  96. if(email!=null){
  97. new MailUtil().send(email,subject,contnet.toString());
  98. return "报警记录添加成功";
  99. }else {
  100. return "email is null";
  101. }
  102. }
  103. }
  104. String result = null;
  105. try {
  106. if (!"二次曲棍".equals(alarmContent)) {
  107. if (StringUtils.isNotEmpty(messageReceiver)) {
  108. String[] split = messageReceiver.split(",");
  109. for (int i = 0; i < split.length; i++) {
  110. if (StringUtils.isNotEmpty(split[i])) {
  111. // Long id = alarmRecord.getId();
  112. // String mess = ";序号:"+String.valueOf(id);
  113. if (StringUtils.isNotEmpty(companyType) && companyType.equals("1")) {
  114. // 如果是七云科技的用户
  115. result = YunPianSms.sendSms(appid, getSCMessage(alarmContent, name, clientId.substring(clientId.length() - 6)), split[i]);
  116. } else {
  117. // 如果是申泽智能的用户
  118. result = YunPianSms.sendSms(appid, getMessage(alarmContent, name, clientId.substring(clientId.length() - 6)), split[i]);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. } catch (Exception e) {
  125. }
  126. return "报警记录添加成功";
  127. }
  128. private String getMessage(String content, String name, String clientId) {
  129. String message = "【申泽智能】您好,机器" + content + ",机器名:" + name + ",设备号:" + clientId;
  130. return message;
  131. }
  132. private String getSCMessage(String content, String name, String clientId) {
  133. String message = "【七云科技】您好,机器报警:" + content + ",机器名:" + name + ",设备编号:" + clientId + "。";
  134. return message;
  135. }
  136. /**
  137. * 获取系统时间
  138. */
  139. @RequestMapping(value = "/getTime", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  140. @ResponseBody
  141. public String getTime() {
  142. Date date = new Date();
  143. SimpleDateFormat sformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//日期格式
  144. return sformat.format(date);
  145. }
  146. /**
  147. * 机器将要到期
  148. *
  149. * @param clientId
  150. * @return
  151. */
  152. @GetMapping(value = "/alarmDate", produces = "text/html;charset=utf-8")
  153. @ResponseBody
  154. public String endDate(String clientId){
  155. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  156. query.eq(TEquipment::getClientId,clientId);
  157. List<TEquipment> list = equipmentService.list(query);
  158. TEquipment equipment = list.get(0);
  159. Date endDate = equipment.getEndDate();
  160. long endDateTime = endDate.getTime();
  161. long time = System.currentTimeMillis();
  162. if(endDateTime>time){
  163. if(endDateTime-time<=3*24*3600*1000L){
  164. //发短信
  165. String result = null;
  166. try {
  167. String messageReceiver = equipment.getMessageReceiver();
  168. if (StringUtils.isNotEmpty(messageReceiver)) {
  169. String[] split = messageReceiver.split(",");
  170. for (int i = 0; i < split.length; i++) {
  171. if (StringUtils.isNotEmpty(split[i])) {
  172. result = YunPianSms.sendSms(appid, getMessage("使用时间即将到期", equipment.getName(), clientId), split[i]);
  173. }
  174. }
  175. }
  176. } catch (Exception e) {
  177. // logger.info("短信发送结果:" + result);
  178. }
  179. }
  180. }else{
  181. // return JsonMessage.success("已过期");
  182. return "已过期";
  183. }
  184. // return JsonMessage.success("success");
  185. return "success";
  186. }
  187. /**
  188. * 更改报警状态 消除
  189. *
  190. * @param
  191. * @return
  192. */
  193. @GetMapping(value = "/eliminate.htm", produces = "text/html;charset=utf-8")
  194. @ResponseBody
  195. public String eliminate(String id){
  196. TAlarmRecord alarmRecord = alarmRecordService.getById(Long.valueOf(id));
  197. alarmRecord.setIsEliminate(1);
  198. alarmRecordService.updateById(alarmRecord);
  199. // return JsonMessage.success("success");
  200. return "success";
  201. }
  202. }