TRX há 1 ano atrás
pai
commit
8b6f5f6490

+ 19 - 4
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/RegisterUserAccountParam.java

@@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.Size;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.hibernate.internal.build.AllowPrintStacktrace;
 
 /**
@@ -20,6 +21,23 @@ import org.hibernate.internal.build.AllowPrintStacktrace;
 @NoArgsConstructor
 public class RegisterUserAccountParam {
 
+    @Schema(description = "登录名", hidden = true)
+    private String loginName;
+
+    public String getLoginName() {
+        if (StringUtils.isNotEmpty(loginName)) {
+            return loginName;
+        }
+        return phone;
+    }
+
+    @Schema(description = "密码", hidden = true)
+    private String password;
+
+    public String getPassword() {
+        return password;
+    }
+
     @Schema(description = "用户手机号")
     @NotEmpty(message = "phone不能为空")
     private String phone;
@@ -33,13 +51,10 @@ public class RegisterUserAccountParam {
     @Schema(description = "证件号码")
     private String cardNumber;
 
-    @Schema(description = "学号/工号")
-    private String code;
-
     @Schema(description = "性别")
     private Sex sex;
 
     @Schema(description = "用户类型", hidden = true)
-    private UserType userType;
+    private UserType userType = UserType.Consumer;
 
 }

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/UserCountAddParam.java

@@ -61,4 +61,7 @@ public class UserCountAddParam extends SuperParam {
 
     @Schema(description = "密码")
     private String passWord;
+
+    @Schema(description = "是否是管理员")
+    private Boolean isAdmin = Boolean.FALSE;
 }

+ 46 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/orgModel/OrgBindUserAllParam.java

@@ -0,0 +1,46 @@
+package com.zhongshu.card.client.model.orgModel;
+
+import com.zhongshu.card.client.type.UserState;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * 机构绑定用户 (基本用户已存在)
+ *
+ * @author TRX
+ * @date 2024/9/29
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class OrgBindUserAllParam {
+
+    @Schema(description = "用户userId")
+    private String userId;
+
+    @Schema(description = "机构oid")
+    private String orgOid;
+
+    @Schema(description = "工号-学号")
+    private String code;
+
+    @Schema(description = "职位")
+    private String positionId;
+
+    @Schema(description = "部门信息")
+    private String departmentId;
+
+    @Schema(description = "角色信息-人员类型")
+    private List<String> roleIds;
+
+    @Schema(description = "用户状态")
+    private UserState state = UserState.Normal;
+
+    @Schema(description = "是否是企业管理员")
+    private Boolean isAdmin = Boolean.FALSE;
+
+}

+ 6 - 6
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/org/OrganizationUserController.java

@@ -6,8 +6,10 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.base.OidModel;
 import com.zhongshu.card.client.model.org.*;
+import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
 import com.zhongshu.card.client.model.project.ProjectSaveParam;
 import com.zhongshu.card.client.service.org.OrganizationService;
+import com.zhongshu.card.server.core.model.org.OrgBindUserParam;
 import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -30,14 +32,12 @@ public class OrganizationUserController {
     @Autowired
     private OrganizationUserServiceImpl organizationUserService;
 
-    //------------------------------项目管理 start----------------------
-    @ResourceAuth(value = "saveProjectInfo", type = AuthType.Platform, remark = "项目管理_保存项目_1_Button")
     @ResourceAuth(value = "user", type = AuthType.User)
     @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
-    @Operation(summary = "项目-保存", description = "项目-保存")
-    @RequestMapping(value = "addProjectUser", method = {RequestMethod.POST})
-    public ResultContent addProjectUser(@RequestBody @Valid UserCountAddParam param) {
-        return this.organizationUserService.addProjectUser(param);
+    @Operation(summary = "机构绑定用户", description = "机构绑定用户,机构已存在 用户已存在")
+    @RequestMapping(value = "orgBindUser", method = {RequestMethod.POST})
+    public ResultContent orgBindUser(@RequestBody @Valid OrgBindUserAllParam param) {
+        return this.organizationUserService.orgBindUser(param);
     }
 
 }

+ 133 - 8
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/OrganizationUserServiceImpl.java

@@ -1,23 +1,34 @@
 package com.zhongshu.card.server.core.service.org;
 
+import com.github.microservice.auth.client.content.ResultState;
+import com.github.microservice.auth.client.service.OrganizationUserService;
+import com.github.microservice.auth.client.service.RoleService;
 import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.org.DepartmentModel;
+import com.zhongshu.card.client.model.org.OidAboutInfo;
 import com.zhongshu.card.client.model.org.OrganizationUserSimpleModel;
 import com.zhongshu.card.client.model.org.UserCountAddParam;
+import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
 import com.zhongshu.card.client.model.school.RegisterBindSchoolParam;
 import com.zhongshu.card.client.type.OrganizationUserType;
 import com.zhongshu.card.client.type.UserState;
 import com.zhongshu.card.server.core.dao.org.*;
+import com.zhongshu.card.server.core.dao.school.DictInfoDao;
 import com.zhongshu.card.server.core.domain.org.*;
+import com.zhongshu.card.server.core.domain.school.DictInfo;
 import com.zhongshu.card.server.core.model.org.OrgBindUserParam;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.orgManager.OrganizationManagerServiceImpl;
 import com.zhongshu.card.server.core.service.user.DepartmentServiceImpl;
 import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -52,21 +63,129 @@ public class OrganizationUserServiceImpl extends SuperService {
     @Autowired
     private RoleDao roleDao;
 
+    @Autowired
+    private OrganizationManagerServiceImpl organizationManagerService;
+
+    @Autowired
+    private DictInfoDao dictInfoDao;
+
+    @Autowired
+    OrganizationUserService organizationUserService;
+
+    @Autowired
+    RoleService roleService;
+
     /**
-     * 项目添加用户
+     * 项目添加用户 (角色、部门、职位都以新的为准)
      *
      * @param param
      * @return
      */
-    public ResultContent addProjectUser(UserCountAddParam param) {
-        String projectOid = param.getProjectOid();
-        Organization projectInfo = organizationDao.findTopByOid(projectOid);
-        if (ObjectUtils.isEmpty(projectInfo)) {
-            return ResultContent.buildFail(String.format("项目不存在:%s", projectOid));
+    @Transactional
+    public ResultContent<OrganizationUser> orgBindUser(OrgBindUserAllParam param) {
+        // 检查数据完整性
+        if (StringUtils.isEmpty(param.getUserId())) {
+            return ResultContent.buildFail("userId不能为空");
+        }
+        if (StringUtils.isEmpty(param.getOrgOid())) {
+            return ResultContent.buildFail("orgOid不能为空");
         }
+        UserAccount userAccount = userCountDao.findTopByUserId(param.getUserId());
+        if (ObjectUtils.isEmpty(userAccount)) {
+            return ResultContent.buildFail(String.format("用户信息不存在:%s", param.getUserId()));
+        }
+        Organization organization = organizationDao.findTopByOid(param.getOrgOid());
+        if (ObjectUtils.isEmpty(organization)) {
+            return ResultContent.buildFail(String.format("机构信息不存在:%s", param.getOrgOid()));
+        }
+        String userId = userAccount.getUserId();
+        OidAboutInfo oidAboutInfo = organizationManagerService.getOidAboutInfo(organization.getOid());
 
+        OrganizationUser codeTemp = null;
+        if (StringUtils.isNotEmpty(param.getCode())) {
+            codeTemp = organizationUserDao.findTopByCodeAndOrganization(param.getCode(), organization);
+        }
+        OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, userAccount);
+        if (ObjectUtils.isEmpty(organizationUser)) {
+            // 添加
+            if (ObjectUtils.isNotEmpty(codeTemp)) {
+                return ResultContent.buildFail(String.format("code已存在:%s", param.getCode()));
+            }
+            organizationUser = new OrganizationUser();
+            organizationUser.setOid(organization.getOid());
+            initEntity(organizationUser);
+            BeanUtils.copyProperties(param, organizationUser);
 
-        return ResultContent.buildSuccess();
+            organizationUser.setOrganization(organization);
+            organizationUser.setUser(userAccount);
+            organizationUser.setUserId(userAccount.getUserId());
+            organizationUser.setCreateUserId(getCurrentUserId());
+            // 在机构中的用户类型
+            organizationUser.setUserType(OrganizationUserType.Consumer);
+        } else {
+            if (ObjectUtils.isNotEmpty(codeTemp) && !codeTemp.getId().equals(organizationUser.getId())) {
+                return ResultContent.buildFail(String.format("code已存在:%s", param.getCode()));
+            }
+            // 编辑
+            BeanUtils.copyProperties(param, organizationUser);
+
+            // 删除以前的角色
+            List<Role> oldRoles = organizationUser.getRoles();
+            if (ObjectUtils.isNotEmpty(oldRoles)) {
+                List<String> ids = oldRoles.stream().map(it -> it.getRoleGroupId()).collect(Collectors.toList());
+                String[] userIds = new String[]{userId};
+                for (Role oldRole : oldRoles) {
+                    if (!ids.contains(oldRole.getRoleGroupId())) {
+                        roleService.removeUserFromRoleGroup(oldRole.getRoleGroupId(), userIds);
+                    }
+                }
+            }
+        }
+
+        List<Role> roles = new ArrayList<>();
+        Department department = null;
+        if (ObjectUtils.isNotEmpty(param.getRoleIds())) {
+            roles = roleDao.findByIdIn(param.getRoleIds());
+        }
+        if (ObjectUtils.isNotEmpty(param.getDepartmentId())) {
+            department = departmentDao.findTopById(param.getDepartmentId());
+        }
+        DictInfo position = null;
+        if (StringUtils.isNotEmpty(param.getPositionId())) {
+            position = dictInfoDao.findTopById(param.getPositionId());
+        }
+
+        if (ObjectUtils.isNotEmpty(roles)) {
+            //权限中心: 在角色组添加用户
+            String[] roleGroupIds = roles.stream().map(it -> it.getRoleGroupId()).collect(Collectors.toList()).toArray(String[]::new);
+            roleService.addUsersToRoleGroup(userId, roleGroupIds);
+        }
+
+        organizationUser.setPosition(position);
+        // 设置角色
+        organizationUser.setRoles(roles);
+        // 设置部门
+        organizationUser.setDepartment(department);
+
+        organizationUser.setProjectOid(oidAboutInfo.getProjectOid());
+        organizationUser.setAboutOid(oidAboutInfo.getOid());
+        organizationUser.setAboutAuthType(oidAboutInfo.getAuthType());
+        organizationUser.setAuthType(organization.getAuthType());
+
+        // 用户信息
+        organizationUser.setPhone(userAccount.getPhone());
+        organizationUser.setName(userAccount.getName());
+        organizationUser.setCardNumber(userAccount.getCardNumber());
+        organizationUserDao.save(organizationUser);
+
+        // 权限中心 绑定用户
+        com.github.microservice.auth.client.content.ResultContent<Void> resultContent = organizationUserService.update(organization.getOid(), new String[]{userId});
+        if (resultContent.getState() == ResultState.Success) {
+            log.info("权限中心:绑定机构和用户关系成功");
+        } else {
+            log.error("权限中心:绑定机构和用户关系出错:{}", resultContent.getMsg());
+        }
+        return ResultContent.buildSuccess(organizationUser);
     }
 
     /**
@@ -207,7 +326,12 @@ public class OrganizationUserServiceImpl extends SuperService {
         return ResultContent.buildSuccess();
     }
 
-
+    /**
+     * 转换机构用户信息(基本信息 角色  部门)
+     *
+     * @param entity
+     * @return
+     */
     public OrganizationUserSimpleModel toModel(OrganizationUser entity) {
         OrganizationUserSimpleModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
@@ -219,6 +343,7 @@ public class OrganizationUserServiceImpl extends SuperService {
             model.setOid(organization.getOid());
             model.setOrgName(organization.getName());
 
+            // 角色
             model.setRoles(roleServiceImpl.toModels(entity.getRoles()));
 
             // 部门信息

+ 0 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/SchoolUserServiceImpl.java

@@ -415,7 +415,6 @@ public class SchoolUserServiceImpl extends SuperService implements SchoolUserSer
 
         // 返回用户所在学校的信息
         RegisterResultModel registerResult = new RegisterResultModel();
-        registerResult.setCode(param.getCode());
         UserCountModel userCountModel = userAccountService.toModel(userAccount);
         registerResult.setUserInfo(userCountModel);
 

+ 76 - 134
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/user/UserAccountServiceImpl.java

@@ -15,6 +15,7 @@ import com.zhongshu.card.client.model.base.AuthTypeParam;
 import com.zhongshu.card.client.model.base.UserIdModel;
 import com.zhongshu.card.client.model.org.*;
 import com.zhongshu.card.client.model.org.role.RoleModel;
+import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
 import com.zhongshu.card.client.model.school.DictInfoSimpleModel;
 import com.zhongshu.card.client.service.org.OrganizationService;
 import com.zhongshu.card.client.service.org.UserAccountService;
@@ -26,6 +27,7 @@ import com.zhongshu.card.server.core.dataConfig.CardSystemDefault;
 import com.zhongshu.card.server.core.domain.org.*;
 import com.zhongshu.card.server.core.domain.school.DictInfo;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
 import com.zhongshu.card.server.core.service.school.DictInfoServiceImpl;
 import com.zhongshu.card.server.core.util.BeanUtils;
 import com.zhongshu.card.server.core.util.CommonUtil;
@@ -94,8 +96,11 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
     @Autowired
     DictInfoServiceImpl dictInfoService;
 
+    @Autowired
+    OrganizationUserServiceImpl organizationUserServiceImpl;
+
     /**
-     * 添加编辑用户 添加机构用户
+     * 添加编辑用户 添加机构用户 (包括角色 部门 职位等信息)
      *
      * @param param
      * @return
@@ -103,9 +108,6 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
     @Override
     public ResultContent<OrganizationUser> update(UserCountAddParam param) {
         String oid = param.getOid();
-        if (StringUtils.isEmpty(oid)) {
-            oid = getCurrentOid();
-        }
         Assert.hasText(oid, "oid不能为空");
         Assert.hasText(param.getName(), "name不能为空");
         if (param.getState() == null) {
@@ -117,153 +119,66 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         if (ObjectUtils.isEmpty(organization)) {
             return ResultContent.buildFail(String.format("oid不存在:%s", oid));
         }
-        List<Role> roles = new ArrayList<>();
-        Department department = null;
-        if (ObjectUtils.isNotEmpty(param.getRoleIds())) {
-            roles = roleDao.findByOidAndIdIn(oid, param.getRoleIds());
-        }
-        if (ObjectUtils.isNotEmpty(param.getDepartmentId())) {
-            department = departmentDao.findTopById(param.getDepartmentId());
-        }
-
-        UserAccount temp = null;
-        String userId = "";
-        // 这的ID是 用户和机构关系数据ID
-        if (StringUtils.isEmpty(param.getId())) {
-            Assert.hasText(param.getPhone(), "phone不能为空");
-
-            String loginName = param.getPhone();
-            // 添加
-            // 判断用户是否存在
-            temp = userCountDao.findTopByLoginName(loginName);
-            if (ObjectUtils.isEmpty(temp)) {
-                String password = param.getPassWord();
-                // 验证密码
-                ValidateResult validateResult = ValidateUtils.validatePassWord(password);
-                if (!validateResult.isSuccess()) {
-                    return ResultContent.buildFail(validateResult.getMsg());
-                }
-                if (StringUtils.isEmpty(password)) {
-                    password = CardSystemDefault.DEFAULT_PASSWORD;
-                }
-
-                //权限中心:添加用户
-                com.github.microservice.auth.client.content.ResultContent<String> addModelResult = userService.add(UserAuthModel.builder().loginType(LoginType.Phone).loginValue(loginName).passWord(password).build());
-                if (addModelResult.getState() != ResultState.Success) {
-                    return ResultContent.buildFail(String.format("权限中心添加用户出错:%s", addModelResult.getMsg()));
-                }
-                temp = new UserAccount();
-                BeanUtils.copyProperties(param, temp);
-
-                userId = addModelResult.getContent();
-                temp.setUserId(userId);
-                temp.setUserType(UserType.Consumer);
-                temp.setLoginType(UserLoginType.All);
-                temp.setOid(null);
-                temp.setLoginName(loginName);
-                temp.setIsLogined(Boolean.FALSE);
-                temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
-                temp.setIsUpdatedPsw(Boolean.FALSE);
-                userCountDao.save(temp);
-            } else {
-                // 编辑用户
-                BeanUtils.copyProperties(param, temp, "id", "loginName", "userId", "userType", "loginType");
-                temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
-                userCountDao.save(temp);
-            }
-        } else {
-            OrganizationUser organizationUser = organizationUserDao.findTopById(param.getId());
-            if (ObjectUtils.isEmpty(organizationUser)) {
-                return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
-            }
-            temp = organizationUser.getUser();
-            if (StringUtils.isEmpty(param.getPhone())) {
-                param.setPhone(temp.getPhone());
-            }
-            // 用户信息
-            BeanUtils.copyProperties(param, temp, "id", "userId", "userType", "loginType");
-            temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
-            userCountDao.save(temp);
-        }
-
-        userId = temp.getUserId();
-        //权限中心: 在角色组添加用户
-        String[] roleGroupIds = roles.stream().map(it -> it.getRoleGroupId()).collect(Collectors.toList()).toArray(String[]::new);
-        roleService.addUsersToRoleGroup(userId, roleGroupIds);
-
-        OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
-        if (ObjectUtils.isEmpty(organizationUser)) {
-            // 不在机构中
-            organizationUser = new OrganizationUser();
-            initEntity(organizationUser);
-            organizationUser.setOid(organization.getOid());
-            organizationUser.setOrganization(organization);
-            organizationUser.setUser(temp);
-            organizationUser.setUserId(temp.getUserId());
-            organizationUser.setIsAdmin(Boolean.FALSE);
-            organizationUser.setAuthType(organization.getAuthType());
-            organizationUser.setCreateUserId(getCurrentUserId());
-            // 在机构中的用户类型
-            organizationUser.setUserType(OrganizationUserType.Consumer);
-        } else {
-            //权限中心: 删除以前的,这不存在的角色组
-            List<Role> oldRoles = organizationUser.getRoles();
-            if (ObjectUtils.isNotEmpty(oldRoles)) {
-                List<String> ids = roles.stream().map(it -> it.getRoleGroupId()).collect(Collectors.toList());
-                String[] userIds = new String[]{userId};
-                for (Role oldRole : oldRoles) {
-                    if (!ids.contains(oldRole.getRoleGroupId())) {
-                        roleService.removeUserFromRoleGroup(oldRole.getRoleGroupId(), userIds);
-                    }
-                }
-            }
-        }
 
-        BeanUtils.copyProperties(param, organizationUser, "id", "oid");
-        // 职位信息
-        DictInfo position = null;
-        if (StringUtils.isNotEmpty(param.getPositionId())) {
-            position = dictInfoDao.findTopById(param.getPositionId());
+        // 用户基本信息维护
+        RegisterUserAccountParam userAccountParam = new RegisterUserAccountParam();
+        userAccountParam.setLoginName(param.getPhone());
+        userAccountParam.setPassword(param.getPassWord());
+        userAccountParam.setPhone(param.getPhone());
+        userAccountParam.setName(param.getName());
+        userAccountParam.setCardNumber(param.getCardNumber());
+        userAccountParam.setSex(param.getSex());
+        ResultContent<String> userAccountContent = registerUserAccount(userAccountParam);
+        if (userAccountContent.isFailed()) {
+            return ResultContent.buildFail(userAccountContent.getMsg());
         }
-        organizationUser.setPosition(position);
+        String userId = userAccountContent.getContent();
+        UserAccount userAccount = userCountDao.findTopByUserId(userId);
 
-        organizationUser.setAuthType(organization.getAuthType());
-        // 设置角色
-        organizationUser.setRoles(roles);
-        // 设置部门
-        organizationUser.setDepartment(department);
-        organizationUserDao.save(organizationUser);
+        OrgBindUserAllParam orgBindUserAllParam = new OrgBindUserAllParam();
+        orgBindUserAllParam.setUserId(userAccount.getUserId());
+        orgBindUserAllParam.setOrgOid(organization.getOid());
+        orgBindUserAllParam.setCode(param.getCode());
+        orgBindUserAllParam.setPositionId(param.getPositionId());
+        orgBindUserAllParam.setDepartmentId(param.getDepartmentId());
+        orgBindUserAllParam.setRoleIds(param.getRoleIds());
+        orgBindUserAllParam.setState(param.getState());
+        orgBindUserAllParam.setIsAdmin(param.getIsAdmin());
 
-        // 权限中心 绑定用户
-        com.github.microservice.auth.client.content.ResultContent<Void> resultContent = organizationUserService.update(organization.getOid(), new String[]{userId});
-        if (resultContent.getState() == ResultState.Success) {
-            log.info("权限中心:绑定机构和用户关系成功");
-        } else {
-            log.error("权限中心:绑定机构和用户关系出错:{}", resultContent.getMsg());
+        ResultContent<OrganizationUser> bindUserContent = organizationUserServiceImpl.orgBindUser(orgBindUserAllParam);
+        if (bindUserContent.isFailed()) {
+            return ResultContent.buildFail(bindUserContent.getMsg());
         }
+        OrganizationUser organizationUser = bindUserContent.getContent();
 
         return ResultContent.buildSuccess(organizationUser);
     }
 
-
     /**
-     * 注册基本用户
+     * 注册基本用户 (没有就注册,有就修改)
      *
      * @param param
      * @return
      */
     @Override
     public ResultContent<String> registerUserAccount(RegisterUserAccountParam param) {
+        if (StringUtils.isEmpty(param.getLoginName())) {
+            return ResultContent.buildFail(String.format("loginName不能为空"));
+        }
         // 电话号码为登录名
-        String loginName = param.getPhone();
+        String loginName = param.getLoginName();
         UserAccount userAccount = userCountDao.findTopByLoginName(loginName);
         if (ObjectUtils.isEmpty(userAccount)) {
             String cardNumber = param.getCardNumber();
-            String passWord = CardSystemDefault.DEFAULT_PASSWORD;
+            String passWord = param.getPassword();
+            if (StringUtils.isEmpty(passWord)) {
+                passWord = CardSystemDefault.DEFAULT_PASSWORD;
+            }
             if (ValidateUtils.isIDCard(cardNumber)) {
                 passWord = cardNumber.substring(12, 18);
                 passWord = passWord.toLowerCase().replace("x", "0");
             }
+
             String userId = "";
             // 检查权限中心有这用户不
             com.github.microservice.auth.client.content.ResultContent<UserModel> queryContent = userService.queryFromLoginType(LoginType.Phone, loginName);
@@ -275,17 +190,18 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
             }
 
             if (StringUtils.isEmpty(userId)) {
-                //权限中心:添加用户
-                com.github.microservice.auth.client.content.ResultContent<String> addModelResult = userService.add(
-                        UserAuthModel.builder().loginType(LoginType.Phone).loginValue(loginName).passWord(passWord).build());
+                // 权限中心:添加用户
+                com.github.microservice.auth.client.content.ResultContent<String> addModelResult = userService.add(UserAuthModel.builder().loginType(LoginType.Phone).loginValue(loginName).passWord(passWord).build());
                 if (addModelResult.getState() != ResultState.Success) {
                     return ResultContent.buildFail(String.format("权限中心添加用户出错:%s", addModelResult.getMsg()));
                 }
                 userId = addModelResult.getContent();
             }
 
+            // 本地用户
             userAccount = new UserAccount();
             BeanUtils.copyProperties(param, userAccount);
+
             String realName = param.getRealName();
             if (StringUtils.isEmpty(realName)) {
                 realName = param.getName();
@@ -293,11 +209,13 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
             userAccount.setRealName(realName);
             userAccount.setUserId(userId);
             userAccount.setLoginType(UserLoginType.All);
+
             userAccount.setOid(null);
             userAccount.setLoginName(loginName);
             userAccount.setIsLogined(Boolean.FALSE);
             userAccount.setSpellCode(CommonUtil.getPinyin(param.getName()));
             userAccount.setIsUpdatedPsw(Boolean.FALSE);
+            userAccount.setUserType(UserType.Consumer);
             userCountDao.save(userAccount);
         } else {
             // 编辑
@@ -412,7 +330,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         }
         Assert.hasText(oid, "oid不能为空");
         Assert.hasText(userId, "userId不能为空");
-
+        // 价差用户数据
         Organization organization = organizationDao.findTopByOid(oid);
         if (ObjectUtils.isEmpty(organization)) {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
@@ -421,6 +339,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         if (ObjectUtils.isEmpty(temp)) {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, userId));
         }
+
         OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
         if (ObjectUtils.isNotEmpty(organizationUser)) {
             organizationUser.setState(param.getUserState());
@@ -514,8 +433,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         if (ObjectUtils.isEmpty(userCount)) {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getUserId()));
         }
-        com.github.microservice.auth.client.content.ResultContent<Void> resultContent =
-                userService.updateLoginPassword(param.getUserId(), CardSystemDefault.DEFAULT_PASSWORD);
+        com.github.microservice.auth.client.content.ResultContent<Void> resultContent = userService.updateLoginPassword(param.getUserId(), CardSystemDefault.DEFAULT_PASSWORD);
         if (resultContent.getState() != ResultState.Success) {
             return ResultContent.buildFail(resultContent.getMsg());
         }
@@ -523,7 +441,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
     }
 
     /**
-     * 查询构用户列表
+     * 查询构用户列表
      *
      * @param param
      * @param pageable
@@ -676,6 +594,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return list;
     }
 
+    /**
+     * 转换数据模型
+     *
+     * @param list
+     * @return
+     */
     public List<UserCountSimpleModel> toListSimpleModel(List<UserAccount> list) {
         if (ObjectUtils.isNotEmpty(list)) {
             return list.stream().map(this::toSimpleModel).collect(Collectors.toList());
@@ -683,6 +607,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return Lists.newArrayList();
     }
 
+    /**
+     * 所有数据字段
+     *
+     * @param entity
+     * @return
+     */
     public UserCountModel toModel(UserAccount entity) {
         UserCountModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
@@ -692,6 +622,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return model;
     }
 
+    /**
+     * 用户的基本信息 (简介模型)
+     *
+     * @param entity
+     * @return
+     */
     public UserCountSimpleModel toSimpleModel(UserAccount entity) {
         UserCountSimpleModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
@@ -701,6 +637,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return model;
     }
 
+    /**
+     * 用户在机构的数据模型(用户信息、职位、部门、角色等)
+     *
+     * @param entity
+     * @return
+     */
     public OrganizationUserModel toOrgUserModel(OrganizationUser entity) {
         OrganizationUserModel model = new OrganizationUserModel();
         if (ObjectUtils.isNotEmpty(entity)) {