Browse Source

update user api

deason 8 months ago
parent
commit
46686e6720

+ 20 - 1
src/main/java/com/qmth/exam/reserve/service/impl/UserServiceImpl.java

@@ -70,11 +70,20 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
     @Override
     @Override
     public void saveUser(LoginUser loginUser, UserSaveReq req) {
     public void saveUser(LoginUser loginUser, UserSaveReq req) {
         if (StringUtils.isBlank(req.getLoginName())) {
         if (StringUtils.isBlank(req.getLoginName())) {
-            throw new StatusException("登录名不能为空");
+            throw new StatusException("账号不能为空");
+        }
+        if (StringUtils.length(req.getLoginName()) > 50) {
+            throw new StatusException("账号限制50字以内");
         }
         }
         if (StringUtils.isBlank(req.getName())) {
         if (StringUtils.isBlank(req.getName())) {
             throw new StatusException("用户名不能为空");
             throw new StatusException("用户名不能为空");
         }
         }
+        if (StringUtils.length(req.getName()) > 50) {
+            throw new StatusException("用户名限制50字以内");
+        }
+        if (StringUtils.length(req.getMobile()) > 20) {
+            throw new StatusException("联系方式限制20字以内");
+        }
         if (req.getRoleCode() == null) {
         if (req.getRoleCode() == null) {
             throw new StatusException("请选择角色");
             throw new StatusException("请选择角色");
         }
         }
@@ -88,6 +97,16 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
                 log.warn("当前用户不存在!userId:{}", req.getId());
                 log.warn("当前用户不存在!userId:{}", req.getId());
                 throw new StatusException("当前用户不存在");
                 throw new StatusException("当前用户不存在");
             }
             }
+
+            if (!req.getLoginName().equals(existUser.getLoginName())) {
+                UserEntity uu = this.findUserByLoginName(loginUser.getOrgId(), req.getLoginName());
+                if (uu != null) {
+                    throw new StatusException("登录账号已存在");
+                }
+
+                existUser.setLoginName(req.getLoginName());
+            }
+
             existUser.setRole(req.getRoleCode());
             existUser.setRole(req.getRoleCode());
             existUser.setName(req.getName());
             existUser.setName(req.getName());
             existUser.setMobile(req.getMobile());
             existUser.setMobile(req.getMobile());

+ 1 - 1
src/main/resources/mapper/UserMapper.xml

@@ -24,7 +24,7 @@
                 and u.name like concat('%', #{req.name}, '%')
                 and u.name like concat('%', #{req.name}, '%')
             </if>
             </if>
             <if test="req.loginName != null and req.loginName !=''">
             <if test="req.loginName != null and req.loginName !=''">
-                and u.login_name = #{req.loginName}
+                and u.login_name like concat('%', #{req.loginName}, '%')
             </if>
             </if>
             <if test="req.roleCode != null and req.roleCode !=''">
             <if test="req.roleCode != null and req.roleCode !=''">
                 and u.role = #{req.roleCode}
                 and u.role = #{req.roleCode}