diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelManageController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelManageController.java index 835c02c9..1f196912 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelManageController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelManageController.java @@ -1,5 +1,6 @@ package com.baiye.modules.agent.controller; +import com.baiye.annotation.Inner; import com.baiye.http.CommonResponse; import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.service.ChannelManageService; @@ -26,10 +27,17 @@ public class ChannelManageController { @ApiOperation("查询任务(分页)") @GetMapping("/queryAll") + @Inner(value = false) public ResponseEntity queryAll(ChannelQuery channelQuery, Pageable pageable) { return new ResponseEntity<>(channelManageService.queryAll(channelQuery, pageable), HttpStatus.OK); } + @GetMapping("/report") + @ApiOperation("统计") + public CommonResponse report() { + return channelManageService.report(); + } + @ApiOperation("激活开通") @PostMapping("/active") public CommonResponse active(@RequestBody Set ids) { 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 4a301362..c34960fb 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 @@ -3,6 +3,7 @@ package com.baiye.modules.agent.controller; import com.baiye.http.CommonResponse; import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ResourceAssignInfoQuery; +import com.baiye.modules.agent.entity.query.ResourceChannelQuery; import com.baiye.modules.agent.service.ChannelResourceAssignService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -28,7 +29,7 @@ public class ChannelResourceAssignController { @ApiOperation("查询任务(分页)") @GetMapping("/queryAll") - public ResponseEntity queryAll(ChannelQuery channelResourceQuery, Pageable pageable) { + public ResponseEntity queryAll(ResourceChannelQuery channelResourceQuery, Pageable pageable) { return new ResponseEntity<>(channelResourceAssignService.queryAll(channelResourceQuery, pageable), HttpStatus.OK); } @@ -45,4 +46,9 @@ public class ChannelResourceAssignController { } + @GetMapping("/report") + @ApiOperation("统计") + public CommonResponse report() { + return channelResourceAssignService.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 0affe312..40710ca8 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 @@ -67,15 +67,19 @@ public class CustomManageController { return CommonResponse.createBySuccess(customManageService.findUrlByCustomId(customId)); } - - @Log @Inner @ApiOperation("修改数量") @GetMapping("/update/quantity") - public ResponseEntity updateQuantity(Long userId, Integer number) { + public CommonResponse updateQuantity(Long userId, Integer number) { customManageService.updateQuantity(userId, number); - return new ResponseEntity<>(HttpStatus.OK); + return CommonResponse.createBySuccess(); } + + @GetMapping("/report") + @ApiOperation("统计") + public CommonResponse report() { + return customManageService.report(); + } } 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 970b380f..1ed4e26f 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 @@ -1,6 +1,8 @@ package com.baiye.modules.agent.entity; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.RandomUtil; +import com.baiye.util.NumUtil; import com.baiye.valid.AddGroup; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -102,10 +104,26 @@ public class ChannelCustom implements Serializable { this.setStatus(1); this.setActivationCode(null); this.setCreateTime(DateUtil.date()); - this.setPurchaseTime(DateUtil.date()); + this.setPurchaseTime(null); this.setParentId(null); this.setUserId(userId); this.setPhone(phone); return this; } + + public ChannelCustom addCustom(String name, String phone, Long userId, Long parentId) { + this.setChannelName(name); + this.setType(2); + this.setTotalNum(0); + this.setSurplusNum(0); + this.setStatus(1); + String activeCode = "by" + NumUtil.getFourNum(parentId.intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); + this.setActivationCode(activeCode); + this.setCreateTime(DateUtil.date()); + this.setPurchaseTime(null); + this.setParentId(parentId); + this.setUserId(userId); + this.setPhone(phone); + return this; + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceChannelQuery.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceChannelQuery.java new file mode 100644 index 00000000..55972fd6 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceChannelQuery.java @@ -0,0 +1,20 @@ +package com.baiye.modules.agent.entity.query; + +import com.baiye.annotation.Query; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author wjt + * @date 2023/4/23 + */ +@Data +public class ResourceChannelQuery { + @ApiModelProperty(value = "客户名称") + @Query(type = Query.Type.INNER_LIKE) + private String channelName; + + @ApiModelProperty(value = "父id") + @Query(propName = "parentId", type = Query.Type.IS_NULL) + private Boolean parentId; +} 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 new file mode 100644 index 00000000..e0ffb038 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/vo/CustomReportVo.java @@ -0,0 +1,61 @@ +package com.baiye.modules.agent.entity.vo; + +import lombok.Data; + +/** + * @author wjt + * @date 2023/4/23 + */ +@Data +public class CustomReportVo { + + /** + * 当前代理商总购买 + */ + private Integer totalNum = 0; + /** + * 当前代理商可分配资源 + */ + private Integer surplusNum = 0; + /** + * 当前代理商历史分配 + */ + private Integer assignNum = 0; + /** + * 渠道商数 + */ + private Integer channelNum = 0; + /** + * 渠道商总配量 + */ + private Integer channelTotalNum = 0; + /** + * 渠道商剩余可分配 + */ + private Integer channelSurplusNum = 0; + /** + * 直客数 + */ + private Integer customNum = 0; + /** + * 直客总配量 + */ + private Integer customTotalNum = 0; + /** + * 直客剩余可分配 + */ + 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) { + this.setTotalNum(totalNum); + this.setSurplusNum(surplusNum); + this.setAssignNum(assignNum); + this.setChannelNum(channelNum); + this.setChannelTotalNum(channelTotalNum); + this.setChannelSurplusNum(channelSurplusNum); + this.setCustomNum(customNum); + this.setCustomTotalNum(customTotalNum); + this.setCustomSurplusNum(customSurplusNum); + 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 1d7b2d00..bc3f78e5 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 @@ -26,13 +26,23 @@ public interface ChannelCustomRepository extends JpaRepository findByParentId(Set parentIds); + @Query("select c from ChannelCustom c where c.type =?1 and c.parentId in ?2") + List findByParentIds(Integer type, Set parentIds); + + /** + * 通过父id查询 + * + * @param parentId 父id + * @return 列表 + */ + @Query("select c from ChannelCustom c where c.parentId = ?1") + List findByParentId(Long parentId); /** * 修改客户的状态 @@ -45,6 +55,7 @@ public interface ChannelCustomRepository extends JpaRepository ids, Integer status); + /** * 修改dmp数量 * @@ -64,6 +75,14 @@ public interface ChannelCustomRepository extends JpaRepository findUserIdByIds(Set ids); /** * 用户id查询渠道商 @@ -77,10 +96,19 @@ public interface ChannelCustomRepository extends JpaRepository findByType(Integer type); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelResourceAssignRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelResourceAssignRepository.java index d457ac06..2afbe8f6 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelResourceAssignRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/repository/ChannelResourceAssignRepository.java @@ -3,12 +3,23 @@ package com.baiye.modules.agent.repository; import com.baiye.modules.agent.entity.ChannelResourceAssign; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + /** * @author wjt * @date 2023/4/13 */ @Repository public interface ChannelResourceAssignRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 查询admin分配列表 + * + * @return + */ + @Query("select c from ChannelResourceAssign as c where c.channelId is null") + List findAdminAssign(); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelManageService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelManageService.java index 8a870c06..97267348 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelManageService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelManageService.java @@ -30,6 +30,12 @@ public interface ChannelManageService { */ Object queryAll(ChannelQuery channelQuery, Pageable pageable); + /** + * 统计 + * + * @return + */ + CommonResponse report(); /** * 激活开通账号 * diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelResourceAssignService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelResourceAssignService.java index f93cb6ab..8c6d7e10 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelResourceAssignService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelResourceAssignService.java @@ -3,6 +3,7 @@ package com.baiye.modules.agent.service; import com.baiye.http.CommonResponse; import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ResourceAssignInfoQuery; +import com.baiye.modules.agent.entity.query.ResourceChannelQuery; import org.springframework.data.domain.Pageable; /** @@ -18,7 +19,7 @@ public interface ChannelResourceAssignService { * @param pageable 分页 * @return 列表 */ - Object queryAll(ChannelQuery channelQuery, Pageable pageable); + Object queryAll(ResourceChannelQuery channelQuery, Pageable pageable); /** * 渠道商 分配记录 @@ -38,5 +39,10 @@ public interface ChannelResourceAssignService { */ CommonResponse assignNum(Long customId, Integer assignNum); - + /** + * 统计 + * + * @return + */ + CommonResponse report(); } 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 a6aaac6b..da2b6731 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 @@ -77,6 +77,13 @@ public interface CustomManageService { */ ChannelCustom findCustomByUserIdAndStatus(Long userId, Integer status); + /** + * 统计 + * + * @return + */ + CommonResponse report(); + /** * 修改数量 * @param userId 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 6fd2099b..f7732c24 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 @@ -1,6 +1,8 @@ package com.baiye.modules.agent.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.http.CommonResponse; import com.baiye.modules.agent.entity.ChannelCustom; @@ -40,76 +42,93 @@ public class ChannelManageServiceImpl implements ChannelManageService { @Override public Object queryAll(ChannelQuery channelQuery, Pageable pageable) { + channelQuery.setType(1); 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)) { return channelCustoms; } - //父级 - Map parentMap = new HashMap<>(8); - for (ChannelCustom channelCustom : content) { - Long parentId = channelCustom.getParentId(); - if (parentId == null) { - parentMap.put(channelCustom.getId(), channelCustom); - } - } - //查询出所有子集 - Set set = parentMap.keySet(); - 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)); - + Set parentIds = content.stream().map(ChannelCustom::getId).collect(Collectors.toSet()); //子集 + List byParentId = channelCustomRepository.findByParentIds(2, parentIds); Map> userMap = byParentId.stream().collect(Collectors.groupingBy(ChannelCustom::getParentId)); int allCustomNum = 0; int normalNum = 0; int waitNum = 0; - for (Long key : userMap.keySet()) { - ChannelCustom channelCustom; - if (parentMap.containsKey(key)) { - channelCustom = parentMap.get(key); - } else { - channelCustom = channelCustomRepository.findById(key).orElse(new ChannelCustom()); + for (ChannelCustom channelCustom : content) { + Long parentId = channelCustom.getId(); + if (userMap.containsKey(parentId)) { + List list = userMap.get(parentId); + if (CollUtil.isNotEmpty(list)) { + List normalNums = list.stream().filter(c -> c.getStatus() == DefaultNumberConstants.ONE_NUMBER).collect(Collectors.toList()); + List waitNums = list.stream().filter(c -> c.getStatus() == DefaultNumberConstants.TWO_NUMBER).collect(Collectors.toList()); + normalNum = normalNums.size(); + waitNum = waitNums.size(); + allCustomNum = list.size(); + } + channelCustom.setAllCustomNum(allCustomNum); + channelCustom.setNormalNum(normalNum); + channelCustom.setWaitNum(waitNum); + channelCustom.setChildren(list); + } + } + return PageUtil.toPage(content, channelCustoms.getTotalElements()); + } + + @Override + public CommonResponse report() { + DateTime time = DateUtil.date(); + DateTime startTime = DateUtil.beginOfDay(DateUtil.offsetDay(time, -7)); + DateTime yesterday = DateUtil.offsetDay(time, -1); + List byTypeAndCreateTime = channelCustomRepository.findByType(1); + Map map = new HashMap<>(3); + if (CollUtil.isEmpty(byTypeAndCreateTime)) { + return CommonResponse.createBySuccess(map); + } + int weekNum = 0; + int dayNum = 0; + for (ChannelCustom channelCustom : byTypeAndCreateTime) { + Date dateTime = channelCustom.getCreateTime(); + if (DateUtil.compare(dateTime, startTime, "yyyy-MM-dd") >= 0) { + weekNum += 1; } - List children = userMap.get(key); - if (CollUtil.isNotEmpty(children)) { - 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(); + if (DateUtil.compare(dateTime, yesterday, "yyyy-MM-dd") >= 0) { + dayNum += 1; } - channelCustom.setAllCustomNum(allCustomNum); - channelCustom.setNormalNum(normalNum); - channelCustom.setWaitNum(waitNum); - channelCustom.setChildren(children); - parentMap.put(key, channelCustom); } - content = new ArrayList<>(parentMap.values()); - return PageUtil.toPage(content, content.size()); + map.put("totalNum", byTypeAndCreateTime.size()); + map.put("weekNum", weekNum); + map.put("dayNum", dayNum); + return CommonResponse.createBySuccess(map); } @Override @Transactional(rollbackFor = Exception.class) public CommonResponse active(Set ids) { List channelCustoms = channelCustomRepository.findAllById(ids); + List list = new ArrayList<>(); for (ChannelCustom channelCustom : channelCustoms) { String channelName = channelCustom.getChannelName(); String phone = channelCustom.getPhone(); - //同步到系统用户 - CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelName, phone); - List userOrFile = userService.createUserOrFile(createUserDTO); - Long userId = userOrFile.get(0); - channelCustom.setUserId(userId); - channelCustom.setStatus(DefaultNumberConstants.ONE_NUMBER); + //判断之前是否同步过 + Long userId1 = channelCustom.getUserId(); + if (userId1 != null) { + channelCustomRepository.updateCustomStatus(ids, 1); + userService.updateStatusById(true, userId1); + } else { + //同步到系统用户 + CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelName, phone); + List userOrFile = userService.createUserOrFile(createUserDTO); + Long userId = userOrFile.get(0); + channelCustom.setUserId(userId); + channelCustom.setStatus(DefaultNumberConstants.ONE_NUMBER); + list.add(channelCustom); + } + } + if (CollUtil.isNotEmpty(list)) { + channelCustomRepository.saveAll(channelCustoms); } - channelCustomRepository.saveAll(channelCustoms); return CommonResponse.createBySuccess(); } @@ -117,7 +136,8 @@ public class ChannelManageServiceImpl implements ChannelManageService { @Transactional(rollbackFor = Exception.class) public CommonResponse forbidden(Set ids) { channelCustomRepository.updateCustomStatus(ids, 3); - userService.updateUserStatusByCompanyId(false, new ArrayList<>(ids)); + List userIdByIds = channelCustomRepository.findUserIdByIds(ids); + userService.updateUserStatusByCompanyId(false, userIdByIds); return CommonResponse.createBySuccess(); } } 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 f328db65..979a4ebb 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,16 +1,20 @@ package com.baiye.modules.agent.service.impl; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.baiye.http.CommonResponse; 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.entity.query.ResourceChannelQuery; 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; +import io.swagger.models.auth.In; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -19,6 +23,11 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * @author wjt * @date 2023/4/14 @@ -30,8 +39,8 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe private final ChannelCustomRepository channelCustomRepository; @Override - public Object queryAll(ChannelQuery channelQuery, Pageable pageable) { - channelQuery.setId(null); + public Object queryAll(ResourceChannelQuery channelQuery, Pageable pageable) { + channelQuery.setParentId(true); 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); @@ -54,8 +63,39 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe channelCustomRepository.save(channelCustom); channelCustom.setPurchaseTime(DateUtil.date()); channelCustomRepository.save(channelCustom); + + //配量记录 + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(null, assignNum, customId, channelCustom.getChannelName()); + channelResourceAssignRepository.save(channelResourceAssign); return CommonResponse.createBySuccess(); } - + @Override + public CommonResponse report() { + List all = channelResourceAssignRepository.findAdminAssign(); + //总分配数 + int totalNum = 0; + int yesterdayNum = 0; + int todayNum = 0; + DateTime date = DateUtil.parseDate(DateUtil.today()); + DateTime yesterday = DateUtil.offsetDay(date, -1); + for (ChannelResourceAssign channelResourceAssign : all) { + //总分配数 + totalNum += channelResourceAssign.getAssignNum(); + Date createTime = channelResourceAssign.getCreateTime(); + //今日日 + if (DateUtil.compare(createTime, date, "yyyy-MM-dd") >= 0) { + todayNum += channelResourceAssign.getAssignNum(); + } + //昨日 + if (DateUtil.compare(createTime, yesterday, "yyyy-MM-dd") >= 0) { + yesterdayNum += channelResourceAssign.getAssignNum(); + } + } + Map map = new HashMap<>(3); + map.put("totalNum", totalNum); + map.put("yesterdayNum", yesterdayNum); + map.put("todayNum", todayNum); + 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 b09b7f18..1be8194c 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 @@ -16,6 +16,7 @@ import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelCustomTag; import com.baiye.modules.agent.entity.ChannelResourceAssign; import com.baiye.modules.agent.entity.query.ChannelQuery; +import com.baiye.modules.agent.entity.vo.CustomReportVo; import com.baiye.modules.agent.repository.ChannelCustomRepository; import com.baiye.modules.agent.repository.ChannelCustomTagRepository; import com.baiye.modules.agent.repository.ChannelResourceAssignRepository; @@ -24,11 +25,7 @@ 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 com.baiye.util.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -37,12 +34,12 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.DecimalFormat; import java.util.*; -import java.util.stream.Collectors; /** * @author wjt @@ -64,6 +61,10 @@ public class CustomManageServiceImpl implements CustomManageService { @Value("${generate.url}") private String configurationUrl; + @Value("${channel.id}") + private Long channelId; + private final PasswordEncoder passwordEncoder; + @Override @Transactional(rollbackFor = Exception.class) public CommonResponse addCustom(ChannelCustom channelCustom) { @@ -104,28 +105,32 @@ public class CustomManageServiceImpl implements CustomManageService { } //激活码 - String activeCode = "by" + getFourNum(parent.getId().intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); + String activeCode = "by" + NumUtil.getFourNum(parent.getId().intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); channelCustom.setActivationCode(activeCode); channelCustom.setParentId(parent.getId()); //这里如果是代理商 直接同步 if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelCustom.getChannelName(), channelCustom.getPhone()); + createUserDTO.setPassword(passwordEncoder.encode + (StringUtils.isNotBlank(createUserDTO.getPassword()) + ? createUserDTO.getPassword() : "123456")); User user = new User(); BeanUtil.copyProperties(createUserDTO, user); user.setUsername(user.getUsername().trim()); - user.setWhichUserId(parent.getUserId()); + //这个地方注意,代理商的创建人为admin。这whichUserId属性会在之前的逻辑里面用到,这里写死了 + user.setWhichUserId(1L); user.setIsReview(Boolean.FALSE); Set roles = new HashSet<>(); Role role = new Role(); - role.setId(14L); + role.setId(channelId); roles.add(role); user.setRoles(roles); Long userId = userServiceImpl.create(user).getId(); channelCustom.setUserId(userId); channelCustom.setStatus(1); } - + channelCustom.setCreateTime(DateUtil.date()); channelCustomRepository.save(channelCustom); return CommonResponse.createBySuccess(); } @@ -155,7 +160,7 @@ public class CustomManageServiceImpl implements CustomManageService { channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); channelCustom.setPurchaseTime(DateUtil.date()); //添加分配记录 - ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getParentId(), assignNum, customId, channelCustom.getChannelName()); + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), assignNum, customId, channelCustom.getChannelName()); channelResourceAssignRepository.save(channelResourceAssign); channelCustomRepository.save(parent); channelCustomRepository.save(channelCustom); @@ -236,11 +241,37 @@ public class CustomManageServiceImpl implements CustomManageService { return channelCustomRepository.findByUserIdAndStatus(userId, status); } - private String getFourNum(Integer num) { - DecimalFormat decimalFormat = new DecimalFormat("0000"); - return decimalFormat.format(num); + @Override + public CommonResponse report() { + ChannelCustom channelCustomByUserId = getChannelCustomByUserId(); + int totalNum = channelCustomByUserId.getTotalNum(); + int surplusNum = channelCustomByUserId.getSurplusNum(); + int assignNum = totalNum - surplusNum; + + List channelCustoms = channelCustomRepository.findByParentId(channelCustomByUserId.getId()); + int channelNum = 0; + int channelTotalNum = 0; + int channelSurplusNum = 0; + int customTotalNum = 0; + int customSurplusNum = 0; + int customNum = 0; + for (ChannelCustom channelCustom : channelCustoms) { + Integer type = channelCustom.getType(); + if (type == 1) { + channelNum += 1; + channelTotalNum += channelCustom.getTotalNum(); + channelSurplusNum += channelCustom.getSurplusNum(); + } else { + customNum += 1; + customTotalNum += channelCustom.getTotalNum(); + customSurplusNum += channelCustom.getSurplusNum(); + } + } + CustomReportVo customReportVo = new CustomReportVo().addCustomReportVo(totalNum, surplusNum, assignNum, channelNum, channelTotalNum, channelSurplusNum, customNum, customTotalNum, customSurplusNum); + return CommonResponse.createBySuccess(customReportVo); } + private ChannelCustom getChannelCustomByUserId() { Long id = SecurityUtils.getCurrentUserId(); ChannelCustom byUserId = channelCustomRepository.findByUserId(id); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java index afde1880..1cf760e1 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java @@ -159,6 +159,7 @@ public interface UserService { */ void updateUserStatusByCompanyId(Boolean flag, List ids); + void updateStatusById(Boolean flag,Long id); /** * 公司删除用户 */ 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 8d13cc32..ca5d196b 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 @@ -61,6 +61,7 @@ import com.google.common.collect.Sets; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -135,6 +136,9 @@ public class UserServiceImpl implements UserService { private final TaskTagRepository taskTagRepository; private final ChannelCustomRepository channelCustomRepository; + @Value("${channel.id}") + private Long channelId; + @Override @Transactional(rollbackFor = Exception.class) public List fileCreateUser(List excels, Long companyId, UserDto userDto) { @@ -213,6 +217,12 @@ public class UserServiceImpl implements UserService { userRepository.updateStatusByUserIds(flag, ids); } + @Override + @Transactional(rollbackFor = Exception.class) + public void updateStatusById(Boolean flag, Long id) { + userRepository.updateStatusById(flag, id); + } + @Override @Transactional(rollbackFor = Exception.class) public void deleteCompany(Long companyId) { @@ -238,14 +248,14 @@ public class UserServiceImpl implements UserService { break; } // TODO 创建渠道商 - if (role.getId() == DefaultNumberConstants.FOURTEEN_NUMBER) { + if (channelId.equals(role.getId())) { BeanUtil.copyProperties(userDTO, user); user.setUsername(user.getUsername().trim()); user.setWhichUserId(userId); user.setIsReview(Boolean.FALSE); create(user); //同步渠道商信息 - channelCustomRepository.save(new ChannelCustom().addChannel(userDTO.getUsername(), userDTO.getPhone(), userId)); + channelCustomRepository.save(new ChannelCustom().addChannel(userDTO.getUsername(), userDTO.getPhone(), user.getId())); return Collections.singletonList(user.getId()); } } @@ -286,6 +296,9 @@ public class UserServiceImpl implements UserService { createTask(userCreateResult.getId(), "员工上传任务", DefaultNumberConstants.TWO_NUMBER); createTask(userCreateResult.getId(), "拓客模块-投流回流池", DefaultNumberConstants.SEVEN_NUMBER); createTask(userCreateResult.getId(), "拓客模块-拓客回流池", DefaultNumberConstants.SIX_NUMBER); + //同步直客 + ChannelCustom byUserId = channelCustomRepository.findByUserId(userId); + channelCustomRepository.save(new ChannelCustom().addCustom(userDTO.getUsername(), userDTO.getPhone(), user.getId(), byUserId.getId())); } MultipartFile file = userDTO.getFile(); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/util/NumUtil.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/util/NumUtil.java new file mode 100644 index 00000000..9d4370e1 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/util/NumUtil.java @@ -0,0 +1,15 @@ +package com.baiye.util; + +import java.text.DecimalFormat; + +/** + * @author wjt + * @date 2023/4/24 + */ +public class NumUtil { + + public static String getFourNum(Integer num) { + DecimalFormat decimalFormat = new DecimalFormat("0000"); + return decimalFormat.format(num); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml index 78e839da..385aafdc 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml @@ -206,3 +206,7 @@ activation: namePrefix: by_ # url: fission-server.xhuatea.com # namePrefix: by_zs_ + +#渠道商的id +channel: + id: 14 \ No newline at end of file diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml index 3f667097..6650cae5 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml @@ -203,3 +203,7 @@ ad-back: activation: url: fission-server.xhuatea.com namePrefix: by_ + +#渠道商的id +channel: + id: 11 \ No newline at end of file