Merge remote-tracking branch 'origin/platform-agent' into platform-agent

# Conflicts:
#	ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/agent/entity/ChannelCustom.java
master
bynt 1 year ago
commit cacf59d2ea

@ -42,7 +42,7 @@ public class ChannelResourceAssignController {
@GetMapping("/assign") @GetMapping("/assign")
@ApiOperation("配量") @ApiOperation("配量")
public CommonResponse<Object> assignNum(@RequestParam("channelId") Long channelId, @RequestParam("customId") Integer assignNum) { public CommonResponse<Object> assignNum(@RequestParam("channelId") Long channelId, @RequestParam("assignNum") Integer assignNum) {
return channelResourceAssignService.assignNum(channelId, assignNum); return channelResourceAssignService.assignNum(channelId, assignNum);
} }

@ -4,14 +4,17 @@ import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ChannelQuery;
import com.baiye.modules.agent.service.CustomManageService; import com.baiye.modules.agent.service.CustomManageService;
import com.baiye.valid.AddGroup;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -27,13 +30,13 @@ public class CustomManageController {
@PostMapping("/add") @PostMapping("/add")
@ApiOperation("新增账号") @ApiOperation("新增账号")
public CommonResponse<Object> addCustom(@RequestBody ChannelCustom channelCustom) { public CommonResponse<Object> addCustom(@RequestBody @Validated({AddGroup.class}) ChannelCustom channelCustom) {
return customManageService.addCustom(channelCustom); return customManageService.addCustom(channelCustom);
} }
@GetMapping("/assign") @GetMapping("/assign")
@ApiOperation("配量") @ApiOperation("配量")
public CommonResponse<Object> assignNum(@RequestParam("customId") Long customId, @RequestParam("customId") Integer assignNum) { public CommonResponse<Object> assignNum(@RequestParam("customId") Long customId, @RequestParam("assignNum") Integer assignNum) {
return customManageService.assignNum(customId, assignNum); return customManageService.assignNum(customId, assignNum);
} }
@ -43,6 +46,12 @@ public class CustomManageController {
return new ResponseEntity<>(customManageService.queryAll(channelCustomQuery, pageable), HttpStatus.OK); return new ResponseEntity<>(customManageService.queryAll(channelCustomQuery, pageable), HttpStatus.OK);
} }
@GetMapping("/dmpLimitNum")
@ApiOperation("修改dmp投送数量")
public CommonResponse<Object> updateDmpLimitNum(@RequestParam("customId") Long customId, @RequestParam("dmpLimitNum") Integer dmpLimitNum) {
return customManageService.updateDmpLimitNum(customId, dmpLimitNum);
}
@GetMapping("/link") @GetMapping("/link")
@ApiOperation("生成链接") @ApiOperation("生成链接")
public CommonResponse<Object> addLink(@RequestParam("customId") Long customId, @RequestParam("type") Integer type) { public CommonResponse<Object> addLink(@RequestParam("customId") Long customId, @RequestParam("type") Integer type) {
@ -50,10 +59,9 @@ public class CustomManageController {
return CommonResponse.createBySuccess(linkUrl); return CommonResponse.createBySuccess(linkUrl);
} }
@GetMapping("/linkList") @GetMapping("/linkList")
@ApiOperation("渠道商链接地址") @ApiOperation("渠道商链接地址")
public CommonResponse<Map<Integer,String>> findCustomList(@RequestParam("customId") Long customId) { public CommonResponse<List<Map<String, Object>>> findCustomList(@RequestParam("customId") Long customId) {
return CommonResponse.createBySuccess(customManageService.findUrlByCustomId(customId)); return CommonResponse.createBySuccess(customManageService.findUrlByCustomId(customId));
} }
} }

@ -47,11 +47,15 @@ public class ChannelCustom implements Serializable {
@ApiModelProperty(value = "总分配量") @ApiModelProperty(value = "总分配量")
@Column(name = "total_num") @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 = "分配余量") @ApiModelProperty(value = "分配余量")
@Column(name = "surplus_num") @Column(name = "surplus_num")
private Integer surplusNum; private Integer surplusNum = 0;
@ApiModelProperty(value = "用户状态 1 正常 2-待开通-3 禁用") @ApiModelProperty(value = "用户状态 1 正常 2-待开通-3 禁用")
@Column(name = "status") @Column(name = "status")
@ -71,21 +75,21 @@ public class ChannelCustom implements Serializable {
@ApiModelProperty(value = "父id") @ApiModelProperty(value = "父id")
@Column(name = "parent_id") @Column(name = "parent_id")
@NotNull(groups = AddGroup.class)
private Long parentId; private Long parentId;
@ApiModelProperty(value = "dmp上传数量") @ApiModelProperty(value = "子账号")
@Column(name = "dmp_limit_num")
@NotNull(groups = AddGroup.class)
private Integer dmpLimitNum;
@Transient @Transient
private List<ChannelCustom> children; private List<ChannelCustom> children;
@ApiModelProperty(value = "所有子账号数量")
@Transient @Transient
private Integer allCustomNum; private Integer allCustomNum;
@ApiModelProperty(value = "已开通的子账号数")
@Transient @Transient
private Integer normalNum; private Integer normalNum;
@ApiModelProperty(value = "待开通的子账号数")
@Transient @Transient
private Integer waitNum; private Integer waitNum;

@ -1,5 +1,6 @@
package com.baiye.modules.agent.entity; package com.baiye.modules.agent.entity;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@ -48,6 +49,7 @@ public class ChannelResourceAssign implements Serializable {
this.setAssignNum(assignNum); this.setAssignNum(assignNum);
this.setAssignBy(assignBy); this.setAssignBy(assignBy);
this.setAssignName(assignName); this.setAssignName(assignName);
this.setCreateTime(DateUtil.date());
return this; return this;
} }
} }

@ -15,14 +15,11 @@ public class ChannelQuery {
@Query(type = Query.Type.INNER_LIKE) @Query(type = Query.Type.INNER_LIKE)
private String channelName; private String channelName;
@ApiModelProperty(value = "默认排序为0 1-总量排序 2-余量排序")
private Integer sort = 0;
@ApiModelProperty(value = "客户类型 1-渠道商 2-直客") @ApiModelProperty(value = "客户类型 1-渠道商 2-直客")
@Query(type = Query.Type.EQUAL) @Query(type = Query.Type.EQUAL)
private Integer type; private Integer type;
@ApiModelProperty(value = "父id")
@Query(propName = "parentId", type = Query.Type.EQUAL) @Query(propName = "parentId", type = Query.Type.EQUAL)
private Long id; private Long id;
} }

@ -14,7 +14,7 @@ import java.util.List;
public class ResourceAssignInfoQuery { public class ResourceAssignInfoQuery {
@Query @Query
private Long id; private Long channelId;
@Query(type = Query.Type.BETWEEN) @Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime; private List<Timestamp> createTime;

@ -45,6 +45,17 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
@Query("UPDATE ChannelCustom set status = ?2 where id in ?1") @Query("UPDATE ChannelCustom set status = ?2 where id in ?1")
int updateCustomStatus(Set<Long> ids, Integer status); int updateCustomStatus(Set<Long> 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 * id
* *

@ -4,7 +4,9 @@ import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ChannelQuery;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -39,8 +41,18 @@ public interface CustomManageService {
*/ */
Object queryAll(ChannelQuery channelCustomQuery, Pageable pageable); Object queryAll(ChannelQuery channelCustomQuery, Pageable pageable);
/**
* dmp
*
* @param customId
* @param dmpLimitNum
* @return
*/
CommonResponse<Object> updateDmpLimitNum(Long customId, Integer dmpLimitNum);
/** /**
* *
*
* @param customId * @param customId
* @param type * @param type
* @return * @return
@ -49,10 +61,11 @@ public interface CustomManageService {
/** /**
* id * id
*
* @param customId * @param customId
* @return * @return
*/ */
Map<Integer, String> findUrlByCustomId(Long customId); List<Map<String, Object>> findUrlByCustomId(Long customId);
/** /**

@ -3,9 +3,9 @@ package com.baiye.modules.agent.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.DefaultNumberConstants;
import com.baiye.http.CommonResponse; 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.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery; 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.agent.service.ChannelManageService;
import com.baiye.modules.platform.service.dto.CreateUserDTO; import com.baiye.modules.platform.service.dto.CreateUserDTO;
import com.baiye.modules.system.service.UserService; import com.baiye.modules.system.service.UserService;
@ -40,16 +40,7 @@ public class ChannelManageServiceImpl implements ChannelManageService {
@Override @Override
public Object queryAll(ChannelQuery channelQuery, Pageable pageable) { public Object queryAll(ChannelQuery channelQuery, Pageable pageable) {
Sort sort; PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime"));
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<ChannelCustom> channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest); Page<ChannelCustom> channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest);
List<ChannelCustom> content = new ArrayList<>(channelCustoms.getContent()); List<ChannelCustom> content = new ArrayList<>(channelCustoms.getContent());
if (CollUtil.isEmpty(content)) { if (CollUtil.isEmpty(content)) {
@ -58,17 +49,25 @@ public class ChannelManageServiceImpl implements ChannelManageService {
//父级 //父级
Map<Long, ChannelCustom> parentMap = new HashMap<>(8); Map<Long, ChannelCustom> parentMap = new HashMap<>(8);
for (ChannelCustom channelCustom : content) { for (ChannelCustom channelCustom : content) {
if (channelCustom.getParentId() == null) { Long parentId = channelCustom.getParentId();
if (parentId == null) {
parentMap.put(channelCustom.getId(), channelCustom); parentMap.put(channelCustom.getId(), channelCustom);
} }
} }
//查询出所有子集 //查询出所有子集
Set<Long> set = parentMap.keySet(); Set<Long> set = parentMap.keySet();
List<ChannelCustom> byParentId = channelCustomRepository.findByParentId(set); List<ChannelCustom> byParentId = new ArrayList<>();
content.addAll(byParentId); if (CollUtil.isNotEmpty(set)) {
byParentId = channelCustomRepository.findByParentId(set);
}
List<ChannelCustom> 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<Long, List<ChannelCustom>> userMap = content.stream().filter(channelCustom -> channelCustom.getParentId() != null) Map<Long, List<ChannelCustom>> userMap = byParentId.stream().collect(Collectors.groupingBy(ChannelCustom::getParentId));
.collect(Collectors.groupingBy(ChannelCustom::getParentId));
int allCustomNum = 0; int allCustomNum = 0;
int normalNum = 0; int normalNum = 0;
int waitNum = 0; int waitNum = 0;
@ -81,8 +80,8 @@ public class ChannelManageServiceImpl implements ChannelManageService {
} }
List<ChannelCustom> children = userMap.get(key); List<ChannelCustom> children = userMap.get(key);
if (CollUtil.isNotEmpty(children)) { if (CollUtil.isNotEmpty(children)) {
List<ChannelCustom> normalNums = children.stream().filter(c -> c.getStatus() == 1).collect(Collectors.toList()); List<ChannelCustom> normalNums = children.stream().filter(c -> c.getStatus() == DefaultNumberConstants.ONE_NUMBER).collect(Collectors.toList());
List<ChannelCustom> waitNums = children.stream().filter(c -> c.getStatus() == 2).collect(Collectors.toList()); List<ChannelCustom> waitNums = children.stream().filter(c -> c.getStatus() == DefaultNumberConstants.TWO_NUMBER).collect(Collectors.toList());
normalNum = normalNums.size(); normalNum = normalNums.size();
waitNum = waitNums.size(); waitNum = waitNums.size();
} }

@ -1,12 +1,13 @@
package com.baiye.modules.agent.service.impl; package com.baiye.modules.agent.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baiye.http.CommonResponse; 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.ChannelCustom;
import com.baiye.modules.agent.entity.ChannelResourceAssign; import com.baiye.modules.agent.entity.ChannelResourceAssign;
import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ChannelQuery;
import com.baiye.modules.agent.entity.query.ResourceAssignInfoQuery; 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.modules.agent.service.ChannelResourceAssignService;
import com.baiye.util.PageUtil; import com.baiye.util.PageUtil;
import com.baiye.util.QueryHelp; import com.baiye.util.QueryHelp;
@ -30,24 +31,17 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe
@Override @Override
public Object queryAll(ChannelQuery channelQuery, Pageable pageable) { 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); channelQuery.setId(null);
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime"));
Page<ChannelResourceAssign> channelCustoms = channelResourceAssignRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest); Page<ChannelCustom> channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest);
return PageUtil.toPage(channelCustoms); return PageUtil.toPage(channelCustoms);
} }
@Override @Override
public Object queryAssign(ResourceAssignInfoQuery resourceAssignInfoQuery, Pageable pageable) { public Object queryAssign(ResourceAssignInfoQuery resourceAssignInfoQuery, Pageable pageable) {
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "create_time")); PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime"));
return channelResourceAssignRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, resourceAssignInfoQuery, criteriaBuilder), pageRequest); Page<ChannelResourceAssign> all = channelResourceAssignRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, resourceAssignInfoQuery, criteriaBuilder), pageRequest);
return PageUtil.toPage(all);
} }
@Override @Override
@ -58,6 +52,8 @@ public class ChannelResourceAssignServiceImpl implements ChannelResourceAssignSe
channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum);
channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum);
channelCustomRepository.save(channelCustom); channelCustomRepository.save(channelCustom);
channelCustom.setPurchaseTime(DateUtil.date());
channelCustomRepository.save(channelCustom);
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }

@ -1,13 +1,16 @@
package com.baiye.modules.agent.service.impl; package com.baiye.modules.agent.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.text.StrPool; import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.http.CommonResponse; import com.baiye.http.CommonResponse;
import com.baiye.model.enums.ResponseCode;
import com.baiye.model.enums.UrlLinkEnum; import com.baiye.model.enums.UrlLinkEnum;
import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.ChannelCustomTag; 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.Role;
import com.baiye.modules.system.domain.User; import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.service.impl.UserServiceImpl; import com.baiye.modules.system.service.impl.UserServiceImpl;
import com.baiye.util.MobileUtil;
import com.baiye.util.FirstLetter; import com.baiye.util.FirstLetter;
import com.baiye.util.PageUtil; import com.baiye.util.PageUtil;
import com.baiye.util.QueryHelp; import com.baiye.util.QueryHelp;
import com.baiye.util.SecurityUtils; import com.baiye.util.SecurityUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -36,10 +41,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.HashSet; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -48,6 +50,7 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class CustomManageServiceImpl implements CustomManageService { public class CustomManageServiceImpl implements CustomManageService {
private final ChannelCustomRepository channelCustomRepository; private final ChannelCustomRepository channelCustomRepository;
@ -69,52 +72,61 @@ public class CustomManageServiceImpl implements CustomManageService {
if (ObjectUtil.isNotEmpty(byAndChannelName)) { if (ObjectUtil.isNotEmpty(byAndChannelName)) {
return CommonResponse.createByErrorMessage("名称重复"); return CommonResponse.createByErrorMessage("名称重复");
} }
if (!MobileUtil.checkPhone(channelCustom.getPhone())) {
return CommonResponse.createByErrorMessage(ResponseCode.PHONE_NUMBER_IS_INCORRECT.getDesc());
}
//新建账号状态为2 待开通 //新建账号状态为2 待开通
channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER); channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER);
//获取父账号的总量
ChannelCustom parent = getChannelCustomByUserId();
//设置分配 //设置分配
if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { if (channelCustom.getTotalNum() != null && channelCustom.getTotalNum() > 0) {
if (channelCustom.getTotalNum() != null) { if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) {
if (channelCustom.getTotalNum() < DefaultNumberConstants.TEN_THOUSAND) { if (channelCustom.getTotalNum() < DefaultNumberConstants.TEN_THOUSAND) {
return CommonResponse.createByErrorMessage("渠道商账号最低分配1万"); return CommonResponse.createByErrorMessage("渠道商账号最低分配1万");
} }
} } else {
} else {
if (channelCustom.getTotalNum() != null) {
if (channelCustom.getTotalNum() < DefaultNumberConstants.ONE_THOUSAND) { if (channelCustom.getTotalNum() < DefaultNumberConstants.ONE_THOUSAND) {
return CommonResponse.createByErrorMessage("直客账号最低分配1000"); 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.setActivationCode(activeCode);
channelCustom.setParentId(parent.getId());
channelCustomRepository.save(channelCustom);
channelCustomRepository.save(parent);
//这里如果是代理商 直接同步 //这里如果是代理商 直接同步
CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelCustom.getChannelName(), channelCustom.getPhone()); if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) {
User user = new User(); CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelCustom.getChannelName(), channelCustom.getPhone());
BeanUtil.copyProperties(createUserDTO, user); User user = new User();
user.setUsername(user.getUsername().trim()); BeanUtil.copyProperties(createUserDTO, user);
user.setWhichUserId(parent.getUserId()); user.setUsername(user.getUsername().trim());
user.setIsReview(Boolean.FALSE); user.setWhichUserId(parent.getUserId());
Set<Role> roles = new HashSet<>(); user.setIsReview(Boolean.FALSE);
Role role = new Role(); Set<Role> roles = new HashSet<>();
role.setId(14L); Role role = new Role();
roles.add(role); role.setId(14L);
user.setRoles(roles); roles.add(role);
userServiceImpl.create(user); user.setRoles(roles);
//分配记录 Long userId = userServiceImpl.create(user).getId();
ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getParentId(), channelCustom.getTotalNum(), channelCustom.getId(), channelCustom.getChannelName()); channelCustom.setUserId(userId);
channelResourceAssignRepository.save(channelResourceAssign); channelCustom.setStatus(1);
}
channelCustomRepository.save(channelCustom);
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }
@ -123,8 +135,7 @@ public class CustomManageServiceImpl implements CustomManageService {
public CommonResponse<Object> assignNum(Long customId, Integer assignNum) { public CommonResponse<Object> assignNum(Long customId, Integer assignNum) {
ChannelCustom channelCustom = channelCustomRepository.findById(customId).orElse(new ChannelCustom()); ChannelCustom channelCustom = channelCustomRepository.findById(customId).orElse(new ChannelCustom());
ChannelCustom parent = channelCustomRepository.findById(channelCustom.getParentId()).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 (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) {
if (assignNum < DefaultNumberConstants.TEN_THOUSAND) { if (assignNum < DefaultNumberConstants.TEN_THOUSAND) {
return CommonResponse.createByErrorMessage("渠道商账号最低分配1万"); return CommonResponse.createByErrorMessage("渠道商账号最低分配1万");
@ -134,42 +145,40 @@ public class CustomManageServiceImpl implements CustomManageService {
return CommonResponse.createByErrorMessage("直客账号最低分配1000"); return CommonResponse.createByErrorMessage("直客账号最低分配1000");
} }
} }
if (parentTotalNum < assignNum) { if (parentSurplusNum < assignNum) {
return CommonResponse.createByErrorMessage("可分配的余量不足"); return CommonResponse.createByErrorMessage("可分配的余量不足");
} }
//扣减父级渠道商的余量 //扣减父级渠道商的余量
parent.setSurplusNum(parent.getSurplusNum() - assignNum); parent.setSurplusNum(parentSurplusNum - assignNum);
//增加客户的总量和余量 //增加客户的总量和余量
channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum); channelCustom.setTotalNum(channelCustom.getTotalNum() + assignNum);
channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum); channelCustom.setSurplusNum(channelCustom.getSurplusNum() + assignNum);
channelCustomRepository.save(parent); channelCustom.setPurchaseTime(DateUtil.date());
channelCustomRepository.save(channelCustom);
//添加分配记录 //添加分配记录
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); channelResourceAssignRepository.save(channelResourceAssign);
channelCustomRepository.save(parent);
channelCustomRepository.save(channelCustom);
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }
@Override @Override
public Object queryAll(ChannelQuery channelCustomQuery, Pageable pageable) { 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; //这里的id 是userId;
Long id = SecurityUtils.getCurrentUserId(); Long customId = getChannelCustomByUserId().getId();
ChannelCustom byUserId = channelCustomRepository.findByUserId(id); channelCustomQuery.setId(customId);
channelCustomQuery.setId(byUserId.getId()); PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime"));
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
Page<ChannelCustom> channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelCustomQuery, criteriaBuilder), pageRequest); Page<ChannelCustom> channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelCustomQuery, criteriaBuilder), pageRequest);
return PageUtil.toPage(channelCustoms); return PageUtil.toPage(channelCustoms);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResponse<Object> updateDmpLimitNum(Long customId, Integer dmpLimitNum) {
channelCustomRepository.updateDmpLimitNum(customId, dmpLimitNum);
return CommonResponse.createBySuccess();
}
@Override @Override
public String createLinkUrl(Long customId, Integer type) { public String createLinkUrl(Long customId, Integer type) {
ChannelCustomTag customTag = channelCustomTagRepository.findByCustomIdAndType(customId, type); ChannelCustomTag customTag = channelCustomTagRepository.findByCustomIdAndType(customId, type);
@ -188,9 +197,9 @@ public class CustomManageServiceImpl implements CustomManageService {
if (ObjectUtil.isNotNull(linkEnum) && linkEnum.getUrl() != null) { if (ObjectUtil.isNotNull(linkEnum) && linkEnum.getUrl() != null) {
String tagUrl = linkEnum.name().toLowerCase().concat(StrPool.DASHED) String tagUrl = linkEnum.name().toLowerCase().concat(StrPool.DASHED)
.concat(firstPinYin.toLowerCase()) .concat(firstPinYin.toLowerCase())
.concat(StrPool.DASHED).concat(DateUtil.format(DateUtil.date(), "MMdd")) .concat(StrPool.DASHED).concat(DateUtil.format(DateUtil.date(), "MMdd"))
.concat(StrPool.DASHED).concat(RandomUtil.randomString .concat(StrPool.DASHED).concat(RandomUtil.randomString
(DefaultNumberConstants.FOUR_NUMBER)); (DefaultNumberConstants.FOUR_NUMBER));
String fullLink = configurationUrl.concat(linkEnum.getUrl()).concat(tagUrl); String fullLink = configurationUrl.concat(linkEnum.getUrl()).concat(tagUrl);
ChannelCustomTag channelCustomTag = new ChannelCustomTag(); ChannelCustomTag channelCustomTag = new ChannelCustomTag();
channelCustomTag.setTagType(type); channelCustomTag.setTagType(type);
@ -204,14 +213,22 @@ public class CustomManageServiceImpl implements CustomManageService {
} }
@Override @Override
public Map<Integer, String> findUrlByCustomId(Long customId) { public List<Map<String, Object>> findUrlByCustomId(Long customId) {
List<ChannelCustomTag> byChannelId = channelCustomTagRepository.findByChannelId(customId); List<ChannelCustomTag> byChannelId = channelCustomTagRepository.findByChannelId(customId);
return byChannelId.stream().collect(Collectors.toMap(ChannelCustomTag::getTagType, tag -> { List<Map<String, Object>> list = new ArrayList<>();
String tagStr = tag.getTagStr(); if (CollUtil.isNotEmpty(byChannelId)) {
Integer tagType = tag.getTagType(); for (ChannelCustomTag tag : byChannelId) {
UrlLinkEnum linkEnum = UrlLinkEnum.find(tagType); Integer tagType = tag.getTagType();
return configurationUrl.concat(linkEnum.getUrl()).concat(tagStr); String tagStr = tag.getTagStr();
})); UrlLinkEnum linkEnum = UrlLinkEnum.find(tagType);
String concat = configurationUrl.concat(linkEnum.getUrl()).concat(tagStr);
Map<String, Object> map = new HashMap<>(2);
map.put("type", tagType);
map.put("link", concat);
list.add(map);
}
}
return list;
} }
@Override @Override
@ -223,4 +240,14 @@ public class CustomManageServiceImpl implements CustomManageService {
DecimalFormat decimalFormat = new DecimalFormat("0000"); DecimalFormat decimalFormat = new DecimalFormat("0000");
return decimalFormat.format(num); 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;
}
} }

@ -9,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -37,7 +38,7 @@ public class CustomTest {
@Test @Test
public void customList() { public void customList() {
Map<Integer, String> urlByCustomId = customManageService.findUrlByCustomId(1L); List<Map<String, Object>> urlByCustomId = customManageService.findUrlByCustomId(1L);
System.out.println(urlByCustomId); System.out.println(urlByCustomId);
} }

@ -57,7 +57,7 @@ public class ClueJpa {
public List<ClueDto> getClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) { public List<ClueDto> getClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) {
StringBuilder sql = new StringBuilder(); 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," + 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.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 " + "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 "); "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<ClueDto> getTalkClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) { public List<ClueDto> getTalkClueList(ClueQueryCriteria clueQueryCriteria, Pageable pageable) {
StringBuilder sql = new StringBuilder(); 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," + 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.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 " + "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 "); "from tb_clue as c LEFT JOIN tb_clue_talk as cm on c.id = cm.clue_id where 1=1 ");

Loading…
Cancel
Save