feat:[REQ-3488] 优化foundation创建节点和协同关系方法
This commit is contained in:
parent
e3630e50ef
commit
56e2b36556
@ -1,5 +1,7 @@
|
||||
package cn.axzo.orgmanax.common;
|
||||
|
||||
import cn.axzo.foundation.exception.Axssert;
|
||||
import cn.axzo.orgmanax.common.config.BizResultCode;
|
||||
import cn.axzo.orgmanax.dto.cooperateship.dto.OrgCooperateShipDTO;
|
||||
import cn.hutool.extra.validation.BeanValidationResult;
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
@ -41,19 +43,6 @@ public class ValidationUtil {
|
||||
return validator.validate(bean, groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验bean的某一个属性
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param bean bean
|
||||
* @param propertyName 属性名称
|
||||
* @param groups 验证分组
|
||||
* @return {@link Set}
|
||||
*/
|
||||
public static <T> Set<ConstraintViolation<T>> validateProperty(T bean, String propertyName, Class<?>... groups) {
|
||||
return validator.validateProperty(bean, propertyName, groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验对象
|
||||
*
|
||||
@ -66,18 +55,18 @@ public class ValidationUtil {
|
||||
return warpBeanValidationResult(validate(bean, groups));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验bean的某一个属性
|
||||
* 校验对象, 抛出异常
|
||||
*
|
||||
* @param <T> bean类型
|
||||
* @param bean bean
|
||||
* @param propertyName 属性名称
|
||||
* @param groups 验证分组
|
||||
* @return {@link BeanValidationResult}
|
||||
* @param <T> Bean类型
|
||||
* @param bean bean
|
||||
* @param groups 校验组
|
||||
* @return {@link Set}
|
||||
*/
|
||||
public static <T> BeanValidationResult warpValidateProperty(T bean, String propertyName, Class<?>... groups) {
|
||||
return warpBeanValidationResult(validateProperty(bean, propertyName, groups));
|
||||
public static <T> void warpValidateThrowError(T bean, Class<?>... groups) {
|
||||
BeanValidationResult validationResult = warpValidate(bean, groups);
|
||||
Axssert.check(validationResult.isSuccess(), BizResultCode.INVALID_PARAM,
|
||||
validationResult.getErrorMessages().stream().map(BeanValidationResult.ErrorMessage::getMessage).findFirst().orElse(""));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -55,6 +55,13 @@ public class CooperateShipServiceImpl implements CooperateShipService {
|
||||
private final WorkspaceGateway workspaceGateway;
|
||||
private final CooperateShipFoundationService cooperateShipFoundationService;
|
||||
|
||||
/**
|
||||
* 场景说明:
|
||||
* *部门管理
|
||||
* ** 创建部门, 创建节点,创建节点用户,(如果是顶级节点)维护协同关系
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public SaasCooperateShip create(CreateOrgCooperateShipReq req) {
|
||||
|
||||
@ -58,10 +58,6 @@ public class NodeFoundationServiceImpl implements NodeFoundationService {
|
||||
Axssert.check(validationResult.isSuccess(), BizResultCode.INVALID_PARAM,
|
||||
validationResult.getErrorMessages().stream().map(BeanValidationResult.ErrorMessage::getMessage).findFirst().orElse(""));
|
||||
|
||||
// 单位是否存在
|
||||
unitQueryRepository.oneOpt(UnitQueryRepository.OneReq.builder().id(nodeCreate.getOrganizationalUnitId()).build())
|
||||
.orElseThrow(() -> BizResultCode.ENTITY_NOT_FOUND.toException("部门所在单位不存在{}", nodeCreate.getOrganizationalUnitId()));
|
||||
|
||||
// 获取上级节点
|
||||
OrganizationalNode parentNode = Objects.isNull(nodeCreate.getParentId()) ? null :
|
||||
nodeQueryRepository.oneOpt(NodeQueryRepository.OneReq.builder().id(nodeCreate.getParentId()).build())
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.axzo.orgmanax.common.config.BizResultCode;
|
||||
import cn.axzo.orgmanax.dto.nodeuser.enums.NodeUserTypeEnum;
|
||||
import cn.axzo.orgmanax.infra.dao.node.entity.OrganizationalNode;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@ -15,6 +16,7 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -62,31 +64,40 @@ public class NodeCreate {
|
||||
*/
|
||||
@NotNull(message = "创建人不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 创建部门的端
|
||||
*/
|
||||
private String terminal;
|
||||
|
||||
/**
|
||||
* 创建部门的页面,需前端传入
|
||||
*/
|
||||
private String page;
|
||||
|
||||
/**
|
||||
* 扩展信息
|
||||
*/
|
||||
private JSONObject extra;
|
||||
|
||||
/**
|
||||
* 扩展信息
|
||||
*/
|
||||
private JSONObject profile;
|
||||
|
||||
/**
|
||||
* 部门管理员
|
||||
*/
|
||||
private List<Long> nodeAdminPersonIds;
|
||||
|
||||
public OrganizationalNode toEntity() {
|
||||
OrganizationalNode node = BeanUtil.toBean(this, OrganizationalNode.class);
|
||||
node.setCreateBy(operatorId);
|
||||
node.setUpdateBy(operatorId);
|
||||
// 将 terminal、page 信息存储到ext
|
||||
node.setExtra(Optional.ofNullable(extra).orElseGet(JSONObject::new)
|
||||
.fluentPut("createScene", ImmutableMap.of("terminal", StrUtil.firstNonBlank(terminal, "UNKNOWN"),
|
||||
"page", StrUtil.firstNonBlank(page, "UNKNOWN"))));
|
||||
.fluentPut("createScene", ImmutableMap.of("terminal", CharSequenceUtil.firstNonBlank(terminal, "UNKNOWN"),
|
||||
"page", CharSequenceUtil.firstNonBlank(page, "UNKNOWN"))));
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@ -4,10 +4,16 @@ import cn.axzo.apollo.workspace.api.v2.workspace.req.ListWorkspaceReq;
|
||||
import cn.axzo.apollo.workspace.api.v2.workspace.req.WorkspaceListReq;
|
||||
import cn.axzo.apollo.workspace.api.v2.workspace.resp.WorkspaceDTO;
|
||||
import cn.axzo.apollo.workspace.api.v2.workspace.resp.WorkspaceDetailListResp;
|
||||
import cn.axzo.foundation.exception.Axssert;
|
||||
import cn.axzo.orgmanax.common.ValidationUtil;
|
||||
import cn.axzo.orgmanax.dto.cooperateship.enums.CooperateShipTypeEnum;
|
||||
import cn.axzo.orgmanax.common.config.BizResultCode;
|
||||
import cn.axzo.orgmanax.dto.cooperateship.req.CreateOrgCooperateShipReq;
|
||||
import cn.axzo.orgmanax.dto.nodeuser.enums.NodeUserTypeEnum;
|
||||
import cn.axzo.orgmanax.infra.client.profile.PersonProfileGateway;
|
||||
import cn.axzo.orgmanax.infra.client.profile.ProfileUserProfileClient;
|
||||
import cn.axzo.orgmanax.infra.client.profile.dto.ProfileGetIdentityProfileLiteReq;
|
||||
import cn.axzo.orgmanax.infra.client.profile.dto.ProfileGetIdentityProfileLiteResp;
|
||||
import cn.axzo.orgmanax.infra.client.workspace.WorkspaceGateway;
|
||||
import cn.axzo.orgmanax.infra.client.workspace.dto.Workspace;
|
||||
import cn.axzo.orgmanax.infra.dao.cooperateship.entity.SaasCooperateShip;
|
||||
@ -19,12 +25,15 @@ import cn.axzo.orgmanax.server.cooperateship.service.CooperateShipService;
|
||||
import cn.axzo.orgmanax.server.node.foundation.NodeFoundationService;
|
||||
import cn.axzo.orgmanax.server.node.foundation.req.NodeCreate;
|
||||
import cn.axzo.orgmanax.server.node.service.processor.NodeProcessor;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -39,16 +48,36 @@ public class CreateNodeProcessor implements NodeProcessor {
|
||||
private final CooperateShipFoundationService cooperateShipFoundationService;
|
||||
private final WorkspaceGateway workspaceGateway;
|
||||
private final UnitQueryRepository unitQueryRepository;
|
||||
private final PersonProfileGateway personProfileGateway;
|
||||
|
||||
@Override
|
||||
public ProcessResult process(ProcessContext context) {
|
||||
|
||||
// 转成该处理器关注的参数对象
|
||||
// 初始化入参
|
||||
NodeCreate nodeCreate = context.getParams().toJavaObject(NodeCreate.class);
|
||||
|
||||
// 入参通用校验
|
||||
ValidationUtil.warpValidateThrowError(nodeCreate);
|
||||
|
||||
// 单位是否存在
|
||||
unitQueryRepository.oneOpt(UnitQueryRepository.OneReq.builder().id(nodeCreate.getOrganizationalUnitId()).build())
|
||||
.orElseThrow(() -> BizResultCode.ENTITY_NOT_FOUND.toException("部门所在单位不存在{}", nodeCreate.getOrganizationalUnitId()));
|
||||
|
||||
|
||||
// 保存node节点
|
||||
OrganizationalNode savedNode = nodeFoundationService.create(nodeCreate);
|
||||
|
||||
// 是否需要创建部门管理员
|
||||
if (CollUtil.isNotEmpty(nodeCreate.getNodeAdminPersonIds())) {
|
||||
// 身份信息
|
||||
List<ProfileGetIdentityProfileLiteResp> profileIdentities = personProfileGateway.listIdentityProfiles(ProfileGetIdentityProfileLiteReq.builder()
|
||||
.personIds(nodeCreate.getNodeAdminPersonIds())
|
||||
.build());
|
||||
Axssert.check(CollUtil.isNotEmpty(profileIdentities), BizResultCode.INVALID_PARAM, "未找到任何从业人员信息");
|
||||
Axssert.check(CollUtil.distinct(nodeCreate.getNodeAdminPersonIds()).size() == profileIdentities.size(), BizResultCode.INVALID_PARAM, "未找到某些从业人员信息");
|
||||
// todo 创建节点用户
|
||||
}
|
||||
|
||||
// 初始化协同关系
|
||||
initCooperateShipIfNeeded(savedNode, nodeCreate.getOperatorId());
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user