|
|
|
@ -2,6 +2,7 @@ package com.baiye.modules.telemarkting.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
@ -11,16 +12,17 @@ import com.baiye.feign.SourceClueClient;
|
|
|
|
|
import com.baiye.http.CommonResponse;
|
|
|
|
|
import com.baiye.model.enums.CallStatusEnum;
|
|
|
|
|
import com.baiye.modules.system.domain.Clue;
|
|
|
|
|
import com.baiye.modules.telemarkting.dao.AllCallInfoRepository;
|
|
|
|
|
import com.baiye.modules.telemarkting.dao.CallClueRepository;
|
|
|
|
|
import com.baiye.modules.telemarkting.dao.ExtensionDisplayRepository;
|
|
|
|
|
import com.baiye.modules.telemarkting.dao.ExtensionNumberRepository;
|
|
|
|
|
import com.baiye.modules.system.domain.Company;
|
|
|
|
|
import com.baiye.modules.system.repository.CompanyRepository;
|
|
|
|
|
import com.baiye.modules.system.service.CompanyService;
|
|
|
|
|
import com.baiye.modules.telemarkting.dao.*;
|
|
|
|
|
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.RollCallReq;
|
|
|
|
|
import com.baiye.modules.telemarkting.service.TelephoneCallService;
|
|
|
|
|
import com.baiye.util.SecurityUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -56,6 +58,12 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
private ExtensionNumberRepository extensionNumberRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
private ExtensionDisplayRepository extensionDisplayRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
private CompanyService companyService;
|
|
|
|
|
@Resource
|
|
|
|
|
private CallDeductRepository callDeductRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
private CompanyRepository companyRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CommonResponse<String> doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) {
|
|
|
|
@ -80,6 +88,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
allCallInfo.setSessionId(sessionId);
|
|
|
|
|
allCallInfo.setRequestId(requestId);
|
|
|
|
|
allCallInfo.setClueId(Long.parseLong(doubleCallReq.getUserData()));
|
|
|
|
|
allCallInfo.setClueType(doubleCallReq.getClueType());
|
|
|
|
|
allCallInfo.setMemberId(doubleCallReq.getMemberId());
|
|
|
|
|
allCallInfo.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
allCallInfo.setType(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
@ -120,7 +129,13 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
if (CallStatusEnum.ANSWER.getDescription().equals(flag)) {
|
|
|
|
|
int status = CallStatusEnum.ANSWER.getValue();
|
|
|
|
|
callClueRepository.updateByStatus(status, userDate);
|
|
|
|
|
allCallInfoRepository.updateByStatus(status, sessionId);
|
|
|
|
|
// allCallInfoRepository.updateByStatus(status, sessionId);
|
|
|
|
|
AllCallInfo allCallInfo = allCallInfoRepository.findBySessionId(sessionId);
|
|
|
|
|
allCallInfo.setStatus(status);
|
|
|
|
|
allCallInfoRepository.save(allCallInfo);
|
|
|
|
|
//实时扣费
|
|
|
|
|
callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), allCallInfo.getDuration(), DefaultNumberConstants.TWO_NUMBER);
|
|
|
|
|
|
|
|
|
|
//更新资源通话状态
|
|
|
|
|
CompletableFuture.runAsync(() -> updateSourceCallStatus(userDate, DefaultNumberConstants.TWO_NUMBER));
|
|
|
|
|
} else {
|
|
|
|
@ -159,6 +174,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
allCallInfo.setSessionId(sessionId);
|
|
|
|
|
allCallInfo.setRequestId(randomString);
|
|
|
|
|
allCallInfo.setClueId(originalNumber);
|
|
|
|
|
allCallInfo.setClueType(doubleCallReq.getClueType());
|
|
|
|
|
allCallInfo.setMemberId(doubleCallReq.getMemberId());
|
|
|
|
|
allCallInfo.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
allCallInfo.setType(DefaultNumberConstants.THREE_NUMBER);
|
|
|
|
@ -241,6 +257,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
allCallInfo.setSessionId(requestId);
|
|
|
|
|
allCallInfo.setRequestId(requestId);
|
|
|
|
|
allCallInfo.setClueId(Long.parseLong(telephoneCallReqDTO.getUserData()));
|
|
|
|
|
allCallInfo.setClueType(telephoneCallReqDTO.getClueType());
|
|
|
|
|
allCallInfo.setMemberId(telephoneCallReqDTO.getMemberId());
|
|
|
|
|
allCallInfo.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
allCallInfo.setType(DefaultNumberConstants.TWO_NUMBER);
|
|
|
|
@ -286,6 +303,8 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
allCallInfoRepository.updateByDurationAndStatus(DefaultNumberConstants.TWO_NUMBER, Integer.valueOf(rollCallBackDTO.getDuration()), allCallInfo.getId());
|
|
|
|
|
//更新资源通话状态
|
|
|
|
|
CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER));
|
|
|
|
|
//TODO 实时扣除话费
|
|
|
|
|
callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2);
|
|
|
|
|
} else {
|
|
|
|
|
//更新资源通话状态
|
|
|
|
|
CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.ONE_NUMBER));
|
|
|
|
@ -308,4 +327,81 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
|
|
|
|
|
clueMiddle.setNewestCallTime(new Date());
|
|
|
|
|
sourceClueClient.update(clueMiddle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 实时扣费
|
|
|
|
|
*
|
|
|
|
|
* @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 companyId = SecurityUtils.getCompanyId();
|
|
|
|
|
Company company = companyService.findCompanyInfo(companyId);
|
|
|
|
|
|
|
|
|
|
//模板费用
|
|
|
|
|
double fee;
|
|
|
|
|
if (callType == DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
//双呼
|
|
|
|
|
fee = company.getDoubleCallFee();
|
|
|
|
|
} else {
|
|
|
|
|
//点呼
|
|
|
|
|
if (clueType == DefaultNumberConstants.THREE_NUMBER) {
|
|
|
|
|
fee = company.getTiktokCallFee();
|
|
|
|
|
} else if (clueType == DefaultNumberConstants.FOUR_NUMBER) {
|
|
|
|
|
fee = company.getDeliveryCallFee();
|
|
|
|
|
} else if (clueType == DefaultNumberConstants.FIVE_NUMBER) {
|
|
|
|
|
fee = company.getTalkCallFee();
|
|
|
|
|
} else {
|
|
|
|
|
fee = company.getRollCallFee();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
double minDuration = dealDuration(duration);
|
|
|
|
|
double mul = NumberUtil.mul(minDuration, fee);
|
|
|
|
|
CallDeduct callDeduct = new CallDeduct();
|
|
|
|
|
callDeduct.setDeductDuration((int) minDuration);
|
|
|
|
|
callDeduct.setDeductAmount(mul);
|
|
|
|
|
callDeduct.setClueId(clueId);
|
|
|
|
|
callDeduct.setMemberId(memberId);
|
|
|
|
|
callDeduct.setCompanyId(companyId);
|
|
|
|
|
callDeduct.setStatus(false);
|
|
|
|
|
callDeduct.setCreateTime(new Date());
|
|
|
|
|
callDeduct.setVersion(company.getVersion());
|
|
|
|
|
callDeduct.setType(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
CallDeduct save = callDeductRepository.save(callDeduct);
|
|
|
|
|
updateBalance(mul, companyId, company.getVersion(), save);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateBalance(Double mul, Long companyId, Integer version, CallDeduct save) {
|
|
|
|
|
int num = companyService.updateBalanceOptimistic(mul, companyId, version);
|
|
|
|
|
if (num > 0) {
|
|
|
|
|
save.setVersion(version);
|
|
|
|
|
save.setStatus(true);
|
|
|
|
|
callDeductRepository.save(save);
|
|
|
|
|
} else {
|
|
|
|
|
updateBalance(mul, companyId, version + 1, save);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将秒 转换为分钟 不满一分钟 按一分钟
|
|
|
|
|
*
|
|
|
|
|
* @param duration
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Double dealDuration(int duration) {
|
|
|
|
|
if (duration <= DefaultNumberConstants.SIXTY) {
|
|
|
|
|
return 1.00;
|
|
|
|
|
} else {
|
|
|
|
|
int i = duration % 60;
|
|
|
|
|
double div = NumberUtil.div(duration, 60);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
return NumberUtil.add(div, 1);
|
|
|
|
|
} else {
|
|
|
|
|
return div;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|