From 9800fa342f9f57bbacfde22b5e9b5676ae5ae1a3 Mon Sep 17 00:00:00 2001 From: wjt Date: Fri, 21 Apr 2023 16:28:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=A0=E9=81=93=E5=95=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChannelResourceAssignController.java | 2 +- .../controller/CustomManageController.java | 17 +- .../modules/agent/entity/ChannelCustom.java | 17 +- .../agent/entity/ChannelResourceAssign.java | 2 + .../agent/entity/query/ChannelQuery.java | 5 +- .../entity/query/ResourceAssignInfoQuery.java | 2 +- .../repository/ChannelCustomRepository.java | 11 ++ .../agent/service/CustomManageService.java | 15 +- .../impl/ChannelManageServiceImpl.java | 35 ++-- .../ChannelResourceAssignServiceImpl.java | 24 ++- .../service/impl/CustomManageServiceImpl.java | 157 ++++++++++-------- .../src/test/java/com/baiye/CustomTest.java | 3 +- .../java/com/baiye/module/dao/ClueJpa.java | 4 +- 13 files changed, 179 insertions(+), 115 deletions(-) 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 1146580d..7a32258f 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 @@ -38,7 +38,7 @@ public class ChannelResourceAssignController { } @GetMapping("/assign") @ApiOperation("配量") - public CommonResponse assignNum(@RequestParam("channelId") Long channelId, @RequestParam("customId") Integer assignNum) { + public CommonResponse assignNum(@RequestParam("channelId") Long channelId, @RequestParam("assignNum") Integer assignNum) { return channelResourceAssignService.assignNum(channelId, assignNum); } 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 d61a5a9e..bfac006a 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 @@ -4,15 +4,17 @@ import com.baiye.http.CommonResponse; import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.service.CustomManageService; +import com.baiye.valid.AddGroup; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.models.auth.In; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -28,13 +30,13 @@ public class CustomManageController { @PostMapping("/add") @ApiOperation("新增账号") - public CommonResponse addCustom(@RequestBody ChannelCustom channelCustom) { + public CommonResponse addCustom(@RequestBody @Validated({AddGroup.class}) ChannelCustom channelCustom) { return customManageService.addCustom(channelCustom); } @GetMapping("/assign") @ApiOperation("配量") - public CommonResponse assignNum(@RequestParam("customId") Long customId, @RequestParam("customId") Integer assignNum) { + public CommonResponse assignNum(@RequestParam("customId") Long customId, @RequestParam("assignNum") Integer assignNum) { return customManageService.assignNum(customId, assignNum); } @@ -44,6 +46,12 @@ public class CustomManageController { return new ResponseEntity<>(customManageService.queryAll(channelCustomQuery, pageable), HttpStatus.OK); } + @GetMapping("/dmpLimitNum") + @ApiOperation("修改dmp投送数量") + public CommonResponse updateDmpLimitNum(@RequestParam("customId") Long customId, @RequestParam("dmpLimitNum") Integer dmpLimitNum) { + return customManageService.updateDmpLimitNum(customId, dmpLimitNum); + } + @GetMapping("/link") @ApiOperation("生成链接") public CommonResponse addLink(@RequestParam("customId") Long customId, @RequestParam("type") Integer type) { @@ -51,10 +59,9 @@ public class CustomManageController { return CommonResponse.createBySuccess(linkUrl); } - @GetMapping("/linkList") @ApiOperation("渠道商链接地址") - public CommonResponse> findCustomList(@RequestParam("customId") Long customId) { + public CommonResponse>> findCustomList(@RequestParam("customId") Long customId) { return CommonResponse.createBySuccess(customManageService.findUrlByCustomId(customId)); } } 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 3bb238b8..5429199a 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 @@ -33,6 +33,7 @@ public class ChannelCustom implements Serializable { @ApiModelProperty(value = "手机") @Column(name = "phone") + @NotNull(groups = AddGroup.class) private String phone; @ApiModelProperty(value = "名称") @@ -47,11 +48,15 @@ public class ChannelCustom implements Serializable { @ApiModelProperty(value = "总分配量") @Column(name = "total_num") - private Integer totalNum; + private Integer totalNum = 0; + + @ApiModelProperty(value = "dmp每日数量") + @Column(name = "dmp_limit_num") + private Integer dmpLimitNum = 100; @ApiModelProperty(value = "分配余量") @Column(name = "surplus_num") - private Integer surplusNum; + private Integer surplusNum = 0; @ApiModelProperty(value = "用户状态 1 正常 2-待开通-3 禁用") @Column(name = "status") @@ -71,15 +76,21 @@ public class ChannelCustom implements Serializable { @ApiModelProperty(value = "父id") @Column(name = "parent_id") - @NotNull(groups = AddGroup.class) private Long parentId; + @ApiModelProperty(value = "子账号") @Transient private List children; + + @ApiModelProperty(value = "所有子账号数量") @Transient private Integer allCustomNum; + + @ApiModelProperty(value = "已开通的子账号数") @Transient private Integer normalNum; + + @ApiModelProperty(value = "待开通的子账号数") @Transient private Integer waitNum; 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 724bd09d..d20c7f2f 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 @@ -1,5 +1,6 @@ package com.baiye.modules.agent.entity; +import cn.hutool.core.date.DateUtil; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -48,6 +49,7 @@ public class ChannelResourceAssign implements Serializable { this.setAssignNum(assignNum); this.setAssignBy(assignBy); this.setAssignName(assignName); + this.setCreateTime(DateUtil.date()); return this; } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ChannelQuery.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ChannelQuery.java index e55369d5..c517b0e4 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ChannelQuery.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ChannelQuery.java @@ -15,14 +15,11 @@ public class ChannelQuery { @Query(type = Query.Type.INNER_LIKE) private String channelName; - @ApiModelProperty(value = "默认排序为0 1-总量排序 2-余量排序") - private Integer sort = 0; - @ApiModelProperty(value = "客户类型 1-渠道商 2-直客") @Query(type = Query.Type.EQUAL) private Integer type; + @ApiModelProperty(value = "父id") @Query(propName = "parentId", type = Query.Type.EQUAL) private Long id; - } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceAssignInfoQuery.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceAssignInfoQuery.java index 8f04c975..79819b02 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceAssignInfoQuery.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceAssignInfoQuery.java @@ -14,7 +14,7 @@ import java.util.List; public class ResourceAssignInfoQuery { @Query - private Long id; + private Long channelId; @Query(type = Query.Type.BETWEEN) private List createTime; 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 91e8f78f..0a883c0d 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 @@ -45,6 +45,17 @@ public interface ChannelCustomRepository extends JpaRepository ids, Integer status); + /** + * 修改dmp数量 + * + * @param customId + * @param dmpLimitNum + * @return + */ + @Modifying + @Query("UPDATE ChannelCustom set dmpLimitNum = ?2 where id = ?1") + int updateDmpLimitNum(Long customId, Integer dmpLimitNum); + /** * 根据关联的系统id查询 * 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 1f141d1f..3e229c5f 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 @@ -4,7 +4,9 @@ import com.baiye.http.CommonResponse; import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.query.ChannelQuery; import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.RequestParam; +import java.util.List; import java.util.Map; /** @@ -39,8 +41,18 @@ public interface CustomManageService { */ Object queryAll(ChannelQuery channelCustomQuery, Pageable pageable); + /** + * 修改dmp数量 + * + * @param customId + * @param dmpLimitNum + * @return + */ + CommonResponse updateDmpLimitNum(Long customId, Integer dmpLimitNum); + /** * 创建智能链接 + * * @param customId * @param type * @return @@ -49,10 +61,11 @@ public interface CustomManageService { /** * 渠道id查询列表 + * * @param customId * @return */ - Map findUrlByCustomId(Long customId); + List> findUrlByCustomId(Long customId); /** 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 7a451233..6fd2099b 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 @@ -3,9 +3,9 @@ package com.baiye.modules.agent.service.impl; import cn.hutool.core.collection.CollUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.http.CommonResponse; -import com.baiye.modules.agent.repository.ChannelCustomRepository; import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.query.ChannelQuery; +import com.baiye.modules.agent.repository.ChannelCustomRepository; import com.baiye.modules.agent.service.ChannelManageService; import com.baiye.modules.platform.service.dto.CreateUserDTO; import com.baiye.modules.system.service.UserService; @@ -40,16 +40,7 @@ public class ChannelManageServiceImpl implements ChannelManageService { @Override public Object queryAll(ChannelQuery channelQuery, Pageable pageable) { - Sort sort; - if (channelQuery.getSort() != null && channelQuery.getSort() == 1) { - sort = Sort.by(Sort.Direction.DESC, "totalNum"); - } else if (channelQuery.getSort() != null && channelQuery.getSort() == 2) { - sort = Sort.by(Sort.Direction.DESC, "surplusNum"); - } else { - sort = Sort.by(Sort.Direction.DESC, "createTime"); - } - - PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); + PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime")); Page channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest); List content = new ArrayList<>(channelCustoms.getContent()); if (CollUtil.isEmpty(content)) { @@ -58,17 +49,25 @@ public class ChannelManageServiceImpl implements ChannelManageService { //父级 Map parentMap = new HashMap<>(8); for (ChannelCustom channelCustom : content) { - if (channelCustom.getParentId() == null) { + Long parentId = channelCustom.getParentId(); + if (parentId == null) { parentMap.put(channelCustom.getId(), channelCustom); } } //查询出所有子集 Set set = parentMap.keySet(); - List byParentId = channelCustomRepository.findByParentId(set); - content.addAll(byParentId); + List byParentId = new ArrayList<>(); + if (CollUtil.isNotEmpty(set)) { + byParentId = channelCustomRepository.findByParentId(set); + } + List childrenList = content.stream().filter(channelCustom -> channelCustom.getParentId() != null).collect(Collectors.toList()); + byParentId.addAll(childrenList); + //根据id去重 + byParentId = byParentId.stream().collect(Collectors.collectingAndThen(Collectors.toCollection( + () -> new TreeSet<>(Comparator.comparing(ChannelCustom::getId))), ArrayList::new)); + //子集 - Map> userMap = content.stream().filter(channelCustom -> channelCustom.getParentId() != null) - .collect(Collectors.groupingBy(ChannelCustom::getParentId)); + Map> userMap = byParentId.stream().collect(Collectors.groupingBy(ChannelCustom::getParentId)); int allCustomNum = 0; int normalNum = 0; int waitNum = 0; @@ -81,8 +80,8 @@ public class ChannelManageServiceImpl implements ChannelManageService { } List children = userMap.get(key); if (CollUtil.isNotEmpty(children)) { - List normalNums = children.stream().filter(c -> c.getStatus() == 1).collect(Collectors.toList()); - List waitNums = children.stream().filter(c -> c.getStatus() == 2).collect(Collectors.toList()); + List normalNums = children.stream().filter(c -> c.getStatus() == DefaultNumberConstants.ONE_NUMBER).collect(Collectors.toList()); + List waitNums = children.stream().filter(c -> c.getStatus() == DefaultNumberConstants.TWO_NUMBER).collect(Collectors.toList()); normalNum = normalNums.size(); waitNum = waitNums.size(); } 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 63bcf90b..1d134eee 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 @@ -1,12 +1,13 @@ package com.baiye.modules.agent.service.impl; +import cn.hutool.core.date.DateUtil; import com.baiye.http.CommonResponse; -import com.baiye.modules.agent.repository.ChannelCustomRepository; -import com.baiye.modules.agent.repository.ChannelResourceAssignRepository; import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelResourceAssign; import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ResourceAssignInfoQuery; +import com.baiye.modules.agent.repository.ChannelCustomRepository; +import com.baiye.modules.agent.repository.ChannelResourceAssignRepository; import com.baiye.modules.agent.service.ChannelResourceAssignService; import com.baiye.util.PageUtil; import com.baiye.util.QueryHelp; @@ -30,24 +31,17 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe @Override public Object queryAll(ChannelQuery channelQuery, Pageable pageable) { - Sort sort; - if (channelQuery.getSort() != null && channelQuery.getSort() == 1) { - sort = Sort.by(Sort.Direction.DESC, "totalNum"); - } else if (channelQuery.getSort() != null && channelQuery.getSort() == 2) { - sort = Sort.by(Sort.Direction.DESC, "surplusNum"); - } else { - sort = Sort.by(Sort.Direction.DESC, "createTime"); - } channelQuery.setId(null); - PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); - Page channelCustoms = channelResourceAssignRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest); + PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime")); + Page channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest); return PageUtil.toPage(channelCustoms); } @Override public Object queryAssign(ResourceAssignInfoQuery resourceAssignInfoQuery, Pageable pageable) { - PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "create_time")); - return channelResourceAssignRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, resourceAssignInfoQuery, criteriaBuilder), pageRequest); + PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime")); + Page all = channelResourceAssignRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, resourceAssignInfoQuery, criteriaBuilder), pageRequest); + return PageUtil.toPage(all); } @Override @@ -58,6 +52,8 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); channelCustomRepository.save(channelCustom); + channelCustom.setPurchaseTime(DateUtil.date()); + channelCustomRepository.save(channelCustom); return CommonResponse.createBySuccess(); } } 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 8a8c67b4..b78251d9 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 @@ -1,13 +1,16 @@ package com.baiye.modules.agent.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.StrPool; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import com.baiye.constant.DefaultNumberConstants; +import com.baiye.exception.BadRequestException; import com.baiye.http.CommonResponse; +import com.baiye.model.enums.ResponseCode; import com.baiye.model.enums.UrlLinkEnum; import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelCustomTag; @@ -21,11 +24,13 @@ import com.baiye.modules.platform.service.dto.CreateUserDTO; import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.domain.User; import com.baiye.modules.system.service.impl.UserServiceImpl; +import com.baiye.util.MobileUtil; import com.baiye.util.FirstLetter; import com.baiye.util.PageUtil; import com.baiye.util.QueryHelp; import com.baiye.util.SecurityUtils; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; @@ -36,10 +41,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.DecimalFormat; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -48,6 +50,7 @@ import java.util.stream.Collectors; */ @Service @RequiredArgsConstructor +@Slf4j public class CustomManageServiceImpl implements CustomManageService { private final ChannelCustomRepository channelCustomRepository; @@ -69,52 +72,61 @@ public class CustomManageServiceImpl implements CustomManageService { if (ObjectUtil.isNotEmpty(byAndChannelName)) { return CommonResponse.createByErrorMessage("名称重复"); } + if (!MobileUtil.checkPhone(channelCustom.getPhone())) { + return CommonResponse.createByErrorMessage(ResponseCode.PHONE_NUMBER_IS_INCORRECT.getDesc()); + } //新建账号状态为2 待开通 channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER); + //获取父账号的总量 + ChannelCustom parent = getChannelCustomByUserId(); //设置分配 - if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { - if (channelCustom.getTotalNum() != null) { + 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() != null) { + } else { if (channelCustom.getTotalNum() < DefaultNumberConstants.ONE_THOUSAND) { return CommonResponse.createByErrorMessage("直客账号最低分配1000"); } } + if (parent.getSurplusNum() == null || parent.getSurplusNum() < channelCustom.getTotalNum()) { + return CommonResponse.createByErrorMessage("可分配的余量不足"); + } + channelCustom.setSurplusNum(channelCustom.getTotalNum()); + //减掉渠道商余量 + parent.setSurplusNum(parent.getTotalNum() - channelCustom.getTotalNum()); + parent.setCreateTime(DateUtil.date()); + channelCustomRepository.save(parent); + //分配记录 + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), channelCustom.getTotalNum(), channelCustom.getId(), channelCustom.getChannelName()); + channelResourceAssignRepository.save(channelResourceAssign); } - //获取父账号的总量 - ChannelCustom parent = channelCustomRepository.findById(channelCustom.getParentId()).orElse(new ChannelCustom()); - if (parent.getSurplusNum() == null || parent.getSurplusNum() < channelCustom.getTotalNum()) { - return CommonResponse.createByErrorMessage("可分配的余量不足"); - } - channelCustom.setSurplusNum(channelCustom.getTotalNum()); - //减掉渠道商余量 - parent.setSurplusNum(parent.getTotalNum() - channelCustom.getTotalNum()); + //激活码 - String activeCode = "by" + getFourNum(channelCustom.getParentId().intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); + String activeCode = "by" + getFourNum(parent.getId().intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); channelCustom.setActivationCode(activeCode); + channelCustom.setParentId(parent.getId()); - channelCustomRepository.save(channelCustom); - channelCustomRepository.save(parent); //这里如果是代理商 直接同步 - CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelCustom.getChannelName(), channelCustom.getPhone()); - User user = new User(); - BeanUtil.copyProperties(createUserDTO, user); - user.setUsername(user.getUsername().trim()); - user.setWhichUserId(parent.getUserId()); - user.setIsReview(Boolean.FALSE); - Set roles = new HashSet<>(); - Role role = new Role(); - role.setId(14L); - roles.add(role); - user.setRoles(roles); - userServiceImpl.create(user); - //分配记录 - ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getParentId(), channelCustom.getTotalNum(), channelCustom.getId(), channelCustom.getChannelName()); - channelResourceAssignRepository.save(channelResourceAssign); + if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { + CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelCustom.getChannelName(), channelCustom.getPhone()); + User user = new User(); + BeanUtil.copyProperties(createUserDTO, user); + user.setUsername(user.getUsername().trim()); + user.setWhichUserId(parent.getUserId()); + user.setIsReview(Boolean.FALSE); + Set roles = new HashSet<>(); + Role role = new Role(); + role.setId(14L); + roles.add(role); + user.setRoles(roles); + Long userId = userServiceImpl.create(user).getId(); + channelCustom.setUserId(userId); + channelCustom.setStatus(1); + } + + channelCustomRepository.save(channelCustom); return CommonResponse.createBySuccess(); } @@ -123,8 +135,7 @@ public class CustomManageServiceImpl implements CustomManageService { public CommonResponse assignNum(Long customId, Integer assignNum) { ChannelCustom channelCustom = channelCustomRepository.findById(customId).orElse(new ChannelCustom()); ChannelCustom parent = channelCustomRepository.findById(channelCustom.getParentId()).orElse(new ChannelCustom()); - int parentTotalNum = parent.getTotalNum(); - + int parentSurplusNum = parent.getSurplusNum(); if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { if (assignNum < DefaultNumberConstants.TEN_THOUSAND) { return CommonResponse.createByErrorMessage("渠道商账号最低分配1万"); @@ -134,42 +145,40 @@ public class CustomManageServiceImpl implements CustomManageService { return CommonResponse.createByErrorMessage("直客账号最低分配1000"); } } - if (parentTotalNum < assignNum) { + if (parentSurplusNum < assignNum) { return CommonResponse.createByErrorMessage("可分配的余量不足"); } //扣减父级渠道商的余量 - parent.setSurplusNum(parent.getSurplusNum() - assignNum); + parent.setSurplusNum(parentSurplusNum - assignNum); //增加客户的总量和余量 channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); - channelCustomRepository.save(parent); - channelCustomRepository.save(channelCustom); + channelCustom.setPurchaseTime(DateUtil.date()); //添加分配记录 - ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getParentId(), assignNum, channelCustom.getId(), channelCustom.getChannelName()); + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getParentId(), assignNum, customId, channelCustom.getChannelName()); channelResourceAssignRepository.save(channelResourceAssign); + channelCustomRepository.save(parent); + channelCustomRepository.save(channelCustom); return CommonResponse.createBySuccess(); } @Override public Object queryAll(ChannelQuery channelCustomQuery, Pageable pageable) { - Sort sort; - if (channelCustomQuery.getSort() != null && channelCustomQuery.getSort() == 1) { - sort = Sort.by(Sort.Direction.DESC, "totalNum"); - } else if (channelCustomQuery.getSort() != null && channelCustomQuery.getSort() == 2) { - sort = Sort.by(Sort.Direction.DESC, "surplusNum"); - } else { - sort = Sort.by(Sort.Direction.DESC, "createTime"); - } //这里的id 是userId; - Long id = SecurityUtils.getCurrentUserId(); - ChannelCustom byUserId = channelCustomRepository.findByUserId(id); - channelCustomQuery.setId(byUserId.getId()); - - PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); + Long customId = getChannelCustomByUserId().getId(); + channelCustomQuery.setId(customId); + PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime")); Page channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelCustomQuery, criteriaBuilder), pageRequest); return PageUtil.toPage(channelCustoms); } + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse updateDmpLimitNum(Long customId, Integer dmpLimitNum) { + channelCustomRepository.updateDmpLimitNum(customId, dmpLimitNum); + return CommonResponse.createBySuccess(); + } + @Override public String createLinkUrl(Long customId, Integer type) { ChannelCustomTag customTag = channelCustomTagRepository.findByCustomIdAndType(customId, type); @@ -188,9 +197,9 @@ public class CustomManageServiceImpl implements CustomManageService { if (ObjectUtil.isNotNull(linkEnum) && linkEnum.getUrl() != null) { String tagUrl = linkEnum.name().toLowerCase().concat(StrPool.DASHED) .concat(firstPinYin.toLowerCase()) - .concat(StrPool.DASHED).concat(DateUtil.format(DateUtil.date(), "MMdd")) - .concat(StrPool.DASHED).concat(RandomUtil.randomString - (DefaultNumberConstants.FOUR_NUMBER)); + .concat(StrPool.DASHED).concat(DateUtil.format(DateUtil.date(), "MMdd")) + .concat(StrPool.DASHED).concat(RandomUtil.randomString + (DefaultNumberConstants.FOUR_NUMBER)); String fullLink = configurationUrl.concat(linkEnum.getUrl()).concat(tagUrl); ChannelCustomTag channelCustomTag = new ChannelCustomTag(); channelCustomTag.setTagType(type); @@ -204,14 +213,22 @@ public class CustomManageServiceImpl implements CustomManageService { } @Override - public Map findUrlByCustomId(Long customId) { + public List> findUrlByCustomId(Long customId) { List byChannelId = channelCustomTagRepository.findByChannelId(customId); - return byChannelId.stream().collect(Collectors.toMap(ChannelCustomTag::getTagType, tag -> { - String tagStr = tag.getTagStr(); - Integer tagType = tag.getTagType(); - UrlLinkEnum linkEnum = UrlLinkEnum.find(tagType); - return configurationUrl.concat(linkEnum.getUrl()).concat(tagStr); - })); + List> list = new ArrayList<>(); + if (CollUtil.isNotEmpty(byChannelId)) { + for (ChannelCustomTag tag : byChannelId) { + Integer tagType = tag.getTagType(); + String tagStr = tag.getTagStr(); + UrlLinkEnum linkEnum = UrlLinkEnum.find(tagType); + String concat = configurationUrl.concat(linkEnum.getUrl()).concat(tagStr); + Map map = new HashMap<>(2); + map.put("type", tagType); + map.put("link", concat); + list.add(map); + } + } + return list; } @Override @@ -223,4 +240,14 @@ public class CustomManageServiceImpl implements CustomManageService { DecimalFormat decimalFormat = new DecimalFormat("0000"); return decimalFormat.format(num); } + + private ChannelCustom getChannelCustomByUserId() { + Long id = SecurityUtils.getCurrentUserId(); + ChannelCustom byUserId = channelCustomRepository.findByUserId(id); + if (ObjectUtil.isNull(byUserId)) { + log.info("系统账号id={}", id); + throw new BadRequestException("账号异常,请联系管理员"); + } + return byUserId; + } } diff --git a/ad-platform-manage/ad-platform-management/src/test/java/com/baiye/CustomTest.java b/ad-platform-manage/ad-platform-management/src/test/java/com/baiye/CustomTest.java index cb47f841..6d9b4958 100644 --- a/ad-platform-manage/ad-platform-management/src/test/java/com/baiye/CustomTest.java +++ b/ad-platform-manage/ad-platform-management/src/test/java/com/baiye/CustomTest.java @@ -8,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import java.util.List; import java.util.Map; /** @@ -34,7 +35,7 @@ public class CustomTest { @Test public void customList() { - Map urlByCustomId = customManageService.findUrlByCustomId(1L); + List> urlByCustomId = customManageService.findUrlByCustomId(1L); System.out.println(urlByCustomId); } 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 86a14666..73ac5d60 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 @@ -57,7 +57,7 @@ public class ClueJpa { public List getClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) { StringBuilder sql = new StringBuilder(); sql.append("select c.id as id,c.name as name,c.nid as nid,c.wx as wx,c.origin as origin,c.collect_time as collectTime,c.address as address,c.record_id as recordId," + - "c.create_time as createTime,c.amount as amount,c.platform as platform,c.tag as tag,c.audio_url as audioUrl,c.cast_info as castInfo,c.is_encryption as isEncryption, cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," + + "cm.create_time as createTime,c.amount as amount,c.platform as platform,c.tag as tag,c.audio_url as audioUrl,c.cast_info as castInfo,c.is_encryption as isEncryption, cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," + "cm.optimistic_version as optimisticVersion,cm.source_label as sourceLabel,cm.task_id as taskId,cm.clue_stage as clueStage,cm.clue_call_status as clueCallStatus," + "cm.newest_call_time as newestCallTime ,cm.turnover_amount as turnoverAmount ,cm.clue_type as clueType " + "from tb_clue as c LEFT JOIN tb_clue_middle as cm on c.id = cm.clue_id where 1=1 "); @@ -71,7 +71,7 @@ public class ClueJpa { public List getTalkClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) { StringBuilder sql = new StringBuilder(); sql.append("select c.id as id,c.name as name,c.nid as nid,c.wx as wx,c.origin as origin,c.collect_time as collectTime,c.address as address,c.record_id as recordId," + - "c.create_time as createTime,c.amount as amount,c.platform as platform,c.tag as tag,c.audio_url as audioUrl,c.cast_info as castInfo,c.is_encryption as isEncryption, cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," + + "cm.create_time as createTime,c.amount as amount,c.platform as platform,c.tag as tag,c.audio_url as audioUrl,c.cast_info as castInfo,c.is_encryption as isEncryption, cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," + "cm.optimistic_version as optimisticVersion,cm.source_label as sourceLabel,cm.task_id as taskId,cm.clue_stage as clueStage,cm.clue_call_status as clueCallStatus," + "cm.newest_call_time as newestCallTime ,cm.turnover_amount as turnoverAmount ,cm.clue_type as clueType " + "from tb_clue as c LEFT JOIN tb_clue_talk as cm on c.id = cm.clue_id where 1=1 ");