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