diff --git a/wfc-api/wfc-api-user/src/main/java/org/wfc/user/api/domain/UUser.java b/wfc-api/wfc-api-user/src/main/java/org/wfc/user/api/domain/UUser.java index 9d6f37f..5e0f340 100644 --- a/wfc-api/wfc-api-user/src/main/java/org/wfc/user/api/domain/UUser.java +++ b/wfc-api/wfc-api-user/src/main/java/org/wfc/user/api/domain/UUser.java @@ -58,6 +58,15 @@ public class UUser extends BaseEntity /** 密码 */ private String password; + /** 用户姓名 */ + private String fullName; + + /** 年龄 */ + private Integer age; + + /** 地址 */ + private String address; + /** 帐号状态(0正常 1停用) */ @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用") private String status; @@ -102,6 +111,30 @@ public class UUser extends BaseEntity this.userId = userId; } + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + public Long getUserId() { return userId; diff --git a/wfc-auth/src/main/java/org/wfc/auth/controller/TokenController.java b/wfc-auth/src/main/java/org/wfc/auth/controller/TokenController.java index 97fe844..c7726f4 100644 --- a/wfc-auth/src/main/java/org/wfc/auth/controller/TokenController.java +++ b/wfc-auth/src/main/java/org/wfc/auth/controller/TokenController.java @@ -5,24 +5,22 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import org.wfc.common.core.web.form.LoginBody; -import org.wfc.common.core.web.form.RegisterBody; import org.wfc.auth.service.SysLoginService; import org.wfc.auth.service.ULoginService; +import org.wfc.common.core.domain.LoginUser; import org.wfc.common.core.domain.R; import org.wfc.common.core.utils.JwtUtils; import org.wfc.common.core.utils.StringUtils; +import org.wfc.common.core.web.form.LoginBody; +import org.wfc.common.core.web.form.RegisterBody; import org.wfc.common.security.auth.AuthUtil; import org.wfc.common.security.service.TokenService; import org.wfc.common.security.utils.SecurityUtils; -import org.wfc.common.core.domain.LoginUser; import org.wfc.system.api.domain.SysUser; import org.wfc.user.api.domain.UUser; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequest; - /** * token 控制 * @@ -89,8 +87,9 @@ public class TokenController @PostMapping("register") public R register(@RequestBody RegisterBody registerBody) { - // 用户注册 sysLoginService.register(registerBody); return R.ok(); } + + } diff --git a/wfc-auth/src/main/java/org/wfc/auth/service/SysLoginService.java b/wfc-auth/src/main/java/org/wfc/auth/service/SysLoginService.java index 3254fc2..5c838fb 100644 --- a/wfc-auth/src/main/java/org/wfc/auth/service/SysLoginService.java +++ b/wfc-auth/src/main/java/org/wfc/auth/service/SysLoginService.java @@ -1,6 +1,7 @@ package org.wfc.auth.service; import cn.hutool.core.util.StrUtil; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.wfc.common.core.constant.CacheConstants; @@ -21,6 +22,8 @@ import org.wfc.common.redis.service.RedisService; import org.wfc.common.security.utils.SecurityUtils; import org.wfc.system.api.RemoteUserService; import org.wfc.system.api.domain.SysUser; +import org.wfc.user.api.RemoteUUserService; +import org.wfc.user.api.domain.UUser; /** * 登录校验方法 @@ -33,6 +36,9 @@ public class SysLoginService @Autowired private RemoteUserService remoteUserService; + @Autowired + private RemoteUUserService remoteUUserService; + @Autowired private SysPasswordService passwordService; @@ -161,12 +167,23 @@ public class SysLoginService sysUser.setFullName(registerBody.getFullName()); sysUser.setSex(registerBody.getSex()); sysUser.setPhonenumber(registerBody.getPhonenumber()); - R registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER); - if (R.FAIL == registerResult.getCode()) - { - throw new ServiceException(registerResult.getMsg()); + if ("u".equals(registerBody.getAuthType())){ + UUser uUser = new UUser(); + BeanUtils.copyProperties(sysUser, uUser); + R registerResult = remoteUUserService.registerUserInfo(uUser, SecurityConstants.INNER); + if (R.FAIL == registerResult.getCode()) + { + throw new ServiceException(registerResult.getMsg()); + } + } if ("sys".equals(registerBody.getAuthType())){ + R registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER); + if (R.FAIL == registerResult.getCode()) + { + throw new ServiceException(registerResult.getMsg()); + } } + // 注册成功删除redis if (StrUtil.isNotBlank(registerBody.getEmail())) { redisService.deleteObject(GlobalConstants.CAPTCHA_CODE_KEY + registerBody.getEmail()); diff --git a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/controller/UUserController.java b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/controller/UUserController.java index c7ebb06..b9fdc6f 100644 --- a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/controller/UUserController.java +++ b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/controller/UUserController.java @@ -1,10 +1,18 @@ package org.wfc.user.controller; import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.wfc.common.core.domain.LoginUser; import org.wfc.common.core.domain.R; @@ -23,7 +31,13 @@ import org.wfc.common.security.utils.SecurityUtils; import org.wfc.user.api.domain.UDept; import org.wfc.user.api.domain.URole; import org.wfc.user.api.domain.UUser; -import org.wfc.user.service.*; +import org.wfc.user.domain.query.UserRepeatQuery; +import org.wfc.user.service.IUConfigService; +import org.wfc.user.service.IUDeptService; +import org.wfc.user.service.IUPermissionService; +import org.wfc.user.service.IUPostService; +import org.wfc.user.service.IURoleService; +import org.wfc.user.service.IUUserService; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -75,6 +89,18 @@ public class UUserController extends BaseController return MessageUtils.message("user.jcaptcha.error"); } + /** + * 检查重复 + */ + @PostMapping("/checkRepeat") + public R checkRepeat(@RequestBody UserRepeatQuery query) + { + UUser user = new UUser(); + BeanUtils.copyProperties(query, user); + return R.ok(!userService.checkUserNameUnique(user) || !userService.checkPhoneUnique(user) + || !userService.checkEmailUnique(user)); + } + /** * 获取用户列表 */ @@ -144,18 +170,29 @@ public class UUserController extends BaseController */ @InnerAuth @PostMapping("/register") - public R register(@RequestBody UUser UUser) + public R register(@RequestBody UUser uUser) { - String username = UUser.getUserName(); - if (!("true".equals(configService.selectConfigByKey("U.account.registerUser")))) + String username = uUser.getUserName(); + if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) { return R.fail("当前系统没有开启注册功能!"); } - if (!userService.checkUserNameUnique(UUser)) + if (!userService.checkUserNameUnique(uUser)) { - return R.fail("保存用户'" + username + "'失败,注册账号已存在"); + return R.fail("user.register.save.error"); } - return R.ok(userService.registerUser(UUser)); + + if (!userService.checkPhoneUnique(uUser)) + { + return R.fail("user.register.phone.save.error"); + } + + if (!userService.checkEmailUnique(uUser)) + { + return R.fail("user.register.email.save.error"); + } + + return R.ok(userService.registerUser(uUser)); } /** diff --git a/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/query/UserRepeatQuery.java b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/query/UserRepeatQuery.java new file mode 100644 index 0000000..7613436 --- /dev/null +++ b/wfc-modules/wfc-modules-user/src/main/java/org/wfc/user/domain/query/UserRepeatQuery.java @@ -0,0 +1,15 @@ +package org.wfc.user.domain.query; + +import lombok.Data; + +/** + * @description: 用户重复query + * @author: caiyuchao + * @date: 2024-11-27 + */ +@Data +public class UserRepeatQuery { + private String userName; + private String email; + private String phonenumber; +} diff --git a/wfc-modules/wfc-modules-user/src/main/resources/mapper/user/UUserMapper.xml b/wfc-modules/wfc-modules-user/src/main/resources/mapper/user/UUserMapper.xml index dbb61ef..e0b9896 100644 --- a/wfc-modules/wfc-modules-user/src/main/resources/mapper/user/UUserMapper.xml +++ b/wfc-modules/wfc-modules-user/src/main/resources/mapper/user/UUserMapper.xml @@ -23,6 +23,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -156,6 +159,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status, create_by, remark, + full_name, + age, + address, create_time )values( #{userId}, @@ -170,6 +176,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{status}, #{createBy}, #{remark}, + #{fullName}, + #{age}, + #{address}, sysdate() )