|
|
@@ -14,8 +14,9 @@ import com.github.microservice.auth.security.type.AuthType;
|
|
|
import com.zhongshu.card.client.model.org.OrganizationAddParam;
|
|
|
import com.zhongshu.card.client.model.org.OrganizationModel;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
import com.zhongshu.card.client.service.org.OrganizationService;
|
|
|
-import com.zhongshu.card.client.type.UserState;
|
|
|
+import com.zhongshu.card.client.utils.type.UserState;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.RoleDao;
|
|
|
@@ -25,7 +26,9 @@ 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.Role;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+import com.zhongshu.card.server.core.util.NextNoUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -43,7 +46,7 @@ import java.util.Set;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class OrganizationServiceImpl implements OrganizationService {
|
|
|
+public class OrganizationServiceImpl extends SuperService implements OrganizationService {
|
|
|
|
|
|
@Autowired
|
|
|
OrganizationDao organizationDao;
|
|
|
@@ -75,13 +78,86 @@ public class OrganizationServiceImpl implements OrganizationService {
|
|
|
@Autowired
|
|
|
DepartmentServiceImpl departmentService;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加机构
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
public ResultContent addOrganization(OrganizationAddParam param) {
|
|
|
+ // 验证数据
|
|
|
+ Organization temp = organizationDao.findTopByName(param.getName());
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIST, param.getName()));
|
|
|
+ }
|
|
|
+ AuthType authType = param.getAuthType();
|
|
|
+ if (authType == AuthType.Platform) {
|
|
|
+ return ResultContent.buildFail("机构类型错误");
|
|
|
+ }
|
|
|
+ String code = param.getCode();
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ code = NextNoUtil.getNextNo(authType.getCode().toUpperCase());
|
|
|
+ }
|
|
|
+ temp = organizationDao.findTopByCode(code);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format("编码已存在,请重新再试:%s", code));
|
|
|
+ }
|
|
|
+ param.setCode(code);
|
|
|
+
|
|
|
+ String oid = "";
|
|
|
+ com.github.microservice.auth.client.model.OrganizationModel organizationModel = new com.github.microservice.auth.client.model.OrganizationModel();
|
|
|
+ organizationModel.setName(param.getName());
|
|
|
+ organizationModel.setAuthType(authType);
|
|
|
+ organizationModel.setRemark(param.getRemark());
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String>
|
|
|
+ resultContent = organizationService.add(organizationModel);
|
|
|
+
|
|
|
+ if (resultContent.getState() == ResultState.Success) {
|
|
|
+ log.info("平台初始成功: {}", resultContent.getContent());
|
|
|
+ oid = resultContent.getContent();
|
|
|
+ } else {
|
|
|
+ String msg = resultContent.getMsg();
|
|
|
+ if (StringUtils.isEmpty(msg) && resultContent.getException() != null) {
|
|
|
+ msg = resultContent.getException().getMessage();
|
|
|
+ }
|
|
|
+ log.info("initSuperOrganization {}", msg);
|
|
|
+ return ResultContent.buildFail(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ Organization organization = new Organization();
|
|
|
+ BeanUtils.copyProperties(param, organization);
|
|
|
+ organization.setOid(oid);
|
|
|
+ organizationDao.save(organization);
|
|
|
+
|
|
|
+ // 初始机构数据
|
|
|
+ initOrganization(organization);
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑机构
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent update(OrganizationAddParam param) {
|
|
|
Organization organization = new Organization();
|
|
|
|
|
|
+
|
|
|
organizationDao.save(organization);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始平台信息
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ResultContent initSuperOrganization() {
|
|
|
String oid = "";
|
|
|
@@ -135,6 +211,7 @@ public class OrganizationServiceImpl implements OrganizationService {
|
|
|
*/
|
|
|
public ResultContent initOrganization(Organization organization) {
|
|
|
String userId = "";
|
|
|
+ // 查询用户是否存在
|
|
|
com.github.microservice.auth.client.content.ResultContent<UserModel> userModelResult =
|
|
|
userService.queryFromLoginType(LoginType.Phone, organization.getContactPhone());
|
|
|
if (userModelResult.getState() != ResultState.Success) {
|
|
|
@@ -155,6 +232,7 @@ public class OrganizationServiceImpl implements OrganizationService {
|
|
|
userAccount = userAccountService.initUserAccountOrg(userId, organization);
|
|
|
}
|
|
|
|
|
|
+ // 用户没在这个企业
|
|
|
if (!organizationUserDao.existsByOrganizationAndUser(organization, userAccount)) {
|
|
|
//本地: 绑定机构和用户的关系
|
|
|
OrganizationUser organizationUser = new OrganizationUser();
|
|
|
@@ -190,50 +268,52 @@ public class OrganizationServiceImpl implements OrganizationService {
|
|
|
*/
|
|
|
public ResultContent initResource(Organization organization, String userId) {
|
|
|
UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
- Set<String> auth = Set.of(AuthConstant.Admin);
|
|
|
- if(organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
- auth = Set.of(AuthConstant.SuperAdmin);
|
|
|
- }
|
|
|
|
|
|
- String oid = organization.getOid();
|
|
|
- // 权限中心: 角色组
|
|
|
- RoleGroupModel admin = new RoleGroupModel();
|
|
|
- admin.setName(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
- admin.setRemark(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
- admin.setOrganizationId(oid);
|
|
|
- admin.setIdentity(auth);
|
|
|
- com.github.microservice.auth.client.content.ResultContent<String> updateRoleGroupAdmin = roleService.updateRoleGroup(admin);
|
|
|
- String groupId = updateRoleGroupAdmin.getContent();
|
|
|
- log.info("初始权限中心角色组成功:{}", groupId);
|
|
|
-
|
|
|
- Role adminRole = null;
|
|
|
- if (!StringUtils.isEmpty(groupId)) {
|
|
|
-
|
|
|
- // 权限中心: 角色信息
|
|
|
- RoleModel roleModel = new RoleModel();
|
|
|
- roleModel.setOrganizationId(oid);
|
|
|
- roleModel.setName(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
- roleModel.setRemark(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
- roleModel.setAuth(auth);
|
|
|
- com.github.microservice.auth.client.content.ResultContent<String> updateRole =
|
|
|
- roleService.updateRole(roleModel);
|
|
|
- roleService.addRoleToRoleGroup(groupId, new String[]{updateRole.getContent()});
|
|
|
- log.info("权限中心:初始角色和角色组关系成功");
|
|
|
-
|
|
|
- // 添加本地角色信息
|
|
|
- adminRole = new Role();
|
|
|
- adminRole.setCode("manager");
|
|
|
- adminRole.setAuth(auth);
|
|
|
- adminRole.setOid(oid);
|
|
|
- adminRole.setRoleGroupId(groupId);
|
|
|
- adminRole.setName(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
- adminRole.setRemark(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
- adminRole.setAdmin(true);
|
|
|
- roleDao.save(adminRole);
|
|
|
-
|
|
|
- //权限中心: 将用户添加进管理员角色组
|
|
|
- roleService.addUserToRoleGroup(groupId, new String[]{userId});
|
|
|
- log.info("权限中心:绑定角色和用户关系成功");
|
|
|
+ Role adminRole = roleDao.findTopByNameAndOid(CardDefault.DEFAULT_ROLE_NAME, organization.getOid());
|
|
|
+ if (ObjectUtils.isEmpty(adminRole)) {
|
|
|
+ Set<String> auth = Set.of(AuthConstant.Admin);
|
|
|
+ if (organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
+ auth = Set.of(AuthConstant.SuperAdmin);
|
|
|
+ }
|
|
|
+
|
|
|
+ String oid = organization.getOid();
|
|
|
+ // 权限中心: 角色组
|
|
|
+ RoleGroupModel admin = new RoleGroupModel();
|
|
|
+ admin.setName(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
+ admin.setRemark(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
+ admin.setOrganizationId(oid);
|
|
|
+ admin.setIdentity(auth);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> updateRoleGroupAdmin = roleService.updateRoleGroup(admin);
|
|
|
+ String groupId = updateRoleGroupAdmin.getContent();
|
|
|
+ log.info("初始权限中心角色组成功:{}", groupId);
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(groupId)) {
|
|
|
+ // 权限中心: 角色信息
|
|
|
+ RoleModel roleModel = new RoleModel();
|
|
|
+ roleModel.setOrganizationId(oid);
|
|
|
+ roleModel.setName(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
+ roleModel.setRemark(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
+ roleModel.setAuth(auth);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> updateRole =
|
|
|
+ roleService.updateRole(roleModel);
|
|
|
+ roleService.addRoleToRoleGroup(groupId, new String[]{updateRole.getContent()});
|
|
|
+ log.info("权限中心:初始角色和角色组关系成功");
|
|
|
+
|
|
|
+ // 添加本地角色信息
|
|
|
+ adminRole = new Role();
|
|
|
+ adminRole.setCode("manager");
|
|
|
+ adminRole.setAuth(auth);
|
|
|
+ adminRole.setOid(oid);
|
|
|
+ adminRole.setRoleGroupId(groupId);
|
|
|
+ adminRole.setName(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
+ adminRole.setRemark(CardDefault.DEFAULT_ROLE_NAME);
|
|
|
+ adminRole.setAdmin(true);
|
|
|
+ roleDao.save(adminRole);
|
|
|
+
|
|
|
+ //权限中心: 将用户添加进管理员角色组
|
|
|
+ roleService.addUserToRoleGroup(groupId, new String[]{userId});
|
|
|
+ log.info("权限中心:绑定角色和用户关系成功");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 本地:保存用户角色信息
|