Browse Source

add 短信通知

459242451@qq.com 2 years ago
parent
commit
0dbd475d23

+ 8 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/SMSUtil.java

@@ -16,10 +16,14 @@ public class SMSUtil {
      * @param phone
      */
     public void sendMessage(String content, String phone) {
-        MessageService messageService = new MessageService();
-        MessageServiceSoap messageServiceSoap = messageService.getMessageServiceSoap();
-        int result = messageServiceSoap.sendMessage(phone, content);
-        log.info("手机号:{},内容:{},短信返回码:{}", phone, content, result);
+        try {
+            MessageService messageService = new MessageService();
+            MessageServiceSoap messageServiceSoap = messageService.getMessageServiceSoap();
+            int result = messageServiceSoap.sendMessage(phone, content);
+            log.info("手机号:{},内容:{},短信返回码:{}", phone, content, result);
+        } catch (Exception e) {
+            log.error("发送短信异常:{}", e.getMessage());
+        }
     }
 
 }

+ 19 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/job/CanalScheduling.java

@@ -30,6 +30,7 @@ import com.ruoyi.system.domain.vo.ShipEepReportRecInfo;
 import com.ruoyi.system.service.IAisInfoService;
 import com.ruoyi.system.service.IIllegalShipDataService;
 import com.ruoyi.system.service.ISysConfigService;
+import com.ruoyi.web.controller.tool.SMSUtil;
 import com.ruoyi.web.core.config.CanalConfig;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -478,6 +479,24 @@ public class CanalScheduling implements Runnable, ApplicationContextAware {
             }
             try {
                 illegalShipDataService.insertIllegalShipData(illegalShipData);
+                // 发送短信给海事人员(常熟海事局)
+                if ((StrUtil.equals(illegalShipData.getOrgName(), "常熟海事局") || StrUtil.equals(illegalShipData.getDestination(), "常熟")) && illegalShipData.getIllegalStatus() != 1) {
+                    String csPhone = configService.selectConfigByKey("sms.cs");
+                    String detail = "";
+                    if ("guangpu".equals(illegalShipData.getIllegalType())) {
+                        detail = "光谱监测到硫含量:" + illegalShipData.getSo2Percent();
+                    } else if ("xiutan".equals(illegalShipData.getIllegalType())) {
+                        detail = "嗅探监测到硫含量:" + illegalShipData.getSo2Percent();
+                    } else if ("heiyan".equals(illegalShipData.getIllegalType())) {
+                        detail = "黑烟监测到黑度:" + illegalShipData.getRcgSoot();
+                    }
+                    String content = StrUtil.concat(true, "尾气系统监测到嫌疑数据。", "MMSI:", illegalShipData.getMmsi(), ",",
+                            "船名:", illegalShipData.getShipName(), "。", detail);
+                    SMSUtil smsUtil = new SMSUtil();
+                    for (String phone : csPhone.split(",")) {
+                        smsUtil.sendMessage(content, phone);
+                    }
+                }
             } catch (Exception ignored) {
                 ignored.printStackTrace();
             }