Quellcode durchsuchen

云短信优化修改

donggaosheng vor 1 Jahr
Ursprung
Commit
0f28a0b69e

+ 1 - 1
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/RemoteAlarmLogService.java

@@ -10,6 +10,6 @@ import org.springframework.cloud.openfeign.FeignClient;
  * @description
  **/
 @FeignClient(contextId = "remoteAlarmLogService", value = ApplicationConstants.LABORATORY_SERVICE, fallbackFactory = RemoteSmsFallbackFactory.class)
-public class RemoteAlarmLogService {
+public interface RemoteAlarmLogService {
 
 }

+ 21 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/fallback/RemoteSmsFallbackFactory.java

@@ -1,6 +1,7 @@
 package com.zd.laboratory.api.feign.fallback;
 
 import com.zd.laboratory.api.feign.RemoteSmsService;
+import com.zd.laboratory.api.vo.TextMessageVo;
 import com.zd.model.domain.ResultData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,6 +26,26 @@ public class RemoteSmsFallbackFactory implements FallbackFactory<RemoteSmsServic
             public ResultData getVoiceReport() {
                 return ResultData.fail("语音回执调用失败 !");
             }
+
+            @Override
+            public ResultData sendTemplateMessage(TextMessageVo textMessageBo) {
+                return ResultData.fail("模版短信发送失败!");
+            }
+
+            @Override
+            public ResultData sendVoiceMessage(TextMessageVo textMessageBo) {
+                return ResultData.fail("语音短信发送失败!");
+            }
+
+            @Override
+            public ResultData send(TextMessageVo textMessageBo) {
+                return ResultData.fail("语音和短信发送失败!");
+            }
+
+            @Override
+            public ResultData getMessageBalance() {
+                return ResultData.fail("获取短信余额失败!");
+            }
         };
     }
 }

+ 1 - 1
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/impl/AlarmRecordServiceImpl.java

@@ -389,7 +389,7 @@ public class AlarmRecordServiceImpl implements IAlarmRecordService {
         }
         String airName = storageRVo.getAirName();
         //电话报警
-        AlarmEntrty alarmEntrty = new AlarmEntrty();
+        // AlarmEntrty alarmEntrty = new AlarmEntrty();
 //        alarmEntrty.setRoute(Routes.NoticePush);
 //        alarmEntrty.setType(SendTypes.Call + "");
 //        alarmEntrty.setTo(phones.toArray(new String[]{}));

+ 3 - 0
zd-modules/zd-base/src/main/java/com/zd/base/job/task/MessageTask.java

@@ -13,6 +13,7 @@ import org.apache.http.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
@@ -36,7 +37,9 @@ public class MessageTask {
     @Autowired
     private RemoteAlarmService remoteAlarmService;
 
+    @Scheduled(cron = "0/10 * * * * ?")
     public void monitorMessageReceipt() {
+        log.info("*****************电话短信回执执行*****************");
         Collection<String> messageKeys = redisService.keys(SmsMessageConstants.ZT_MESSAGE_KEY + "*");
         if (messageKeys.size() > 0) {
             List<String> messageIds = new ArrayList<>();

+ 2 - 21
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/config/MessagePropertiesConfig.java

@@ -3,6 +3,7 @@ package com.zd.laboratory.config;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
 
 /**
  * @Author donggaosheng
@@ -11,7 +12,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
  **/
 @RefreshScope
 @ConfigurationProperties(prefix = "zhutong.sms")
-@EnableConfigurationProperties(MessagePropertiesConfig.class)
+@Component
 public class MessagePropertiesConfig {
     //用户名
     private String userName;
@@ -19,10 +20,6 @@ public class MessagePropertiesConfig {
     private String passWord;
     //签名
     private String signature;
-    //第三方模版id
-    private String agentId;
-    //模版内容
-    private String tempContent;
 
     public String getUserName() {
         return userName;
@@ -47,20 +44,4 @@ public class MessagePropertiesConfig {
     public void setSignature(String signature) {
         this.signature = signature;
     }
-
-    public String getAgentId() {
-        return agentId;
-    }
-
-    public void setAgentId(String agentId) {
-        this.agentId = agentId;
-    }
-
-    public String getTempContent() {
-        return tempContent;
-    }
-
-    public void setTempContent(String tempContent) {
-        this.tempContent = tempContent;
-    }
 }

+ 3 - 2
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/event/RedisExpiredPhotographListener.java

@@ -244,8 +244,9 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
                                         textMessageVo.setTempContent("【忠江科技】{sub_name} -监测到实验人员违规未穿戴{protective_clothing},请尽快确认。");
                                         remoteSmsService.sendTemplateMessage(textMessageVo);
                                         log.info("未穿戴实验服发送短信打电话消息推送完成!");
+                                    }else{
+                                        log.info("接收短信号码为空,请仔细检查!userPhoneInfoList:{}",userPhoneInfoList);
                                     }
-                                    log.info("接收短信号码为空,请仔细检查!userPhoneInfoList:{}",userPhoneInfoList);
                                 }
                             }
                             long l2 = noticeCount % warningConfig.getVoiceNotcie();
@@ -294,4 +295,4 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
             }
         }
     }
-}
+}

+ 6 - 18
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabMessageServiceImpl.java

@@ -2,6 +2,7 @@ package com.zd.laboratory.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.zd.common.core.redis.RedisService;
+import com.zd.laboratory.api.constant.SmsMessageConstants;
 import com.zd.laboratory.api.vo.TextMessageVo;
 import com.zd.laboratory.config.MessagePropertiesConfig;
 import com.zd.laboratory.service.ILabMessageService;
@@ -12,8 +13,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-
 /**
  * @Author donggaosheng
  * @Date 2024-02-21
@@ -32,40 +31,29 @@ public class LabMessageServiceImpl implements ILabMessageService {
 
     @Override
     public JSONObject sendMessageTemp(TextMessageVo textMessageBo) {
-        JSONObject jsonObject= TextMessageUtils.sendSimpleMessageTemp(messagePropertiesConfig.getUserName(),messagePropertiesConfig.getPassWord(),messagePropertiesConfig.getSignature(),messagePropertiesConfig.getAgentId(),messagePropertiesConfig.getTempContent(),textMessageBo.getPhoneList(),textMessageBo.getVariableList());
-        boolean state = Boolean.FALSE;
+        JSONObject jsonObject= TextMessageUtils.sendSimpleMessageTemp(messagePropertiesConfig.getUserName(),messagePropertiesConfig.getPassWord(),messagePropertiesConfig.getSignature(),textMessageBo.getTempId(),textMessageBo.getTempContent(),textMessageBo.getPhoneList(),textMessageBo.getVariableList());
         if(jsonObject.getIntValue("code")== HttpStatus.SC_OK){
-            state = Boolean.TRUE;
             JSONObject redisJson=new JSONObject();
             redisJson.put("msgId",jsonObject.getString("msgId"));
-//            redisJson.put("title",iotAlarmTemplate.getTemplateName());
-//            redisJson.put("receiver",iotAlarmTemplate.getReceiver());
-            String tempContent=TextMessageUtils.getSimpleTemplateContent(messagePropertiesConfig.getUserName(),messagePropertiesConfig.getPassWord(),messagePropertiesConfig.getTempContent(),textMessageBo.getVariableList());
+            redisJson.put("receiver",textMessageBo.getPhoneList());
+            String tempContent=TextMessageUtils.getSimpleTemplateContent(messagePropertiesConfig.getUserName(),messagePropertiesConfig.getPassWord(),textMessageBo.getTempContent(),textMessageBo.getVariableList());
             redisJson.put("content",tempContent);
-           // redisService.setCacheObject(IotConstant.ZT_MESSAGE_KEY+jsonObject.getString("msgId"),redisJson);
+            redisService.setCacheObject(SmsMessageConstants.ZT_MESSAGE_KEY+jsonObject.getString("msgId"),redisJson);
         }
-        //添加消息日志
-        String receiver = textMessageBo.getPhoneList().toString();
-        //iotAlarmLogService.addAlarmMessageLog(AlarmTypeEnum.Type.SMS, receiver, null, iotAlarmTemplate.getContent(), null, state, !state ? jsonObject.toJSONString() : null);
         return jsonObject;
     }
 
     @Override
     public JSONObject sendMessageVoice(TextMessageVo textMessageBo) {
         JSONObject jsonObject=TextMessageUtils.sendMessageVoice(messagePropertiesConfig.getUserName(),messagePropertiesConfig.getPassWord(),textMessageBo.getTempContent(),textMessageBo.getPhoneList());
-        boolean state = Boolean.FALSE;
         if(jsonObject.getIntValue("code")== HttpStatus.SC_OK){
-            state = Boolean.TRUE;
             String msgId=jsonObject.getJSONObject("data").getString("msgId");
             JSONObject object=new JSONObject();
             object.put("receiver",textMessageBo.getPhoneList());
             object.put("content",textMessageBo.getTempContent());
             object.put("msgId",msgId);
-            //redisService.setCacheObject(IotConstant.ZT_VOICE_KEY+msgId,object);
+            redisService.setCacheObject(SmsMessageConstants.ZT_VOICE_KEY+msgId,object);
         }
-        //添加消息日志
-        // String receiver = textMessageBo.getPhoneList().toString();
-        //iotAlarmLogService.addAlarmMessageLog(AlarmTypeEnum.Type.PHONE, receiver, null, textMessageBo.getTempContent(), null, state, !state ? jsonObject.toJSONString() : null);
         return jsonObject;
     }