|
|
@@ -0,0 +1,296 @@
|
|
|
+package com.zhongshu.card.server.core.service.orgManager;
|
|
|
+
|
|
|
+import com.github.microservice.auth.client.constant.AuthConstant;
|
|
|
+import com.github.microservice.auth.client.content.ResultState;
|
|
|
+import com.github.microservice.auth.client.model.RoleGroupModel;
|
|
|
+import com.github.microservice.auth.client.model.RoleModel;
|
|
|
+import com.github.microservice.auth.client.model.UserAuthModel;
|
|
|
+import com.github.microservice.auth.client.model.UserModel;
|
|
|
+import com.github.microservice.auth.client.service.OrganizationUserService;
|
|
|
+import com.github.microservice.auth.client.service.RoleService;
|
|
|
+import com.github.microservice.auth.client.service.UserService;
|
|
|
+import com.github.microservice.auth.client.type.LoginType;
|
|
|
+import com.github.microservice.auth.security.helper.AuthHelper;
|
|
|
+import com.github.microservice.auth.security.type.AuthType;
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.net.ResultMessage;
|
|
|
+import com.zhongshu.card.client.model.org.*;
|
|
|
+import com.zhongshu.card.client.model.orgModel.OrgSaveParam;
|
|
|
+import com.zhongshu.card.client.model.project.ProjectSaveParam;
|
|
|
+import com.zhongshu.card.client.service.org.OrganizationService;
|
|
|
+import com.zhongshu.card.client.type.*;
|
|
|
+import com.zhongshu.card.client.utils.DateUtils;
|
|
|
+import com.zhongshu.card.server.core.dao.org.*;
|
|
|
+import com.zhongshu.card.server.core.dataConfig.CardSystemDefault;
|
|
|
+import com.zhongshu.card.server.core.domain.org.*;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.org.*;
|
|
|
+import com.zhongshu.card.server.core.service.projectAbout.ProjectCommonConfigService;
|
|
|
+import com.zhongshu.card.server.core.service.projectAbout.ProjectIotInfoService;
|
|
|
+import com.zhongshu.card.server.core.service.projectAbout.ProjectWeChatInfoService;
|
|
|
+import com.zhongshu.card.server.core.service.sync.ProjectSyncIotCenterService;
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+import com.zhongshu.card.server.core.util.NextNoUtil;
|
|
|
+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;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 机构管理
|
|
|
+ *
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/5/31
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OrganizationManagerServiceImpl extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ com.github.microservice.auth.client.service.OrganizationService organizationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationUserService organizationUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RoleService roleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserCountDao userCountDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserAccountServiceImpl userAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationUserDao organizationUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RoleDao roleDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DepartmentServiceImpl departmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AuthHelper authHelper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RegionDao regionDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationRelationDao organizationRelationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ProjectSyncIotCenterService projectSyncIotCenterService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationUserServiceImpl organizationUserServiceImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RoleServiceImpl roleServiceImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ProjectIotInfoService projectIotInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ProjectWeChatInfoService projectWeChatInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ProjectCommonConfigService projectCommonConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationServiceImpl organizationServiceImpl;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存项目 下的机构信息
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public ResultContent saveOrgInfo(OrgSaveParam param) {
|
|
|
+ AuthType authType = param.getAuthType();
|
|
|
+ if (authType == AuthType.User || authType == AuthType.Platform
|
|
|
+ || authType == AuthType.Project) {
|
|
|
+ return ResultContent.buildFail("authType 类型错误");
|
|
|
+ }
|
|
|
+ // 项目信息
|
|
|
+ ResultContent<Organization> checkProjectContent = checkProject(param.getProjectOid());
|
|
|
+ if (checkProjectContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(checkProjectContent.getMsg());
|
|
|
+ }
|
|
|
+ Organization projectInfo = checkProjectContent.getContent();
|
|
|
+
|
|
|
+ String code = param.getCode();
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ code = NextNoUtil.getNextNo(authType.getCode().toUpperCase());
|
|
|
+ param.setCode(code);
|
|
|
+ }
|
|
|
+ String name = param.getName();
|
|
|
+
|
|
|
+ Organization organization = null;
|
|
|
+ Organization nameOrganization = organizationDao.findTopByNameAndAuthType(name, authType);
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ organization = organizationDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(nameOrganization) && !nameOrganization.getId().equals(organization.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIST, param.getName()));
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, organization, "code");
|
|
|
+ initUpdateEntity(organization);
|
|
|
+ } else {
|
|
|
+ if (ObjectUtils.isNotEmpty(nameOrganization)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIST, param.getName()));
|
|
|
+ }
|
|
|
+ // 初始权限中心的机构信息
|
|
|
+ ResultContent<String> initOrgContent = organizationServiceImpl.authCenterAddOrgInfo(name, authType, param.getRemark());
|
|
|
+ if (initOrgContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(initOrgContent.getMsg());
|
|
|
+ }
|
|
|
+ String oid = initOrgContent.getContent();
|
|
|
+ organization = new Organization();
|
|
|
+ BeanUtils.copyProperties(param, organization);
|
|
|
+ initEntityNoCheckOid(organization);
|
|
|
+ organization.setIsOrg(Boolean.TRUE);
|
|
|
+
|
|
|
+ organization.setOid(oid);
|
|
|
+ organization.setProjectOid(projectInfo.getOid());
|
|
|
+ organization.setAboutOid(projectInfo.getOid());
|
|
|
+ organization.setAboutAuthType(projectInfo.getAuthType());
|
|
|
+ organizationDao.save(organization);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 机构列表
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<Page<OrganizationSimpleModel>> orgPage(OrganizationSearchParam param, Pageable pageable) {
|
|
|
+ initSearchParam(param);
|
|
|
+ param.setIsOrg(Boolean.TRUE);
|
|
|
+ Page<Organization> page = organizationDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toSimpleModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 机构详情
|
|
|
+ *
|
|
|
+ * @param oid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<OrganizationSimpleModel> getOrgDetail(String oid) {
|
|
|
+ Organization organization = organizationDao.findTopByOid(oid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toSimpleModel(organization));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除机构
|
|
|
+ *
|
|
|
+ * @param oid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public ResultContent deleteOrg(String oid) {
|
|
|
+ Organization organization = organizationDao.findTopByOid(oid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
|
|
|
+ }
|
|
|
+ if (organization.getIsOrg() == null || !organization.getIsOrg()) {
|
|
|
+ return ResultContent.buildFail("当前不属于结构类型,不能删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ //1. 判断是否可以删除
|
|
|
+
|
|
|
+ //2. 删除机构
|
|
|
+ organizationDao.delete(organization);
|
|
|
+
|
|
|
+ //3. 删除关联的信息
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ //---------------------------------供其他服务调用接口 start---------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询项目下所有的机构信息列表
|
|
|
+ *
|
|
|
+ * @param projectOid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<List<OrganizationSimpleModel>> getProjectOrgList(String projectOid) {
|
|
|
+ List<OrganizationSimpleModel> models = new ArrayList<>();
|
|
|
+ List<Organization> list = organizationDao.findByProjectOidAndIsOrg(projectOid, Boolean.TRUE);
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ models = list.stream().map(this::toSimpleModel).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目关联的结构 数量
|
|
|
+ *
|
|
|
+ * @param projectOid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public long countProjectOrgNumber(String projectOid) {
|
|
|
+ return organizationDao.countByProjectOid(projectOid, Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查项目是否存在 是否是项目类型
|
|
|
+ *
|
|
|
+ * @param projectOid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<Organization> checkProject(String projectOid) {
|
|
|
+ if (StringUtils.isEmpty(projectOid)) {
|
|
|
+ return ResultContent.buildFail("projectOid不能为空");
|
|
|
+ }
|
|
|
+ Organization organization = organizationDao.findTopByOid(projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format("项目不存在:%s", projectOid));
|
|
|
+ }
|
|
|
+ if (organization.getAuthType() != AuthType.Project) {
|
|
|
+ return ResultContent.buildFail(String.format("%s 不属于项目类型", organization.getName()));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ public OrganizationSimpleModel toSimpleModel(Organization entity) {
|
|
|
+ OrganizationSimpleModel model = new OrganizationSimpleModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|