From 8760312b1b705ef7138665339b3badfa085e057b Mon Sep 17 00:00:00 2001 From: wjt Date: Fri, 19 May 2023 19:15:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=9D=E8=B4=B9=E5=92=8C=E8=A1=A5=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/DefaultNumberConstants.java | 3 + .../com/baiye/feign/SourceClueClient.java | 6 + .../callback/SourceClueClientFallback.java | 7 + .../ChannelResourceAssignController.java | 5 +- .../controller/CustomManageController.java | 6 +- .../modules/agent/entity/ChannelCustom.java | 24 ++-- .../agent/entity/ChannelResourceAssign.java | 9 +- .../agent/entity/vo/CustomReportVo.java | 34 ++++- .../repository/ChannelCustomRepository.java | 17 ++- .../service/ChannelResourceAssignService.java | 7 +- .../agent/service/CustomManageService.java | 3 +- .../impl/ChannelManageServiceImpl.java | 48 +------ .../ChannelResourceAssignServiceImpl.java | 36 +++-- .../service/impl/CustomManageServiceImpl.java | 115 +++++++++------ .../baiye/modules/platform/domain/Clue.java | 3 + .../service/impl/CompanyServiceImpl.java | 1 + .../system/service/impl/UserServiceImpl.java | 1 + .../api/TelephoneCallController.java | 11 +- .../telemarkting/entity/ClueBoost.java | 5 + .../telemarkting/entity/ClueBoostRecord.java | 4 + .../telemarkting/entity/dto/ClueBoostDTO.java | 5 +- .../service/impl/ClueBoostServiceImpl.java | 20 ++- .../impl/TelephoneCallServiceImpl.java | 135 ++++++++++-------- .../java/com/baiye/model/dto/CallClueDTO.java | 24 ++++ .../baiye/model/dto/ClueQueryCriteria.java | 3 + .../java/com/baiye/model/dto/UserDto.java | 2 + .../module/controller/ClueController.java | 6 + .../java/com/baiye/module/dao/ClueJpa.java | 48 ++++++- .../com/baiye/module/entity/ClueTalk.java | 2 +- .../com/baiye/module/service/ClueService.java | 3 + .../module/service/impl/ClueServiceImpl.java | 5 + 31 files changed, 400 insertions(+), 198 deletions(-) create mode 100644 ad-platform-pojo/src/main/java/com/baiye/model/dto/CallClueDTO.java diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java index 4455331f..8d811044 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java @@ -113,6 +113,8 @@ public class DefaultNumberConstants { * 20 */ public static final int TWENTY_NUMBER = 20; + + public static final int TWENTY_ONE = 21; /** * 23 */ @@ -126,6 +128,7 @@ public class DefaultNumberConstants { */ public static final int THIRTY = 30; + public static final int FORTY_EIGHT = 48; /** * 60 */ diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java index a0350781..248e54cd 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java @@ -2,6 +2,8 @@ package com.baiye.feign; import com.baiye.feign.callback.SourceClueClientFallback; import com.baiye.http.CommonResponse; +import com.baiye.model.dto.CallClueDTO; +import com.baiye.model.dto.ClueDto; import com.baiye.model.dto.ClueQueryCriteria; import com.baiye.model.dto.DistributeResponseDTO; import com.baiye.model.vo.ResSourceLabel; @@ -56,6 +58,10 @@ public interface SourceClueClient { @GetMapping(API_PREFIX + "/queryDetails") ResponseEntity queryDetails(@RequestParam("clueId") Long clueId); + @ApiOperation("查询资源详情") + @GetMapping(API_PREFIX + "/queryDetailsByClueType") + ResponseEntity queryDetailsByClueType(@RequestParam("clueId") Long clueId, @RequestParam("clueType") Integer clueType); + @ApiOperation("查询资源标签") @PostMapping(API_PREFIX + "/findSourceLabel") ResponseEntity> findSourceLabel(@RequestBody List clueIds); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java index cf4e2c1c..7d499ef4 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java @@ -2,6 +2,8 @@ package com.baiye.feign.callback; import com.baiye.feign.SourceClueClient; import com.baiye.http.CommonResponse; +import com.baiye.model.dto.CallClueDTO; +import com.baiye.model.dto.ClueDto; import com.baiye.model.dto.ClueQueryCriteria; import com.baiye.model.dto.DistributeResponseDTO; import com.baiye.model.vo.ResSourceLabel; @@ -53,6 +55,11 @@ public class SourceClueClientFallback implements SourceClueClient { return null; } + @Override + public ResponseEntity queryDetailsByClueType(Long clueId, Integer clueType) { + return null; + } + @Override public ResponseEntity> findSourceLabel(List clueIds) { return null; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelResourceAssignController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelResourceAssignController.java index 3069f803..c81dcbce 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelResourceAssignController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelResourceAssignController.java @@ -40,11 +40,10 @@ public class ChannelResourceAssignController { @GetMapping("/assign") @ApiOperation("配量") - public CommonResponse assignNum(@RequestParam("channelId") Long channelId, @RequestParam("assignNum") Integer assignNum) { - return channelResourceAssignService.assignNum(channelId, assignNum); + public CommonResponse assignNum(@RequestParam("channelId") Long channelId, @RequestParam(value = "assignNum", required = false) Integer assignNum, @RequestParam(value = "assignBill", required = false) Integer assignBill) { + return channelResourceAssignService.assignNum(channelId, assignNum, assignBill); } - @GetMapping("/report") @ApiOperation("统计") public CommonResponse report() { diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/CustomManageController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/CustomManageController.java index 5480b106..818effda 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/CustomManageController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/CustomManageController.java @@ -38,8 +38,10 @@ public class CustomManageController { @GetMapping("/assign") @ApiOperation("配量") - public CommonResponse assignNum(@RequestParam("customId") Long customId, @RequestParam("assignNum") Integer assignNum) { - return customManageService.assignNum(customId, assignNum); + public CommonResponse assignNum(@RequestParam("customId") Long customId, + @RequestParam(value = "assignNum", required = false) Integer assignNum, + @RequestParam(value = "assignBill", required = false) Integer assignBill) { + return customManageService.assignNum(customId, assignNum, assignBill); } @ApiOperation("查询任务(分页)") diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelCustom.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelCustom.java index 0fd1cf48..c43f1d9d 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelCustom.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelCustom.java @@ -89,13 +89,13 @@ public class ChannelCustom implements Serializable { @Column(name = "custom_limit_num") private Integer customLimitNum; -// @ApiModelProperty(value = "总话费") -// @Column(name = "total_phone_bill") -// private Integer totalPhoneBill; -// -// @ApiModelProperty(value = "剩余话费") -// @Column(name = "surplus_phone_bill") -// private Integer surplusPhoneBill; + @ApiModelProperty(value = "总话费") + @Column(name = "total_phone_bill") + private Integer totalPhoneBill; + + @ApiModelProperty(value = "剩余话费") + @Column(name = "surplus_phone_bill") + private Integer surplusPhoneBill; @ApiModelProperty(value = "子账号") @Transient @@ -119,8 +119,8 @@ public class ChannelCustom implements Serializable { this.setType(1); this.setTotalNum(0); this.setSurplusNum(0); -// this.setTotalPhoneBill(0); -// this.setSurplusPhoneBill(0); + this.setTotalPhoneBill(0); + this.setSurplusPhoneBill(0); this.setStatus(1); this.setActivationCode(null); this.setCreateTime(DateUtil.date()); @@ -138,8 +138,8 @@ public class ChannelCustom implements Serializable { this.setType(2); this.setTotalNum(0); this.setSurplusNum(0); -// this.setTotalPhoneBill(0); -// this.setSurplusPhoneBill(0); + this.setTotalPhoneBill(0); + this.setSurplusPhoneBill(0); this.setStatus(1); String activeCode = "by" + NumUtil.getFourNum(parentId.intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); this.setActivationCode(activeCode); @@ -148,6 +148,8 @@ public class ChannelCustom implements Serializable { this.setParentId(parentId); this.setUserId(userId); this.setPhone(phone); + this.setCustomLimitNum(100); + this.setChannelLimitNum(1); return this; } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelResourceAssign.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelResourceAssign.java index d20c7f2f..bbb01920 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelResourceAssign.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelResourceAssign.java @@ -32,6 +32,10 @@ public class ChannelResourceAssign implements Serializable { @Column(name = "assign_num") private Integer assignNum; + @ApiModelProperty(value = "分配话费") + @Column(name = "assign_bill") + private Integer assignBill; + @ApiModelProperty(value = "分配人id") @Column(name = "assign_by") private Long assignBy; @@ -44,9 +48,10 @@ public class ChannelResourceAssign implements Serializable { @Column(name = "create_time") private Date createTime; - public ChannelResourceAssign addChannelResourceAssign(Long channelId, Integer assignNum, Long assignBy, String assignName) { + public ChannelResourceAssign addChannelResourceAssign(Long channelId, Long assignBy, String assignName) { this.setChannelId(channelId); - this.setAssignNum(assignNum); + this.setAssignNum(0); + this.setAssignBill(0); this.setAssignBy(assignBy); this.setAssignName(assignName); this.setCreateTime(DateUtil.date()); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/vo/CustomReportVo.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/vo/CustomReportVo.java index e0ffb038..195f971f 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/vo/CustomReportVo.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/vo/CustomReportVo.java @@ -46,7 +46,33 @@ public class CustomReportVo { */ private Integer customSurplusNum = 0; - public CustomReportVo addCustomReportVo(Integer totalNum, Integer surplusNum, Integer assignNum, Integer channelNum, Integer channelTotalNum, Integer channelSurplusNum, Integer customNum, Integer customTotalNum, Integer customSurplusNum) { + /** + * 总话费分钟数 + */ + private Integer totalBill = 0; + /** + * 可分配分钟数 + */ + private Integer surplusBill = 0; + /** + * 已分配分钟数 + */ + private Integer assignBill = 0; +// /** +// * 渠道商总分配数 +// */ +// private Integer channelTotalBill = 0; +// /** +// * 直客总分钟数 +// */ +// private Integer customTotalBill = 0; +// /** +// * 直客剩余可分配数 +// */ +// private Integer customSurplusBill = 0; + + public CustomReportVo addCustomReportVo(Integer totalNum, Integer surplusNum, Integer assignNum, Integer channelNum, Integer channelTotalNum, Integer channelSurplusNum, Integer customNum, Integer customTotalNum, Integer customSurplusNum, + Integer totalBill, Integer surplusBill, Integer assignBill) { this.setTotalNum(totalNum); this.setSurplusNum(surplusNum); this.setAssignNum(assignNum); @@ -56,6 +82,12 @@ public class CustomReportVo { this.setCustomNum(customNum); this.setCustomTotalNum(customTotalNum); this.setCustomSurplusNum(customSurplusNum); + this.setTotalBill(totalBill); + this.setSurplusBill(surplusBill); + this.setAssignBill(assignBill); +// this.setChannelTotalBill(channelTotalBill); +// this.setCustomTotalBill(customTotalBill); +// this.setCustomSurplusBill(customSurplusBill); return this; } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelCustomRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelCustomRepository.java index b6b7fb22..07bb9536 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelCustomRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelCustomRepository.java @@ -122,6 +122,18 @@ public interface ChannelCustomRepository extends JpaRepository assignNum(Long customId, Integer assignNum); + CommonResponse assignNum(Long customId, Integer assignNum, Integer assignBill); /** * 统计 diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/CustomManageService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/CustomManageService.java index 553fd9bb..84416dad 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/CustomManageService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/CustomManageService.java @@ -27,9 +27,10 @@ public interface CustomManageService { * * @param customId 客户id * @param assignNum 分配量 + * @param assignNum 分配话费 * @return 成功状态 */ - CommonResponse assignNum(Long customId, Integer assignNum); + CommonResponse assignNum(Long customId, Integer assignNum, Integer assignBill); /** * 渠道商 客户列表 diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelManageServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelManageServiceImpl.java index 2c17c84f..2d4b9bfd 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelManageServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelManageServiceImpl.java @@ -95,7 +95,7 @@ public class ChannelManageServiceImpl implements ChannelManageService { if (DateUtil.compare(dateTime, startTime, "yyyy-MM-dd") >= 0) { weekNum += 1; } - if (DateUtil.compare(dateTime, yesterday, "yyyy-MM-dd") >= 0) { + if (DateUtil.compare(dateTime, yesterday, "yyyy-MM-dd") == 0) { dayNum += 1; } } @@ -149,9 +149,11 @@ public class ChannelManageServiceImpl implements ChannelManageService { channelCustom.setStatus(3); channelCustom.setSurplusNum(0); //返回话费 + int bill = channelCustom.getSurplusPhoneBill(); + channelCustom.setSurplusPhoneBill(0); list.add(channelCustom); if (channelCustom.getParentId() != null) { - channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num); + channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num, bill); } } channelCustomRepository.saveAll(list); @@ -174,46 +176,4 @@ public class ChannelManageServiceImpl implements ChannelManageService { } channelCustomRepository.save(channelCustomNew); } - - /** - * 可以禁用渠道商的方法 - * - * @param ids - */ - @Transactional(rollbackFor = Exception.class) - public void forbiddenAll(Set ids) { - List list = new ArrayList<>(); - List channelCustoms = channelCustomRepository.findAllById(ids); - for (ChannelCustom channelCustom : channelCustoms) { - int num = 0; - num = disableChannelById(channelCustom, list, num); - //增加父渠道商的余量 - if (channelCustom.getParentId() != null) { - channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num); - } - } - channelCustomRepository.saveAll(list); - //同步 - List userIdByIds = channelCustomRepository.findUserIdByIds(ids); - userService.updateUserStatusByCompanyId(false, userIdByIds); - } - - private Integer disableChannelById(ChannelCustom custom, List channelCustoms, Integer num) { - //禁用自己 - custom.setStatus(3); - custom.setSurplusNum(0); - custom.setTotalNum(0); - channelCustoms.add(custom); - num += custom.getSurplusNum(); - //代理商 - if (custom.getType() == 1) { - List byParentId = channelCustomRepository.findByParentId(custom.getId()); - if (CollUtil.isNotEmpty(byParentId)) { - for (ChannelCustom channelCustom : byParentId) { - num += disableChannelById(channelCustom, channelCustoms, num); - } - } - } - return num; - } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelResourceAssignServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelResourceAssignServiceImpl.java index 74e005fc..01871b68 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelResourceAssignServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelResourceAssignServiceImpl.java @@ -55,16 +55,27 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe @Override @Transactional(rollbackFor = Exception.class) - public CommonResponse assignNum(Long customId, Integer assignNum) { + public CommonResponse assignNum(Long customId, Integer assignNum, Integer assignBill) { + if (assignBill == null && assignNum == null) { + return CommonResponse.createByErrorMessage("请选择正确充值数量"); + } ChannelCustom channelCustom = channelCustomRepository.findById(customId).orElse(new ChannelCustom()); + //配量记录 + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(null, customId, channelCustom.getChannelName()); + //增加客户的总量和余量 - channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); - channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); + if (assignNum != null && assignNum > 0) { + channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); + channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); + channelResourceAssign.setAssignNum(assignNum); + } + if (assignBill != null) { + channelCustom.setTotalPhoneBill(channelCustom.getTotalPhoneBill() + assignBill); + channelCustom.setSurplusPhoneBill(channelCustom.getSurplusPhoneBill() + assignBill); + channelResourceAssign.setAssignBill(assignBill); + } channelCustom.setPurchaseTime(DateUtil.date()); channelCustomRepository.save(channelCustom); - - //配量记录 - ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(null, assignNum, customId, channelCustom.getChannelName()); channelResourceAssignRepository.save(channelResourceAssign); return CommonResponse.createBySuccess(); } @@ -76,25 +87,34 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe int totalNum = 0; int yesterdayNum = 0; int todayNum = 0; + int totalBill = 0; + int yesterdayBill = 0; + int todayBill = 0; DateTime date = DateUtil.parseDate(DateUtil.today()); DateTime yesterday = DateUtil.offsetDay(date, -1); for (ChannelResourceAssign channelResourceAssign : all) { //总分配数 totalNum += channelResourceAssign.getAssignNum(); + totalBill += channelResourceAssign.getAssignBill(); Date createTime = channelResourceAssign.getCreateTime(); //今日日 - if (DateUtil.compare(createTime, date, "yyyy-MM-dd") >= 0) { + if (DateUtil.compare(createTime, date, "yyyy-MM-dd") == 0) { todayNum += channelResourceAssign.getAssignNum(); + todayBill += channelResourceAssign.getAssignBill(); } //昨日 - if (DateUtil.compare(createTime, yesterday, "yyyy-MM-dd") >= 0) { + if (DateUtil.compare(createTime, yesterday, "yyyy-MM-dd") == 0) { yesterdayNum += channelResourceAssign.getAssignNum(); + yesterdayBill += channelResourceAssign.getAssignBill(); } } Map map = new HashMap<>(3); map.put("totalNum", totalNum); map.put("yesterdayNum", yesterdayNum); map.put("todayNum", todayNum); + map.put("totalBill", totalBill); + map.put("yesterdayBill", yesterdayBill); + map.put("todayBill", todayBill); return CommonResponse.createBySuccess(map); } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/CustomManageServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/CustomManageServiceImpl.java index 73d5d53a..5fefa951 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/CustomManageServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/CustomManageServiceImpl.java @@ -93,23 +93,23 @@ public class CustomManageServiceImpl implements CustomManageService { channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER); //设置分配 - if (channelCustom.getTotalNum() != null && channelCustom.getTotalNum() > 0) { -// if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { -// if (channelCustom.getTotalNum() < DefaultNumberConstants.TEN_THOUSAND) { -// return CommonResponse.createByErrorMessage("渠道商账号最低分配1万"); -// } -// } else { -// if (channelCustom.getTotalNum() < DefaultNumberConstants.ONE_THOUSAND) { -// return CommonResponse.createByErrorMessage("直客账号最低分配1000"); -// } -// } - if (parent.getSurplusNum() == null || parent.getSurplusNum() < channelCustom.getTotalNum()) { - return CommonResponse.createByErrorMessage("可分配的余量不足"); + if (channelCustom.getTotalNum() != null && channelCustom.getTotalPhoneBill() != null) { + if (channelCustom.getTotalNum() != null && channelCustom.getTotalNum() > 0) { + if (parent.getSurplusNum() == null || parent.getSurplusNum() < channelCustom.getTotalNum()) { + return CommonResponse.createByErrorMessage("可分配的余量不足"); + } + channelCustom.setSurplusNum(channelCustom.getTotalNum()); + //减掉渠道商余量 + parent.setSurplusNum(parent.getSurplusNum() - channelCustom.getTotalNum()); + } + if (channelCustom.getTotalPhoneBill() != null && channelCustom.getTotalPhoneBill() > 0) { + if (parent.getSurplusPhoneBill() == null || parent.getSurplusPhoneBill() < channelCustom.getTotalPhoneBill()) { + return CommonResponse.createByErrorMessage("可分配的话费不足"); + } + channelCustom.setSurplusPhoneBill(channelCustom.getTotalPhoneBill()); + parent.setSurplusPhoneBill(parent.getSurplusPhoneBill() - channelCustom.getSurplusPhoneBill()); } - channelCustom.setSurplusNum(channelCustom.getTotalNum()); channelCustom.setPurchaseTime(DateUtil.date()); - //减掉渠道商余量 - parent.setSurplusNum(parent.getSurplusNum() - channelCustom.getTotalNum()); channelCustomRepository.save(parent); } @@ -142,10 +142,21 @@ public class CustomManageServiceImpl implements CustomManageService { channelCustom.setCustomLimitNum(100); } channelCustom.setCreateTime(DateUtil.date()); + channelCustom.setCustomLimitNum(100); + channelCustom.setChannelLimitNum(1); channelCustomRepository.save(channelCustom); + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), channelCustom.getId(), channelCustom.getChannelName()); + boolean flag = false; if (channelCustom.getSurplusNum() != null && channelCustom.getSurplusNum() > 0) { //分配记录 - ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), channelCustom.getTotalNum(), channelCustom.getId(), channelCustom.getChannelName()); + channelResourceAssign.setAssignNum(channelCustom.getSurplusNum()); + flag = true; + } + if (channelCustom.getSurplusPhoneBill() != null && channelCustom.getSurplusPhoneBill() > 0) { + channelResourceAssign.setAssignBill(channelCustom.getSurplusPhoneBill()); + flag = true; + } + if (flag) { channelResourceAssignRepository.save(channelResourceAssign); } return CommonResponse.createBySuccess(); @@ -153,30 +164,36 @@ public class CustomManageServiceImpl implements CustomManageService { @Override @Transactional(rollbackFor = Exception.class) - public CommonResponse assignNum(Long customId, Integer assignNum) { + public CommonResponse assignNum(Long customId, Integer assignNum, Integer assignBill) { + if (assignBill == null && assignNum == null) { + return CommonResponse.createByErrorMessage("请选择正确充值数量"); + } ChannelCustom channelCustom = channelCustomRepository.findById(customId).orElse(new ChannelCustom()); ChannelCustom parent = channelCustomRepository.findById(channelCustom.getParentId()).orElse(new ChannelCustom()); + //添加分配记录 + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), customId, channelCustom.getChannelName()); int parentSurplusNum = parent.getSurplusNum(); -// if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { -// if (assignNum < DefaultNumberConstants.TEN_THOUSAND) { -// return CommonResponse.createByErrorMessage("渠道商账号最低分配1万"); -// } -// } else { -// if (assignNum < DefaultNumberConstants.ONE_THOUSAND) { -// return CommonResponse.createByErrorMessage("直客账号最低分配1000"); -// } -// } - if (parentSurplusNum < assignNum) { - return CommonResponse.createByErrorMessage("可分配的余量不足"); + int parentSurplusBill = parent.getSurplusPhoneBill(); + if (assignNum != null) { + if (parentSurplusNum < assignNum) { + return CommonResponse.createByErrorMessage("可分配的余量不足"); + } + parent.setSurplusNum(parentSurplusNum - assignNum); + channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); + channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); + channelResourceAssign.setAssignNum(assignNum); + } + if (assignBill != null) { + if (parentSurplusBill < assignBill) { + return CommonResponse.createByErrorMessage("可分配的话费不足"); + } + parent.setSurplusPhoneBill(parentSurplusBill - assignBill); + channelCustom.setTotalPhoneBill(channelCustom.getTotalPhoneBill() + assignBill); + channelCustom.setSurplusPhoneBill(channelCustom.getSurplusPhoneBill() + assignBill); + channelResourceAssign.setAssignBill(assignBill); } - //扣减父级渠道商的余量 - parent.setSurplusNum(parentSurplusNum - assignNum); - //增加客户的总量和余量 - channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); - channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); channelCustom.setPurchaseTime(DateUtil.date()); - //添加分配记录 - ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), assignNum, customId, channelCustom.getChannelName()); + channelResourceAssignRepository.save(channelResourceAssign); channelCustomRepository.save(parent); channelCustomRepository.save(channelCustom); @@ -269,6 +286,10 @@ public class CustomManageServiceImpl implements CustomManageService { int surplusNum = channelCustomByUserId.getSurplusNum(); int assignNum = totalNum - surplusNum; + int totalBill = channelCustomByUserId.getTotalPhoneBill(); + int surplusBill = channelCustomByUserId.getSurplusPhoneBill(); + int assignBill = totalBill - surplusBill; + List channelCustoms = channelCustomRepository.findByParentId(channelCustomByUserId.getId()); int channelNum = 0; int channelTotalNum = 0; @@ -288,7 +309,8 @@ public class CustomManageServiceImpl implements CustomManageService { customSurplusNum += channelCustom.getSurplusNum(); } } - CustomReportVo customReportVo = new CustomReportVo().addCustomReportVo(totalNum, surplusNum, assignNum, channelNum, channelTotalNum, channelSurplusNum, customNum, customTotalNum, customSurplusNum); + CustomReportVo customReportVo = new CustomReportVo().addCustomReportVo(totalNum, surplusNum, assignNum, channelNum, channelTotalNum, channelSurplusNum, customNum, customTotalNum, customSurplusNum, + totalBill, surplusBill, assignBill); return CommonResponse.createBySuccess(customReportVo); } @@ -331,12 +353,14 @@ public class CustomManageServiceImpl implements CustomManageService { @Transactional(rollbackFor = Exception.class) public void deleteByUserId(Long userId) { ChannelCustom byUserId = channelCustomRepository.findByUserId(userId); - Integer num = 0; + int num = 0; + int bill = 0; if (byUserId.getType() == 2) { num = byUserId.getSurplusNum(); + bill = byUserId.getSurplusPhoneBill(); channelCustomRepository.deleteByUserId(userId); } - channelCustomRepository.updateSurplusNum(byUserId.getParentId(), num); + channelCustomRepository.updateSurplusNum(byUserId.getParentId(), num, bill); } @@ -360,13 +384,15 @@ public class CustomManageServiceImpl implements CustomManageService { ChannelCustom custom = channelCustomRepository.findByUserId(userId); List channelCustoms = new ArrayList<>(); List num = new ArrayList<>(); - disableChannelById(custom, channelCustoms, num); + List bill = new ArrayList<>(); + disableChannelById(custom, channelCustoms, num, bill); //禁用 channelCustomRepository.saveAll(channelCustoms); //增加父渠道商的余量 if (custom.getParentId() != null) { - Integer integer = num.stream().reduce(Integer::sum).orElse(0); - channelCustomRepository.updateSurplusNum(custom.getParentId(), integer); + int integer = num.stream().reduce(Integer::sum).orElse(0); + int integer1 = bill.stream().reduce(Integer::sum).orElse(0); + channelCustomRepository.updateSurplusNum(custom.getParentId(), integer, integer1); } return channelCustoms.stream().map(ChannelCustom::getUserId).collect(Collectors.toList()); } @@ -379,10 +405,13 @@ public class CustomManageServiceImpl implements CustomManageService { } } - private void disableChannelById(ChannelCustom custom, List channelCustoms, List num) { + private void disableChannelById(ChannelCustom custom, List channelCustoms, List num, List bill) { num.add(custom.getSurplusNum()); + bill.add(custom.getSurplusPhoneBill()); custom.setStatus(3); custom.setSurplusNum(0); + custom.setSurplusPhoneBill(0); + custom.setTotalPhoneBill(0); custom.setTotalNum(0); channelCustoms.add(custom); //代理商 @@ -390,7 +419,7 @@ public class CustomManageServiceImpl implements CustomManageService { List byParentId = channelCustomRepository.findByParentId(custom.getId()); if (CollUtil.isNotEmpty(byParentId)) { for (ChannelCustom channelCustom : byParentId) { - disableChannelById(channelCustom, channelCustoms, num); + disableChannelById(channelCustom, channelCustoms, num, bill); } } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Clue.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Clue.java index eb4cc1c2..a267d55c 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Clue.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Clue.java @@ -28,4 +28,7 @@ public class Clue extends BaseClue { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @ApiModelProperty(value = "线索分配人") + @Transient + private Long memberId; } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java index c85b1d52..dc5c6760 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java @@ -252,3 +252,4 @@ public class CompanyServiceImpl implements CompanyService { return PageUtil.toPage(comboVOList, page.getTotalElements()); } } + diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java index a1d482a3..2ad69ef2 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java @@ -764,6 +764,7 @@ public class UserServiceImpl implements UserService { ChannelCustom custom = customManageService.findByUserId(user.getId()); if (custom != null) { convert.setSurplusNum(custom.getSurplusNum()); + convert.setSurplusBill(custom.getSurplusPhoneBill()); } } OrganizeUser organizeUser = organizeUserRepository.findByUserId(user.getId()); 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 d8ce1a0b..cef3d127 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 @@ -48,6 +48,10 @@ public class TelephoneCallController { @PostMapping("/telephone/req") @ApiOperation("拨打电话") public CommonResponse doubleCallReq(@Validated @RequestBody TelephoneCallReqDTO telephoneCallReqDTO) { + int hour = DateUtil.hour(DateUtil.date(), true); + if (hour < DefaultNumberConstants.EIGHT_NUMBER || hour >= DefaultNumberConstants.TWENTY_ONE) { + return CommonResponse.createByErrorMessage("请在8点-21点之间拨打电话"); + } //判断账号是否到期 Date expirationTime = userService.findExpirationTimeByUserId(SecurityUtils.getCurrentUserId()); if (ObjectUtil.isNull(expirationTime) @@ -66,9 +70,10 @@ public class TelephoneCallController { if (ObjectUtil.isNull(organize) || ObjectUtil.isNull(company)) { return CommonResponse.createByErrorMessage("缺失小组信息或公司信息"); } - if (company.getUserBalance() == null || company.getUserBalance() <= 0) { - return CommonResponse.createByErrorMessage("余额不足,请充值后使用"); - } +// if (company.getUserBalance() == null || company.getUserBalance() <= 0) { +// return CommonResponse.createByErrorMessage("余额不足,请充值后使用"); +// } + if (organize.getCallMode() == null) { return CommonResponse.createByErrorMessage("请指定呼叫方式后使用"); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoost.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoost.java index 623db55a..b44addb6 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoost.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoost.java @@ -50,11 +50,16 @@ public class ClueBoost { @ApiModelProperty(value = "创建时间") private Date createTime; + @Column(name = "update_time") + @ApiModelProperty(value = "修改时间") + private Date updateTime; + public ClueBoost addClueBoost(Long clueId, Long memberId, Integer clueType, Long whichUserId) { this.setClueId(clueId); this.setMemberId(memberId); this.setClueType(clueType); this.setCreateTime(DateUtil.date()); + this.setUpdateTime(DateUtil.date()); this.setWhichUserId(whichUserId); this.setStatus(false); return this; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoostRecord.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoostRecord.java index 2a113eaa..2e5a8fa8 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoostRecord.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/ClueBoostRecord.java @@ -28,6 +28,10 @@ public class ClueBoostRecord { @ApiModelProperty(value = "线索id") private Long whichUserId; + @Column(name = "boost_num") + @ApiModelProperty(value = "补量数") + private Integer boostNum; + @Column(name = "create_time") @ApiModelProperty(value = "创建时间") private Date createTime; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/ClueBoostDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/ClueBoostDTO.java index b03d621b..edf4a05d 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/ClueBoostDTO.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/dto/ClueBoostDTO.java @@ -30,7 +30,7 @@ public class ClueBoostDTO { private Date lastTime; private Long memberId; - + private Long whichUserId; private Integer clueType; /** @@ -38,9 +38,10 @@ public class ClueBoostDTO { */ private Boolean status; - public ClueBoostDTO addClueBoostDTO(Long clueId, Long memberId, Integer clueType, Boolean status) { + public ClueBoostDTO addClueBoostDTO(Long clueId, Long memberId, Long whichUserId, Integer clueType, Boolean status) { this.setClueId(clueId); this.setMemberId(memberId); + this.setWhichUserId(whichUserId); this.setClueType(clueType); this.setStatus(status); return this; 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 996a2568..277f40f9 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 @@ -4,11 +4,9 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import com.baiye.constant.DefaultNumberConstants; import com.baiye.feign.SourceClueClient; -import com.baiye.model.dto.UserDto; import com.baiye.modules.agent.repository.ChannelCustomRepository; -import com.baiye.modules.system.domain.User; -import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.telemarkting.dao.ClueBoostRecordRepository; import com.baiye.modules.telemarkting.dao.ClueBoostRepository; import com.baiye.modules.telemarkting.entity.ClueBoost; @@ -55,8 +53,6 @@ public class ClueBoostServiceImpl implements ClueBoostService { private ChannelCustomRepository channelCustomRepository; @Resource private ClueBoostRecordRepository clueBoostRecordRepository; - @Resource - private UserRepository userRepository; @Override public Object queryAll(ClueBoostQueryCriteria clueBoostQueryCriteria, Pageable pageable) { @@ -72,9 +68,11 @@ public class ClueBoostServiceImpl implements ClueBoostService { Integer integer = clueBoostRepository.updateStatusByIds(true, ids); Long currentUserId = SecurityUtils.getCurrentUserId(); channelCustomRepository.updateSurplusNumByUserId(currentUserId, integer); + ClueBoostRecord clueBoostRecord = new ClueBoostRecord(); clueBoostRecord.setWhichUserId(currentUserId); clueBoostRecord.setCreateTime(DateUtil.date()); + clueBoostRecord.setBoostNum(integer); clueBoostRecordRepository.save(clueBoostRecord); } @@ -94,24 +92,22 @@ public class ClueBoostServiceImpl implements ClueBoostService { //上一次拨打距离当前时间间隔1小时 Date lastTime = clueBoost.getLastTime(); long betweenLast = DateUtil.between(lastTime, DateUtil.date(), DateUnit.HOUR); - if (betweenLast < 1) { + if (betweenLast < DefaultNumberConstants.ONE_NUMBER) { return; } //第一次拨打后 24小时内需2通 Date firstTime = clueBoost.getFirstTime(); long betweenFirst = DateUtil.between(firstTime, DateUtil.date(), DateUnit.HOUR); Integer callNum = clueBoost.getCallNum(); - if (betweenFirst <= 24) { + if (betweenFirst <= DefaultNumberConstants.TWENTY_FOUR) { clueBoost.setCallNum(callNum + 1); clueBoost.setLastTime(DateUtil.date()); redisUtils.set(KEY + clueBoostDTO.getClueId(), clueBoost, 48 - betweenFirst, TimeUnit.HOURS); return; - } else if (betweenFirst < 48) { - if (callNum >= 2) { + } else if (betweenFirst < DefaultNumberConstants.FORTY_EIGHT) { + if (callNum >= DefaultNumberConstants.TWO_NUMBER) { //满足补量 - User user = userRepository.findById(clueBoost.getMemberId()).orElseGet(User::new); - Long whichUserId = user.getWhichUserId(); - ClueBoost clueBoostNew = new ClueBoost().addClueBoost(clueBoost.getClueId(), clueBoost.getMemberId(), clueBoost.getClueType(), whichUserId); + ClueBoost clueBoostNew = new ClueBoost().addClueBoost(clueBoost.getClueId(), clueBoost.getMemberId(), clueBoost.getClueType(), clueBoostDTO.getWhichUserId()); // 修改线索为冻结 sourceClueClient.updateTalkClueFreeze(clueBoost.getClueId(), true); clueBoostRepository.save(clueBoostNew); 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 f113528a..8129003f 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 @@ -11,12 +11,17 @@ import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; import com.baiye.feign.SourceClueClient; import com.baiye.http.CommonResponse; +import com.baiye.model.dto.CallClueDTO; +import com.baiye.model.dto.ClueDto; +import com.baiye.model.dto.UserDto; import com.baiye.model.enums.CallStatusEnum; +import com.baiye.modules.agent.repository.ChannelCustomRepository; import com.baiye.modules.platform.domain.CallDeduct; import com.baiye.modules.platform.domain.Clue; import com.baiye.modules.platform.domain.Company; import com.baiye.modules.platform.repository.CallDeductRepository; import com.baiye.modules.platform.service.CompanyService; +import com.baiye.modules.system.domain.User; import com.baiye.modules.system.service.UserService; import com.baiye.modules.telemarkting.dao.*; import com.baiye.modules.telemarkting.entity.*; @@ -70,6 +75,9 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { @Resource private ApplicationContext applicationContext; + @Resource + private ChannelCustomRepository channelCustomRepository; + @Override public CommonResponse doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) { String requestId = RandomUtil.randomString(10); @@ -124,8 +132,10 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { callClueRepository.updateByStatus(status, userDate); allCallInfo.setStatus(status); allCallInfoRepository.save(allCallInfo); + UserDto user = userService.findById(allCallInfo.getMemberId()); + Long whichUserId = user.getWhichUserId(); //实时扣费 - callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), allCallInfo.getDuration(), DefaultNumberConstants.TWO_NUMBER); + callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), allCallInfo.getDuration(), DefaultNumberConstants.TWO_NUMBER, whichUserId); //更新资源通话状态 CompletableFuture.runAsync(() -> updateSourceCallStatus(userDate, DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType())); } else { @@ -175,6 +185,13 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { @Override public CommonResponse rollCallReq(TelephoneCallReqDTO telephoneCallReqDTO, Long companyId) { + //检查余量 + UserDto user = userService.findById(telephoneCallReqDTO.getMemberId()); + Long whichUserId = user.getWhichUserId(); + Integer surplusPhoneBillByUserId = channelCustomRepository.findSurplusPhoneBillByUserId(whichUserId); + if (surplusPhoneBillByUserId == null || surplusPhoneBillByUserId <= 0) { + return CommonResponse.createByErrorMessage("话费不足"); + } String requestId = RandomUtil.randomString(10); telephoneCallReqDTO.setRequestId(requestId); if (telephoneCallReqDTO.getDisplay() == null || telephoneCallReqDTO.getTelA() == null) { @@ -219,9 +236,9 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } //获取被叫号 - Clue body; + CallClueDTO body; try { - body = sourceClueClient.queryDetails(Long.parseLong(telephoneCallReqDTO.getUserData())).getBody(); + body = sourceClueClient.queryDetailsByClueType(Long.parseLong(telephoneCallReqDTO.getUserData()), telephoneCallReqDTO.getClueType()).getBody(); } catch (Exception e) { log.error("获取被叫号错误:{},time:{} ", e.getMessage(), DateUtil.now()); throw new BadRequestException("呼叫失败"); @@ -230,6 +247,9 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { log.error("未获取到号码"); return CommonResponse.createByErrorMessage("未获取到号码"); } + if (body.getMemberId() == null) { + return CommonResponse.createByErrorMessage("线索未分配,请刷新后重试"); + } telephoneCallReqDTO.setTelB("474" + telephoneCallReqDTO.getDisplay() + body.getNid()); //请求呼叫 String reqId = rollCallReq.startReq(telephoneCallReqDTO); @@ -273,6 +293,8 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { allCallInfoRepository.updateByRecord(DefaultNumberConstants.ONE_NUMBER, rollCallBackDTO.getRecord_file_url(), allCallInfo.getId()); } else { log.info("被叫回调-点呼:otherLeg:{},详情:{}", otherLeg, rollCallBackDTO); + UserDto user = userService.findById(allCallInfo.getMemberId()); + Long whichUserId = user.getWhichUserId(); boolean status; //拨打线索号的回调 if (StrUtil.isNotBlank(rollCallBackDTO.getCallee_answer_time())) { @@ -282,7 +304,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { //更新资源通话状态 CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType())); //实时扣除话费 - callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2); + callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2, whichUserId); status = true; } else { //更新资源通话状态 @@ -290,7 +312,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { status = false; } if (Arrays.asList(ClueTypeConstants.TOKER_TYPE).contains(allCallInfo.getClueType())) { - ClueBoostDTO clueBoostDTO = new ClueBoostDTO().addClueBoostDTO(allCallInfo.getClueId(), allCallInfo.getMemberId(), allCallInfo.getClueType(), null); + ClueBoostDTO clueBoostDTO = new ClueBoostDTO().addClueBoostDTO(allCallInfo.getClueId(), allCallInfo.getMemberId(), whichUserId, allCallInfo.getClueType(), null); clueBoostDTO.setStatus(status); applicationContext.publishEvent(clueBoostDTO); } @@ -323,73 +345,74 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { * @param duration 通话时长(秒) * @param callType 呼叫类型 1-双呼 2-点呼 */ - public void callCostCount(Long memberId, Long clueId, Integer clueType, Integer duration, Integer callType) { -// Long companyId = SecurityUtils.getCompanyId(); + public void callCostCount(Long memberId, Long clueId, Integer clueType, Integer duration, Integer callType, Long whichUserId) { Long companyId = userService.findUserInfo(memberId).getCompanyId(); - Company company = companyService.findCompanyInfo(companyId); - - double minDuration = dealDuration(duration); +// Company company = companyService.findById(companyId); + int minDuration = dealDuration(duration); CallDeduct callDeduct = new CallDeduct(); - callDeduct.setDeductDuration((int) minDuration); + callDeduct.setDeductDuration(minDuration); callDeduct.setClueId(clueId); callDeduct.setMemberId(memberId); callDeduct.setCompanyId(companyId); callDeduct.setStatus(false); callDeduct.setCreateTime(new Date()); - callDeduct.setVersion(company.getVersion()); + 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 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.setComboType(typeStr); +// 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); +// updateBalance(mul, companyId, company.getVersion(), save, whichUserId); + updateBalance(save, whichUserId, minDuration); } - private void updateBalance(Double mul, Long companyId, Integer version, CallDeduct save) { - int num = companyService.updateBalanceOptimistic(mul, companyId, version); + 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.setVersion(version); save.setStatus(true); callDeductRepository.save(save); - } else { - updateBalance(mul, companyId, version + 1, save); } +// else { +// updateBalance(mul, companyId, version + 1, save); +// } } /** @@ -398,9 +421,9 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { * @param duration * @return */ - private double dealDuration(int duration) { + private Integer dealDuration(int duration) { if (duration <= DefaultNumberConstants.SIXTY) { - return 1.00; + return 1; } else { //余数 int i = duration % 60; @@ -408,7 +431,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { int q = duration / 60; if (i > 0) { - return NumberUtil.add(q, 1); + return q + 1; } else { return q; } diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/CallClueDTO.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/CallClueDTO.java new file mode 100644 index 00000000..9f98fd37 --- /dev/null +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/CallClueDTO.java @@ -0,0 +1,24 @@ +package com.baiye.model.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * @author wjt + * @date 2023/5/19 + */ +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class CallClueDTO { + + @ApiModelProperty(value = "nid") + private String nid; + + @ApiModelProperty(value = "所属组员id") + private Long memberId; +} diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/ClueQueryCriteria.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/ClueQueryCriteria.java index 3cf10b34..b3d47abe 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/dto/ClueQueryCriteria.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/ClueQueryCriteria.java @@ -83,4 +83,7 @@ public class ClueQueryCriteria { @ApiModelProperty(value = "是否是业务管理员查询, 判断是否加密字段") private Boolean isAdmin = false; + + @ApiModelProperty(value = "是否冻结") + private Boolean isFreeze; } diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java index 1317ea6b..3313a09b 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java @@ -98,4 +98,6 @@ public class UserDto extends BaseDTO implements Serializable { private String jobNumber; private Integer surplusNum; + + private Integer surplusBill; } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java index 0bc3f160..d625be93 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java @@ -92,6 +92,12 @@ public class ClueController { return new ResponseEntity<>(clueService.queryDetails(clueId), HttpStatus.OK); } + @ApiOperation("查询资源详情") + @GetMapping("/queryDetailsByClueType") + public ResponseEntity queryDetailsByClueType(@RequestParam("clueId") Long clueId, @RequestParam("clueType") Integer clueType) { + return new ResponseEntity<>(clueService.queryDetailsByClueType(clueId,clueType), HttpStatus.OK); + } + @ApiOperation("更新资源信息") @PostMapping("/update") @Inner(value = false) diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java index 57988542..7c3b374d 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java @@ -5,13 +5,12 @@ import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONUtil; +import com.baiye.constant.AdPlatFormConstants; +import com.baiye.constant.ClueTypeConstants; import com.baiye.constant.KeyFieldConstants; import com.baiye.exception.BadRequestException; import com.baiye.feign.TaskClient; -import com.baiye.model.dto.ClueDto; -import com.baiye.model.dto.ClueQueryCriteria; -import com.baiye.model.dto.PublicCluePoolDto; -import com.baiye.model.dto.PublicCluePoolQueryCriteria; +import com.baiye.model.dto.*; import com.baiye.model.vo.ResSourceLabel; import com.baiye.module.service.dto.ClueTalkDTO; import com.baiye.util.AESUtils; @@ -192,6 +191,9 @@ public class ClueJpa { if (userId != null) { sql.append("and c.create_by = :userId "); } + if (clueQueryCriteria.getIsFreeze() != null) { + sql.append("and cm.is_freeze = :isFreeze "); + } //拼接最后加入时间排序,没加id排序出现数据重复问题(注意空格) sql.append("ORDER BY c.create_time desc ,c.id "); @@ -264,6 +266,9 @@ public class ClueJpa { if (userId != null) { query.setParameter("userId", userId); } + if (clueQueryCriteria.getIsFreeze() != null) { + query.setParameter("isFreeze", clueQueryCriteria.getIsFreeze()); + } query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); return query.getResultList(); } @@ -551,4 +556,39 @@ public class ClueJpa { } return clueDtoList; } + + + /** + * 查询线索 + * + * @param clueId + * @return + */ + @Transactional(rollbackOn = Exception.class) + public CallClueDTO queryDetailsByClueType(Long clueId, Integer clueType) { + StringBuilder sql = null; + if (Arrays.asList(ClueTypeConstants.SCREEN_TYPE).contains(clueType)) { + sql = new StringBuilder("select tc.nid as nid ,tcm.member_id as memberId " + + "from tb_clue_middle as tcm left join tb_clue as tc on tcm.clue_id =tc.id where tc.id =:clueId "); + } else if (Arrays.asList(ClueTypeConstants.TOKER_TYPE).contains(clueType)) { + sql = new StringBuilder("select tc.nid as nid ,tcm.member_id as memberId " + + "from tb_clue_talk as tcm left join tb_clue as tc on tcm.clue_id =tc.id where tc.id =:clueId "); + } + assert sql != null; + Query query = entityManager.createNativeQuery(sql.toString()); + query.setParameter("clueId", clueId); + query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); + List list = query.getResultList(); + if (CollUtil.isNotEmpty(list) && list.size() > 0) { + Map row = (Map) list.get(0); + CallClueDTO clueDto = new CallClueDTO(); + String s = (String) row.get("nid"); + String nid = AESUtils.decrypt(s, AdPlatFormConstants.AD_PLATFORM); + clueDto.setNid(nid); + BigInteger memberId = (BigInteger) row.get("memberId"); + clueDto.setMemberId(memberId.longValue()); + return clueDto; + } + return null; + } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueTalk.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueTalk.java index 11e44e2f..2cd7154b 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueTalk.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueTalk.java @@ -28,7 +28,7 @@ public class ClueTalk extends BaseClueMiddle { @ApiModelProperty(value = "是否冻结") @Column(name = "is_freeze") - private Boolean isFreeze; + private Boolean isFreeze = false; @Transient private String clueName; diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java index e27a94b9..adc0a7d5 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java @@ -88,6 +88,8 @@ public interface ClueService { */ Clue queryDetails(Long clueId); + CallClueDTO queryDetailsByClueType(Long clueId, Integer clueType); + /** * 查询资源标签 */ @@ -188,6 +190,7 @@ public interface ClueService { /** * 修改拓客和投流线索的冻结状态 + * * @param clueId * @param isFreeze */ 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 a9d3dd81..84cb703c 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 @@ -439,6 +439,11 @@ public class ClueServiceImpl implements ClueService { return clueRepository.findById(clueId).orElseGet(Clue::new); } + @Override + public CallClueDTO queryDetailsByClueType(Long clueId, Integer clueType) { + return clueJpa.queryDetailsByClueType(clueId, clueType); + } + @Override public List findSourceLabel(List clueIds) { return clueJpa.findSourceLabel(clueIds);