|
|
|
@ -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<TelephoneCallStopDTO> 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<Object> ctiCallStop(TelephoneCallStopDTO telephoneCallStopDTO) {
|
|
|
|
|
if (ctiCallReq.stopReq(telephoneCallStopDTO)) {
|
|
|
|
|
return CommonResponse.createBySuccess();
|
|
|
|
|
}
|
|
|
|
|
return CommonResponse.createByError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CommonResponse<Object> 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);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|