Merge branch 'platform-agent'

master
bynt 1 year ago
commit ef191ebea1

@ -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<Object> queryAll(ChannelQuery channelQuery, Pageable pageable) {
return new ResponseEntity<>(channelManageService.queryAll(channelQuery, pageable), HttpStatus.OK);
}
@GetMapping("/report")
@ApiOperation("统计")
public CommonResponse<Object> report() {
return channelManageService.report();
}
@ApiOperation("激活开通")
@PostMapping("/active")
public CommonResponse<Object> active(@RequestBody Set<Long> ids) {

@ -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<Object> queryAll(ChannelQuery channelResourceQuery, Pageable pageable) {
public ResponseEntity<Object> 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<Object> report() {
return channelResourceAssignService.report();
}
}

@ -67,15 +67,19 @@ public class CustomManageController {
return CommonResponse.createBySuccess(customManageService.findUrlByCustomId(customId));
}
@Log
@Inner
@ApiOperation("修改数量")
@GetMapping("/update/quantity")
public ResponseEntity<Void> updateQuantity(Long userId, Integer number) {
public CommonResponse<Object> updateQuantity(Long userId, Integer number) {
customManageService.updateQuantity(userId, number);
return new ResponseEntity<>(HttpStatus.OK);
return CommonResponse.createBySuccess();
}
@GetMapping("/report")
@ApiOperation("统计")
public CommonResponse<Object> report() {
return customManageService.report();
}
}

@ -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;
}
}

@ -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;
}

@ -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;
}
}

@ -26,13 +26,23 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
ChannelCustom findByAndChannelName(String name);
/**
* id
* id
*
* @param type
* @param parentIds id
* @return
*/
@Query("select c from ChannelCustom c where c.parentId in ?1")
List<ChannelCustom> findByParentId(Set<Long> parentIds);
@Query("select c from ChannelCustom c where c.type =?1 and c.parentId in ?2")
List<ChannelCustom> findByParentIds(Integer type, Set<Long> parentIds);
/**
* id
*
* @param parentId id
* @return
*/
@Query("select c from ChannelCustom c where c.parentId = ?1")
List<ChannelCustom> findByParentId(Long parentId);
/**
*
@ -45,6 +55,7 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
@Query("UPDATE ChannelCustom set status = ?2 where id in ?1")
int updateCustomStatus(Set<Long> ids, Integer status);
/**
* dmp
*
@ -64,6 +75,14 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
*/
ChannelCustom findByUserId(Long userId);
/**
* id
*
* @param ids
* @return
*/
@Query("select c.userId from ChannelCustom as c where c.id in ?1 ")
List<Long> findUserIdByIds(Set<Long> ids);
/**
* id
@ -77,10 +96,19 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
/**
*
*
* @param userId
* @param number
*/
@Modifying
@Query("UPDATE ChannelCustom set surplusNum = surplusNum - ?2 where userId = ?1")
void updateQuantity(Long userId, Integer number);
/**
*
* @param type
* @return
*/
@Query("from ChannelCustom where type = ?1")
List<ChannelCustom> findByType(Integer type);
}

@ -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<ChannelResourceAssign, Long>, JpaSpecificationExecutor<ChannelResourceAssign> {
/**
* admin
*
* @return
*/
@Query("select c from ChannelResourceAssign as c where c.channelId is null")
List<ChannelResourceAssign> findAdminAssign();
}

@ -30,6 +30,12 @@ public interface ChannelManageService {
*/
Object queryAll(ChannelQuery channelQuery, Pageable pageable);
/**
*
*
* @return
*/
CommonResponse<Object> report();
/**
*
*

@ -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<Object> assignNum(Long customId, Integer assignNum);
/**
*
*
* @return
*/
CommonResponse<Object> report();
}

@ -77,6 +77,13 @@ public interface CustomManageService {
*/
ChannelCustom findCustomByUserIdAndStatus(Long userId, Integer status);
/**
*
*
* @return
*/
CommonResponse<Object> report();
/**
*
* @param userId

@ -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<ChannelCustom> channelCustoms = channelCustomRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, channelQuery, criteriaBuilder), pageRequest);
List<ChannelCustom> content = new ArrayList<>(channelCustoms.getContent());
if (CollUtil.isEmpty(content)) {
return channelCustoms;
}
//父级
Map<Long, ChannelCustom> parentMap = new HashMap<>(8);
for (ChannelCustom channelCustom : content) {
Long parentId = channelCustom.getParentId();
if (parentId == null) {
parentMap.put(channelCustom.getId(), channelCustom);
}
}
//查询出所有子集
Set<Long> set = parentMap.keySet();
List<ChannelCustom> byParentId = new ArrayList<>();
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));
Set<Long> parentIds = content.stream().map(ChannelCustom::getId).collect(Collectors.toSet());
//子集
List<ChannelCustom> byParentId = channelCustomRepository.findByParentIds(2, parentIds);
Map<Long, List<ChannelCustom>> 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<ChannelCustom> list = userMap.get(parentId);
if (CollUtil.isNotEmpty(list)) {
List<ChannelCustom> normalNums = list.stream().filter(c -> c.getStatus() == DefaultNumberConstants.ONE_NUMBER).collect(Collectors.toList());
List<ChannelCustom> 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<Object> report() {
DateTime time = DateUtil.date();
DateTime startTime = DateUtil.beginOfDay(DateUtil.offsetDay(time, -7));
DateTime yesterday = DateUtil.offsetDay(time, -1);
List<ChannelCustom> byTypeAndCreateTime = channelCustomRepository.findByType(1);
Map<String, Integer> 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<ChannelCustom> children = userMap.get(key);
if (CollUtil.isNotEmpty(children)) {
List<ChannelCustom> normalNums = children.stream().filter(c -> c.getStatus() == DefaultNumberConstants.ONE_NUMBER).collect(Collectors.toList());
List<ChannelCustom> 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<Object> active(Set<Long> ids) {
List<ChannelCustom> channelCustoms = channelCustomRepository.findAllById(ids);
List<ChannelCustom> list = new ArrayList<>();
for (ChannelCustom channelCustom : channelCustoms) {
String channelName = channelCustom.getChannelName();
String phone = channelCustom.getPhone();
//同步到系统用户
CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelName, phone);
List<Long> 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<Long> 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<Object> forbidden(Set<Long> ids) {
channelCustomRepository.updateCustomStatus(ids, 3);
userService.updateUserStatusByCompanyId(false, new ArrayList<>(ids));
List<Long> userIdByIds = channelCustomRepository.findUserIdByIds(ids);
userService.updateUserStatusByCompanyId(false, userIdByIds);
return CommonResponse.createBySuccess();
}
}

@ -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<ChannelCustom> 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<Object> report() {
List<ChannelResourceAssign> 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<String, Integer> map = new HashMap<>(3);
map.put("totalNum", totalNum);
map.put("yesterdayNum", yesterdayNum);
map.put("todayNum", todayNum);
return CommonResponse.createBySuccess(map);
}
}

@ -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<Object> 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<Role> 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<Object> report() {
ChannelCustom channelCustomByUserId = getChannelCustomByUserId();
int totalNum = channelCustomByUserId.getTotalNum();
int surplusNum = channelCustomByUserId.getSurplusNum();
int assignNum = totalNum - surplusNum;
List<ChannelCustom> 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);

@ -159,6 +159,7 @@ public interface UserService {
*/
void updateUserStatusByCompanyId(Boolean flag, List<Long> ids);
void updateStatusById(Boolean flag,Long id);
/**
*
*/

@ -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<Long> fileCreateUser(List<UserFavorOfExcel> 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();

@ -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);
}
}

@ -206,3 +206,7 @@ activation:
namePrefix: by_
# url: fission-server.xhuatea.com
# namePrefix: by_zs_
#渠道商的id
channel:
id: 14

@ -203,3 +203,7 @@ ad-back:
activation:
url: fission-server.xhuatea.com
namePrefix: by_
#渠道商的id
channel:
id: 11
Loading…
Cancel
Save