添加接口:强制注册用户(陈勇)

This commit is contained in:
liuchengqian 2023-02-16 08:52:53 +08:00
parent 61bfb895cd
commit 958bcd5f75
5 changed files with 119 additions and 76 deletions

View File

@ -43,6 +43,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.POST, "/globalConfig").permitAll()
.antMatchers(HttpMethod.POST, "/globalConfigDict").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()
// 所有 app 用户注册 的POST请求 都放行

View File

@ -223,17 +223,13 @@ public class SysUserController {
* 注册系统用户
*/
@RequestMapping(value = "/add2", method = RequestMethod.POST)
public String addUser2(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult, HttpServletRequest servletRequest) {
// 验证数据合法性
if (bindingResult.hasErrors()) {
return outputEncapsulationErrorList(bindingResult.getFieldErrors(), locale);
}
public String addUser2(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo) {
// 验证用户名是否重复
if (!sysUserService.checkUserName(userQo.getUserName())) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale);
}
// 添加新用户
return sysUserService.addUser(userQo, servletRequest);
return sysUserService.addUser2(userQo);
}
/**

View File

@ -2,18 +2,12 @@ package com.xkrs.model.qo;
import com.xkrs.model.validation.SysUserQoInsert;
import com.xkrs.model.validation.SysUserQoUpdate;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
/**
* SysUserQo
*
* @author tajochen
*/
public class SysUserQo {
@NotNull(message = "{SysUser.id.blank}", groups = {SysUserQoUpdate.class})
@ -34,30 +28,14 @@ public class SysUserQo {
@Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$", message = "{SysUser.password.format.illegal}", groups = {SysUserQoInsert.class, SysUserQoUpdate.class})
private String password;
@Pattern(regexp = "^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\\d{8}$", message = "{SysUser.telephone.format.illegal}", groups = {SysUserQoInsert.class, SysUserQoUpdate.class})
private String telephone;
@NotNull(message = "{SysUser.statusCode.illegal}", groups = {SysUserQoUpdate.class})
@Range(min = 0, max = 2, message = "{SysUser.statusCode.illegal}", groups = {SysUserQoInsert.class, SysUserQoUpdate.class})
private Integer statusCode;
@NotNull(message = "{SysUser.countyName.blank}", groups = {SysUserQoUpdate.class})
private String countyName;
@NotNull(message = "{SysUser.countyCode.blank}", groups = {SysUserQoUpdate.class})
private String countyCode;
@NotNull(message = "{SysUser.deleteFlag.null}", groups = {SysUserQoUpdate.class})
private Integer deleteFlag;
private Integer roleId;
private Integer authorityId;
private String verificationCode;
private String accountType;
/**
* 代理组织ID
*/
@ -98,22 +76,6 @@ public class SysUserQo {
this.password = password;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public Integer getStatusCode() {
return statusCode;
}
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
public String getCountyName() {
return countyName;
}
@ -130,30 +92,6 @@ public class SysUserQo {
this.countyCode = countyCode;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public Integer getAuthorityId() {
return authorityId;
}
public void setAuthorityId(Integer authorityId) {
this.authorityId = authorityId;
}
public String getVerificationCode() {
return verificationCode;
}
@ -162,14 +100,6 @@ public class SysUserQo {
this.verificationCode = verificationCode;
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}
public Long getAgentOrgId() {
return agentOrgId;
}

View File

@ -37,6 +37,15 @@ public interface SysUserService {
*/
String addUser(SysUserQo sysUserQo, HttpServletRequest servletRequest);
/**
* 保存用户
*
* @param sysUserQo
* @return
*/
String addUser2(SysUserQo sysUserQo);
/**
* 删除系统用户
*

View File

@ -209,6 +209,113 @@ public class SysUserServiceImpl implements SysUserService {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "注册成功!", locale);
}
/**
* 新增用户
*
* @param sysUserQo
*/
@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天后过期
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(7L)));
} else {//省市区县账号5天后过期
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
}
sysUserEntity.setStatusCode(0);
sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now()));
sysUserEntity.setDeleteFlag(0);
sysUserEntity.setDayNum(7);
sysUserEntity.setLoginNum(0);
sysUserEntity.setCountyCode(countyCode);
sysUserEntity.setCountyName(countyName);
sysUserEntity.setVipLevel(0);
sysUserEntity.setReceiveSms(0);
sysUserEntity.setRemark("");//备注
sysUserEntity.setAgentOrgId(sysUserQo.getAgentOrgId() == null ? 1L : sysUserQo.getAgentOrgId());
sysUserDao.save(sysUserEntity);
RelUserRoleEntity relUserRoleEntity = new RelUserRoleEntity();
relUserRoleEntity.setUserId(sysUserEntity.getId().longValue());
relUserRoleEntity.setRoleId(2);
RelRoleAuthorityEntity relRoleAuthorityEntity = new RelRoleAuthorityEntity();
relRoleAuthorityEntity.setRoleId(2);
relRoleAuthorityEntity.setAuthorityId(2);
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) {