TRX 1 rok pred
rodič
commit
abeff07d1a

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

@@ -19,6 +19,9 @@ import java.util.List;
 @NoArgsConstructor
 public class OrgBindUserAllParam {
 
+    @Schema(description = "数据ID")
+    private String id;
+
     @Schema(description = "用户userId")
     private String userId;
 

+ 0 - 3
FullCardClient/src/main/java/com/zhongshu/card/client/service/org/UserAccountService.java

@@ -16,9 +16,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
 
 public interface UserAccountService {
 
-    @Operation(summary = "编辑-添加用户", description = "编辑添加用户")
-    ResultContent update(UserCountAddParam param);
-
     // 注册基本用户
     ResultContent<String> registerUserAccount(RegisterUserAccountParam param);
 

+ 4 - 10
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/user/UserManagerController.java

@@ -9,6 +9,7 @@ import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.service.org.OrganizationService;
 import com.zhongshu.card.client.service.org.UserAccountService;
 import com.zhongshu.card.server.core.service.org.IndexService;
+import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -31,18 +32,11 @@ import org.springframework.web.bind.annotation.RestController;
 @Tag(name = "用户管理")
 public class UserManagerController {
 
-    @Autowired
-    IndexService indexService;
-
-    @Autowired
-    OrganizationService organizationService;
-
-    @Autowired
-    AuthHelper authHelper;
-
     @Autowired
     UserAccountService userAccountService;
 
+    @Autowired
+    OrganizationUserServiceImpl organizationUserService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "机构用户列表-分页查询", description = "机构用户列表-分页查询")
@@ -57,7 +51,7 @@ public class UserManagerController {
     @Operation(summary = "添加-编辑机构用户", description = "添加-编辑机构用户")
     @RequestMapping(value = {"update"}, method = {RequestMethod.POST})
     public ResultContent update(@RequestBody UserCountAddParam param) {
-        return userAccountService.update(param);
+        return organizationUserService.saveOrgUser(param);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)

+ 6 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/base/SuperService.java

@@ -40,8 +40,12 @@ public abstract class SuperService {
      * @return
      */
     public String getCurrentUserId() {
-        if (authHelper != null && authHelper.getCurrentUser() != null) {
-            return authHelper.getCurrentUser().getUserId();
+        try {
+            if (authHelper != null && authHelper.getCurrentUser() != null) {
+                return authHelper.getCurrentUser().getUserId();
+            }
+        } catch (Exception e) {
+            log.error("getCurrentUserId error: {}", e.getMessage());
         }
         return null;
     }

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

@@ -38,6 +38,7 @@ public class OpenAPIRegisterService {
         } else {
             log.info("openApi注册成功");
         }
+        str = null;
         return ResultContent.buildSuccess();
     }
 

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

@@ -5,10 +5,7 @@ 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.org.*;
 import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
 import com.zhongshu.card.client.model.school.RegisterBindSchoolParam;
 import com.zhongshu.card.client.type.OrganizationUserType;
@@ -22,6 +19,7 @@ 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 com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -29,6 +27,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -75,8 +74,81 @@ public class OrganizationUserServiceImpl extends SuperService {
     @Autowired
     RoleService roleService;
 
+    @Autowired
+    UserAccountServiceImpl userAccountService;
+
     /**
-     * 项目添加用户 (角色、部门、职位都以新的为准)
+     * 添加编辑用户 添加机构用户 (包括角色 部门 职位等信息)
+     * 用户可能不存在
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent<OrganizationUser> saveOrgUser(UserCountAddParam param) {
+        String oid = param.getOid();
+        Assert.hasText(oid, "oid不能为空");
+        Assert.hasText(param.getName(), "name不能为空");
+        if (param.getState() == null) {
+            param.setState(UserState.Normal);
+        }
+
+        // 机构信息
+        Organization organization = organizationDao.findTopByOid(oid);
+        if (ObjectUtils.isEmpty(organization)) {
+            return ResultContent.buildFail(String.format("oid不存在:%s", oid));
+        }
+        OrganizationUser temp = null;
+        if (StringUtils.isNotEmpty(param.getId())) {
+            temp = organizationUserDao.findTopById(param.getId());
+            if (ObjectUtils.isEmpty(temp)) {
+                return ResultContent.buildFail(String.format("数据不存在:%s", param.getId()));
+            }
+        }
+
+        // 用户基本信息维护
+        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());
+        if (temp != null && temp.getUser() != null) {
+            userAccountParam.setLoginName(temp.getUser().getLoginName());
+        }
+        ResultContent<String> userAccountContent = userAccountService.registerUserAccount(userAccountParam);
+        if (userAccountContent.isFailed()) {
+            return ResultContent.buildFail(userAccountContent.getMsg());
+        }
+        String userId = userAccountContent.getContent();
+        UserAccount userAccount = userCountDao.findTopByUserId(userId);
+
+        OrgBindUserAllParam orgBindUserAllParam = new OrgBindUserAllParam();
+        orgBindUserAllParam.setId(param.getId());
+        orgBindUserAllParam.setUserId(userAccount.getUserId());
+        orgBindUserAllParam.setOrgOid(organization.getOid());
+        if (temp != null && temp.getOrganization() != null) {
+            orgBindUserAllParam.setOrgOid(temp.getOrganization().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());
+
+        ResultContent<OrganizationUser> bindUserContent = orgBindUser(orgBindUserAllParam);
+        if (bindUserContent.isFailed()) {
+            return ResultContent.buildFail(bindUserContent.getMsg());
+        }
+        OrganizationUser organizationUser = bindUserContent.getContent();
+
+        return ResultContent.buildSuccess(organizationUser);
+    }
+
+    /**
+     * 结构绑定用户 (角色、部门、职位都以新的为准)
+     * 用户基本信息已存在
      *
      * @param param
      * @return
@@ -105,7 +177,15 @@ public class OrganizationUserServiceImpl extends SuperService {
         if (StringUtils.isNotEmpty(param.getCode())) {
             codeTemp = organizationUserDao.findTopByCodeAndOrganization(param.getCode(), organization);
         }
-        OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, userAccount);
+        OrganizationUser organizationUser = null;
+        if (StringUtils.isNotEmpty(param.getId())) {
+            organizationUser = organizationUserDao.findTopById(param.getId());
+            if (ObjectUtils.isEmpty(organizationUser)) {
+                return ResultContent.buildFail(String.format("数据不存在:%s", param.getId()));
+            }
+        } else {
+            organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, userAccount);
+        }
         if (ObjectUtils.isEmpty(organizationUser)) {
             // 添加
             if (ObjectUtils.isNotEmpty(codeTemp)) {
@@ -115,11 +195,6 @@ public class OrganizationUserServiceImpl extends SuperService {
             organizationUser.setOid(organization.getOid());
             initEntity(organizationUser);
             BeanUtils.copyProperties(param, organizationUser);
-
-            organizationUser.setOrganization(organization);
-            organizationUser.setUser(userAccount);
-            organizationUser.setUserId(userAccount.getUserId());
-            organizationUser.setCreateUserId(getCurrentUserId());
             // 在机构中的用户类型
             organizationUser.setUserType(OrganizationUserType.Consumer);
         } else {
@@ -142,6 +217,11 @@ public class OrganizationUserServiceImpl extends SuperService {
             }
         }
 
+        organizationUser.setOrganization(organization);
+        organizationUser.setUser(userAccount);
+        organizationUser.setUserId(userAccount.getUserId());
+        organizationUser.setCreateUserId(getCurrentUserId());
+
         List<Role> roles = new ArrayList<>();
         Department department = null;
         if (ObjectUtils.isNotEmpty(param.getRoleIds())) {

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

@@ -142,7 +142,7 @@ public class SchoolUserServiceImpl extends SuperService implements SchoolUserSer
 
                 // 添加到
                 for (UserCountAddParam param : userList) {
-                    ResultContent resultContent = userAccountService.update(param);
+                    ResultContent resultContent = organizationUserService.saveOrgUser(param);
                     log.info("添加日志: {}", resultContent.getMsg());
                 }
                 model.setSuccess(userList.size());
@@ -230,7 +230,7 @@ public class SchoolUserServiceImpl extends SuperService implements SchoolUserSer
         passWord = passWord.toLowerCase().replace("x", "0");
         param.setPassWord(passWord);
 
-        ResultContent resultContent = userAccountService.update(param);
+        ResultContent resultContent = organizationUserService.saveOrgUser(param);
         if (resultContent.isFailed()) {
             return resultContent;
         }

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

@@ -15,23 +15,24 @@ 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;
-import com.zhongshu.card.client.type.*;
-
+import com.zhongshu.card.client.type.Sex;
+import com.zhongshu.card.client.type.UserLoginType;
+import com.zhongshu.card.client.type.UserState;
+import com.zhongshu.card.client.type.UserType;
 import com.zhongshu.card.server.core.dao.org.*;
 import com.zhongshu.card.server.core.dao.school.DictInfoDao;
 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.domain.org.Organization;
+import com.zhongshu.card.server.core.domain.org.OrganizationUser;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
 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;
-import com.zhongshu.card.server.core.util.ValidateResult;
 import com.zhongshu.card.server.core.util.ValidateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
@@ -66,94 +67,21 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
     @Autowired
     UserService userService;
 
-    @Autowired
-    RoleDao roleDao;
-
-    @Autowired
-    DepartmentDao departmentDao;
-
     @Autowired
     OrganizationDao organizationDao;
 
     @Autowired
     OrganizationUserDao organizationUserDao;
 
-    @Autowired
-    RoleService roleService;
-
     @Autowired
     RoleServiceImpl roleServiceImpl;
 
     @Autowired
     DepartmentServiceImpl departmentService;
 
-    @Autowired
-    DictInfoDao dictInfoDao;
-
-    @Autowired
-    OrganizationUserService organizationUserService;
-
     @Autowired
     DictInfoServiceImpl dictInfoService;
 
-    @Autowired
-    OrganizationUserServiceImpl organizationUserServiceImpl;
-
-    /**
-     * 添加编辑用户 添加机构用户 (包括角色 部门 职位等信息)
-     *
-     * @param param
-     * @return
-     */
-    @Override
-    public ResultContent<OrganizationUser> update(UserCountAddParam param) {
-        String oid = param.getOid();
-        Assert.hasText(oid, "oid不能为空");
-        Assert.hasText(param.getName(), "name不能为空");
-        if (param.getState() == null) {
-            param.setState(UserState.Normal);
-        }
-
-        // 机构信息
-        Organization organization = organizationDao.findTopByOid(oid);
-        if (ObjectUtils.isEmpty(organization)) {
-            return ResultContent.buildFail(String.format("oid不存在:%s", oid));
-        }
-
-        // 用户基本信息维护
-        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());
-        }
-        String userId = userAccountContent.getContent();
-        UserAccount userAccount = userCountDao.findTopByUserId(userId);
-
-        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());
-
-        ResultContent<OrganizationUser> bindUserContent = organizationUserServiceImpl.orgBindUser(orgBindUserAllParam);
-        if (bindUserContent.isFailed()) {
-            return ResultContent.buildFail(bindUserContent.getMsg());
-        }
-        OrganizationUser organizationUser = bindUserContent.getContent();
-
-        return ResultContent.buildSuccess(organizationUser);
-    }
-
     /**
      * 注册基本用户 (没有就注册,有就修改)
      *