master
wjt 1 year ago
parent 4a7e9381f5
commit 0aa1ea2f7a

@ -49,4 +49,6 @@ public class ChannelManageController {
public CommonResponse<Object> forbidden(@RequestBody Set<Long> ids) {
return channelManageService.forbidden(ids);
}
}

@ -82,4 +82,5 @@ public class CustomManageController {
public CommonResponse<Object> report() {
return customManageService.report();
}
}

@ -49,12 +49,20 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
*
* @param ids id
* @param status
* @return
*/
@Modifying
@Query("UPDATE ChannelCustom set status = ?2 where id in ?1")
int updateCustomStatus(Set<Long> ids, Integer status);
void updateCustomStatus(Set<Long> ids, Integer status);
/**
*
*
* @param id id
* @param status
*/
@Modifying
@Query("UPDATE ChannelCustom set status = ?2 where id = ?1")
void updateCustomStatus(Long id, Integer status);
/**
* dmp
@ -104,6 +112,16 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
@Query("UPDATE ChannelCustom set surplusNum = surplusNum - ?2 where userId = ?1")
void updateQuantity(Long userId, Integer number);
/**
*
*
* @param id
* @param surplusNum
*/
@Modifying
@Query("UPDATE ChannelCustom set surplusNum = surplusNum + ?2 where id = ?1")
void updateSurplusNum(Long id, Integer surplusNum);
/**
* id
*

@ -77,6 +77,14 @@ public interface CustomManageService {
*/
ChannelCustom findCustomByUserIdAndStatus(Long userId, Integer status);
/**
* id
*
* @param userId
* @return
*/
ChannelCustom findByUserId(Long userId);
/**
*
*
@ -86,8 +94,51 @@ public interface CustomManageService {
/**
*
*
* @param userId
* @param number
*/
void updateQuantity(Long userId, Integer number);
/**
*
*
* @param name
* @param phone
* @param userId
*/
void saveChannelCustom(String name, String phone, Long userId);
/**
*
*
* @param name
* @param phone
* @param userId
* @param parentId
*/
void saveChannelCustom(String name, String phone, Long userId, Long parentId);
/**
*
*
* @param userId
* @return
*/
List<Long> disableChannelCustom(Long userId);
/**
*
*
* @param userId
*/
void enableChannelCustom(Long userId);
/**
* id
*
* @param userId
* @return
*/
void deleteByUserId(Long userId);
}

@ -4,6 +4,7 @@ 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.feign.IRemoteAuthService;
import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery;
@ -33,6 +34,7 @@ import java.util.stream.Collectors;
public class ChannelManageServiceImpl implements ChannelManageService {
private final ChannelCustomRepository channelCustomRepository;
private final UserService userService;
private final IRemoteAuthService remoteAuthService;
@Override
public CommonResponse<Object> addChannel(String channelName, String phone, Long userId) {
@ -136,9 +138,68 @@ public class ChannelManageServiceImpl implements ChannelManageService {
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResponse<Object> forbidden(Set<Long> ids) {
channelCustomRepository.updateCustomStatus(ids, 3);
List<Long> userIdByIds = channelCustomRepository.findUserIdByIds(ids);
List<ChannelCustom> list = new ArrayList<>();
List<ChannelCustom> channelCustoms = channelCustomRepository.findAllById(ids);
for (ChannelCustom channelCustom : channelCustoms) {
if (channelCustom.getType() == 1) {
continue;
}
int num = channelCustom.getSurplusNum();
channelCustom.setStatus(3);
channelCustom.setSurplusNum(0);
list.add(channelCustom);
if (channelCustom.getParentId() != null) {
channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num);
}
}
channelCustomRepository.saveAll(list);
//同步系统
List<Long> userIdByIds = list.stream().map(ChannelCustom::getUserId).collect(Collectors.toList());
userService.updateUserStatusByCompanyId(false, userIdByIds);
//踢出用户
this.remoteAuthService.delete(new HashSet<>(userIdByIds));
return CommonResponse.createBySuccess();
}
/**
*
*
* @param ids
*/
@Transactional(rollbackFor = Exception.class)
public void forbiddenAll(Set<Long> ids) {
List<ChannelCustom> list = new ArrayList<>();
List<ChannelCustom> channelCustoms = channelCustomRepository.findAllById(ids);
for (ChannelCustom channelCustom : channelCustoms) {
int num = 0;
num = disableChannelById(channelCustom, list, num);
//增加父渠道商的余量
if (channelCustom.getParentId() != null) {
channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num);
}
}
channelCustomRepository.saveAll(list);
//同步
List<Long> userIdByIds = channelCustomRepository.findUserIdByIds(ids);
userService.updateUserStatusByCompanyId(false, userIdByIds);
}
private Integer disableChannelById(ChannelCustom custom, List<ChannelCustom> channelCustoms, Integer num) {
//禁用自己
custom.setStatus(3);
custom.setSurplusNum(0);
custom.setTotalNum(0);
channelCustoms.add(custom);
num += custom.getSurplusNum();
//代理商
if (custom.getType() == 1) {
List<ChannelCustom> byParentId = channelCustomRepository.findByParentId(custom.getId());
if (CollUtil.isNotEmpty(byParentId)) {
for (ChannelCustom channelCustom : byParentId) {
num += disableChannelById(channelCustom, channelCustoms, num);
}
}
}
return num;
}
}

@ -9,6 +9,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.exception.EntityExistException;
import com.baiye.http.CommonResponse;
import com.baiye.model.enums.ResponseCode;
import com.baiye.model.enums.UrlLinkEnum;
@ -24,7 +25,7 @@ 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.modules.system.repository.UserRepository;
import com.baiye.util.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -38,8 +39,8 @@ 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
@ -55,9 +56,7 @@ public class CustomManageServiceImpl implements CustomManageService {
private final ChannelResourceAssignRepository channelResourceAssignRepository;
private final UserServiceImpl userServiceImpl;
private final UserRepository userRepository;
@Value("${generate.url}")
private String configurationUrl;
@ -77,8 +76,9 @@ public class CustomManageServiceImpl implements CustomManageService {
return CommonResponse.createByErrorMessage(ResponseCode.PHONE_NUMBER_IS_INCORRECT.getDesc());
}
//验证号码重复
userServiceImpl.verifyPhone(channelCustom.getPhone());
if (userRepository.findByPhone(channelCustom.getPhone()) != null) {
throw new EntityExistException(User.class, "phone", channelCustom.getPhone());
}
//新建账号状态为2 待开通
channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER);
//获取父账号的总量
@ -99,7 +99,7 @@ public class CustomManageServiceImpl implements CustomManageService {
}
channelCustom.setSurplusNum(channelCustom.getTotalNum());
//减掉渠道商余量
parent.setSurplusNum(parent.getTotalNum() - channelCustom.getTotalNum());
parent.setSurplusNum(parent.getSurplusNum() - channelCustom.getTotalNum());
parent.setCreateTime(DateUtil.date());
channelCustomRepository.save(parent);
//分配记录
@ -129,7 +129,7 @@ public class CustomManageServiceImpl implements CustomManageService {
role.setId(channelId);
roles.add(role);
user.setRoles(roles);
Long userId = userServiceImpl.create(user).getId();
Long userId = create(user).getId();
channelCustom.setUserId(userId);
channelCustom.setStatus(1);
}
@ -244,6 +244,11 @@ public class CustomManageServiceImpl implements CustomManageService {
return channelCustomRepository.findByUserIdAndStatus(userId, status);
}
@Override
public ChannelCustom findByUserId(Long userId) {
return channelCustomRepository.findByUserId(userId);
}
@Override
public CommonResponse<Object> report() {
ChannelCustom channelCustomByUserId = getChannelCustomByUserId();
@ -290,4 +295,89 @@ public class CustomManageServiceImpl implements CustomManageService {
public void updateQuantity(Long userId, Integer number) {
channelCustomRepository.updateQuantity(userId, number);
}
/**
*
*
* @param name
* @param phone
* @param userId
*/
@Override
public void saveChannelCustom(String name, String phone, Long userId) {
channelCustomRepository.save(new ChannelCustom().addChannel(name, phone, userId));
}
@Override
public void saveChannelCustom(String name, String phone, Long userId, Long parentId) {
ChannelCustom byUserId = channelCustomRepository.findByUserId(userId);
channelCustomRepository.save(new ChannelCustom().addCustom(name, phone, userId, byUserId.getId()));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteByUserId(Long userId) {
ChannelCustom byUserId = channelCustomRepository.findByUserId(userId);
Integer num = 0;
if (byUserId.getType() == 2) {
num = byUserId.getSurplusNum();
channelCustomRepository.deleteByUserId(userId);
}
channelCustomRepository.updateSurplusNum(byUserId.getParentId(), num);
}
@Transactional(rollbackFor = Exception.class)
public User create(User resources) {
if (userRepository.findByUsername(resources.getUsername()) != null) {
throw new EntityExistException(User.class, "username", resources.getUsername());
}
if (userRepository.findByPhone(resources.getPhone()) != null) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
return userRepository.save(resources);
}
/**
*
*/
@Override
@Transactional(rollbackFor = Exception.class)
public List<Long> disableChannelCustom(Long userId) {
ChannelCustom custom = channelCustomRepository.findByUserId(userId);
List<ChannelCustom> channelCustoms = new ArrayList<>();
List<Integer> num = new ArrayList<>();
disableChannelById(custom, channelCustoms, num);
//禁用
channelCustomRepository.saveAll(channelCustoms);
//增加父渠道商的余量
if (custom.getParentId() != null) {
Integer integer = num.stream().reduce(Integer::sum).orElse(0);
channelCustomRepository.updateSurplusNum(custom.getParentId(), integer);
}
return channelCustoms.stream().map(ChannelCustom::getUserId).collect(Collectors.toList());
}
@Override
public void enableChannelCustom(Long userId) {
ChannelCustom custom = channelCustomRepository.findByUserId(userId);
channelCustomRepository.updateCustomStatus(custom.getId(), 1);
}
private void disableChannelById(ChannelCustom custom, List<ChannelCustom> channelCustoms, List<Integer> num) {
num.add(custom.getSurplusNum());
custom.setStatus(3);
custom.setSurplusNum(0);
custom.setTotalNum(0);
channelCustoms.add(custom);
//代理商
if (custom.getType() == 1) {
List<ChannelCustom> byParentId = channelCustomRepository.findByParentId(custom.getId());
if (CollUtil.isNotEmpty(byParentId)) {
for (ChannelCustom channelCustom : byParentId) {
disableChannelById(channelCustom, channelCustoms, num);
}
}
}
}
}

@ -37,6 +37,8 @@ import com.baiye.model.dto.*;
import com.baiye.model.enums.ResponseCode;
import com.baiye.modules.agent.repository.ChannelCustomRepository;
import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.service.ChannelManageService;
import com.baiye.modules.agent.service.CustomManageService;
import com.baiye.modules.platform.domain.*;
import com.baiye.modules.platform.repository.*;
import com.baiye.modules.platform.service.*;
@ -134,8 +136,8 @@ public class UserServiceImpl implements UserService {
private final ExtensionNumberService extensionNumberService;
private final TaskImeiService taskImeiService;
private final TaskTagRepository taskTagRepository;
private final ChannelCustomRepository channelCustomRepository;
// private final ChannelCustomRepository channelCustomRepository;
private final CustomManageService customManageService;
@Value("${channel.id}")
private Long channelId;
@ -255,7 +257,7 @@ public class UserServiceImpl implements UserService {
user.setIsReview(Boolean.FALSE);
create(user);
//同步渠道商信息
channelCustomRepository.save(new ChannelCustom().addChannel(userDTO.getUsername(), userDTO.getPhone(), user.getId()));
customManageService.saveChannelCustom(userDTO.getUsername(), userDTO.getPhone(), user.getId());
return Collections.singletonList(user.getId());
}
}
@ -298,8 +300,7 @@ public class UserServiceImpl implements UserService {
createTask(userCreateResult.getId(), "拓客模块-拓客回流池", DefaultNumberConstants.SIX_NUMBER);
//同步直客
if (userDTO.getIsChannelActive() == null || !userDTO.getIsChannelActive()) {
ChannelCustom byUserId = channelCustomRepository.findByUserId(userId);
channelCustomRepository.save(new ChannelCustom().addCustom(userDTO.getUsername(), userDTO.getPhone(), user.getId(), byUserId.getId()));
customManageService.saveChannelCustom(userDTO.getUsername(), userDTO.getPhone(), user.getId(), null);
}
}
@ -486,12 +487,6 @@ public class UserServiceImpl implements UserService {
return userRepository.save(resources);
}
public void verifyPhone(String phone) {
if (userRepository.findByPhone(phone) != null) {
throw new EntityExistException(User.class, "phone", phone);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(User resources) throws Exception {
@ -539,6 +534,14 @@ public class UserServiceImpl implements UserService {
}
}
}
List<Long> list = customManageService.disableChannelCustom(user.getId());
if (CollUtil.isNotEmpty(list)) {
updateUserStatusByCompanyId(false, list);
//踢出用户
this.remoteAuthService.delete(new HashSet<>(list));
}
} else {
customManageService.enableChannelCustom(user.getId());
}
if (!user.getUsername().equals(resources.getUsername()) && user.getCompanyId() != null) {
@ -683,8 +686,8 @@ public class UserServiceImpl implements UserService {
//13.删除imei和tag
taskImeiService.deleteTaskImei(taskIds);
taskTagRepository.deleteByTaskIds(taskIds);
//14 删除代理商系统下的用户信息
channelCustomRepository.deleteByUserId(user.getId());
//14.代理商下的用户
customManageService.deleteByUserId(user.getId());
return;
} else if (roleIds.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) {
// 二: 删除或者替换组长
@ -707,8 +710,9 @@ public class UserServiceImpl implements UserService {
}
this.sourceDel(userId, replaceUserId);
} else if (roleIds.contains(channelId)) {
throw new BadRequestException("暂时不支持删除渠道商");
throw new BadRequestException("暂不支持删除代理商");
}
//分机号
extensionNumberService.updateExtensionNumber(userId, replaceUserId);
// 清理缓存
@ -754,7 +758,7 @@ public class UserServiceImpl implements UserService {
convert.setCompanyType(companyByUserId.getCompanyType());
convert.setCompanyStatus(companyByUserId.getStatus());
}
ChannelCustom custom = channelCustomRepository.findByUserId(user.getId());
ChannelCustom custom = customManageService.findByUserId(user.getId());
if (custom != null) {
convert.setSurplusNum(custom.getSurplusNum());
}

Loading…
Cancel
Save