|
|
|
@ -3,8 +3,8 @@ package com.baiye.modules.agent.service.impl;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
|
|
import cn.hutool.core.text.StrPool;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import com.baiye.constant.DefaultNumberConstants;
|
|
|
|
@ -23,6 +23,12 @@ import com.baiye.modules.agent.repository.ChannelCustomRepository;
|
|
|
|
|
import com.baiye.modules.agent.repository.ChannelCustomTagRepository;
|
|
|
|
|
import com.baiye.modules.agent.repository.ChannelResourceAssignRepository;
|
|
|
|
|
import com.baiye.modules.agent.service.CustomManageService;
|
|
|
|
|
import com.baiye.modules.platform.domain.Task;
|
|
|
|
|
import com.baiye.modules.platform.repository.TaskRepository;
|
|
|
|
|
import com.baiye.modules.platform.service.CompanyService;
|
|
|
|
|
import com.baiye.modules.platform.service.PayFatherTemplateService;
|
|
|
|
|
import com.baiye.modules.platform.service.QualityScoreService;
|
|
|
|
|
import com.baiye.modules.platform.service.dto.CompanyDto;
|
|
|
|
|
import com.baiye.modules.platform.service.dto.CreateUserDTO;
|
|
|
|
|
import com.baiye.modules.system.domain.Role;
|
|
|
|
|
import com.baiye.modules.system.domain.User;
|
|
|
|
@ -51,6 +57,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ChannelCustomRepository channelCustomRepository;
|
|
|
|
|
|
|
|
|
|
private final ChannelCustomTagRepository channelCustomTagRepository;
|
|
|
|
@ -58,6 +66,11 @@ public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
private final ChannelResourceAssignRepository channelResourceAssignRepository;
|
|
|
|
|
|
|
|
|
|
private final UserRepository userRepository;
|
|
|
|
|
|
|
|
|
|
private final CompanyService companyService;
|
|
|
|
|
private final TaskRepository taskRepository;
|
|
|
|
|
private final QualityScoreService qualityScoreService;
|
|
|
|
|
private final PayFatherTemplateService payFatherTemplateService;
|
|
|
|
|
@Value("${generate.url}")
|
|
|
|
|
private String configurationUrl;
|
|
|
|
|
|
|
|
|
@ -122,15 +135,21 @@ public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
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) {
|
|
|
|
|
addChannelCustom(channelCustom);
|
|
|
|
|
}
|
|
|
|
|
channelCustom.setCreateTime(DateUtil.date());
|
|
|
|
|
channelCustom.setCustomLimitNum(100);
|
|
|
|
|
channelCustom.setChannelLimitNum(1);
|
|
|
|
|
//这里如果是代理商 直接同步
|
|
|
|
|
if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
syncChannelCustom(channelCustom);
|
|
|
|
|
}
|
|
|
|
|
//todo 自动激活账号 如果不需要自动激活 去掉这个else就可以
|
|
|
|
|
else {
|
|
|
|
|
syncCustom(channelCustom);
|
|
|
|
|
channelCustom.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
}
|
|
|
|
|
channelCustomRepository.save(channelCustom);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChannelResourceAssign channelResourceAssign = new ChannelResourceAssign().addChannelResourceAssign(parent.getId(), channelCustom.getId(), channelCustom.getChannelName());
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
if (channelCustom.getSurplusNum() != null && channelCustom.getSurplusNum() > 0) {
|
|
|
|
@ -148,7 +167,12 @@ public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
return CommonResponse.createBySuccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addChannelCustom(ChannelCustom channelCustom) {
|
|
|
|
|
/**
|
|
|
|
|
* 同步创建代理商账号
|
|
|
|
|
*
|
|
|
|
|
* @param channelCustom
|
|
|
|
|
*/
|
|
|
|
|
private void syncChannelCustom(ChannelCustom channelCustom) {
|
|
|
|
|
CreateUserDTO createUserDTO = new CreateUserDTO().addCreateUserDTO(channelCustom.getChannelName(), channelCustom.getPhone());
|
|
|
|
|
createUserDTO.setPassword(passwordEncoder.encode
|
|
|
|
|
(StringUtils.isNotBlank(createUserDTO.getPassword())
|
|
|
|
@ -156,7 +180,7 @@ public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
User user = new User();
|
|
|
|
|
BeanUtil.copyProperties(createUserDTO, user);
|
|
|
|
|
user.setUsername(user.getUsername().trim());
|
|
|
|
|
//这个地方注意,代理商的创建人为admin。这whichUserId属性会在之前的逻辑里面用到,这里写死了
|
|
|
|
|
//todo 这个地方注意,代理商的创建人为admin。这whichUserId属性会在之前的逻辑里面用到,这里写死了
|
|
|
|
|
user.setWhichUserId(1L);
|
|
|
|
|
user.setIsReview(Boolean.FALSE);
|
|
|
|
|
Set<Role> roles = new HashSet<>();
|
|
|
|
@ -169,6 +193,73 @@ public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
channelCustom.setStatus(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同步创建直客账号(公司用户)
|
|
|
|
|
*
|
|
|
|
|
* @param channelCustom
|
|
|
|
|
*/
|
|
|
|
|
private void syncCustom(ChannelCustom channelCustom) {
|
|
|
|
|
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(1L);
|
|
|
|
|
user.setIsReview(Boolean.FALSE);
|
|
|
|
|
|
|
|
|
|
//创建公司
|
|
|
|
|
CompanyDto companyDto = new CompanyDto();
|
|
|
|
|
companyDto.setCompanyName(user.getUsername().trim());
|
|
|
|
|
// companyDto.setTemplateId(userDTO.getTemplateId());
|
|
|
|
|
companyDto.setCompanyType(createUserDTO.getCompanyType());
|
|
|
|
|
companyDto.setStatus(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
Long companyId = companyService.createCompany(companyDto).getId();
|
|
|
|
|
user.setCompanyId(companyId);
|
|
|
|
|
|
|
|
|
|
user.setTurnCrmNum(50);
|
|
|
|
|
//创建账号
|
|
|
|
|
Long userId = create(user).getId();
|
|
|
|
|
|
|
|
|
|
//公司名称做的对应,所以将公司名设为表单任务名
|
|
|
|
|
createTask(userId, user.getUsername(), DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
createTask(userId, "员工上传任务", DefaultNumberConstants.TWO_NUMBER);
|
|
|
|
|
createTask(userId, "拓客模块-投流回流池", DefaultNumberConstants.SEVEN_NUMBER);
|
|
|
|
|
createTask(userId, "拓客模块-拓客回流池", DefaultNumberConstants.SIX_NUMBER);
|
|
|
|
|
|
|
|
|
|
//添加质量图
|
|
|
|
|
qualityScoreService.addDefault(userId);
|
|
|
|
|
//todo 创建默认的支付模板 (因为这快业务已经不需要了,为了避免多余业务操作,默认创建一个)
|
|
|
|
|
payFatherTemplateService.addDefaultTemplate(user.getUsername(), userId, user.getExpirationTime(), companyId);
|
|
|
|
|
|
|
|
|
|
channelCustom.setUserId(userId);
|
|
|
|
|
channelCustom.setStatus(1);
|
|
|
|
|
channelCustom.setUserId(userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在创建用户时 创建一个表单任动态务
|
|
|
|
|
*
|
|
|
|
|
* @param username
|
|
|
|
|
*/
|
|
|
|
|
private void createTask(Long id, String username, Integer isForm) {
|
|
|
|
|
Long taskId = IdUtil.getSnowflake(9, 9).nextId();
|
|
|
|
|
Task task = new Task();
|
|
|
|
|
task.setId(taskId);
|
|
|
|
|
task.setTaskName(username);
|
|
|
|
|
task.setEncryptionType(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
//设置默认值
|
|
|
|
|
if (isForm == DefaultNumberConstants.SIX_NUMBER || isForm == DefaultNumberConstants.SEVEN_NUMBER) {
|
|
|
|
|
task.setIsDistribution(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
} else {
|
|
|
|
|
task.setIsDistribution(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
}
|
|
|
|
|
task.setTaskType(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
task.setIsForm(isForm);
|
|
|
|
|
task.setCreateBy(id);
|
|
|
|
|
taskRepository.save(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@ -513,4 +604,5 @@ public class CustomManageServiceImpl implements CustomManageService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|