Преглед изворни кода

:feat: 通知客户花型数量已更新
:memo: 5楼生产定位录入修改改为蒋文偕

Ritchie пре 1 година
родитељ
комит
850b9e5663

+ 2 - 0
src/main/java/com/szwl/controller/TEquipmentController.java

@@ -583,6 +583,8 @@ public class TEquipmentController {
             if (StringUtils.isNotEmpty(oldEquipment.getFlowers()) && !oldEquipment.getFlowers().equals(equipment.getFlowers())) {
                 //发信息
                 tEquipmentService.sentMessage(oldEquipment.getClientId(), PushUtils.buildJson("flowers", equipment.getFlowers()).toString());
+                // 通知客户
+                tEquipmentService.informClient(oldEquipment.getAdminId(), oldEquipment.getClientId());
             }
             oldEquipment.setFlowers(equipment.getFlowers());
         }

+ 2 - 2
src/main/java/com/szwl/controller/TLocationCheckController.java

@@ -124,7 +124,7 @@ public class TLocationCheckController {
 //        if (!("shouhoumi".equals(modUsername)) && !("admin".equals(modUsername)) && !("chenfanghao".equals(modUsername)) && !("ethan".equals(modUsername))) {
 //            return R.fail("该账号无权修改");
 //        }
-        Set<String> allowedUsernames = new HashSet<>(Arrays.asList("shouhoumi", "admin", "chenfanghao", "ethan"));
+        Set<String> allowedUsernames = new HashSet<>(Arrays.asList("shouhoumi", "admin", "jiang123", "ethan"));
         if (!allowedUsernames.contains(modUsername)) {
             return R.fail("该账号无权修改");
         }
@@ -186,7 +186,7 @@ public class TLocationCheckController {
             return R.fail("此设备信息已录入");
         }
 
-        Set<String> allowedUsers = new HashSet<>(Arrays.asList("admin", "chenfanghao", "huangkantong", "shouhou121", "shouhou369", "shouhou397", "shouhoumi", "zhl123", "ethan"));
+        Set<String> allowedUsers = new HashSet<>(Arrays.asList("admin", "jiang123", "shouhou121", "shouhou369", "shouhou397", "shouhoumi", "zhl123", "ethan"));
         if (!allowedUsers.contains(username)) {
             return R.fail("该账号无权操作");
         }

+ 2 - 0
src/main/java/com/szwl/service/TEquipmentService.java

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

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

@@ -9,7 +9,9 @@ import com.szwl.model.entity.TEquipment;
 import com.szwl.mapper.TEquipmentMapper;
 import com.szwl.model.entity.TWechat;
 import com.szwl.model.query.StatisticsParam;
+import com.szwl.model.utils.MailUtil;
 import com.szwl.model.utils.PushUtils;
+import com.szwl.model.utils.YunPianSms;
 import com.szwl.service.TAdminService;
 import com.szwl.service.TEquipmentService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -22,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.IOException;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
@@ -56,6 +59,8 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
     @Resource
     TWechatService wechatService;
 
+    private static final String appid = "07784f5fedb508046c841b391005b7de";
+
     @Override
     public String sentMessage(String clientId, String json) {
         LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
@@ -328,6 +333,63 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
         }
     }
 
+    @Override
+    public void informClient(Long adminId, String deviceId) {
+        LambdaQueryWrapper<TAdmin> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(TAdmin::getId, adminId);
+        TAdmin admin = adminService.getOne(queryWrapper);
+        String ifForeign = admin.getIfForeign();
+        String phone = admin.getPhone();
+        String email = admin.getEmail();
+        switch (ifForeign) {
+            case "0": { // 国内发短信
+                if (StringUtils.isEmpty(phone)) {
+                    return;
+                }
+                try {
+                    String sms = YunPianSms.sendSms(appid, getInformText(deviceId), phone);
+                    System.out.println("短信已发送:" + sms);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+                break;
+            }
+            case "1": { // 海外发邮箱
+                if (StringUtils.isEmpty(email)) {
+                    return;
+                }
+                String subject = "Reset the price of the flowers"; // 邮件标题
+                String content = getInformContent(deviceId); // 邮件正文
+                new MailUtil().send(email, subject, content);
+                break;
+            }
+            default:
+                System.out.println("无效的ifForeign");
+                break;
+        }
+    }
+
+    private String getInformContent(String deviceId) {
+        String content = "";
+        String str = "Dear customer:<br>" +
+                "<br>" +
+                "Your machine number is <" + deviceId + "> cotton candy machine, the number of flowers has been pushed, please reset the price of the flowers!" +
+                "<br>" +
+                "<br>" +
+                "Best Regards.<br>" +
+                "Sunzee Intelligent";
+        content = String.format(str);
+        return content;
+    }
+
+    private String getInformText(String deviceId) {
+        String sms = "";
+        if(StringUtils.isNotEmpty(deviceId)){
+            sms = "【申泽智能】您好,您名下设备编号为" + deviceId + "的机器,花型数量已推送,请重新设置价格!";
+        }
+        return sms;
+    }
+
     /**
      * 根据经度获取时区
      * @param currentLon

+ 2 - 2
src/main/java/com/szwl/service/impl/TLocationCheckServiceImpl.java

@@ -98,11 +98,11 @@ public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper,
     public void schSendMsg(String locErrorEq) throws IOException {
         String phone = "18620242721";
 //        String phone1 = "13631231970"; // 基哥
-//        String phone2 = "15018460394"; // 龙
+        String phone2 = "15018460394"; // 龙
         String messages = "【申泽部门】设备编号:" + locErrorEq + ",所在ip与设定位置不符,请及时查看。";
         YunPianSms.sendSms(appid, messages, phone);
 //        YunPianSms.sendSms(appid, messages, phone1);
-//        YunPianSms.sendSms(appid, messages, phone2);
+        YunPianSms.sendSms(appid, messages, phone2);
     }
 
 

+ 72 - 0
src/test/java/com/szwl/service/impl/TEquipmentServiceImplTest.java

@@ -0,0 +1,72 @@
+package com.szwl.service.impl;
+
+import com.szwl.model.utils.MailUtil;
+import com.szwl.model.utils.YunPianSms;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+
+import java.io.IOException;
+
+
+class TEquipmentServiceImplTest {
+
+    public static void main(String[] args) {
+        String ifForeign = "0";
+        String phone = "18620242721";
+        String email = "446678759@qq.com";
+        String appid = "07784f5fedb508046c841b391005b7de";
+        String deviceId = "c12345678";
+
+        doTest( ifForeign,  phone,  email,  appid,  deviceId);
+    }
+    public static void doTest(String ifForeign, String phone, String email, String appid, String deviceId) {
+        switch (ifForeign) {
+            case "0": { // 国内发短信
+                if (StringUtils.isEmpty(phone)) {
+                    return;
+                }
+                try {
+                    String sms = YunPianSms.sendSms(appid, getInformText(deviceId), phone);
+                    System.out.println("短信已发送:" + sms);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+                break;
+            }
+            case "1": { // 海外发邮箱
+                if (StringUtils.isEmpty(email)) {
+                    return;
+                }
+                String subject = "Reset the price of the flowers"; // 邮件标题
+                String content = getInformContent(deviceId); // 邮件正文
+                new MailUtil().send(email, subject, content);
+                break;
+            }
+            default:
+                System.out.println("无效的ifForeign");
+                break;
+        }
+    }
+
+    private static String getInformContent(String deviceId) {
+        String content = "";
+        String str = "Dear customer:<br>" +
+                "<br>" +
+                "Your machine number is <" + deviceId + "> cotton candy machine, the number of flowers has been pushed, please reset the price of the flowers!" +
+                "<br>" +
+                "<br>" +
+                "Best Regards.<br>" +
+                "Sunzee Intelligent";
+        content = String.format(str);
+        return content;
+    }
+
+    private static String getInformText(String deviceId) {
+        String sms = "";
+        if(StringUtils.isNotEmpty(deviceId)){
+            sms = "【申泽智能】您好,您名下设备编号为" + deviceId + "的机器,花型数量已推送,请重新设置价格!";
+        }
+        return sms;
+    }
+
+}