From b68722bb7d3540b2dd4561e8ee55c227fafa31f9 Mon Sep 17 00:00:00 2001 From: wujingtao Date: Thu, 1 Dec 2022 17:40:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=82=B9=E5=91=BC=E6=8C=82?= =?UTF-8?q?=E6=96=AD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/TaskServiceImpl.java | 3 ++ .../api/TelephoneCallController.java | 8 +++-- .../telemarkting/httpRequest/RollCallReq.java | 34 ++++++++++++++++++- .../service/TelephoneCallService.java | 30 +++++----------- .../impl/TelephoneCallServiceImpl.java | 32 ++++++++++++----- .../main/resources/config/application-dev.yml | 10 +++--- .../resources/config/application-prod.yml | 2 +- .../baiye/module/dao/ClueTalkRepository.java | 1 - .../module/service/impl/ClueServiceImpl.java | 4 +-- 9 files changed, 82 insertions(+), 42 deletions(-) diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java index 32f4156e..ccf4d291 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java @@ -62,6 +62,9 @@ public class TaskServiceImpl implements TaskService { private int datacenterId; private final RedisUtils redisUtils; + public static void main(String[] args) { + System.out.println(IdUtil.getSnowflake(9, 9).nextId()); + } @Override @Transactional(rollbackOn = Exception.class) public void saveTask(Task task) { diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java index f60775f3..8d045201 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java @@ -43,7 +43,7 @@ public class TelephoneCallController { @PostMapping("/telephone/req") @ApiOperation("拨打电话") - public CommonResponse doubleCallReq(@Validated @RequestBody TelephoneCallReqDTO telephoneCallReqDTO) { + public CommonResponse doubleCallReq(@Validated @RequestBody TelephoneCallReqDTO telephoneCallReqDTO) { if (ObjectUtil.isEmpty(telephoneCallReqDTO)) { return CommonResponse.createByError(); } @@ -132,7 +132,11 @@ public class TelephoneCallController { public CommonResponse doubleCallStop(@RequestBody TelephoneCallStopDTO telephoneCallStopDTO) { return telephoneCallService.doubleCallStop(telephoneCallStopDTO); } - + @PostMapping("/roll/stop") + @ApiOperation("点呼挂断呼叫") + public CommonResponse rollCallStop(@RequestBody TelephoneCallStopDTO telephoneCallStopDTO) { + return telephoneCallService.rollCallStop(telephoneCallStopDTO); + } @PostMapping("/roll/cdrUrl") @ApiOperation("点呼系统回调话单") diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/RollCallReq.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/RollCallReq.java index 2a165246..a1b46798 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/RollCallReq.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/RollCallReq.java @@ -6,6 +6,8 @@ import cn.hutool.core.codec.Base64; import cn.hutool.core.date.DateUtil; import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; @@ -13,6 +15,7 @@ import com.baiye.http.RollCallResponse; import com.baiye.model.enums.ResponseCode; import com.baiye.modules.telemarkting.entity.dto.RollCallSystemDTO; import com.baiye.modules.telemarkting.entity.dto.TelephoneCallReqDTO; +import com.baiye.modules.telemarkting.entity.dto.TelephoneCallStopDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -36,6 +39,8 @@ public class RollCallReq { private String appId; @Value("${roll.call.accountSid}") private String accountSid; + @Value("${roll.call.stopUrl}") + private String stopUrl; public String startReq(TelephoneCallReqDTO doubleCallReq) { log.info("=======================RollCallReq start in {}", DateUtil.date()); @@ -66,7 +71,7 @@ public class RollCallReq { log.info("点呼返回值为 {}", httpResponse); RollCallResponse doubleCallResponse = JSONUtil.toBean(httpResponse, RollCallResponse.class); if (String.valueOf - (DefaultNumberConstants.ZERO_NUMBER) + (DefaultNumberConstants.ZERO_NUMBER) .equals(doubleCallResponse.getResult())) { return doubleCallResponse.getReqid(); } else { @@ -82,6 +87,33 @@ public class RollCallReq { throw new BadRequestException(ResponseCode.CALL_ERROR.getDesc()); } + public Boolean stopReq(TelephoneCallStopDTO telephoneCallStopDTO) { + return stopTask(telephoneCallStopDTO); + } + + private Boolean stopTask(TelephoneCallStopDTO telephoneCallStopDTO) { + int count = 0; + int flag = 3; + while (count <= flag) { + JSONObject json = new JSONObject(); + json.putOpt("callid", telephoneCallStopDTO.getSessionid()); + JSONObject jsonObject = new JSONObject(); + jsonObject.putOpt("req_id",telephoneCallStopDTO.getCallId()); + jsonObject.putOpt("type", "hangup"); + jsonObject.putOpt("bsname", "aibot"); + jsonObject.putOpt("body", json); + HttpResponse httpResponse = HttpRequest.post(stopUrl).body(JSONUtil.toJsonPrettyStr(jsonObject)).execute(); + if (httpResponse.isOk()) { + log.info("请求挂断成功,返回值:{}", httpResponse.body()); + return Boolean.TRUE; + } else { + count++; + log.error("请求失败,response==={}", httpResponse.body()); + } + } + return Boolean.FALSE; + } + private String sendCallReq(Map json, String url, String authorization) { return HttpRequest.post(url). header(Header.AUTHORIZATION, authorization). diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java index cc66aac0..f064a1e4 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java @@ -11,53 +11,41 @@ public interface TelephoneCallService { /** * 双呼请求 - * - * @param telephoneCallReqDTO - * @return */ - CommonResponse doubleCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); + CommonResponse doubleCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); /** * 回调话单 - * @param telephoneCallBackDTO */ void doubleCallBack(TelephoneCallBackDTO telephoneCallBackDTO); /** * 回调状态 - * - * @param telephoneCallBackStatusDTO */ void doubleCallBackStatus(TelephoneCallBackStatusDTO telephoneCallBackStatusDTO); /** - * 停止通话 - * - * @param telephoneCallStopDTO - * @return + * 双呼挂断 */ CommonResponse doubleCallStop(TelephoneCallStopDTO telephoneCallStopDTO); + /** + * 点呼挂断 + */ + CommonResponse rollCallStop(TelephoneCallStopDTO telephoneCallStopDTO); + /** * axb拨打电话 - * - * @param telephoneCallReqDTO - * @return */ - CommonResponse axbDialNumber(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); + CommonResponse axbDialNumber(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); /** * 点呼请求 - * - * @param telephoneCallReqDTO - * @return */ - CommonResponse rollCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); + CommonResponse rollCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); /** * 点呼回调 - * - * @param rollCallBackDTO */ void rollCallBack(RollCallBackDTO rollCallBackDTO); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java index 76c6ddc0..8aaa784c 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java @@ -67,7 +67,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { private UserService userService; @Override - public CommonResponse doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) { + public CommonResponse doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) { String requestId = RandomUtil.randomString(10); doubleCallReq.setRequestId(requestId); Clue body; @@ -106,7 +106,10 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } else { return CommonResponse.createByError(); } - return CommonResponse.createBySuccess(sessionId); + TelephoneCallStopDTO telephoneCallStopDTO = new TelephoneCallStopDTO(); + telephoneCallStopDTO.setSessionid(sessionId); + telephoneCallStopDTO.setCallId(requestId); + return CommonResponse.createBySuccess(telephoneCallStopDTO); } @Override @@ -153,7 +156,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } @Override - public CommonResponse axbDialNumber(TelephoneCallReqDTO doubleCallReq, Long companyId) { + public CommonResponse axbDialNumber(TelephoneCallReqDTO doubleCallReq, Long companyId) { long originalNumber = Long.parseLong(doubleCallReq.getUserData()); ResponseEntity body; try { @@ -188,14 +191,17 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { clueInfo.setCompanyId(companyId); allCallInfoRepository.save(allCallInfo); callClueRepository.save(clueInfo); - return CommonResponse.createBySuccess(sessionId); + TelephoneCallStopDTO telephoneCallStopDTO = new TelephoneCallStopDTO(); + telephoneCallStopDTO.setSessionid(sessionId); + telephoneCallStopDTO.setCallId(randomString); + return CommonResponse.createBySuccess(telephoneCallStopDTO); } } return CommonResponse.createByError(); } @Override - public CommonResponse rollCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId) { + public CommonResponse rollCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId) { String requestId = RandomUtil.randomString(10); telephoneCallReqDTO.setRequestId(requestId); if (telephoneCallReqDTO.getDisplay() == null || telephoneCallReqDTO.getTelA() == null) { @@ -251,8 +257,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } telephoneCallReqDTO.setTelB(body.getNid()); String reqId = rollCallReq.startReq(telephoneCallReqDTO); - log.info("=============================reqId {}", reqId); -// if (StrUtil.isNotBlank(reqId)) { + AllCallInfo allCallInfo = new AllCallInfo(); allCallInfo.setSessionId(requestId); allCallInfo.setRequestId(requestId); @@ -272,9 +277,18 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { clueInfo.setCompanyId(companyId); allCallInfoRepository.save(allCallInfo); callClueRepository.save(clueInfo); - return CommonResponse.createBySuccess(requestId); + TelephoneCallStopDTO telephoneCallStopDTO = new TelephoneCallStopDTO(); + telephoneCallStopDTO.setSessionid(reqId); + telephoneCallStopDTO.setCallId(requestId); + return CommonResponse.createBySuccess(telephoneCallStopDTO); + } + @Override + public CommonResponse rollCallStop(TelephoneCallStopDTO telephoneCallStopDTO) { + if (rollCallReq.stopReq(telephoneCallStopDTO)) { + return CommonResponse.createBySuccess(); + } + return CommonResponse.createByError(); } - /** * 点呼回调 会得到两个,一个是针对分机号 一个是针对真实被叫 保存信息取值被叫回调,录音取分机号回调(被叫回调没有录音) * diff --git a/manage/ad-platform-management/src/main/resources/config/application-dev.yml b/manage/ad-platform-management/src/main/resources/config/application-dev.yml index d717021f..0ff8e1e3 100644 --- a/manage/ad-platform-management/src/main/resources/config/application-dev.yml +++ b/manage/ad-platform-management/src/main/resources/config/application-dev.yml @@ -3,8 +3,8 @@ spring: cloud: nacos: discovery: - server-addr: ${NACOS_HOST:8.130.96.163}:${NACOS_PORT:8848} -# server-addr: localhost:8848 +# server-addr: ${NACOS_HOST:8.130.96.163}:${NACOS_PORT:8848} + server-addr: localhost:8848 redis: database: 2 host: 8.130.96.163 @@ -83,8 +83,8 @@ login: font-size: 25 business: ids: - - 8 - - 10 + - 8 + - 10 #是否允许生成代码,生产环境设置为false @@ -141,7 +141,7 @@ roll: cdrUrl: http://8.130.96.163:8866/api/roll/cdrUrl #cdrUrl: https://baiyee.vip/api/roll/cdrUrl #cdrUrl: http://localhost:8866/api/roll/cdrUrl - + stopUrl: http://api.hzdaba.cn/v3/Accounts/default/Esl/Process alipay: protocol: https # 不需要加/gateway.do,这是新旧SDK的区别,切记 diff --git a/manage/ad-platform-management/src/main/resources/config/application-prod.yml b/manage/ad-platform-management/src/main/resources/config/application-prod.yml index 78cd05c4..c0e9b341 100644 --- a/manage/ad-platform-management/src/main/resources/config/application-prod.yml +++ b/manage/ad-platform-management/src/main/resources/config/application-prod.yml @@ -145,7 +145,7 @@ roll: accountSid: dbby_hangzhoubaiyehl appId: app1 cdrUrl: https://baiyee.vip/api/roll/cdrUrl - + stopUrl: http://api.hzdaba.cn/v3/Accounts/default/Esl/Process alipay: protocol: https diff --git a/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java b/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java index 1639467c..004cb0c6 100644 --- a/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java +++ b/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java @@ -1,6 +1,5 @@ package com.baiye.module.dao; -import com.baiye.module.entity.ClueMiddle; import com.baiye.module.entity.ClueTalk; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java b/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java index 65c0c8d3..ce49dcb4 100644 --- a/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java +++ b/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java @@ -840,8 +840,8 @@ public class ClueServiceImpl implements ClueService { if (clueTalk.getMemberStatus() == DefaultNumberConstants.FOUR_NUMBER) { throw new BadRequestException("已经转为crm,请勿重复操作"); } - if (clueTalk.getClueCallStatus() == null || clueTalk.getClueCallStatus() == DefaultNumberConstants.ZERO_NUMBER) { - throw new BadRequestException("未拨打电话,不能转crm"); + if (clueTalk.getClueCallStatus() == null || clueTalk.getClueCallStatus() != DefaultNumberConstants.TWO_NUMBER) { + throw new BadRequestException("未拨打有效电话,不能转crm"); } int userCount = turnCrmLogRepository.findByUserIdCount(clueTalk.getMemberId()) + DefaultNumberConstants.ONE_NUMBER; UserDto userInfo = userClient.findUserInfo(clueTalk.getMemberId());