|
|
@@ -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("语音通知配置参数为空,无法发送通知");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|