Browse Source

修改问题

lilt085163@126.com 3 năm trước cách đây
mục cha
commit
8393c7638e

+ 8 - 1
src/main/java/com/care/bms/service/BmsEventOrderService.java

@@ -679,7 +679,14 @@ public class BmsEventOrderService {
             log.setOrderId(order.getId());
             log.setLogType(LogTypeEnum.SMS.getValue());
             log.setLogObjectId(order.getMemberId());
-            log.setLogObjectName(careMemberInfo.getNickname());
+            String name = careMemberInfo.getPhone();
+            if (StrUtil.isNotEmpty(careMemberInfo.getName())){
+                name = careMemberInfo.getName();
+            }else if (StrUtil.isNotEmpty(careMemberInfo.getNickname())){
+                name = careMemberInfo.getNickname();
+            }
+
+            log.setLogObjectName(name);
             log.setLogResult(content+"短信通知");
             log.setOpUserRole(UserRoleEnum.SEAT.getValue());
             log.setCreateTime(DateUtil.date());

+ 5 - 2
src/main/java/com/care/common/service/VoiceSendService.java

@@ -1,6 +1,9 @@
 package com.care.common.service;
 
 
+import com.care.common.vo.MySendStatus;
+import com.tencentcloudapi.vms.v20200902.models.SendStatus;
+
 /**
  * 编码类型表(SysDimType)表服务接口
  *
@@ -15,12 +18,12 @@ public interface VoiceSendService {
      * @param params
      * @return
      */
-    boolean sendVoiceHappen(String phone, String[] params);
+    MySendStatus sendVoiceHappen(String sessionContext, String phone, String[] params);
     /**
      * 事件取消给紧急联系人等发送语音提示
      * @param phone
      * @param params
      * @return
      */
-    boolean sendVoiceCancel(String phone, String[] params);
+    MySendStatus sendVoiceCancel(String sessionContext,String phone, String[] params);
 }

+ 23 - 18
src/main/java/com/care/common/service/impl/CareEventOrderServiceImpl.java

@@ -14,6 +14,7 @@ import com.care.common.entity.*;
 import com.care.common.enums.*;
 import com.care.common.mapper.CareEventOrderMapper;
 import com.care.common.service.*;
+import com.care.common.vo.MySendStatus;
 import com.care.common.vo.order.EventStaVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.compress.utils.Lists;
@@ -292,20 +293,21 @@ public class CareEventOrderServiceImpl extends ServiceImpl<CareEventOrderMapper,
                 CareHouse house = this.careHouseService.getById(order.getHouseId());
                 if (CollUtil.isNotEmpty(contacts)){
                     contacts.forEach(item ->{
-                        boolean voiceResult = false;
+                        MySendStatus sendStatus = null;
                         String[] params = null;
+                        log.info(" 准备发送语音消息 : 工单ID:{}, 联系人:{}",order.getId(),item.getContactPhone());
                         if (OrderTypeEnum.JIU_ZHI.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"久滞",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceHappen(item.getContactPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceHappen(order.getId()+"",item.getContactPhone(),params);
                         } else if(OrderTypeEnum.DIE_DAO.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"跌倒",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceHappen(item.getContactPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceHappen(order.getId()+"",item.getContactPhone(),params);
                         }else if(OrderTypeEnum.ZHUI_CHUANG.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"坠床",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceHappen(item.getContactPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceHappen(order.getId()+"",item.getContactPhone(),params);
                         }
 
-                        if (voiceResult) {
+                        if (sendStatus != null && sendStatus.isSuccess()) {
                             CareEventOrderHandleHis his2 = new CareEventOrderHandleHis();
                             his2.setOrgId(item.getOrgId());
                             his2.setStationId(item.getStationId());
@@ -318,6 +320,7 @@ public class CareEventOrderServiceImpl extends ServiceImpl<CareEventOrderMapper,
                             his2.setCreateTime(DateUtil.date());
                             his2.setRelationTypeDesc(item.getRelationTypeDesc());
                             this.careEventOrderHandleHisService.save(his2);
+                            log.info(" 事件语音通知成功 : 工单ID:{}, 联系人:{}",order.getId(),item);
                         }else{
                             log.error(" 事件语音通知失败 : 工单ID:{}, 联系人:{}",order.getId(),item);
                         }
@@ -326,16 +329,17 @@ public class CareEventOrderServiceImpl extends ServiceImpl<CareEventOrderMapper,
                 //给管家发语音通知
                 if (CollUtil.isNotEmpty(chambList)){
                     chambList.forEach(item ->{
-                        boolean voiceResult = false;
+                        MySendStatus sendStatus = null;
                         String[] params = null;
+                        log.info(" 准备发送语音消息 : 工单ID:{}, 联系人:{}",order.getId(),item.getPhone());
                         if (OrderTypeEnum.JIU_ZHI.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"久滞",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceHappen(item.getPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceHappen(order.getId()+"",item.getPhone(),params);
                         }else if(OrderTypeEnum.DIE_DAO.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"跌倒",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceHappen(item.getPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceHappen(order.getId()+"",item.getPhone(),params);
                         }
-                        if (voiceResult){
+                        if (sendStatus != null && sendStatus.isSuccess()){
                             CareEventOrderHandleHis his2 = new CareEventOrderHandleHis();
                             his2.setOrgId(item.getOrgId());
                             his2.setStationId(item.getStationId());
@@ -348,8 +352,9 @@ public class CareEventOrderServiceImpl extends ServiceImpl<CareEventOrderMapper,
                             his2.setCreateTime(DateUtil.date());
                             his2.setRelationTypeDesc("管家");
                             this.careEventOrderHandleHisService.save(his2);
+                            log.info(" 事件语音通知成功 : 工单ID:{}, 管家:{}",order.getId(),item);
                         }else{
-                            log.error(" 事件语音短信通知失败 : 工单ID:{}, 联系人:{}",order.getId(),item);
+                            log.error(" 事件语音短信通知失败 : 工单ID:{}, 管家:{}",order.getId(),item);
                         }
                     });
                 }
@@ -619,16 +624,16 @@ public class CareEventOrderServiceImpl extends ServiceImpl<CareEventOrderMapper,
                 CareHouse house = this.careHouseService.getById(order.getHouseId());
                 if (CollUtil.isNotEmpty(contacts)){
                     contacts.forEach(item ->{
-                        boolean voiceResult = false;
+                        MySendStatus sendStatus = null;
                         String[] params = null;
                         if (OrderTypeEnum.JIU_ZHI.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分ss秒"),"久滞",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceCancel(item.getContactPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceCancel(order.getId()+"",item.getContactPhone(),params);
                         }else if(OrderTypeEnum.DIE_DAO.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分ss秒"),"跌倒",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceCancel(item.getContactPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceCancel(order.getId()+"",item.getContactPhone(),params);
                         }
-                        if (voiceResult){
+                        if (sendStatus != null && sendStatus.getCallId() != null){
                             CareEventOrderHandleHis his2 = new CareEventOrderHandleHis();
                             his2.setOrgId(item.getOrgId());
                             his2.setStationId(item.getStationId());
@@ -647,16 +652,16 @@ public class CareEventOrderServiceImpl extends ServiceImpl<CareEventOrderMapper,
                 //给管家发短信
                 if (CollUtil.isNotEmpty(chambList)){
                     chambList.forEach(item ->{
-                        boolean voiceResult = false;
+                        MySendStatus sendStatus = null;
                         String[] params = null;
                         if (OrderTypeEnum.JIU_ZHI.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"久滞",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceCancel(item.getPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceCancel(order.getId()+"",item.getPhone(),params);
                         }else if(OrderTypeEnum.DIE_DAO.getValue().equals(order.getOrderType())){
                             params = new String[]{DateUtil.format(order.getCreateTime(),"MM月dd日HH时mm分"),"跌倒",house.getName()};
-                            voiceResult = voiceSendService.sendVoiceCancel(item.getPhone(),params);
+                            sendStatus = voiceSendService.sendVoiceCancel(order.getId()+"",item.getPhone(),params);
                         }
-                        if (voiceResult){
+                        if (sendStatus != null && sendStatus.getCallId() != null){
                             CareEventOrderHandleHis his2 = new CareEventOrderHandleHis();
                             his2.setOrgId(item.getOrgId());
                             his2.setStationId(item.getStationId());

+ 15 - 14
src/main/java/com/care/common/service/impl/VoiceSendServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
 import com.care.common.enums.SmsTemplateTypeEnum;
 import com.care.common.service.VoiceSendService;
 import com.care.common.util.VoiceUtil;
+import com.care.common.vo.MySendStatus;
 import com.tencentcloudapi.vms.v20200902.models.SendStatus;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -33,11 +34,12 @@ public class VoiceSendServiceImpl implements VoiceSendService {
     private String templateidCancel;
 
     @Override
-    public boolean sendVoiceHappen(String phone, String[] params) {
+    public MySendStatus sendVoiceHappen(String sessionContext,String phone, String[] params) {
         String[] _p = params;
+        MySendStatus mySendStatus = new MySendStatus();
         String _noticeTemplateId =  templateidHappen;
         if (StrUtil.isNotEmpty(_noticeTemplateId)){
-            SendStatus sendStatus =  VoiceUtil.sendTtsVoice(noticeEndpoint,
+            SendStatus sendStatus =  VoiceUtil.sendTtsVoice(sessionContext,noticeEndpoint,
                     noticeRegion,
                     noticeSecretId,
                     noticeecretKey,
@@ -45,20 +47,20 @@ public class VoiceSendServiceImpl implements VoiceSendService {
                     _noticeTemplateId,
                     phone,_p);
             if (sendStatus != null && sendStatus.getCallId() != null){
-                return true;
-            }else{
-                return  false;
+                mySendStatus.setCallId(sendStatus.getCallId());
+                mySendStatus.setSessionContext(sendStatus.getSessionContext());
+                mySendStatus.setSuccess(true);
             }
-        }else {
-            return  false;
         }
+        return  mySendStatus;
     }
     @Override
-    public boolean sendVoiceCancel(String phone, String[] params) {
+    public MySendStatus sendVoiceCancel(String sessionContext, String phone, String[] params) {
         String[] _p = params;
+        MySendStatus mySendStatus = new MySendStatus();
         String _noticeTemplateId =  templateidCancel;
         if (StrUtil.isNotEmpty(_noticeTemplateId)){
-            SendStatus sendStatus =  VoiceUtil.sendTtsVoice(noticeEndpoint,
+            SendStatus sendStatus =  VoiceUtil.sendTtsVoice(sessionContext,noticeEndpoint,
                     noticeRegion,
                     noticeSecretId,
                     noticeecretKey,
@@ -66,12 +68,11 @@ public class VoiceSendServiceImpl implements VoiceSendService {
                     _noticeTemplateId,
                     phone,_p);
             if (sendStatus != null && sendStatus.getCallId() != null){
-                return true;
-            }else{
-                return  false;
+                mySendStatus.setCallId(sendStatus.getCallId());
+                mySendStatus.setSessionContext(sendStatus.getSessionContext());
+                mySendStatus.setSuccess(true);
             }
-        }else {
-            return  false;
         }
+        return  mySendStatus;
     }
 }

+ 6 - 6
src/main/java/com/care/common/util/VoiceUtil.java

@@ -14,15 +14,16 @@ import com.tencentcloudapi.vms.v20200902.VmsClient;
 import com.tencentcloudapi.vms.v20200902.models.SendStatus;
 import com.tencentcloudapi.vms.v20200902.models.SendTtsVoiceRequest;
 import com.tencentcloudapi.vms.v20200902.models.SendTtsVoiceResponse;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * Tencent Cloud Vms SendTtsVoice
  * https://cloud.tencent.com/document/product/1128/51558
  *
  */
-
+@Slf4j
 public class VoiceUtil {
-    public static SendStatus sendTtsVoice(String endpoint,
+    public static SendStatus sendTtsVoice(String sessionContext,String endpoint,
                                           String region,
                                           String secretId,
                                           String secretKey,
@@ -100,7 +101,6 @@ public class VoiceUtil {
             req.setPlayTimes(playTimes);
 
             // 用户的 session 内容,腾讯 server 回包中会原样返回
-            String sessionContext = "xxxx";
             req.setSessionContext(sessionContext);
 
             /* 通过 client 对象调用 SendTtsVoice 方法发起请求。注意请求方法名与请求对象是对应的
@@ -108,13 +108,13 @@ public class VoiceUtil {
             SendTtsVoiceResponse res = client.SendTtsVoice(req);
 
             // 输出json格式的字符串回包
-            System.out.println(SendTtsVoiceResponse.toJsonString(res));
+            log.info("语音消息发送:{},{}",sessionContext,res);
 
             // 也可以取出单个值,您可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
             System.out.println(res.getRequestId());
             return res.getSendStatus();
         } catch (TencentCloudSDKException e) {
-            e.printStackTrace();
+            log.error("语音发送失败:号码:"+phoneNumber+" ,session:"+sessionContext,e);
             return null;
         }
     }
@@ -127,7 +127,7 @@ public class VoiceUtil {
         String templateId="1182623";
         String phoneNumber="18010375763";
         String[] templateParam = {"yyyy年MM月dd日HH时mm分ss秒","久滞","双华时代"};
-        SendStatus sendStatus = VoiceUtil.sendTtsVoice( endpoint,
+        SendStatus sendStatus = VoiceUtil.sendTtsVoice("", endpoint,
                  region,
                  secretId,
                  secretKey,

+ 16 - 0
src/main/java/com/care/common/vo/MySendStatus.java

@@ -0,0 +1,16 @@
+package com.care.common.vo;
+
+import lombok.Data;
+
+@Data
+public class MySendStatus {
+    // 请求ID
+    private String callId;
+    // 本地传入的参数
+    private String SessionContext;
+    // 是否成功
+    boolean isSuccess = false;
+    public MySendStatus(){
+        this.isSuccess = false;
+    }
+}

+ 1 - 1
src/main/java/com/care/mqtt/schedule/MqttHeartbeatSchedule.java

@@ -27,7 +27,7 @@ public class MqttHeartbeatSchedule {
      * 5 分钟调用一次
      */
     @Async
-    @Scheduled(cron = "0 0/5 * * * ?")
+    @Scheduled(cron = "0 0/3 * * * ?")
     public void rotationDev() {
         try {
             mqttHearbeatService.rotationDev();