suntianwu 3 роки тому
батько
коміт
474a7ab243

+ 59 - 0
src/main/java/com/care/bms/controller/VoiceCallbackController.java

@@ -0,0 +1,59 @@
+package com.care.bms.controller;
+
+import com.care.bms.params.VoiceCallbackParams;
+import com.care.bms.service.BmsEventOrderService;
+import com.care.common.cache.RedisKeyConstant;
+import com.care.common.cache.RedisUtil;
+import com.care.common.enums.ContactorStatusEnum;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Author: lilt
+ * @Date: 2021/5/26
+ * @Desc:
+ */
+@RestController
+@Api(value = "VoiceCallbackController", tags = { "语音通知回调接口" })
+@Slf4j
+@RequestMapping("/bms")
+public class VoiceCallbackController {
+    @Resource
+    private RedisUtil redisUtil;
+    @Autowired
+    private BmsEventOrderService bmsEventOrderService;
+
+    @PostMapping("/voice/callback")
+    @ApiOperation(tags = {"语音通知回调接口"},value = "语音通知回调接口")
+    public Map<String,Object> callback(@RequestBody VoiceCallbackParams voiceCallbackParams) {
+        String callid = voiceCallbackParams.getCallid();
+        String orderId = (String) redisUtil.hget(RedisKeyConstant.VOICE_CALLBACK_INFO, callid);
+        String mobile = voiceCallbackParams.getMobile();
+
+        Integer status = null;
+        String result = voiceCallbackParams.getResult();
+        if("0".equals(result)) { //用户正常接听
+            status = ContactorStatusEnum.YI_LIAN_XI.getValue();
+        } else if("1".equals(result)){ //用户未接听
+            status = ContactorStatusEnum.WEI_JIE_TONG.getValue();
+        } else { //呼叫异常
+            status = ContactorStatusEnum.WEI_JIE_TONG.getValue();
+        }
+        bmsEventOrderService.updateOrderContactStatus4Callback(Long.parseLong(orderId),mobile,status);
+
+        Map<String,Object> rtn = new HashMap<>();
+        rtn.put("result",0);
+        rtn.put("errmsg","OK");
+        return rtn;
+    }
+
+
+
+}

+ 38 - 0
src/main/java/com/care/bms/params/VoiceCallbackParams.java

@@ -0,0 +1,38 @@
+package com.care.bms.params;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class VoiceCallbackParams {
+
+    @ApiModelProperty("错误码,0表示用户正常接听,1表示用户未接听, 2表示呼叫异常")
+    private String result;
+
+    @ApiModelProperty("用户接听时间")
+    private String accept_time;
+
+    @ApiModelProperty("呼入号码")
+    private String call_from;
+
+    @ApiModelProperty("标识本次发送 ID")
+    private String callid;
+
+    @ApiModelProperty("结束语音通知呼叫时间")
+    private String end_calltime;
+
+    @ApiModelProperty("计费时长,单位为分钟")
+    private String fee;
+
+    @ApiModelProperty("手机号码")
+    private String mobile;
+
+    @ApiModelProperty("国家(或地区)码")
+    private String nationcode;
+
+    @ApiModelProperty("开始发起语音通知呼叫时间")
+    private String start_calltime;
+
+}

+ 35 - 0
src/main/java/com/care/bms/service/BmsEventOrderService.java

@@ -592,6 +592,41 @@ public class BmsEventOrderService {
         return this.careEventOrderContactStatusService.update(updateWrapper);
     }
 
+    /**
+     * 语音通知回调后修改联系人状态
+     *
+     * @param orderId
+     * @param status
+     * @return
+     */
+    public boolean updateOrderContactStatus4Callback(Long orderId,String contactPhone, Integer status) {
+
+        UpdateWrapper<CareEventOrderContactStatus> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.lambda().eq(CareEventOrderContactStatus::getOrderId, orderId).eq(CareEventOrderContactStatus::getContactPhone,contactPhone)
+                .set(CareEventOrderContactStatus::getStatus, status);
+
+        QueryWrapper<CareEventOrderContactStatus> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(CareEventOrderContactStatus::getOrderId,orderId).eq(CareEventOrderContactStatus::getContactPhone,contactPhone);
+        CareEventOrderContactStatus contact = this.careEventOrderContactStatusService.getOne(queryWrapper);
+
+        CareEventOrderHandleHis his = new CareEventOrderHandleHis();
+        his.setOrgId(contact.getOrgId());
+        his.setStationId(contact.getStationId());
+        his.setOrderId(contact.getOrderId());
+        his.setLogType(LogTypeEnum.OUT_CALL.getValue());
+        his.setLogObjectId(contact.getContactId());
+        his.setLogObjectName(contact.getContactName());
+        his.setLogResult(ContactorStatusEnum.getCodeToName(status));
+        his.setOpUserRole(UserRoleEnum.SEAT.getValue());
+//        his.setOpUserId(loginUser.getId());
+//        his.setOpUserName(loginUser.getName());
+        his.setCreateTime(DateUtil.date());
+        his.setRelationTypeDesc(contact.getRelationTypeDesc());
+        this.careEventOrderHandleHisService.save(his);
+        return this.careEventOrderContactStatusService.update(updateWrapper);
+    }
+
+
     /**
      * 获取通话结果
      *

+ 4 - 0
src/main/java/com/care/common/cache/RedisKeyConstant.java

@@ -54,6 +54,10 @@ public class RedisKeyConstant {
     public static final String SWITCH_SMS = "SWITCH:SMS";
     public static final String SWITCH_VOICE = "SWITCH:VOICE";
 
+    //存放语音通知信息callId和orderId用于回调 1h
+    public static final String VOICE_CALLBACK_INFO = "VOICE:CALLBACK";
+    public static final int VOICE_CALLBACK_INFO_TIME = 3600 * 1;
+
     // 频安保用户微信登录信息 2h
     public static final String PINANBAO_WX_LOGIN_INFO = "PINANBAO:WXLOGIN";
     public static final int PINANBAO_WX_LOGIN_INFO_TIME = 3600 * 2;

+ 1 - 0
src/main/java/com/care/common/interceptor/AuthorizationInterceptorConf.java

@@ -32,6 +32,7 @@ public class AuthorizationInterceptorConf extends WebMvcConfigurerAdapter implem
             //不拦截登录接口
             "/bms/login",
             "/bms/event/testData",
+            "/bms/voice/callback",
             "/bms/switch/autoSms",
             "/installation/api/**"
     };

+ 8 - 0
src/main/java/com/care/common/service/impl/VoiceSendServiceImpl.java

@@ -1,6 +1,8 @@
 package com.care.common.service.impl;
 
 import cn.hutool.core.util.StrUtil;
+import com.care.common.cache.RedisKeyConstant;
+import com.care.common.cache.RedisUtil;
 import com.care.common.enums.SmsTemplateTypeEnum;
 import com.care.common.service.VoiceSendService;
 import com.care.common.util.VoiceUtil;
@@ -9,6 +11,8 @@ import com.tencentcloudapi.vms.v20200902.models.SendStatus;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+
 /**
  * @Author: lilt
  * @Date: 2021/6/5
@@ -16,6 +20,8 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class VoiceSendServiceImpl implements VoiceSendService {
+    @Resource
+    private RedisUtil redisUtil;
 
     @Value("${voice.notice.endpoint:#{null}}")
     private String noticeEndpoint;
@@ -49,6 +55,8 @@ public class VoiceSendServiceImpl implements VoiceSendService {
             if (sendStatus != null && sendStatus.getCallId() != null){
                 mySendStatus.setCallId(sendStatus.getCallId());
                 mySendStatus.setSessionContext(sendStatus.getSessionContext());
+                //存入redis
+                redisUtil.hset(RedisKeyConstant.VOICE_CALLBACK_INFO, sendStatus.getCallId(), sendStatus.getSessionContext(), RedisKeyConstant.VOICE_CALLBACK_INFO_TIME);
                 mySendStatus.setSuccess(true);
             }
         }