Browse Source

fix:“修复邮件提醒部分不发送的问题"

soobin 8 tháng trước cách đây
mục cha
commit
80120ed32f

+ 13 - 0
src/main/java/com/szwl/config/MqttConfig.java

@@ -1,6 +1,8 @@
 package com.szwl.config;
 
 import com.szwl.manager.MqttHandlerManager;
+import com.szwl.model.entity.MqttMsg;
+import com.szwl.service.MqttMsgService;
 import com.szwl.service.MqttTopicsService;
 import lombok.extern.slf4j.Slf4j;
 import org.eclipse.paho.client.mqttv3.*;
@@ -13,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Date;
 
 /**
  * mqtt配置
@@ -45,6 +48,9 @@ public class MqttConfig {
     @Autowired
     private MqttTopicsService mqttTopicsService;
 
+    @Autowired
+    private MqttMsgService mqttMsgService;
+
     public MqttConfig(MqttHandlerManager handlerManager) {
         this.handlerManager = handlerManager;
     }
@@ -74,6 +80,12 @@ public class MqttConfig {
                 }
                 // 将消息转发到处理逻辑
                 handleIncomingMessage(topic, payload);
+
+                MqttMsg mqttMsg = new MqttMsg();
+                mqttMsg.setCreateDate(new Date());
+                mqttMsg.setTopic(topic);
+                mqttMsg.setMessage(payload);
+                mqttMsgService.save(mqttMsg);
             }
 
             @Override
@@ -98,6 +110,7 @@ public class MqttConfig {
             // 使会话保持
             options.setCleanSession(false);
             options.setKeepAliveInterval(60);
+            options.setAutomaticReconnect(true);
             // 建立连接
             mqttClient.connect(options);
             // 订阅主题

+ 14 - 3
src/main/java/com/szwl/constant/ResponseCodesEnum.java

@@ -8,8 +8,8 @@ public enum ResponseCodesEnum {
     A0101("A0101", "出生日期格式错误"),
     A0200("A0200", "用户编号已存在"),
     A0201("A0201", "用户登录名已存在"),
-    A0202("A0202", "用户手机已存在"),
-    A0203("A0203", "用户已存在"),
+    A0202("A0202", "用户手机已存在"),
+    A0203("A0203", "用户手机/邮箱已存在"),
     A0204("A0204", "用户ID集合不能为空"),
     A0205("A0205", "用户名不能为空"),
     A0206("A0206", "用户不存在"),
@@ -57,7 +57,18 @@ public enum ResponseCodesEnum {
     F0005("F0005","读取文件失败"),
     S0001("S0001","定时任务不存在"),
     P0001("P0001","无权限访问"),
-    P0002("P0002","无权限删除");
+    P0002("P0002","无权限删除"),
+    R0001("R0001","邀请码不存在"),
+    R0002("R0002","手机号为空"),
+    R0003("R0003","邮箱为空"),
+    R0004("R0004","不是有效的手机号或邮箱地址"),
+    R0005("R0005","验证码为空"),
+    R0006("R0006","验证码错误"),
+    R0007("R0007","验证码不存在"),
+    R0008("R0008","请勿频繁发送,10分钟后再试"),
+    R0009("R0009","手机号或邮箱为空"),
+    R0010("R0010","登录名或手机号出错"),
+    R0011("R0011","登录名或邮箱出错");
 
 
     private final String errorCode;

+ 3 - 3
src/main/java/com/szwl/controller/IndexController.java

@@ -1445,12 +1445,12 @@ public class IndexController {
             // 查询用户
             TAdmin admin = adminService.getById(equipment.getAdminId());
             // 如果有绑定微信
-            if (wechat != null && StringUtils.isNotEmpty(wechat.getOpenId()) && admin != null) {
+            if (admin != null) {
                 // 查询是申泽还是七云的
                 String companyType = admin.getCompanyType();
                 // 查询用户是否开启设备上线提醒功能
                 String onOffNotice = admin.getOnOffNotice();
-                if (StringUtils.isNotEmpty(onOffNotice) && onOffNotice.equals("1")) {
+                if (wechat != null && StringUtils.isNotEmpty(wechat.getOpenId()) && StringUtils.isNotEmpty(onOffNotice) && onOffNotice.equals("1")) {
                     // 微信发送设备上下线提醒消息
                     wechatService.sendOnOffMessage(wechat.getOpenId(), equipment.getClientId(), netTime, companyType, name, eqeStatus);
                 }
@@ -1901,7 +1901,7 @@ public class IndexController {
             //旧优惠码
             return "0";
         }
-        if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
+        if (promoCode.getDiscount() == 0) {
             //0折
             return "0";
         }

+ 13 - 16
src/main/java/com/szwl/controller/TAdminController.java

@@ -428,7 +428,7 @@ public class TAdminController {
     @Audit(type = AuditEnum.INSERT, content = "#loginUser.name + '注册账号'")
     public ResponseModel<?> save(@RequestBody RegisterParamDTO registerParam) {
         if (StringUtils.isEmpty(registerParam.getUsername()) || StringUtils.isEmpty(registerParam.getName()) || StringUtils.isEmpty(registerParam.getPassword())) {
-            return R.fail(ResponseCodesEnum.A0100, "数据有空!");
+            return R.fail(ResponseCodesEnum.A0001);
         }
 
         String phoneOrEmail = registerParam.getPhoneOrEmail();
@@ -445,38 +445,35 @@ public class TAdminController {
             relationAdminId = String.valueOf(AdminUtils.decrypt(false, registerParam.getInviteCode()));
             TAdmin admin = tAdminService.getById(relationAdminId);
             if (admin == null) {
-                return R.fail(ResponseCodesEnum.A0100, "邀请码不存在!");
+                return R.fail(ResponseCodesEnum.R0001);
             }
             if (admin.getType() != 4) {
-                return R.fail(ResponseCodesEnum.A0100, "邀请码不存在!");
+                return R.fail(ResponseCodesEnum.R0001);
             }
         }
         // 国内用户注册
         if (registerParam.getIfForeign().equals("0")) {
             // 判断 phoneOrEmail 是手机号还是邮箱
             if (Pattern.matches(phoneReg, phoneOrEmail)) {
-                System.out.println("这是一个手机号");
                 if (StringUtils.isEmpty(registerParam.getPhoneOrEmail())) {
-                    return R.fail(ResponseCodesEnum.A0100, "手机号为空!");
+                    return R.fail(ResponseCodesEnum.R0002);
                 }
             } else if (Pattern.matches(emailReg, phoneOrEmail)) {
-                System.out.println("这是一个邮箱地址");
                 if (StringUtils.isEmpty(registerParam.getPhoneOrEmail())) {
-                    return R.fail(ResponseCodesEnum.A0100, "邮箱为空!");
+                    return R.fail(ResponseCodesEnum.R0003);
                 }
             } else {
-                System.out.println("不是有效的手机号或邮箱地址");
-                return R.fail(ResponseCodesEnum.A0100, "不是有效的手机号或邮箱地址");
+                return R.fail(ResponseCodesEnum.R0004);
             }
         } else {
             //海外用户注册
             if (StringUtils.isEmpty(registerParam.getPhoneOrEmail())) {
-                return R.fail(ResponseCodesEnum.A0100, "邮箱为空!");
+                return R.fail(ResponseCodesEnum.R0003);
             }
         }
 
         if (StringUtils.isEmpty(registerParam.getCode())) {
-            return R.fail(ResponseCodesEnum.A0100, "验证码为空!");
+            return R.fail(ResponseCodesEnum.R0005);
         }
 
         //校验是否有重复的
@@ -484,7 +481,7 @@ public class TAdminController {
         query.eq(TAdmin::getUsername, registerParam.getUsername());
         List<TAdmin> list = tAdminService.list(query);
         if (!list.isEmpty()) {
-            return R.fail(ResponseCodesEnum.A0201, "用户登录名已存在");
+            return R.fail(ResponseCodesEnum.A0201);
         }
         LambdaQueryWrapper<TAdmin> query1 = Wrappers.lambdaQuery();
         if (registerParam.getIfForeign().equals("0")) {
@@ -499,7 +496,7 @@ public class TAdminController {
         }
         List<TAdmin> list1 = tAdminService.list(query1);
         if (!list1.isEmpty()) {
-            return R.fail(ResponseCodesEnum.A0203, "用户手机/邮箱已存在");
+            return R.fail(ResponseCodesEnum.A0203);
         }
 
         //校验验证码是否正确
@@ -523,7 +520,7 @@ public class TAdminController {
         if (!messageCodeList.isEmpty()) {
             TMessageCode tMessageCode = messageCodeList.get(messageCodeList.size() - 1);
             if (!tMessageCode.getCode().equals(registerParam.getCode())) {
-                return R.fail(ResponseCodesEnum.A0002, "验证码错误");
+                return R.fail(ResponseCodesEnum.R0006);
             }
             tMessageCode.setStatus("1");
 //            admin.setId(IDGenerator.commonID()); // admin 表改回原来的自增ID
@@ -552,7 +549,7 @@ public class TAdminController {
             } else if (Pattern.matches(emailReg, phoneOrEmail)) {
                 admin.setEmail(registerParam.getPhoneOrEmail());
             } else {
-                return R.fail(ResponseCodesEnum.A0100, "不是有效的手机号或邮箱地址");
+                return R.fail(ResponseCodesEnum.R0004);
             }
             if (registerParam.getCompanyType().equals("1")) { // 如果是七云平台
                 admin.setTradeMerchantNo("777138500523174"); //七云商户报备号
@@ -606,7 +603,7 @@ public class TAdminController {
             return R.ok(b);
 
         } else {
-            return R.fail(ResponseCodesEnum.A0002, "没有找到验证码");
+            return R.fail(ResponseCodesEnum.R0007);
         }
 
     }

+ 21 - 24
src/main/java/com/szwl/controller/TMessageCodeController.java

@@ -17,10 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-
 import org.springframework.web.bind.annotation.RestController;
 
-import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.regex.Pattern;
@@ -46,7 +44,7 @@ public class TMessageCodeController {
     @GetMapping("/getLastSendTime")
     public ResponseModel<?> getLastSendTime(String phoneOrEmail) {
         if (StringUtils.isEmpty(phoneOrEmail)) {
-            return R.fail(ResponseCodesEnum.A0100, "手机号或邮箱为空!");
+            return R.fail(ResponseCodesEnum.R0009);
         }
         // 查询该 手机号/邮箱 最后一次发送验证码的时间
         Date lastSendTime = tMessageCodeService.getLastSendTime(phoneOrEmail);
@@ -62,14 +60,14 @@ public class TMessageCodeController {
     public ResponseModel<?> sentRegisterCode(String ifForeign, String phoneOrEmail, String hostName) {
         if (StringUtils.isEmpty(phoneOrEmail)) {
             // 说明参数为空
-            return R.fail(ResponseCodesEnum.A0100, "手机号或邮箱为空!");
+            return R.fail(ResponseCodesEnum.R0009);
         }
         // 查询该 手机号/邮箱 最后一次发送验证码的时间
         Date lastSendTime = tMessageCodeService.getLastSendTime(phoneOrEmail);
         long lastTime = lastSendTime.getTime();
         long currentTime = System.currentTimeMillis();
         if (currentTime - lastTime < 10 * 60 * 1000) {
-            return R.fail("请勿频繁发送,10分钟后再试");
+            return R.fail(ResponseCodesEnum.R0008);
         }
 //        String SZ = "Sunzee";
         String SC = "Sevencloud";
@@ -93,7 +91,7 @@ public class TMessageCodeController {
                 query.eq(TAdmin::getPhone, phoneOrEmail);
                 List<TAdmin> list = tAdminService.list(query);
                 if (list.size() > 0) {
-                    return R.fail(ResponseCodesEnum.A0202, "用户手机号已存在");
+                    return R.fail(ResponseCodesEnum.A0202);
                 }
                 // 国内发送短信
                 String result = tMessageCodeService.sentMessage("0", phoneOrEmail, companyType);
@@ -104,14 +102,13 @@ public class TMessageCodeController {
                 query.eq(TAdmin::getEmail, phoneOrEmail);
                 List<TAdmin> list = tAdminService.list(query);
                 if (list.size() > 0) {
-                    return R.fail(ResponseCodesEnum.A0207, "用户邮箱已存在");
+                    return R.fail(ResponseCodesEnum.A0207);
                 }
                 // 国内发送邮箱
                 String result = tMessageCodeService.sentEmail("0", phoneOrEmail);
                 return R.ok(result);
             } else {
-                System.out.println("不是有效的手机号或邮箱地址");
-                return R.fail(ResponseCodesEnum.A0100, "不是有效的手机号或邮箱地址");
+                return R.fail(ResponseCodesEnum.R0004);
             }
         } else {
             //检测是否已有邮箱注册
@@ -119,7 +116,7 @@ public class TMessageCodeController {
             query.eq(TAdmin::getEmail, phoneOrEmail);
             List<TAdmin> list = tAdminService.list(query);
             if (list.size() > 0) {
-                return R.fail(ResponseCodesEnum.A0207, "用户邮箱已存在");
+                return R.fail(ResponseCodesEnum.A0207);
             }
             //海外发邮件验证码
             if (AETI.equals(hostName)) {  // 美国孙总域名
@@ -152,7 +149,7 @@ public class TMessageCodeController {
         // 如果是国内
         if (ifForeign.equals("0")) {
             if (StringUtils.isEmpty(phoneOrEmail)) {
-                return R.fail(ResponseCodesEnum.A0100, "手机号或邮箱为空!");
+                return R.fail(ResponseCodesEnum.R0009);
             }
             // 定义国内手机号和邮箱的正则表达式
             String phoneReg = "^1[3-9]\\d{9}$";
@@ -166,32 +163,32 @@ public class TMessageCodeController {
                 query.eq(TAdmin::getPhone, phoneOrEmail);
                 query.eq(TAdmin::getUsername, username);
                 List<TAdmin> list = tAdminService.list(query);
-                if (list.size() <= 0) { // 说明手机未注册
-                    return R.fail(ResponseCodesEnum.A0001, "登录名或手机号出错");
+                if (list.size() <= 0) {
+                    // 说明手机未注册
+                    return R.fail(ResponseCodesEnum.R0010);
                 }
                 //国内发送短信
                 String result = tMessageCodeService.sentMessage("1", phoneOrEmail, companyType);
                 return R.ok(result);
             } else if (Pattern.matches(emailReg, phoneOrEmail)) {
-                System.out.println("忘记密码 >>> 这是一个邮箱地址");
                 //检测是否已有邮箱注册
                 LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
                 query.eq(TAdmin::getEmail, phoneOrEmail);
                 query.eq(TAdmin::getUsername, username);
                 List<TAdmin> list = tAdminService.list(query);
-                if (list.size() <= 0) { // 邮箱未注册
-                    return R.fail(ResponseCodesEnum.A0001, "登录名或邮箱出错");
+                if (list.size() <= 0) {
+                    // 邮箱未注册
+                    return R.fail(ResponseCodesEnum.R0011);
                 }
                 //国内发邮件
                 String result = tMessageCodeService.sentEmail("1", phoneOrEmail);
                 return R.ok(result);
             } else {
-                System.out.println("忘记密码 >>> 不是有效的手机号或邮箱地址");
-                return R.fail(ResponseCodesEnum.A0001, "非有效的手机号或邮箱地址");
+                return R.fail(ResponseCodesEnum.R0004);
             }
         } else {
             if (StringUtils.isEmpty(phoneOrEmail)) {
-                return R.fail(ResponseCodesEnum.A0100, "邮箱为空!");
+                return R.fail(ResponseCodesEnum.R0003);
             }
             //检测是否已有邮箱注册
             LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
@@ -199,7 +196,7 @@ public class TMessageCodeController {
             query.eq(TAdmin::getUsername, username);
             List<TAdmin> list = tAdminService.list(query);
             if (list.size() <= 0) {
-                return R.fail(ResponseCodesEnum.A0001, "登录名或邮箱出错");
+                return R.fail(ResponseCodesEnum.R0011);
             }
             //海外发邮件验证码
             String result = tMessageCodeService.sendEmailAbroad("1", phoneOrEmail);
@@ -212,7 +209,7 @@ public class TMessageCodeController {
     @PostMapping("/checkForgetCode")
     public ResponseModel<?> checkForgetCode(String ifForeign, String code, String phoneOrEmail) {
         if (StringUtils.isEmpty(code)) {
-            return R.fail(ResponseCodesEnum.A0100, "验证码为空!");
+            return R.fail(ResponseCodesEnum.R0005);
         }
         if (ifForeign.equals("2")) {
             ifForeign = "0";
@@ -223,13 +220,13 @@ public class TMessageCodeController {
         } else {
             query2.eq(TMessageCode::getPhone, phoneOrEmail);
         }
-        query2.eq(TMessageCode::getType, "1");//1,忘记密码验证码
+        query2.eq(TMessageCode::getType, "1");
         query2.eq(TMessageCode::getStatus, "0");
         List<TMessageCode> messageCodeList = tMessageCodeService.list(query2);
         if (messageCodeList.size() > 0) {
             TMessageCode tMessageCode = messageCodeList.get(messageCodeList.size() - 1);
             if (!tMessageCode.getCode().equals(code)) {
-                return R.fail(ResponseCodesEnum.A0002, "验证码错误");
+                return R.fail(ResponseCodesEnum.R0006);
             } else {
                 tMessageCode.setStatus("1");
                 tMessageCode.setModifyDate(new Date());
@@ -237,7 +234,7 @@ public class TMessageCodeController {
                 return R.ok();
             }
         } else {
-            return R.fail(ResponseCodesEnum.A0002, "没有找到验证码");
+            return R.fail(ResponseCodesEnum.R0007);
         }
     }
 

+ 8 - 12
src/main/java/com/szwl/handle/ConnectedMessageHandler.java

@@ -1,14 +1,10 @@
 package com.szwl.handle;
 
-import com.alibaba.fastjson.JSONObject;
-import com.szwl.model.entity.MqttMsg;
 import com.szwl.service.MqttMsgService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
-
 /**
  * 连接消息处理
  */
@@ -21,13 +17,13 @@ public class ConnectedMessageHandler implements MqttMessageHandler{
 
     @Override
     public void handle(String topic, String payload) {
-        JSONObject jsonObject = JSONObject.parseObject(payload);
-        String clientId = jsonObject.getString("clientid");
-        MqttMsg mqttMsg = new MqttMsg();
-        mqttMsg.setCreateDate(new Date());
-        mqttMsg.setClientId(clientId);
-        mqttMsg.setTopic(topic);
-        mqttMsg.setMessage(payload);
-        mqttMsgService.save(mqttMsg);
+//        JSONObject jsonObject = JSONObject.parseObject(payload);
+//        String clientId = jsonObject.getString("clientid");
+//        MqttMsg mqttMsg = new MqttMsg();
+//        mqttMsg.setCreateDate(new Date());
+//        mqttMsg.setClientId(clientId);
+//        mqttMsg.setTopic(topic);
+//        mqttMsg.setMessage(payload);
+//        mqttMsgService.save(mqttMsg);
     }
 }

+ 8 - 12
src/main/java/com/szwl/handle/DisconnectedMessageHandler.java

@@ -1,14 +1,10 @@
 package com.szwl.handle;
 
-import com.alibaba.fastjson.JSONObject;
-import com.szwl.model.entity.MqttMsg;
 import com.szwl.service.MqttMsgService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
-
 /**
  * 断开连接处理
  */
@@ -21,13 +17,13 @@ public class DisconnectedMessageHandler implements MqttMessageHandler{
 
     @Override
     public void handle(String topic, String payload) {
-        JSONObject jsonObject = JSONObject.parseObject(payload);
-        String clientId = jsonObject.getString("clientid");
-        MqttMsg mqttMsg = new MqttMsg();
-        mqttMsg.setCreateDate(new Date());
-        mqttMsg.setClientId(clientId);
-        mqttMsg.setTopic(topic);
-        mqttMsg.setMessage(payload);
-        mqttMsgService.save(mqttMsg);
+//        JSONObject jsonObject = JSONObject.parseObject(payload);
+//        String clientId = jsonObject.getString("clientid");
+//        MqttMsg mqttMsg = new MqttMsg();
+//        mqttMsg.setCreateDate(new Date());
+//        mqttMsg.setClientId(clientId);
+//        mqttMsg.setTopic(topic);
+//        mqttMsg.setMessage(payload);
+//        mqttMsgService.save(mqttMsg);
     }
 }

+ 6 - 9
src/main/java/com/szwl/handle/HeartMessageHandler.java

@@ -3,7 +3,6 @@ package com.szwl.handle;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.szwl.model.entity.MqttMsg;
 import com.szwl.model.entity.TEquipment;
 import com.szwl.model.entity.TEquipmentDesc;
 import com.szwl.model.jsonParm.HeartParam;
@@ -14,8 +13,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
-
 /**
  * 心跳消息处理
  */
@@ -36,12 +33,12 @@ public class HeartMessageHandler implements MqttMessageHandler{
     public void handle(String topic, String payload) {
         HeartParam heartParam = JSON.parseObject(payload, HeartParam.class);
         String clientId = heartParam.getClientId();
-        MqttMsg mqttMsg = new MqttMsg();
-        mqttMsg.setCreateDate(new Date());
-        mqttMsg.setClientId(clientId);
-        mqttMsg.setTopic(topic);
-        mqttMsg.setMessage(payload);
-        mqttMsgService.save(mqttMsg);
+//        MqttMsg mqttMsg = new MqttMsg();
+//        mqttMsg.setCreateDate(new Date());
+//        mqttMsg.setClientId(clientId);
+//        mqttMsg.setTopic(topic);
+//        mqttMsg.setMessage(payload);
+//        mqttMsgService.save(mqttMsg);
 
         // 查询设备
         LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();