Sfoglia il codice sorgente

feat:“添加设备上线下线微信提醒功能“

soobin 1 anno fa
parent
commit
9214d0aae6

+ 22 - 2
src/main/java/com/szwl/constant/ConfigConsts.java

@@ -47,16 +47,36 @@ public class ConfigConsts {
     public static final String SC_WX_APP_SECRET = "f131c85c06a80e466bd7e366cd477b93";
 
     /**
-     * 申泽商户模板ID
+     * 申泽商户异常离线模板ID
      */
     public static final String SZ_TEMPLATE_ID = "4h0WwP60QR_6nzhkhEJTcYJHeZApCwxGYggKUNProW4";
 
     /**
-     * 七云商户模板ID
+     * 七云商户异常离线模板ID
      */
     public static final String SC_TEMPLATE_ID = "ilJA4oCUn_4ffPzS0PrWFKnNS7UX_j-PxjkNqLwYaCw";
 
     /**
+     * 申泽商户设备上线模板ID
+     */
+    public static final String SZ_ON_TEMPLATE_ID = "zvBdwEQbFjnIve6WgwHCzWyGVQ-wtznwSnxfuZjnf18";
+
+    /**
+     * 申泽商户设备离线模板ID
+     */
+    public static final String SZ_OFF_TEMPLATE_ID = "hJVBzuJjVY8HWhG0Un71ciXaSBr-uSS_CzmRqwMLgM8";
+
+    /**
+     * 七云商户设备上线模板ID
+     */
+    public static final String SC_ON_TEMPLATE_ID = "vSzTge9ILaylD0F1Zr1Gec4Sf2hxHZpMg7oVwmt9iFs";
+
+    /**
+     * 七云商户设备离线模板ID
+     */
+    public static final String SC_OFF_TEMPLATE_ID = "q0POCOXjIPN8JB8nkh10Fqd5PKxqfQqHOszwvAkbJEw";
+
+    /**
      *
      */
     public static final String SZ_RETURN_URL = "http://szwlh.sunzee.com.cn";

+ 41 - 20
src/main/java/com/szwl/controller/IndexController.java

@@ -99,6 +99,9 @@ public class IndexController {
     @Autowired
     private AmqpAdmin amqpAdmin;
 
+    @Autowired
+    TWechatService wechatService;
+
     @Resource
     TLocationCheckService locationCheckService;
 
@@ -568,29 +571,29 @@ public class IndexController {
                         TEquipment equipment = equipmentService.getOne(query1);
                         Long equipmentId = equipment.getId();
                         // 如果存在旧花型,就删除重新创建
-//                        LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
-//                        queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
-//                        List<TProduct> productList = productService.list(queryProduct);
-//                        if (productList.size() > 0) {
+                        LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
+                        queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
+                        List<TProduct> productList = productService.list(queryProduct);
+                        if (productList.size() == 0) {
 //                            for (TProduct product : productList) {
 //                                productService.removeById(product.getId());
 //                            }
-//                        }
-                        if (StringUtils.isEmpty(machineType) || machineType.equals("0")) {
-                            if (equipmentApply.getEquimentType() != null && equipmentApply.getEquimentType().equals("MG280")) {
-                                saveProductMG280(equipmentId);
-                            } else if (equipmentApply.getEquimentType() != null && equipmentApply.getEquimentType().equals("MG320-1")) {
-                                saveProductMG1(equipmentId);
-                            } else {
-                                saveProduct(equipmentId);
-                            }
-                        } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("1")){
-                            if (equimentType.equals("P30")) {
-                                saveGoodsData(equipmentId, machineType, 6);
-                            }
-                        } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("2")){
-                            if (equimentType.equals("SI320")) {
-                                saveGoodsData(equipmentId, machineType, 6);
+                            if (StringUtils.isEmpty(machineType) || machineType.equals("0")) {
+                                if (equipmentApply.getEquimentType() != null && equipmentApply.getEquimentType().equals("MG280")) {
+                                    saveProductMG280(equipmentId);
+                                } else if (equipmentApply.getEquimentType() != null && equipmentApply.getEquimentType().equals("MG320-1")) {
+                                    saveProductMG1(equipmentId);
+                                } else {
+                                    saveProduct(equipmentId);
+                                }
+                            } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("1")){
+                                if (equimentType.equals("P30")) {
+                                    saveGoodsData(equipmentId, machineType, 6);
+                                }
+                            } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("2")){
+                                if (equimentType.equals("SI320")) {
+                                    saveGoodsData(equipmentId, machineType, 6);
+                                }
                             }
                         }
 
@@ -1444,9 +1447,27 @@ public class IndexController {
         if (equipment == null) {
             return "该设备不存在";
         }
+        // 设备名称
+        String name = equipment.getName();
+        // 如果为空就拿设备编号后六位
+        if(StringUtils.isEmpty(name)) {
+            name = equipment.getClientId().substring(equipment.getClientId().length() - 6);
+        }
         if (eqeStatus != null) {
             equipment.setNetwork(netTime);
             equipment.setEqeStatus(eqeStatus);
+            // 查询是否有绑定微信
+            LambdaQueryWrapper<TWechat> wechatQuery = Wrappers.lambdaQuery();
+            wechatQuery.eq(TWechat::getAdminId, equipment.getAdminId());
+            TWechat wechat = wechatService.getOne(wechatQuery);
+            // 如果有绑定微信
+            if (wechat != null && StringUtils.isNotEmpty(wechat.getOpenId())) {
+                // 发送模板消息
+                TAdmin admin = adminService.getById(equipment.getAdminId());
+                // 查询是申泽还是七云的
+                String companyType = admin.getCompanyType();
+                wechatService.sendOnOffMessage(wechat.getOpenId(), equipment.getClientId(), netTime, companyType, name, eqeStatus);
+            }
             if (eqeStatus == 0) {
                 equipment.setCabinetTm("");
                 equipment.setCabinetHd("");

+ 6 - 1
src/main/java/com/szwl/service/TEquipmentService.java

@@ -33,6 +33,11 @@ public interface TEquipmentService extends MyIService<TEquipment> {
      * 检查设备
      */
     void checkEquipmentStatus();
-    // 通知客户重置花型价格
+
+    /**
+     * 通知客户重置花型价格
+     * @param adminId
+     * @param deviceId
+     */
     void informClient(Long adminId, String deviceId);
 }

+ 12 - 1
src/main/java/com/szwl/service/TWechatService.java

@@ -24,7 +24,7 @@ public interface TWechatService extends IService<TWechat> {
      * @param companyType
      * @return
      */
-    void sendNoworkMessage(String openId, String clientId, String name, String ifForeign, String companyType);
+    void sendNetworkMessage(String openId, String clientId, String name, String ifForeign, String companyType);
 
     /**
      * 异常报警通知
@@ -44,4 +44,15 @@ public interface TWechatService extends IService<TWechat> {
      * @return
      */
      String getAccessToken(String companyType);
+
+    /**
+     * 发送设备上下线通知
+     * @param openId
+     * @param clientId
+     * @param networkTime
+     * @param companyType
+     * @param name
+     * @param eqeStatus
+     */
+    void sendOnOffMessage(String openId, String clientId, String networkTime, String companyType, String name, Integer eqeStatus);
 }

+ 1 - 1
src/main/java/com/szwl/service/impl/TEquipmentServiceImpl.java

@@ -298,7 +298,7 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
                         if(wechat != null) {
                             // 有绑定微信的话发公众号
                             String openId = wechat.getOpenId();
-                            wechatService.sendNoworkMessage(openId,equipment.getClientId(),name, ifForeign, companyType);
+                            wechatService.sendNetworkMessage(openId,equipment.getClientId(),name, ifForeign, companyType);
                             if (ifForeign.equals("1")) {
                                 // 国外再发邮件
                                 String messageReceiver = equipment.getMessageReceiver();

+ 51 - 7
src/main/java/com/szwl/service/impl/TWechatServiceImpl.java

@@ -58,7 +58,7 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
 
 
     @Override
-    public void sendNoworkMessage(String openId, String clientId, String name, String ifForeign, String companyType) {
+    public void sendNetworkMessage(String openId, String clientId, String name, String ifForeign, String companyType) {
         // 模板参数
         Map<String, WeChatTemplateMsg> sendMag = new HashMap();
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -81,7 +81,11 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
             sendMag.put("time5", new WeChatTemplateMsg(alarmTime));
             sendMag.put("thing6", new WeChatTemplateMsg("Power/Network loss."));
         }
-        sendWechatMessage(openId, sendMag, companyType);
+        if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
+            sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SZ_TEMPLATE_ID);
+        } else {
+            sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SC_TEMPLATE_ID);
+        }
     }
 
     @Override
@@ -101,7 +105,11 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
         sendMag.put("thing4", new WeChatTemplateMsg("高"));
         sendMag.put("time5", new WeChatTemplateMsg(alarmTime));
         sendMag.put("thing6", new WeChatTemplateMsg(alarmContent));
-        sendWechatMessage(openId, sendMag, companyType);
+        if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
+            sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SZ_TEMPLATE_ID);
+        } else {
+            sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SC_TEMPLATE_ID);
+        }
     }
 
     @Override
@@ -180,6 +188,44 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
         return accessToken;
     }
 
+    @Override
+    public void sendOnOffMessage(String openId, String clientId, String networkTime, String companyType, String name, Integer eqeStatus) {
+        // 模板参数
+        Map<String, WeChatTemplateMsg> sendMag = new HashMap();
+        // 转换时间为String类型
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Long time = Long.valueOf(networkTime);
+        String workTime = format.format(time);
+        clientId = clientId.substring(clientId.length() - 6);
+        // 模版参数
+        if(name.length() > 20) {
+            sendMag.put("thing2", new WeChatTemplateMsg(name.substring(0, 16) + "..."));
+        } else {
+            sendMag.put("thing2", new WeChatTemplateMsg(name));
+        }
+        if (eqeStatus == 1) {
+            sendMag.put("character_string9", new WeChatTemplateMsg(clientId));
+        } else {
+            sendMag.put("thing6", new WeChatTemplateMsg(clientId));
+        }
+        sendMag.put("time4", new WeChatTemplateMsg(workTime));
+        String templateId = "";
+        if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
+            if(eqeStatus == 1) {
+                templateId = ConfigConsts.SZ_ON_TEMPLATE_ID;
+            } else {
+                templateId = ConfigConsts.SZ_OFF_TEMPLATE_ID;
+            }
+        } else {
+            if(eqeStatus == 1) {
+                templateId = ConfigConsts.SC_ON_TEMPLATE_ID;
+            } else {
+                templateId = ConfigConsts.SC_OFF_TEMPLATE_ID;
+            }
+        }
+        sendWechatMessage(openId, sendMag, companyType, templateId);
+    }
+
     /**
      * 获取accessToken推送消息
      * @param openId
@@ -187,7 +233,7 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
      * @param companyType
      * @return
      */
-    public void sendWechatMessage(String openId, Map<String, WeChatTemplateMsg> sendMag, String companyType) {
+    public void sendWechatMessage(String openId, Map<String, WeChatTemplateMsg> sendMag, String companyType, String templateId) {
         String accessToken = "";
         try {
             if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
@@ -209,13 +255,11 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
         sendBody.put("touser", openId);
         sendBody.put("topcolor", "#FF0000");
         sendBody.put("data", sendMag);
+        sendBody.put("template_id", templateId);
         if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
-            sendBody.put("template_id", ConfigConsts.SZ_TEMPLATE_ID);
             sendBody.put("url", "http://szwlh.sunzee.com.cn/shenze/");
         } else {
-            sendBody.put("template_id", ConfigConsts.SC_TEMPLATE_ID);
             sendBody.put("url", "http://sevencloud.com.cn/sc/");
-
         }
         String sendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
         ResponseEntity<String> forEntity = restTemplate.postForEntity(sendUrl, sendBody, String.class);