|
@@ -0,0 +1,362 @@
|
|
|
+package com.hboxs.control.api.equipment;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.hboxs.ViewObject.AlarmRecordVo;
|
|
|
+import com.hboxs.common.JsonMessage;
|
|
|
+import com.hboxs.common.utils.MailUtil;
|
|
|
+import com.hboxs.common.utils.YunPianSms;
|
|
|
+import com.hboxs.control.api.BaseController;
|
|
|
+import com.hboxs.entity.Admin;
|
|
|
+import com.hboxs.entity.AlarmRecord;
|
|
|
+import com.hboxs.entity.CleanHistory;
|
|
|
+import com.hboxs.entity.Equipment;
|
|
|
+import com.hboxs.service.AdminService;
|
|
|
+import com.hboxs.service.AlarmRecordService;
|
|
|
+import com.hboxs.service.CleanHistoryService;
|
|
|
+import com.hboxs.service.EquipmentService;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+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.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Controller("appCleanController")
|
|
|
+@RequestMapping("/api/app_alarmRecord/clean")
|
|
|
+public class CleanController extends BaseController {
|
|
|
+
|
|
|
+ @Resource(name = "alarmRecordServiceImpl")
|
|
|
+ private AlarmRecordService alarmRecordService;
|
|
|
+
|
|
|
+ @Resource(name = "equipmentServiceImpl")
|
|
|
+ private EquipmentService equipmentService;
|
|
|
+
|
|
|
+ @Resource(name = "cleanHistoryServiceImpl")
|
|
|
+ private CleanHistoryService cleanHistoryService;
|
|
|
+
|
|
|
+ @Resource(name = "adminServiceImpl")
|
|
|
+ private AdminService adminService;
|
|
|
+ private static final String appid = "07784f5fedb508046c841b391005b7de";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取清洗记录
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getCleanHistory", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
|
|
|
+ @ResponseBody
|
|
|
+ public Object getCleanHistory(String clientId, int type) {
|
|
|
+ CleanHistory cleanHistory = cleanHistoryService.findByClentId(clientId, type);
|
|
|
+ if (cleanHistory == null) {
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取机器到期时间及次数
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getCleanTimeAndRemaining", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
|
|
|
+ @ResponseBody
|
|
|
+ public Object getCleanTimeAndRemaining(String clientId) {
|
|
|
+ Equipment equipment = equipmentService.findByClientId(clientId);
|
|
|
+ String overdueDate = equipment.getOverdueDate();
|
|
|
+ String remaining = equipment.getRemaining();
|
|
|
+ String messageReceiver = equipment.getMessageReceiver();
|
|
|
+ Date now = new Date();
|
|
|
+ long nowTime = now.getTime();
|
|
|
+
|
|
|
+ if (remaining == null || remaining.equals("")) {
|
|
|
+ if (overdueDate == null || overdueDate.equals("")) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ Date date = sdf.parse(overdueDate);
|
|
|
+ long overdueTime = date.getTime();
|
|
|
+ if (nowTime < overdueTime) {
|
|
|
+ //提醒快要到期了
|
|
|
+ if (overdueTime - nowTime < 86400000l) {
|
|
|
+ //todo 发短信
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("使用时间即将到期", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nowTime > overdueTime) {
|
|
|
+ //提醒已到期了
|
|
|
+ //todo 发短信
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ if (equipment.getSmsFlag() == null || equipment.getSmsFlag().equals("")) {
|
|
|
+ equipment.setSmsFlag(0);
|
|
|
+ }
|
|
|
+ if (equipment.getSmsFlag() != null && !equipment.getSmsFlag().equals("")) {
|
|
|
+ if (equipment.getSmsFlag() < 4) {
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("因使用时间已过而停机,请充值后开机恢复使用", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ equipment.setSmsFlag(equipment.getSmsFlag() + 1);
|
|
|
+ equipmentService.update(equipment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (overdueDate == null || overdueDate.equals("")) {
|
|
|
+ int re = Integer.parseInt(remaining);
|
|
|
+ //提醒次数快要用完了
|
|
|
+ if (re <= 5 && re > 0) {
|
|
|
+ //todo 发短信
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("使用次数即将用完", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //已用完
|
|
|
+ if (re == 0) {
|
|
|
+ //todo 发短信
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ if (equipment.getTimesFlag() == null || equipment.getTimesFlag().equals("")) {
|
|
|
+ equipment.setTimesFlag(0);
|
|
|
+ }
|
|
|
+ if (equipment.getTimesFlag() != null && !equipment.getTimesFlag().equals("")) {
|
|
|
+ if (equipment.getTimesFlag() < 4) {
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("因使用次数不足停机,请充值后开机恢复使用", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ equipment.setTimesFlag(equipment.getTimesFlag() + 1);
|
|
|
+ equipmentService.update(equipment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //时间告急
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = null;
|
|
|
+ try {
|
|
|
+ date = sdf.parse(overdueDate);
|
|
|
+ long overdueTime = date.getTime();
|
|
|
+ if (overdueTime > nowTime) {
|
|
|
+ if (overdueTime - nowTime < 86400000l) {
|
|
|
+ int re = Integer.parseInt(remaining);
|
|
|
+ if (re > 0) {
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("按天数运行时间即将到期。还剩余" + remaining + "次清洗次数", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (re == 0) {
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("使用时间即将到期", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int re = Integer.parseInt(remaining);
|
|
|
+ if (re > 0) {
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ if (equipment.getSmsFlag() == null || equipment.getSmsFlag().equals("")) {
|
|
|
+ equipment.setTimesFlag(0);
|
|
|
+ }
|
|
|
+ if(equipment.getSmsFlag()<4){
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("按天数运行时间已到期。还剩余" + remaining + "次清洗次数", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ equipment.setSmsFlag(equipment.getSmsFlag()+1);
|
|
|
+ }
|
|
|
+ if(equipment.getSmsFlag()>=4){
|
|
|
+ if(re<5&&re>0){
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("使用次数即将用完", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ equipmentService.update(equipment);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (re == 0) {
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ if (equipment.getSmsFlag() == null || equipment.getSmsFlag().equals("")) {
|
|
|
+ equipment.setSmsFlag(0);
|
|
|
+ }
|
|
|
+ if (equipment.getTimesFlag() == null || equipment.getTimesFlag().equals("")) {
|
|
|
+ equipment.setTimesFlag(0);
|
|
|
+ }
|
|
|
+ if(equipment.getSmsFlag()<4){
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("因使用时间已过而停机,请充值后开机恢复使用", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ equipment.setSmsFlag(equipment.getSmsFlag()+1);
|
|
|
+ equipmentService.update(equipment);
|
|
|
+ }else{
|
|
|
+ if (equipment.getTimesFlag() < 4) {
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ result = YunPianSms.sendSms(appid, getMessage("因使用次数不足停机,请充值后开机恢复使用", equipment.getName(), clientId), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ equipment.setTimesFlag(equipment.getTimesFlag() + 1);
|
|
|
+ equipmentService.update(equipment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("短信发送结果:" + result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("overdueDate", overdueDate);
|
|
|
+ jsonObject.put("remaining", remaining);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清洗报告
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/cleanReport", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
|
|
|
+ @ResponseBody
|
|
|
+ public Object getCleanReport(String clientId, int type, int water, int electricity) {
|
|
|
+ Equipment equipment = equipmentService.findByClientId(clientId);
|
|
|
+ CleanHistory cleanHistory = new CleanHistory();
|
|
|
+ cleanHistory.setType(String.valueOf(type));
|
|
|
+ cleanHistory.setClientId(clientId);
|
|
|
+ cleanHistory.setAdminId(equipment.getAdminId());
|
|
|
+ cleanHistory.setAdminName(equipment.getAdminUserName());
|
|
|
+ cleanHistory.setCreateDate(new Date());
|
|
|
+ cleanHistory.setModifyDate(new Date());
|
|
|
+ cleanHistory.setEquipmentId(equipment.getId());
|
|
|
+ cleanHistory.setElectricity(electricity);
|
|
|
+ cleanHistory.setWater(water);
|
|
|
+ cleanHistory.setName(equipment.getName());
|
|
|
+ cleanHistoryService.save(cleanHistory);
|
|
|
+ //TODO减次数
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMessage1(String content, String name, String clientId) {
|
|
|
+ //使用次数快要用完
|
|
|
+ String message = "您好,您的机器:" + name + ",设备号:" + clientId + "使用次数即将用完。为避免停机,请尽快充值。";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMessage(String content, String name, String clientId) {
|
|
|
+ //即将到期
|
|
|
+// String message = "您好,您的机器:" + name + ",设备号:" + clientId + "即将到期。为避免停机,请尽快充值。";
|
|
|
+ String message = "您好,机器" + content + ",机器名:" + name + ",设备号:" + clientId;
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMessage3(String content, String name, String clientId) {
|
|
|
+ //次数用完
|
|
|
+ String message = "您好,您的机器:" + name + ",设备号:" + clientId + "因使用次数不足停机,请充值后开机恢复使用。";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMessage4(String content, String name, String clientId) {
|
|
|
+ //已到期
|
|
|
+ String message = "您好,您的机器:" + name + ",设备号:" + clientId + "因使用时间已过而停机,请充值后开机恢复使用。";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMessage5(String content, String name, String clientId) {
|
|
|
+ //即将到期
|
|
|
+ String message = "您好,您的机器:" + name + ",设备号:" + clientId + "按天数运行时间即将到期。还剩余" + content + "次清洗次数";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMessage6(String content, String name, String clientId) {
|
|
|
+ //即将到期
|
|
|
+ String message = "您好,您的机器:" + name + ",设备号:" + clientId + "按天数运行时间已到期。还剩余" + content + "次清洗次数";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+ private String getMessage7(String content, String name, String clientId) {
|
|
|
+ //即将到期
|
|
|
+ String message = "您好,您的机器:" + name + ",设备号:" + clientId + "天按天数运行时间已到期。还剩余" + content + "次清洗次数";
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+}
|