新增用户 直接注册

This commit is contained in:
liuchengqian 2023-03-14 15:37:26 +08:00
parent 3068935bbf
commit c3c96456c4
4 changed files with 132 additions and 2 deletions

View File

@ -40,7 +40,8 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/debug").permitAll()
.antMatchers("/queryNotice").permitAll()//查询通知
.antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll()
.antMatchers(HttpMethod.POST, "/api/user/add").permitAll()
.antMatchers(HttpMethod.POST, "/api/user/add").permitAll()//新增用户
.antMatchers(HttpMethod.POST, "/api/user/add2").permitAll()//新增用户直接注册
.antMatchers(HttpMethod.POST, "/api/user/check/duplicate").permitAll()
.antMatchers(HttpMethod.POST, "/api/login").permitAll()
.antMatchers(HttpMethod.GET, "/api/user/booleanUserName").permitAll()

View File

@ -162,6 +162,19 @@ public class SysUserController {
return sysUserService.addUser(userQo, servletRequest);
}
/**
* 注册系统用户
*/
@RequestMapping(value = "/add2", method = RequestMethod.POST)
public String addUser2(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo) {
// 验证用户名是否重复
if (!sysUserService.checkUserName(userQo.getUserName())) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale);
}
// 添加新用户
return sysUserService.addUser2(userQo);
}
/**
* 删除系统用户
*/

View File

@ -20,13 +20,21 @@ public interface SysUserService {
boolean checkUserName(String userName);
/**
* 保存用户
* 新增用户
*
* @param sysUserQo
* @return
*/
String addUser(SysUserQo sysUserQo, HttpServletRequest servletRequest);
/**
* 新增用户直接注册版
*
* @param sysUserQo
* @return
*/
String addUser2(SysUserQo sysUserQo);
/**
* 删除系统用户
*

View File

@ -178,6 +178,114 @@ public class SysUserServiceImpl implements SysUserService {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "注册成功!", locale);
}
/**
* 新增用户直接注册版
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String addUser2(SysUserQo sysUserQo) {
// 获取区域信息
String salt = KeyGenerators.string().generateKey();
SysUserEntity sysUserEntity = new SysUserEntity();
sysUserEntity.setUserName(sysUserQo.getUserName());
sysUserEntity.setUserAgent("");
if ("".equals(sysUserQo.getReallyName()) || sysUserQo.getReallyName() == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "真实姓名不能为空!", locale);
}
sysUserEntity.setReallyName(sysUserQo.getReallyName());
sysUserEntity.setSalt(salt);
sysUserEntity.setPassword(encry256(sysUserQo.getPassword() + salt));
sysUserEntity.setTelephone(sysUserQo.getUserName());
String countyCode = sysUserQo.getCountyCode();
String countyName = sysUserQo.getCountyName();
if (TextUtils.isEmpty(countyCode)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省市区街道编码不能为空!", locale);
}
if (TextUtils.isEmpty(countyName)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省市区街道名称不能为空!", locale);
}
if (9 == countyCode.length()) {
List<StreetEntity> streetCodeList = streetDao.findByStreetCode(countyCode);
if (streetCodeList == null || streetCodeList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "街道编码不存在!", locale);
}
List<StreetEntity> streetNameList = streetDao.findByStreetName(countyName);
if (streetNameList == null || streetNameList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
}
sysUserEntity.setActiveFlag(0);
sysUserEntity.setAccountType("街道级");
} else if ("0000".equals(countyCode.substring(2))) {
List<StreetEntity> proCodeList = streetDao.findByProCode(countyCode);
if (proCodeList == null || proCodeList.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省编码不存在!", locale);
}
List<StreetEntity> proNameList = streetDao.findByProName(countyName);
if (proNameList == null || proNameList.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
}
sysUserEntity.setActiveFlag(1);
sysUserEntity.setAccountType("省级");
} else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) {
List<StreetEntity> cityCodeList = streetDao.findByCityCode(countyCode);
if (cityCodeList == null || cityCodeList.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "市编码不存在!", locale);
}
List<StreetEntity> cityNameList = streetDao.findByCityName(countyName);
if (cityNameList == null || cityNameList.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
}
sysUserEntity.setActiveFlag(1);
sysUserEntity.setAccountType("市级");
} else {
List<StreetEntity> countyCodeList = streetDao.findByCountyCode(countyCode);
if (countyCodeList == null || countyCodeList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "区县编码不存在!", locale);
}
List<StreetEntity> countyNameList = streetDao.findByCountyName(countyName);
if (countyNameList == null || countyNameList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
}
sysUserEntity.setActiveFlag(0);
sysUserEntity.setAccountType("县级");
}
if (9 == countyCode.length()) {//街道账号7天后过期
//生成新的VIP时间范围Json内容
String newVipTimeRangeJson = VipTimeRangeUtils.obtainNewVipTimeRangeJson(null, LocalDateTime.now().plusDays(7L));
//更新字段
sysUserEntity.setVipTimeRangeJson(newVipTimeRangeJson);
} else {//省市区县账号5天后过期
//生成新的VIP时间范围Json内容
String newVipTimeRangeJson = VipTimeRangeUtils.obtainNewVipTimeRangeJson(null, LocalDateTime.now().plusDays(5L));
//更新字段
sysUserEntity.setVipTimeRangeJson(newVipTimeRangeJson);
}
sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now()));
sysUserEntity.setLoginNum(0);
sysUserEntity.setCountyCode(countyCode);
sysUserEntity.setCountyName(countyName);
sysUserEntity.setVipLevel(0);
sysUserEntity.setReceiveSms(0);
sysUserEntity.setRemark("");//备注
sysUserDao.save(sysUserEntity);
RelUserRoleEntity relUserRoleEntity = new RelUserRoleEntity();
relUserRoleEntity.setUserId(sysUserEntity.getId());
relUserRoleEntity.setRoleId(2L);
RelRoleAuthorityEntity relRoleAuthorityEntity = new RelRoleAuthorityEntity();
relRoleAuthorityEntity.setRoleId(2L);
relRoleAuthorityEntity.setAuthorityId(2L);
relRoleAuthorityEntity.setUserId(sysUserEntity.getId());
relUserRoleDao.save(relUserRoleEntity);
relRoleAuthorityDao.save(relRoleAuthorityEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "注册成功!", locale);
}
@Transactional(rollbackFor = Exception.class)
@Override
public String deleteSysUser(String userName) {