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 90d96017..cbb89ce3 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 @@ -181,6 +181,11 @@ public class DefaultNumberConstants { */ public static final int FIVE_THOUSAND = 5000; + /** + * 1万 + */ + public static final int TEN_THOUSAND = 10000; + /** * 五万 */ 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 new file mode 100644 index 00000000..835c02c9 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelManageController.java @@ -0,0 +1,44 @@ +package com.baiye.modules.agent.controller; + +import com.baiye.http.CommonResponse; +import com.baiye.modules.agent.entity.query.ChannelQuery; +import com.baiye.modules.agent.service.ChannelManageService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Set; + +/** + * @author wjt + * @date 2023/4/12 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/channel") +@Api(tags = "渠道商管理") +public class ChannelManageController { + private final ChannelManageService channelManageService; + + @ApiOperation("查询任务(分页)") + @GetMapping("/queryAll") + public ResponseEntity queryAll(ChannelQuery channelQuery, Pageable pageable) { + return new ResponseEntity<>(channelManageService.queryAll(channelQuery, pageable), HttpStatus.OK); + } + + @ApiOperation("激活开通") + @PostMapping("/active") + public CommonResponse active(@RequestBody Set ids) { + return channelManageService.active(ids); + } + + @ApiOperation("禁用") + @PostMapping("/forbidden") + public CommonResponse forbidden(@RequestBody Set ids) { + return channelManageService.forbidden(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 new file mode 100644 index 00000000..1146580d --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/ChannelResourceAssignController.java @@ -0,0 +1,45 @@ +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.service.ChannelResourceAssignService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author wjt + * @date 2023/4/14 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/resource") +@Api(tags = "资源包管理") +public class ChannelResourceAssignController { + private final ChannelResourceAssignService channelResourceAssignService; + + @ApiOperation("查询任务(分页)") + @GetMapping("/queryAll") + public ResponseEntity queryAll(ChannelQuery channelResourceQuery, Pageable pageable) { + return new ResponseEntity<>(channelResourceAssignService.queryAll(channelResourceQuery, pageable), HttpStatus.OK); + } + @ApiOperation("查询任务(分页)") + @GetMapping("/query/assign") + public ResponseEntity queryAssign(ResourceAssignInfoQuery resourceAssignInfoQuery, Pageable pageable) { + return new ResponseEntity<>(channelResourceAssignService.queryAssign(resourceAssignInfoQuery, pageable), HttpStatus.OK); + } + @GetMapping("/assign") + @ApiOperation("配量") + public CommonResponse assignNum(@RequestParam("channelId") Long channelId, @RequestParam("customId") 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 new file mode 100644 index 00000000..b8b65679 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/controller/CustomManageController.java @@ -0,0 +1,50 @@ +package com.baiye.modules.agent.controller; + +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 io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +/** + * @author wjt + * @date 2023/4/12 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/custom") +@Api(tags = "客户管理") +public class CustomManageController { + private final CustomManageService customManageService; + + @PostMapping("/add") + @ApiOperation("新增账号") + public CommonResponse addCustom(@RequestBody ChannelCustom channelCustom) { + return customManageService.addCustom(channelCustom); + } + + @GetMapping("/assign") + @ApiOperation("配量") + public CommonResponse assignNum(@RequestParam("customId") Long customId, @RequestParam("customId") Integer assignNum) { + return customManageService.assignNum(customId, assignNum); + } + + @ApiOperation("查询任务(分页)") + @GetMapping("/queryAll") + public ResponseEntity queryAll(ChannelQuery channelCustomQuery, Pageable pageable) { + return new ResponseEntity<>(customManageService.queryAll(channelCustomQuery, pageable), HttpStatus.OK); + } + + @GetMapping("/link") + @ApiOperation("生成链接") + public CommonResponse addLink(@RequestParam("customId") Long customId, @RequestParam("type") Integer type) { + + return CommonResponse.createBySuccess(); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/dao/ChannelCustomDao.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/dao/ChannelCustomDao.java new file mode 100644 index 00000000..fce6bae3 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/dao/ChannelCustomDao.java @@ -0,0 +1,55 @@ +package com.baiye.modules.agent.dao; + +import com.baiye.modules.agent.entity.ChannelCustom; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Set; + +/** + * @author wjt + * @date 2023/4/12 + */ +@Repository +public interface ChannelCustomDao extends JpaRepository, JpaSpecificationExecutor { + + /** + * 通过名称查询 + * + * @param name 名称 + * @return 对象 + */ + ChannelCustom findByAndChannelName(String name); + + /** + * 通过父id查询 + * + * @param parentIds 父id + * @return 列表 + */ + @Query("select c from ChannelCustom c where c.parentId in ?1") + List findByParentId(Set parentIds); + + /** + * 修改客户的状态 + * + * @param ids id + * @param status 状态 + * @return 成功条数 + */ + @Modifying + @Query("UPDATE ChannelCustom set status = ?2 where id in ?1") + int updateCustomStatus(Set ids, Integer status); + + /** + * 根据关联的系统id查询 + * + * @param userId + * @return + */ + ChannelCustom findByUserId(Long userId); +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/dao/ChannelResourceAssignDao.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/dao/ChannelResourceAssignDao.java new file mode 100644 index 00000000..21fdf7e3 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/dao/ChannelResourceAssignDao.java @@ -0,0 +1,14 @@ +package com.baiye.modules.agent.dao; + +import com.baiye.modules.agent.entity.ChannelResourceAssign; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; + +/** + * @author wjt + * @date 2023/4/13 + */ +@Repository +public interface ChannelResourceAssignDao extends JpaRepository, JpaSpecificationExecutor { +} 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 new file mode 100644 index 00000000..3bb238b8 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelCustom.java @@ -0,0 +1,101 @@ +package com.baiye.modules.agent.entity; + +import cn.hutool.core.date.DateUtil; +import com.baiye.valid.AddGroup; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author wjt + * @date 2023/4/12 + */ +@Data +@Entity +@Table(name = "tb_channel_custom") +@EntityListeners(AuditingEntityListener.class) +public class ChannelCustom implements Serializable { + + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ApiModelProperty(value = "系统用户id") + @Column(name = "user_id") + private Long userId; + + @ApiModelProperty(value = "手机") + @Column(name = "phone") + private String phone; + + @ApiModelProperty(value = "名称") + @Column(name = "channel_name") + @NotNull(groups = AddGroup.class) + private String channelName; + + @ApiModelProperty(value = "客户类型 1-渠道商 2-直客") + @Column(name = "type") + @NotNull(groups = AddGroup.class) + private Integer type; + + @ApiModelProperty(value = "总分配量") + @Column(name = "total_num") + private Integer totalNum; + + @ApiModelProperty(value = "分配余量") + @Column(name = "surplus_num") + private Integer surplusNum; + + @ApiModelProperty(value = "用户状态 1 正常 2-待开通-3 禁用") + @Column(name = "status") + private Integer status; + + @ApiModelProperty(value = "激活码") + @Column(name = "activation_code") + private String activationCode; + + @ApiModelProperty(value = "创建时间") + @Column(name = "create_time") + private Date createTime; + + @ApiModelProperty(value = "最近一次购包时间") + @Column(name = "purchase_time") + private Date purchaseTime; + + @ApiModelProperty(value = "父id") + @Column(name = "parent_id") + @NotNull(groups = AddGroup.class) + private Long parentId; + + @Transient + private List children; + @Transient + private Integer allCustomNum; + @Transient + private Integer normalNum; + @Transient + private Integer waitNum; + + + public ChannelCustom addChannel(String name, String phone, Long userId) { + this.setChannelName(name); + this.setType(1); + this.setTotalNum(0); + this.setSurplusNum(0); + this.setStatus(1); + this.setActivationCode(null); + this.setCreateTime(DateUtil.date()); + this.setPurchaseTime(DateUtil.date()); + this.setParentId(null); + 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/ChannelResourceAssign.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelResourceAssign.java new file mode 100644 index 00000000..724bd09d --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelResourceAssign.java @@ -0,0 +1,53 @@ +package com.baiye.modules.agent.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * @author wjt + * @date 2023/4/12 + */ +@Data +@Entity +@Table(name = "tb_channel_resource_assign") +@EntityListeners(AuditingEntityListener.class) +public class ChannelResourceAssign implements Serializable { + + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ApiModelProperty(value = "渠道商id") + @Column(name = "channel_id") + private Long channelId; + + @ApiModelProperty(value = "分配量") + @Column(name = "assign_num") + private Integer assignNum; + + @ApiModelProperty(value = "分配人id") + @Column(name = "assign_by") + private Long assignBy; + + @ApiModelProperty(value = "分配人名称") + @Column(name = "assign_name") + private String assignName; + + @ApiModelProperty(value = "时间") + @Column(name = "create_time") + private Date createTime; + + public ChannelResourceAssign addChannelResourceAssign(Long channelId, Integer assignNum, Long assignBy, String assignName) { + this.setChannelId(channelId); + this.setAssignNum(assignNum); + this.setAssignBy(assignBy); + this.setAssignName(assignName); + 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 new file mode 100644 index 00000000..e55369d5 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ChannelQuery.java @@ -0,0 +1,28 @@ +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/13 + */ +@Data +public class ChannelQuery { + + @ApiModelProperty(value = "客户名称") + @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; + + @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 new file mode 100644 index 00000000..8f04c975 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/query/ResourceAssignInfoQuery.java @@ -0,0 +1,21 @@ +package com.baiye.modules.agent.entity.query; + +import com.baiye.annotation.Query; +import lombok.Data; + +import java.sql.Timestamp; +import java.util.List; + +/** + * @author wjt + * @date 2023/4/14 + */ +@Data +public class ResourceAssignInfoQuery { + + @Query + private Long id; + + @Query(type = Query.Type.BETWEEN) + private List createTime; +} 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 new file mode 100644 index 00000000..8a870c06 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelManageService.java @@ -0,0 +1,48 @@ +package com.baiye.modules.agent.service; + +import com.baiye.http.CommonResponse; +import com.baiye.modules.agent.entity.query.ChannelQuery; +import org.springframework.data.domain.Pageable; + +import java.util.Set; + +/** + * @author wjt + * @date 2023/4/12 + */ +public interface ChannelManageService { + /** + * 新增渠道商 + * + * @param channelName 渠道商名称 + * @param userId 系统用户id + * @param phone 号码 + * @return 成功码 + */ + CommonResponse addChannel(String channelName, String phone, Long userId); + + /** + * admin查询渠道商 + * + * @param channelQuery 查询条件 + * @param pageable 分页 + * @return 列表 + */ + Object queryAll(ChannelQuery channelQuery, Pageable pageable); + + /** + * 激活开通账号 + * + * @param ids 账号ids + * @return 成功状态 + */ + CommonResponse active(Set ids); + + /** + * 禁用 + * + * @param ids 账号ids + * @return 成功状态 + */ + CommonResponse forbidden(Set ids); +} 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 new file mode 100644 index 00000000..8842fed5 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/ChannelResourceAssignService.java @@ -0,0 +1,40 @@ +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 org.springframework.data.domain.Pageable; + +/** + * @author wjt + * @date 2023/4/14 + */ +public interface ChannelResourceAssignService { + + /** + * admin查询渠道商 分配 + * + * @param channelQuery 查询条件 + * @param pageable 分页 + * @return 列表 + */ + Object queryAll(ChannelQuery channelQuery, Pageable pageable); + + /** + * 渠道商 分配记录 + * + * @param resourceAssignInfoQuery 查询条件 + * @param pageable 分页 + * @return 列表 + */ + Object queryAssign(ResourceAssignInfoQuery resourceAssignInfoQuery, Pageable pageable); + + /** + * 配量 + * + * @param customId 客户id + * @param assignNum 分配量 + * @return 成功状态 + */ + CommonResponse assignNum(Long customId, Integer assignNum); +} 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 new file mode 100644 index 00000000..27165198 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/CustomManageService.java @@ -0,0 +1,40 @@ +package com.baiye.modules.agent.service; + +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; + +/** + * @author wjt + * @date 2023/4/12 + */ +public interface CustomManageService { + + /** + * 新增 + * + * @param channelCustom 客户信息 + * @return 成功状态 + */ + CommonResponse addCustom(ChannelCustom channelCustom); + + /** + * 配量 + * + * @param customId 客户id + * @param assignNum 分配量 + * @return 成功状态 + */ + CommonResponse assignNum(Long customId, Integer assignNum); + + /** + * 渠道商 客户列表 + * + * @param channelCustomQuery 查询参数 + * @param pageable 分页 + * @return 列表 + */ + Object queryAll(ChannelQuery channelCustomQuery, Pageable pageable); + +} 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 new file mode 100644 index 00000000..b7f7e529 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelManageServiceImpl.java @@ -0,0 +1,124 @@ +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.dao.ChannelCustomDao; +import com.baiye.modules.agent.entity.ChannelCustom; +import com.baiye.modules.agent.entity.query.ChannelQuery; +import com.baiye.modules.agent.service.ChannelManageService; +import com.baiye.modules.platform.service.dto.CreateUserDTO; +import com.baiye.modules.system.service.UserService; +import com.baiye.util.PageUtil; +import com.baiye.util.QueryHelp; +import lombok.RequiredArgsConstructor; +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.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author wjt + * @date 2023/4/12 + */ +@Service +@RequiredArgsConstructor +public class ChannelManageServiceImpl implements ChannelManageService { + private final ChannelCustomDao channelCustomDao; + private final UserService userService; + + @Override + public CommonResponse addChannel(String channelName, String phone, Long userId) { + channelCustomDao.save(new ChannelCustom().addChannel(channelName, phone, userId)); + return CommonResponse.createBySuccess(); + } + + @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); + Page channelCustoms = channelCustomDao.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) { + if (channelCustom.getParentId() == null) { + parentMap.put(channelCustom.getId(), channelCustom); + } + } + //查询出所有子集 + Set set = parentMap.keySet(); + List byParentId = channelCustomDao.findByParentId(set); + content.addAll(byParentId); + //子集 + Map> userMap = content.stream().filter(channelCustom -> channelCustom.getParentId() != null) + .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 = channelCustomDao.findById(key).orElse(new ChannelCustom()); + } + 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()); + normalNum = normalNums.size(); + waitNum = waitNums.size(); + } + 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()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse active(Set ids) { + List channelCustoms = channelCustomDao.findAllById(ids); + 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); + } + channelCustomDao.saveAll(channelCustoms); + return CommonResponse.createBySuccess(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse forbidden(Set ids) { + channelCustomDao.updateCustomStatus(ids, 3); + userService.updateUserStatusByCompanyId(false, new ArrayList<>(ids)); + 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 new file mode 100644 index 00000000..73ffe4f9 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/ChannelResourceAssignServiceImpl.java @@ -0,0 +1,63 @@ +package com.baiye.modules.agent.service.impl; + +import com.baiye.http.CommonResponse; +import com.baiye.modules.agent.dao.ChannelCustomDao; +import com.baiye.modules.agent.dao.ChannelResourceAssignDao; +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.service.ChannelResourceAssignService; +import com.baiye.util.PageUtil; +import com.baiye.util.QueryHelp; +import lombok.RequiredArgsConstructor; +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.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author wjt + * @date 2023/4/14 + */ +@Service +@RequiredArgsConstructor +public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignService { + private final ChannelResourceAssignDao channelResourceAssignDao; + private final ChannelCustomDao channelCustomDao; + + @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 = channelResourceAssignDao.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 channelResourceAssignDao.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, resourceAssignInfoQuery, criteriaBuilder), pageRequest); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse assignNum(Long customId, Integer assignNum) { + ChannelCustom channelCustom = channelCustomDao.findById(customId).orElse(new ChannelCustom()); + //增加客户的总量和余量 + channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); + channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); + channelCustomDao.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 new file mode 100644 index 00000000..83f7d8c7 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/service/impl/CustomManageServiceImpl.java @@ -0,0 +1,158 @@ +package com.baiye.modules.agent.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; +import com.baiye.constant.DefaultNumberConstants; +import com.baiye.http.CommonResponse; +import com.baiye.modules.agent.dao.ChannelCustomDao; +import com.baiye.modules.agent.dao.ChannelResourceAssignDao; +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.service.CustomManageService; +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.PageUtil; +import com.baiye.util.QueryHelp; +import com.baiye.util.SecurityUtils; +import lombok.RequiredArgsConstructor; +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.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.text.DecimalFormat; +import java.util.HashSet; +import java.util.Set; + +/** + * @author wjt + * @date 2023/4/12 + */ +@Service +@RequiredArgsConstructor +public class CustomManageServiceImpl implements CustomManageService { + private final ChannelCustomDao channelCustomDao; + private final ChannelResourceAssignDao channelResourceAssignDao; + private final UserServiceImpl userServiceImpl; + + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse addCustom(ChannelCustom channelCustom) { + //验证重复 + ChannelCustom byAndChannelName = channelCustomDao.findByAndChannelName(channelCustom.getChannelName()); + if (ObjectUtil.isNotEmpty(byAndChannelName)) { + return CommonResponse.createByErrorMessage("名称重复"); + } + //新建账号状态为2 待开通 + channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER); + //设置分配 + if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { + if (channelCustom.getTotalNum() != null) { + if (channelCustom.getTotalNum() < DefaultNumberConstants.TEN_THOUSAND) { + return CommonResponse.createByErrorMessage("渠道商账号最低分配1万"); + } + } + } else { + if (channelCustom.getTotalNum() != null) { + if (channelCustom.getTotalNum() < DefaultNumberConstants.ONE_THOUSAND) { + return CommonResponse.createByErrorMessage("直客账号最低分配1000"); + } + } + } + //获取父账号的总量 + ChannelCustom parent = channelCustomDao.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); + channelCustom.setActivationCode(activeCode); + + channelCustomDao.save(channelCustom); + channelCustomDao.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()); + channelResourceAssignDao.save(channelResourceAssign); + return CommonResponse.createBySuccess(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public CommonResponse assignNum(Long customId, Integer assignNum) { + ChannelCustom channelCustom = channelCustomDao.findById(customId).orElse(new ChannelCustom()); + ChannelCustom parent = channelCustomDao.findById(channelCustom.getParentId()).orElse(new ChannelCustom()); + int parentTotalNum = parent.getTotalNum(); + + 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 (parentTotalNum < assignNum) { + return CommonResponse.createByErrorMessage("可分配的余量不足"); + } + //扣减父级渠道商的余量 + parent.setSurplusNum(parent.getSurplusNum() - assignNum); + //增加客户的总量和余量 + channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); + channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); + channelCustomDao.save(parent); + channelCustomDao.save(channelCustom); + //添加分配记录 + ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getParentId(), assignNum, channelCustom.getId(), channelCustom.getChannelName()); + channelResourceAssignDao.save(channelResourceAssign); + 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 = channelCustomDao.findByUserId(id); + channelCustomQuery.setId(byUserId.getId()); + + PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); + Page channelCustoms = channelCustomDao.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelCustomQuery, criteriaBuilder), pageRequest); + return PageUtil.toPage(channelCustoms); + } + + private String getFourNum(Integer num) { + DecimalFormat decimalFormat = new DecimalFormat("0000"); + return decimalFormat.format(num); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CreateUserDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CreateUserDTO.java index d61b7940..3ce9098f 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CreateUserDTO.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CreateUserDTO.java @@ -10,14 +10,11 @@ import org.springframework.web.multipart.MultipartFile; import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import java.util.Date; -import java.util.Objects; -import java.util.Set; +import java.util.*; /** * @author Enzo * @date : 2022/1/21 - * */ @Data public class CreateUserDTO { @@ -50,7 +47,7 @@ public class CreateUserDTO { @ApiModelProperty(value = "用户性别") private String gender; - @ApiModelProperty(value = "头像真实名称",hidden = true) + @ApiModelProperty(value = "头像真实名称", hidden = true) private String avatarName; @ApiModelProperty(value = "头像存储的路径", hidden = true) @@ -94,5 +91,22 @@ public class CreateUserDTO { return Objects.hash(id, username); } - + public CreateUserDTO addCreateUserDTO(String name, String phone) { + this.setCompanyType(0); + this.setEnabled(true); + this.setGender("男"); + this.setNickName(name); + this.setUsername(name); + this.setPhone(phone); + Set roles = new HashSet<>(); + Role role = new Role(); + role.setId(8L); + Role role1 = new Role(); + role1.setId(10L); + roles.add(role); + roles.add(role1); + this.setRoles(roles); + this.setTurnCrmNum(50); + return this; + } } 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 e44ed251..8dfcbc83 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 @@ -35,6 +35,8 @@ import com.baiye.feign.IRemoteAuthService; import com.baiye.feign.SourceClueClient; import com.baiye.model.dto.*; import com.baiye.model.enums.ResponseCode; +import com.baiye.modules.agent.dao.ChannelCustomDao; +import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.platform.domain.*; import com.baiye.modules.platform.repository.*; import com.baiye.modules.platform.service.*; @@ -132,6 +134,7 @@ public class UserServiceImpl implements UserService { private final ExtensionNumberService extensionNumberService; private final TaskImeiService taskImeiService; private final TaskTagRepository taskTagRepository; + private final ChannelCustomDao channelCustomDao; @Override @Transactional(rollbackFor = Exception.class) @@ -236,12 +239,14 @@ public class UserServiceImpl implements UserService { break; } // TODO 创建渠道商 - if (role.getId() == DefaultNumberConstants.ELEVEN_NUMBER) { + if (role.getId() == DefaultNumberConstants.FOURTEEN_NUMBER) { BeanUtil.copyProperties(userDTO, user); user.setUsername(user.getUsername().trim()); user.setWhichUserId(userId); user.setIsReview(Boolean.FALSE); create(user); + //同步渠道商信息 + channelCustomDao.save(new ChannelCustom().addChannel(userDTO.getUsername(), userDTO.getPhone(), userId)); return Collections.singletonList(user.getId()); } }