Przeglądaj źródła

应急救援阿里云语音通知功能提交

lihao16 4 miesięcy temu
rodzic
commit
f680396a0c

+ 6 - 0
elevator-admin/src/main/java/com/inspur/idm/media/comm/CommConstant.java

@@ -252,6 +252,12 @@ public class CommConstant {
     public static final String PUB_CONFIG_KEY_ALIYUN_TRAP_SMS_TPLID = "aliyun-sms-trap-tplid";
     // 阿里云,短信签名
     public static final String PUB_CONFIG_KEY_ALIYUN_SMS_SIGN = "aliyun-sms-sign";
+
+    // 阿里云,短信签名
+    public static final String PUB_CONFIG_KEY_ALIYUN_TTS_TPLID = "aliyun-tts-tplid";
+    // 阿里云,短信签名
+    public static final String PUB_CONFIG_KEY_ALIYUN_TTS_PHONE = "aliyun-tts-phone";
+
     // wvp云端录像下载地址
     public static final String PUB_CONFIG_KEY_WVP_DOWNLOAD_PREFIX = "wvp-download-prefix";
 

+ 22 - 0
elevator-admin/src/main/java/com/inspur/idm/media/config/AliyunConfig.java

@@ -35,4 +35,26 @@ public class AliyunConfig {
         }
         return null;
     }
+
+    /**
+     +     * 阿里云语音客户端初始化
+     +     *
+     +     * @return
+     +     */
+    @Bean(name = "aliyunTtsClient")
+    public com.aliyun.dyvmsapi20170525.Client intAliyunTtsClient() {
+        String ak = pubConfigService.getPubConfigValue(CommConstant.PUB_CONFIG_KEY_ALIYUN_AK);
+        String sk = pubConfigService.getPubConfigValue(CommConstant.PUB_CONFIG_KEY_ALIYUN_SK);
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+                .setAccessKeyId(ak)
+                .setAccessKeySecret(sk);
+        // 访问的域名
+                config.endpoint = "dyvmsapi.aliyuncs.com";
+        try {
+            return new com.aliyun.dyvmsapi20170525.Client(config);
+        } catch (Exception e) {
+            log.error("初始化阿里云语音客户端失败", e);
+        }
+        return null;
+    }
 }

+ 5 - 2
elevator-admin/src/main/java/com/inspur/idm/media/controller/rescue/RescueAppController.java

@@ -396,9 +396,12 @@ public class RescueAppController {
             }
         }
 
-        //获取呼叫方式(救援配置) calltype
+        //获取呼叫方式(救援配置) calltype : 1 voip、2 voip&video
         detailVO.setCallType(rescueConfigDomain.getCallType(detailVO.getElevatorId()));
-
+        // 2024-09-13 新需求,增加类型3:语音通知&video,为了兼容移动端app旧版,这里把3强制改成2
+        if (StringUtils.equals(detailVO.getCallType(),"3")) {
+            detailVO.setCallType("2");
+        }
         return detailVO;
     }
 

+ 13 - 1
elevator-admin/src/main/java/com/inspur/idm/media/service/rescue/RescueInfoServiceImpl.java

@@ -26,6 +26,7 @@ import com.inspur.idm.media.service.rate.WorkRateDomain;
 import com.inspur.idm.media.service.rescueconfig.RescueConfigDomain;
 import com.inspur.idm.media.util.AppMsgUtil;
 import com.inspur.idm.media.util.MyUserUtil;
+import com.inspur.idm.media.util.PhoneUtil;
 import com.inspur.idm.media.util.SmsUtil;
 import com.inspur.idm.media.vo.device.EleDeviceCameraVO;
 import com.inspur.idm.media.vo.device.EleDeviceConfigVO;
@@ -108,7 +109,7 @@ public class RescueInfoServiceImpl implements RescueInfoService {
     private RescueConfigDomain rescueConfigDomain;
     @Lazy
     @Autowired
-    private AsyncTaskService asyncTaskService;
+    private PhoneUtil phoneUtil;
     @Autowired
     private SmsUtil smsUtil;
     @Autowired
@@ -808,6 +809,17 @@ public class RescueInfoServiceImpl implements RescueInfoService {
 //                log.info("语音通知禁用");
 //            }
 //        }
+        // 2024-09-13 新增救援呼叫方式3:语音通知
+        String callType = rescueConfigDomain.getCallType(elevatorId);
+        if (StringUtils.equals("3", callType) && StringUtils.equals(faultSource, CommConstant.RESCUE_SOURCE_SCREEN)) {
+            // 发送通知语音电话
+            String enablePhone = pubConfigService.getPubConfigValue(CommConstant.PUB_CONFIG_KEY_TRAP_PHONE);
+            if (StringUtils.equals(enablePhone, "1")) {
+                phoneUtil.sendPhone(elevatorInfoVO);
+            } else {
+                log.info("语音通知禁用");
+            }
+        }
     }
 
     @Override

+ 110 - 0
elevator-admin/src/main/java/com/inspur/idm/media/util/PhoneUtil.java

@@ -0,0 +1,110 @@
+package com.inspur.idm.media.util;
+
+import com.alibaba.fastjson.JSON;
+import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsRequest;
+import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsResponse;
+import com.inspur.idm.media.comm.CommConstant;
+import com.inspur.idm.media.service.EleEstateService;
+import com.inspur.idm.media.service.EleRescuePhoneService;
+import com.inspur.idm.media.vo.elevator.ElevatorInfoVO;
+import com.inspur.idm.media.vo.estate.EleEstateVO;
+import com.inspur.idm.media.vo.estate.EleRescuePhoneVO;
+import com.inspur.idm.sys.service.PubConfigService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 语音通知推送
+ */
+@Component
+@Slf4j
+public class PhoneUtil {
+
+    @Autowired
+    private EleEstateService eleEstateService;
+
+    @Autowired
+    private EleRescuePhoneService eleRescuePhoneService;
+
+    @Autowired
+    private PubConfigService pubConfigService;
+
+    @Autowired
+    private com.aliyun.dyvmsapi20170525.Client aliyunTtsClient;
+
+    /**
+     * 发送救援通知电话
+     *
+     * @param elevatorInfoVO
+     */
+    public void sendPhone(ElevatorInfoVO elevatorInfoVO) {
+        if (StringUtils.isNotBlank(elevatorInfoVO.getEstateId())) {
+            EleEstateVO eleEstateVO = eleEstateService.getEleEstateBasicById(elevatorInfoVO.getEstateId());
+            if (eleEstateVO != null) {
+                // 语音电话通知物业、维保、平台相关人员
+                EleRescuePhoneVO eleRescuePhoneVO = eleRescuePhoneService.getEleRescuePhoneByEstate(elevatorInfoVO.getEstateId());
+                if (eleRescuePhoneVO != null && StringUtils.isNotBlank(eleRescuePhoneVO.getEstatePhone())) {
+                    new Thread(() -> {
+                        execPhoneCall(eleRescuePhoneVO.getEstatePhone(), eleEstateVO.getEstateName(), elevatorInfoVO.getElevatorName());
+                    }).start();
+                }
+                if (eleRescuePhoneVO != null && StringUtils.isNotBlank(eleRescuePhoneVO.getMaintenPhone())) {
+                    new Thread(() -> {
+                        execPhoneCall(eleRescuePhoneVO.getMaintenPhone(), eleEstateVO.getEstateName(), elevatorInfoVO.getElevatorName());
+                    }).start();
+                }
+                if (eleRescuePhoneVO != null && StringUtils.isNotBlank(eleRescuePhoneVO.getPlatPhone())) {
+                    new Thread(() -> {
+                        execPhoneCall(eleRescuePhoneVO.getPlatPhone(), eleEstateVO.getEstateName(), elevatorInfoVO.getElevatorName());
+                    }).start();
+                }
+            } else {
+                log.info("elevatorId={}, estateId={}, 小区信息不存在", elevatorInfoVO.getElevatorId(), elevatorInfoVO.getEstateId());
+            }
+        } else {
+            log.info("elevatorId={}, 未配置小区信息", elevatorInfoVO.getElevatorId());
+        }
+
+    }
+
+    /**
+     * 调用aliyun语音通知服务
+     *
+     * @param phone
+     * @param estateName
+     * @param elevatorName
+     */
+    public void execPhoneCall(String phone, String estateName, String elevatorName) {
+        if (StringUtils.contains(phone, "-")) {
+            // 固话去掉-
+            phone = StringUtils.replace(phone, "-", "");
+        } else {
+            while (StringUtils.startsWith(phone, "0")) {
+                // 集团内线要求的手机号0,阿里云这里不需要
+                phone = StringUtils.substring(phone, 1);
+            }
+        }
+        String ttsTplid = pubConfigService.getPubConfigValue(CommConstant.PUB_CONFIG_KEY_ALIYUN_TTS_TPLID);
+        String ttsPhone = pubConfigService.getPubConfigValue(CommConstant.PUB_CONFIG_KEY_ALIYUN_TTS_PHONE);
+        if (StringUtils.isNoneBlank(ttsTplid, ttsPhone)) {
+            SingleCallByTtsRequest singleCallByTtsRequest = new com.aliyun.dyvmsapi20170525.models.SingleCallByTtsRequest();
+            singleCallByTtsRequest.setCalledShowNumber(ttsPhone);
+            singleCallByTtsRequest.setCalledNumber(phone);
+            singleCallByTtsRequest.setTtsCode(ttsTplid);
+            // 您好,${community}小区的${number}有人呼救,请尽快处理。
+            singleCallByTtsRequest.setTtsParam("{\"community\":\"" + estateName + "\",\"number\":\"" + elevatorName + "\"}");
+            com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+            try {
+                log.info("语音通知发送,request={}", JSON.toJSONString(singleCallByTtsRequest));
+                SingleCallByTtsResponse response = aliyunTtsClient.singleCallByTtsWithOptions(singleCallByTtsRequest, runtime);
+                log.info("语音通知发送,response={}", JSON.toJSONString(response));
+            } catch (Exception _error) {
+                log.error(_error.getMessage(), _error);
+            }
+        } else {
+            log.info("语音通知配置参数为空,无法发送通知");
+        }
+    }
+}

+ 31 - 0
elevator-data-collect/src/main/java/com/inspur/elevator_data_collect/utils/CachedThreadPoolUtil.java

@@ -0,0 +1,31 @@
+package com.inspur.elevator_data_collect.utils;
+
+import java.util.concurrent.*;
+
+/**
+ * 线程池工具类
+ * @author lihao16
+ */
+public class CachedThreadPoolUtil {
+
+    private static final ExecutorService executor = new ThreadPoolExecutor(
+            5,
+            10,
+            60L,
+            TimeUnit.SECONDS,
+            new LinkedBlockingQueue<>(100),
+            new ThreadPoolExecutor.DiscardPolicy()
+    );
+
+    public static void executeTask(Runnable task) {
+        executor.execute(task);
+    }
+
+    public static <T> Future<T> submitTask(Callable<T> task) {
+        return executor.submit(task);
+    }
+
+    public static void shutdown() {
+        executor.shutdown();
+    }
+}

+ 32 - 0
elevator-media-gb/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java

@@ -288,5 +288,37 @@ public class PlayController {
 		return result;
 	}
 
+	public static void main(String[] args) {
+
+		String start = "37117100301320000001";
+		int count = 120;
+
+		for (int i = 0; i < count; i++) {
+			System.out.println(incrementString(start));
+			start = incrementString(start); // 更新start为新的递增字符串
+		}
+	}
+
+	// 方法:递增字符串
+	private static String incrementString(String str) {
+		StringBuilder sb = new StringBuilder(str);
+		int index = sb.length() - 1;
+
+		while (index >= 0 && sb.charAt(index) == '9') {
+			sb.setCharAt(index, '0');
+			index--;
+		}
+
+		if (index >= 0) {
+			sb.setCharAt(index, (char) (sb.charAt(index) + 1));
+		} else {
+			// 如果全是9,比如 "9999",则需要特殊处理(比如前置 "1" 并补零)
+			// 但在这个特定场景下,由于我们知道字符串是递增且从非全9开始,这里不会执行
+			throw new IllegalStateException("Unexpected all-nines string encountered.");
+		}
+
+		return sb.toString();
+	}
+
 }