From d4663ba6c01bc80db1b4e1493a798b52a9e2d9bc Mon Sep 17 00:00:00 2001 From: wjt Date: Mon, 5 Jun 2023 17:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ecti=E9=80=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/baiye/http/CtiCallResponse.java | 15 ++ .../api/TelephoneCallController.java | 33 +++- .../entity/dto/NfpCallInfoResponseDTO.java | 44 +++++ .../entity/dto/NfpCallReqDTO.java | 30 ++++ .../entity/dto/NfpCallStatusResponseDTO.java | 18 ++ .../entity/dto/TelephoneCallStopDTO.java | 3 +- .../telemarkting/httpRequest/CtiCallReq.java | 85 +++++++++ .../service/TelephoneCallService.java | 35 ++++ .../service/impl/ClueBoostServiceImpl.java | 1 - .../impl/TelephoneCallServiceImpl.java | 168 +++++++++++++----- .../main/resources/config/application-dev.yml | 5 + .../resources/config/application-prod.yml | 6 + .../module/service/impl/ClueServiceImpl.java | 1 - .../java/com/baiye/util/DecryptPnoUtil.java | 4 - 14 files changed, 392 insertions(+), 56 deletions(-) create mode 100644 ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CtiCallResponse.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallInfoResponseDTO.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallReqDTO.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallStatusResponseDTO.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/CtiCallReq.java diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CtiCallResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CtiCallResponse.java new file mode 100644 index 00000000..a38fc365 --- /dev/null +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CtiCallResponse.java @@ -0,0 +1,15 @@ +package com.baiye.http; + +import lombok.Data; + +/** + * @author wjt + * @date 2023/6/2 + */ +@Data +public class CtiCallResponse { + private String content; + private String reqId; + private Boolean result; + private String action; +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java index fe022c76..43c36688 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/TelephoneCallController.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; +import com.baiye.annotation.Inner; import com.baiye.annotation.Log; import com.baiye.common.CommonLog; import com.baiye.constant.DefaultNumberConstants; @@ -86,7 +87,7 @@ public class TelephoneCallController { telephoneCallReqDTO.setXGroup(company.getXGroup()); return telephoneCallService.axbDialNumber(telephoneCallReqDTO, companyId); case DefaultNumberConstants.ONE_NUMBER: - return telephoneCallService.rollCallReq(telephoneCallReqDTO, companyId); + return telephoneCallService.ctiCallReq(telephoneCallReqDTO, companyId); default: return CommonResponse.createByErrorMessage("未配置呼叫"); } @@ -155,4 +156,34 @@ public class TelephoneCallController { public CommonResponse rollCallStop(@RequestBody TelephoneCallStopDTO telephoneCallStopDTO) { return telephoneCallService.rollCallStop(telephoneCallStopDTO); } + + + @PostMapping("/cti/cdrUrl") + @ApiOperation("cti系统回调话单") + @Inner(value = false) + public CommonResponse ctiCallBack(@RequestBody NfpCallInfoResponseDTO json) { + telephoneCallService.ctiCallBackInfo(json); + return CommonResponse.createBySuccess(); + } + + @ApiOperation("cti系统回调状态") + @Inner(value = false) + @PostMapping("/cti/status") + public CommonResponse ctiCallBackStatus(@RequestBody NfpCallStatusResponseDTO json) { + log.info("cti回调状态:{}", json); + return CommonResponse.createBySuccess(); + } + + @PostMapping("/cti/stop") + @ApiOperation("cti挂断呼叫") + public CommonResponse ctiCallStop(@RequestBody TelephoneCallStopDTO telephoneCallStopDTO) { + return telephoneCallService.ctiCallStop(telephoneCallStopDTO); + } + + @GetMapping("/cti/set") + @ApiOperation("cti配置") + @Inner(value = false) + public CommonResponse ctiSet(@RequestParam("callBackUrl") String callBackUrl, @RequestParam("notifyUrl") String notifyUrl) { + return telephoneCallService.ctiSet(callBackUrl, notifyUrl); + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallInfoResponseDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallInfoResponseDTO.java new file mode 100644 index 00000000..fcf00aae --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallInfoResponseDTO.java @@ -0,0 +1,44 @@ +package com.baiye.modules.telemarkting.entity.dto; + +import lombok.Data; +/** + * @author wjt + * @date 2023/6/2 + */ +@Data +public class NfpCallInfoResponseDTO { + + private String action; + private String orgCode; + private String reqId; + private Calllog calllog; + + @Data + public static class Calllog { + private Boolean answer; + private String callBeginTime; + private String callId; + private String callInNum; + private Integer callTime; + private Integer callType; + private String calledAnswerTime; + private String calledBeginTime; + private String calledCity; + private String calledCityCode; + private String calledId; + private String calledIsp; + private String calledNum; + private String calledProvince; + private String calledRingTime; + private String caller; + private String callerAnswerTime; + private String callerRingTime; + private String crmStr; + private String hangupCode; + private String hangupTime; + private Boolean rec; + private String recPath; + private String showNum; + + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallReqDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallReqDTO.java new file mode 100644 index 00000000..9f2ff9fc --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallReqDTO.java @@ -0,0 +1,30 @@ +package com.baiye.modules.telemarkting.entity.dto; + +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; + +/** + * @author wjt + * @date 2023/5/30 + */ +@Data +public class NfpCallReqDTO { + private String reqId; + private String caller; + private String callee; + private String showNum; + @Value("${nfp.call.orgCode}") + private String orgCode; + private String crmStr; + private String action; + + public NfpCallReqDTO addNfpCallReq(String reqId, String caller, String callee, String showNum) { + this.setReqId(reqId); + this.setCaller(caller); + this.setCallee(callee); + this.setShowNum(showNum); + this.setCrmStr(reqId); + this.setAction("1000"); + return this; + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallStatusResponseDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallStatusResponseDTO.java new file mode 100644 index 00000000..7f787f53 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/NfpCallStatusResponseDTO.java @@ -0,0 +1,18 @@ +package com.baiye.modules.telemarkting.entity.dto; + +import lombok.Data; + +/** + * @author wjt + * @date 2023/6/2 + */ +@Data +public class NfpCallStatusResponseDTO { + private String action; + private String called; + private String caller; + private String content; + private String orgCode; + private String reqId; + private Integer state; +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/TelephoneCallStopDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/TelephoneCallStopDTO.java index 121d6d69..ffec65b2 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/TelephoneCallStopDTO.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/TelephoneCallStopDTO.java @@ -8,6 +8,7 @@ import lombok.Data; */ @Data public class TelephoneCallStopDTO { - private String sessionid; + private String content; private String callId; + private String sessionid; } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/CtiCallReq.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/CtiCallReq.java new file mode 100644 index 00000000..09ed9dd8 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/httpRequest/CtiCallReq.java @@ -0,0 +1,85 @@ +package com.baiye.modules.telemarkting.httpRequest; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baiye.common.CommonLog; +import com.baiye.exception.BadRequestException; +import com.baiye.http.CtiCallResponse; +import com.baiye.modules.telemarkting.entity.dto.NfpCallReqDTO; +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; + + +/** + * @author wjt + * @date 2023/5/30 + */ +@Slf4j +@Component +public class CtiCallReq { + @Value("${cti.call.reqUrl}") + private String reqUrl; + @Value("${cti.call.setUrl}") + private String setUrl; + @Value("${cti.call.orgCode}") + private String orgCode; + + public String startReq(TelephoneCallReqDTO req) { + NfpCallReqDTO reqDTO = new NfpCallReqDTO().addNfpCallReq(req.getRequestId(), req.getTelA(), req.getTelB(), String.valueOf(req.getDisplay())); + reqDTO.setOrgCode(orgCode); + CommonLog.info("CTI请求参数: " + BeanUtil.beanToMap(reqDTO)); + try { + String httpResponse = sendCallReq(JSONUtil.toJsonPrettyStr(reqDTO), reqUrl).body(); + CtiCallResponse ctiCallResponse = JSONUtil.toBean(httpResponse, CtiCallResponse.class); + if (ctiCallResponse.getResult()) { + return ctiCallResponse.getContent(); + } + CommonLog.error("nfp请求失败,response===" + ctiCallResponse.getContent()); + throw new BadRequestException("呼叫失败"); + } catch (Exception e) { + log.error("method【reqTask】 roll_call error :{}", e.getMessage()); + e.printStackTrace(); + } + throw new BadRequestException("呼叫失败"); + } + + + public Boolean stopReq(TelephoneCallStopDTO telephoneCallStopDTO) { + JSONObject json = new JSONObject(); + json.putOpt("reqId", telephoneCallStopDTO.getCallId()); + json.putOpt("callId", telephoneCallStopDTO.getSessionid()); + json.putOpt("orgCode", orgCode); + json.putOpt("action", "1001"); + HttpResponse httpResponse = HttpRequest.post(reqUrl).body(JSONUtil.toJsonPrettyStr(json)).execute(); + log.info("请求挂断,session={},{}", telephoneCallStopDTO.getSessionid(), httpResponse.body()); + if (httpResponse.isOk()) { + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + public Boolean setReq(String callBackUrl, String notifyUrl) { + JSONObject json = new JSONObject(); + json.putOpt("reqId", RandomUtil.randomString(10)); + json.putOpt("orgCode", orgCode); + json.putOpt("callBackUrl", callBackUrl); + json.putOpt("notifyUrl", notifyUrl); + HttpResponse httpResponse = HttpRequest.post(setUrl).body(JSONUtil.toJsonPrettyStr(json)).execute(); + log.info("请求配置,{}", httpResponse.body()); + if (httpResponse.isOk()) { + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + private HttpResponse sendCallReq(String json, String url) { + return HttpRequest.post(url).body(json).execute(); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java index f064a1e4..68064bc8 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/TelephoneCallService.java @@ -48,4 +48,39 @@ public interface TelephoneCallService { * 点呼回调 */ void rollCallBack(RollCallBackDTO rollCallBackDTO); + + + /** + * cti请求 + * + * @param telephoneCallReqDTO + * @param companyId + * @return + */ + CommonResponse ctiCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId); + + /** + * cti挂斷 + * + * @param telephoneCallStopDTO + * @return + */ + CommonResponse ctiCallStop(TelephoneCallStopDTO telephoneCallStopDTO); + + /** + * cti配置回调路径 + * + * @param callBackUrl + * @param notifyUrl + * @return + */ + CommonResponse ctiSet(String callBackUrl, String notifyUrl); + + /** + * cti话单回调 + * + * @param json + */ + void ctiCallBackInfo(NfpCallInfoResponseDTO json); + } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ClueBoostServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ClueBoostServiceImpl.java index 42db76e2..9a08a921 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ClueBoostServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ClueBoostServiceImpl.java @@ -78,7 +78,6 @@ public class ClueBoostServiceImpl implements ClueBoostService { CommonLog.info("赔付线索:" + integer + "条"); } - @EventListener(ClueBoostDTO.class) @Transactional(rollbackFor = Exception.class) public void boost(ClueBoostDTO clueBoostDTO) { diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java index 07f83ac4..37489628 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java @@ -25,6 +25,7 @@ import com.baiye.modules.telemarkting.entity.*; import com.baiye.modules.telemarkting.entity.dto.*; import com.baiye.modules.telemarkting.httpRequest.AxbRequest; import com.baiye.modules.telemarkting.httpRequest.DoubleCallReq; +import com.baiye.modules.telemarkting.httpRequest.CtiCallReq; import com.baiye.modules.telemarkting.httpRequest.RollCallReq; import com.baiye.modules.telemarkting.service.TelephoneCallService; import com.baiye.util.RedisUtils; @@ -56,6 +57,8 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { @Resource private RollCallReq rollCallReq; @Resource + private CtiCallReq ctiCallReq; + @Resource private AllCallInfoRepository allCallInfoRepository; @Resource private CallClueRepository callClueRepository; @@ -135,7 +138,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { UserDto user = userService.findById(allCallInfo.getMemberId()); Long whichUserId = user.getWhichUserId(); //实时扣费 - callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), allCallInfo.getDuration(), DefaultNumberConstants.TWO_NUMBER, whichUserId); + callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getDuration(), whichUserId); //更新资源通话状态 CompletableFuture.runAsync(() -> updateSourceCallStatus(userDate, DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType(), null)); } else { @@ -219,7 +222,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { //请求呼叫 String reqId = rollCallReq.startReq(telephoneCallReqDTO); - AllCallInfo allCallInfo = new AllCallInfo().init(requestId, requestId, Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getClueType(), telephoneCallReqDTO.getMemberId(), DefaultNumberConstants.ONE_NUMBER, DefaultNumberConstants.TWO_NUMBER); + AllCallInfo allCallInfo = new AllCallInfo().init(reqId, requestId, Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getClueType(), telephoneCallReqDTO.getMemberId(), DefaultNumberConstants.ONE_NUMBER, DefaultNumberConstants.TWO_NUMBER); allCallInfoRepository.save(allCallInfo); CallClueInfo clueInfo = new CallClueInfo().init(Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getTeamId(), telephoneCallReqDTO.getMemberId(), telephoneCallReqDTO.getTaskId(), companyId, DefaultNumberConstants.ONE_NUMBER); @@ -314,7 +317,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { //更新资源通话状态 CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType(), traceId)); //实时扣除话费 - callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2, whichUserId); + callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), Integer.valueOf(rollCallBackDTO.getDuration()), whichUserId); status = true; } else { //更新资源通话状态 @@ -330,6 +333,119 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } } + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse ctiCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId) { + //检查余量 + UserDto user = userService.findById(telephoneCallReqDTO.getMemberId()); + Long whichUserId = user.getWhichUserId(); + Integer surplusPhoneBillByUserId = channelCustomRepository.findSurplusPhoneBillByUserId(whichUserId); + if (surplusPhoneBillByUserId == null || surplusPhoneBillByUserId <= 0) { + CommonLog.error("话费不足"); + return CommonResponse.createByErrorMessage("话费不足"); + } + String requestId = RandomUtil.randomString(10); + telephoneCallReqDTO.setRequestId(requestId); + if (telephoneCallReqDTO.getDisplay() == null || telephoneCallReqDTO.getTelA() == null) { + //获取去显号和分机号 + getNumberAndDisplay(telephoneCallReqDTO, companyId); + } + //获取被叫号 + CallClueDTO body; + try { + body = sourceClueClient.queryDetailsByClueType(Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getClueType()).getBody(); + } catch (Exception e) { + CommonLog.error("呼叫失败"); + throw new BadRequestException("呼叫失败"); + } + if (ObjectUtil.isNull(body) || StrUtil.isEmpty(body.getNid())) { + CommonLog.error("未获取到号码"); + return CommonResponse.createByErrorMessage("未获取到号码"); + } + if (body.getMemberId() == null || body.getIsFreeze()) { + CommonLog.error("线索异常"); + return CommonResponse.createByErrorMessage("线索异常,请刷新后重试"); + } + telephoneCallReqDTO.setTelB(body.getNid()); + //请求呼叫 + String content = ctiCallReq.startReq(telephoneCallReqDTO); + AllCallInfo allCallInfo = new AllCallInfo().init(requestId, requestId, Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getClueType(), telephoneCallReqDTO.getMemberId(), DefaultNumberConstants.ONE_NUMBER, DefaultNumberConstants.TWO_NUMBER); + allCallInfoRepository.save(allCallInfo); + + CallClueInfo clueInfo = new CallClueInfo().init(Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getTeamId(), telephoneCallReqDTO.getMemberId(), telephoneCallReqDTO.getTaskId(), companyId, DefaultNumberConstants.ONE_NUMBER); + callClueRepository.save(clueInfo); + + redisUtils.set(requestId, CommonLog.getTraceId(), 3, TimeUnit.HOURS); + TelephoneCallStopDTO telephoneCallStopDTO = new TelephoneCallStopDTO(); + telephoneCallStopDTO.setSessionid(requestId); + telephoneCallStopDTO.setContent(content); + telephoneCallStopDTO.setCallId(requestId); + return CommonResponse.createBySuccess(telephoneCallStopDTO); + + } + + @Override + public CommonResponse ctiCallStop(TelephoneCallStopDTO telephoneCallStopDTO) { + if (ctiCallReq.stopReq(telephoneCallStopDTO)) { + return CommonResponse.createBySuccess(); + } + return CommonResponse.createByError(); + } + + @Override + public CommonResponse ctiSet(String callBackUrl, String notifyUrl) { + if (ctiCallReq.setReq(callBackUrl, notifyUrl)) { + return CommonResponse.createBySuccess(); + } + return CommonResponse.createByError(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void ctiCallBackInfo(NfpCallInfoResponseDTO response) { + CommonLog.infoBusinessPartyType("CTI话单:" + response, BusinessPartyType.DB); + String sessionId = response.getCalllog().getCrmStr(); + String traceId = String.valueOf(redisUtils.get(sessionId)); + AllCallInfo allCallInfo = allCallInfoRepository.findBySessionId(sessionId); + if (ObjectUtil.isNotEmpty(allCallInfo)) { + UserDto user = userService.findById(allCallInfo.getMemberId()); + Long whichUserId = user.getWhichUserId(); + boolean status; + //拨打线索号的回调 + if (response.getCalllog().getAnswer()) { + //表示接通,更新线索状态 + callClueRepository.updateByStatus(DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueId()); + allCallInfo.setStatus(DefaultNumberConstants.TWO_NUMBER); + allCallInfo.setDuration(response.getCalllog().getCallTime()); + + //更新资源通话状态 + CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType(), traceId)); + //实时扣除话费 + callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), response.getCalllog().getCallTime(), whichUserId); + status = true; + } else { + allCallInfo.setStatus(DefaultNumberConstants.ONE_NUMBER); + //更新资源通话状态 + CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.ONE_NUMBER, allCallInfo.getClueType(), traceId)); + status = false; + } + if (Arrays.asList(ClueTypeConstants.TOKER_TYPE).contains(allCallInfo.getClueType())) { + ClueBoostDTO clueBoostDTO = new ClueBoostDTO().addClueBoostDTO(allCallInfo.getClueId(), allCallInfo.getMemberId(), whichUserId, allCallInfo.getClueType(), null); + clueBoostDTO.setStatus(status); + applicationContext.publishEvent(clueBoostDTO); + } + if (response.getCalllog().getRec()) { + allCallInfo.setRecordFlag(1); + allCallInfo.setRecordFileDownloadUrl(response.getCalllog().getRecPath()); + } else { + allCallInfo.setRecordFlag(0); + allCallInfo.setRecordFileDownloadUrl(null); + } + + allCallInfoRepository.save(allCallInfo); + } + } + /** * 更新资源通话状态 * @@ -348,13 +464,10 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { * * @param memberId 用户id * @param clueId 线索id - * @param clueType 线索类型 * @param duration 通话时长(秒) - * @param callType 呼叫类型 1-双呼 2-点呼 */ - public void callCostCount(Long memberId, Long clueId, Integer clueType, Integer duration, Integer callType, Long whichUserId) { + public void callCostCount(Long memberId, Long clueId, Integer duration, Long whichUserId) { Long companyId = userService.findUserInfo(memberId).getCompanyId(); -// Company company = companyService.findById(companyId); int minDuration = dealDuration(duration); CallDeduct callDeduct = new CallDeduct(); callDeduct.setDeductDuration(minDuration); @@ -366,52 +479,14 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { callDeduct.setVersion(0); callDeduct.setType(DefaultNumberConstants.ONE_NUMBER); - //模板费用 -// double fee = 0; -// String typeStr; -// if (callType == DefaultNumberConstants.ONE_NUMBER) { -// //双呼 -// if (company.getDoubleCallFee() != null) { -// fee = company.getDoubleCallFee(); -// } -// typeStr = "双呼套餐"; -// } else { -// //点呼 -// if (clueType == DefaultNumberConstants.THREE_NUMBER) { -// if (company.getTiktokCallFee() != null) { -// fee = company.getTiktokCallFee(); -// } -// typeStr = "抖音套餐"; -// } else if (clueType == DefaultNumberConstants.FOUR_NUMBER) { -// if (company.getDeliveryCallFee() != null) { -// fee = company.getDeliveryCallFee(); -// } -// typeStr = "投流套餐"; -// } else if (clueType == DefaultNumberConstants.FIVE_NUMBER) { -// if (company.getTalkCallFee() != null) { -// fee = company.getTalkCallFee(); -// } -// typeStr = "拓客套餐"; -// } else { -// if (company.getRollCallFee() != null) { -// fee = company.getRollCallFee(); -// } -// typeStr = "crm套餐"; -// } -// } - -// double mul = NumberUtil.mul(minDuration, fee); -// callDeduct.setDeductAmount(mul); callDeduct.setDeductAmount(0.0); callDeduct.setComboType("话费"); CallDeduct save = callDeductRepository.save(callDeduct); -// updateBalance(mul, companyId, company.getVersion(), save, whichUserId); updateBalance(save, whichUserId, minDuration); } private void updateBalance(CallDeduct save, Long whichUserId, Integer bill) { -// int num = companyService.updateBalanceOptimistic(mul, companyId, version); int num = channelCustomRepository.updateSurplusBill(whichUserId, bill); if (num > 0) { save.setStatus(true); @@ -419,9 +494,6 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } else { CommonLog.error("话费扣除失败,记录id:" + save.getId()); } -// else { -// updateBalance(mul, companyId, version + 1, save); -// } } /** diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml index a8dda8c2..beb2b642 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml @@ -148,6 +148,11 @@ roll: #cdrUrl: https://baiyee.vip/api/roll/cdrUrl #cdrUrl: http://localhost:8866/api/roll/cdrUrl stopUrl: http://api.hzdaba.cn/v3/Accounts/default/Esl/Process +cti: + call: + reqUrl: https://cti.hzdaba.cn/cti/call-api + orgCode: org_by + setUrl: https://cti.hzdaba.cn/cti/call-set alipay: protocol: https # 不需要加/gateway.do,这是新旧SDK的区别,切记 diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml index 4544e6fe..4f2257da 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml @@ -152,6 +152,12 @@ roll: cdrUrl: https://baiyee.vip/api/roll/cdrUrl stopUrl: http://api.hzdaba.cn/v3/Accounts/default/Esl/Process +cti: + call: + reqUrl: https://cti.hzdaba.cn/cti/call-api + orgCode: org_by + setUrl: https://cti.hzdaba.cn/cti/call-set + alipay: protocol: https # 不需要加/gateway.do,这是新旧SDK的区别,切记 diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java index 0624a45b..b5f13c81 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java @@ -972,7 +972,6 @@ public class ClueServiceImpl implements ClueService { @Override @Transactional(rollbackFor = Exception.class) public void updateCallStatus(Long clueId, Integer clueCallStatus, Integer clueType) { - CommonLog.info("修改线索:" + clueId + " 通话状态为:" + clueCallStatus); if (Arrays.asList(ClueTypeConstants.TOKER_TYPE).contains(clueType)) { clueTalkRepository.updateCallStatus(clueId, clueCallStatus, DateUtil.now()); } else { diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/util/DecryptPnoUtil.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/util/DecryptPnoUtil.java index 6a847f25..c79fa18c 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/util/DecryptPnoUtil.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/util/DecryptPnoUtil.java @@ -3,21 +3,17 @@ package com.baiye.util; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.lang.Console; import cn.hutool.core.text.StrPool; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONUtil; import com.baiye.constant.DefaultNumberConstants; -import com.baiye.exception.BadRequestException; import com.baiye.module.constant.SecretConstant; import com.baiye.module.service.dto.SecretResponseBean; import com.google.common.base.Joiner; import com.google.common.collect.Lists; -import com.mchange.v2.log.log4j2.Log4j2MLog; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils;