|
|
@@ -33,6 +33,8 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -42,8 +44,12 @@ import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.ydtech.constants.RedisConstant.PHONE_VERIFICATION_CODE_KEY;
|
|
|
+import static com.ydtech.constants.RedisConstant.PHONE_VERIFICATION_CODE_KEY_TIME;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 用户控制器
|
|
|
@@ -71,6 +77,8 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
private final EsmUserImageService esmUserImageService;
|
|
|
|
|
|
+ private final StringRedisTemplate redisTemplate;
|
|
|
+
|
|
|
// @PreAuthorize("hasAuthority('sys:user:delete')")
|
|
|
@ApiOperation(value = "逻辑删除")
|
|
|
@PostMapping(value = "/deleteFlag")
|
|
|
@@ -481,34 +489,51 @@ public class SysUserController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 个代注册
|
|
|
+ * 个代注册、出单员注册
|
|
|
*
|
|
|
* @author: lig
|
|
|
* @date: 2023年07月03日 0003
|
|
|
*/
|
|
|
- @ApiOperation(value = "(new)个代注册")
|
|
|
+ @ApiOperation(value = "(new)个代/出单员注册")
|
|
|
@PostMapping(value = "/agentRegist")
|
|
|
@Transactional
|
|
|
public HttpResult agentRegist(@RequestBody AgentUserDto dto) {
|
|
|
int noCount = 3;//顺序号是几位的
|
|
|
|
|
|
- String phoneMsg = dto.getMobileMsg();
|
|
|
- if (StringUtils.isNullOrEmpty(phoneMsg)) {
|
|
|
- return HttpResult.error("短信验证码不能为空");
|
|
|
+ if(StringUtils.isNullOrEmpty(dto.getFlag())){
|
|
|
+ return HttpResult.error("个代、出单员标识不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNullOrEmpty(dto.getMobile())||StringUtils.isNullOrEmpty(dto.getMobileMsg())) {
|
|
|
+ return HttpResult.error("手机号、验证码不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNullOrEmpty(dto.getName())){
|
|
|
+ return HttpResult.error("姓名不能为空");
|
|
|
+ }
|
|
|
+ if(StringUtils.isNullOrEmpty(dto.getPassword())){
|
|
|
+ return HttpResult.error("密码不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNullOrEmpty(dto.getReferrerId())){
|
|
|
+ return HttpResult.error("推荐人不能为空");
|
|
|
+ }
|
|
|
+ String captcha_redis =(String)redisTemplate.opsForValue().get(PHONE_VERIFICATION_CODE_KEY + dto.getMobile());
|
|
|
+ redisTemplate.delete(PHONE_VERIFICATION_CODE_KEY + dto.getMobile());
|
|
|
+ if(captcha_redis == null){
|
|
|
+ return HttpResult.error("验证码已失效");
|
|
|
+ }
|
|
|
+ if(!dto.getMobileMsg().equals(captcha_redis)){
|
|
|
+ return HttpResult.error("验证码错误");
|
|
|
}
|
|
|
- String recommenderid = dto.getReferrerId();
|
|
|
|
|
|
+ String recommenderid = dto.getReferrerId();
|
|
|
SysUser recommender = sysUserService.getById(recommenderid);
|
|
|
if (recommender == null) {
|
|
|
return HttpResult.error("推荐人信息不存在");
|
|
|
}
|
|
|
//只有团队长和代理人才能邀请 by gws
|
|
|
SysUserRole recommenderRole = sysUserRoleService.selectByUserId(recommenderid);
|
|
|
-
|
|
|
if (!"20".equals(recommenderRole.getRoleId().toString()) && !"21".equals(recommenderRole.getRoleId().toString())) {
|
|
|
- return HttpResult.error("只有团队长和代理人才能邀请");
|
|
|
+ return HttpResult.error("只有团队长和代理人才能推荐");
|
|
|
}
|
|
|
-
|
|
|
SysUser sysUser = sysUserService.findByPhone(dto.getMobile());
|
|
|
if (sysUser != null) {
|
|
|
return HttpResult.error("手机号已存在");
|
|
|
@@ -523,37 +548,34 @@ public class SysUserController extends BaseController {
|
|
|
} else {
|
|
|
nextPK = IdGenerate.nextCode(maxId, noCount);
|
|
|
}
|
|
|
- if (dto.getName() != null && !dto.getName().isEmpty()) {
|
|
|
- } else {
|
|
|
- sysUser.setName("游客");
|
|
|
- }
|
|
|
+ sysUser.setName(dto.getName());
|
|
|
sysUser.setMobile(dto.getMobile());
|
|
|
sysUser.setDeptId(recommender.getDeptId());
|
|
|
//密码加密
|
|
|
- if(StringUtils.isEmpty(dto.getPassword())){
|
|
|
- return HttpResult.error("密码不能为空");
|
|
|
- }
|
|
|
String salt = PasswordUtils.getSalt();
|
|
|
String password = PasswordUtils.encode(dto.getPassword(), salt);
|
|
|
sysUser.setPassword(password);
|
|
|
sysUser.setSalt(salt);
|
|
|
- sysUser.setStatus(2);
|
|
|
+ sysUser.setStatus(dto.getFlag().equals("1")?2:1);//1:正常 2:审批中
|
|
|
sysUser.setId(nextPK);
|
|
|
sysUser.setCreateBy("admin");
|
|
|
+ if(dto.getFlag().equals("2")){
|
|
|
+ sysUser.setOperatorCode(recommenderid);
|
|
|
+ }
|
|
|
sysUserService.save(sysUser);
|
|
|
|
|
|
//角色配置
|
|
|
SysUserRole userRole = new SysUserRole();
|
|
|
userRole.setUserId(nextPK);
|
|
|
- userRole.setRoleId(20L);
|
|
|
+ userRole.setRoleId(dto.getFlag().equals("1")?20L:19L);
|
|
|
sysUserRoleService.save(userRole);
|
|
|
|
|
|
- esmUserReferrerService.addReferrer(dto.getReferrerId(), nextPK);
|
|
|
-
|
|
|
+ if(dto.getFlag().equals("1")){
|
|
|
+ esmUserReferrerService.addReferrer(dto.getReferrerId(), nextPK);
|
|
|
+ }
|
|
|
return HttpResult.ok("保存成功", sysUser.getId());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@PostMapping(value = "/newUserImport")
|
|
|
@ApiOperation(value = "新用户导入")
|
|
|
@ApiImplicitParams({
|