|
|
@@ -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())) {
|