From c3c96456c49e65d26559b48f697e1413242bec33 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Tue, 14 Mar 2023 15:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=20?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 3 +- .../xkrs/controller/SysUserController.java | 13 +++ .../java/com/xkrs/service/SysUserService.java | 10 +- .../xkrs/service/impl/SysUserServiceImpl.java | 108 ++++++++++++++++++ 4 files changed, 132 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 37d2c62..dbf7d6a 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -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() diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index 9f400d6..ad50af1 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -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); + } + /** * 删除系统用户 */ diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index 56e2790..a1a9b7e 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -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); + /** * 删除系统用户 * diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index fa29388..27fd6db 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -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 streetCodeList = streetDao.findByStreetCode(countyCode); + if (streetCodeList == null || streetCodeList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "街道编码不存在!", locale); + } + List 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 proCodeList = streetDao.findByProCode(countyCode); + if (proCodeList == null || proCodeList.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省编码不存在!", locale); + } + List 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 cityCodeList = streetDao.findByCityCode(countyCode); + if (cityCodeList == null || cityCodeList.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "市编码不存在!", locale); + } + List cityNameList = streetDao.findByCityName(countyName); + if (cityNameList == null || cityNameList.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale); + } + sysUserEntity.setActiveFlag(1); + sysUserEntity.setAccountType("市级"); + } else { + List countyCodeList = streetDao.findByCountyCode(countyCode); + if (countyCodeList == null || countyCodeList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "区县编码不存在!", locale); + } + List 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) {