diff --git a/know_sub_business/src/main/java/com/supervision/knowsub/service/impl/FlowManageServiceImpl.java b/know_sub_business/src/main/java/com/supervision/knowsub/service/impl/FlowManageServiceImpl.java index 3af2ace..b1b36d9 100644 --- a/know_sub_business/src/main/java/com/supervision/knowsub/service/impl/FlowManageServiceImpl.java +++ b/know_sub_business/src/main/java/com/supervision/knowsub/service/impl/FlowManageServiceImpl.java @@ -2,7 +2,9 @@ package com.supervision.knowsub.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.supervision.knowsub.dto.flow.SystemFlowTypeDTO; import com.supervision.knowsub.exception.BusinessException; import com.supervision.knowsub.model.SystemBase; import com.supervision.knowsub.model.SystemFlow; @@ -207,21 +209,35 @@ public class FlowManageServiceImpl implements FlowManageService { */ private void updateFlowTypeRelation(String flowId, List flowTypeList,List baseIdList){ List flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery().eq(SystemFlowTypeRelation::getFlowId, flowId).list(); - List dbFlowTypeList = flowTypeRelationList.stream().map(SystemFlowTypeRelation::getFlowType).toList(); - // 数据库中不存在,入参中存在,新增 - List needInsert = flowTypeList.stream().filter(flowType -> !dbFlowTypeList.contains(flowType)).toList(); + // 从数据库中查询出来的数据 + List dbFlowTypeDTOList = flowTypeRelationList.stream().map(SystemFlowTypeDTO::buildWithFlowTypeRelation).toList(); + + // 入参中的数据 + List flowTypeDTOList = flowTypeList.stream().map(flowType -> + baseIdList.stream().map(baseId -> + SystemFlowTypeDTO.builder().baseId(baseId).flowId(flowId).flowType(flowType).build()).toList() + ).flatMap(Collection::stream).toList(); + + // 数据库中不存在,入参中存在,新增 流程类型与子库id组合成唯一数据 + List needInsert = flowTypeDTOList.stream().filter(systemFlowTypeDTO -> + dbFlowTypeDTOList.stream().noneMatch(dbSystemFlowTypeDTO -> + dbSystemFlowTypeDTO.contentEquals(systemFlowTypeDTO)) + ).toList(); + + // 数据库中存在,入参中不存在,删除 流程类型与子库id组合成唯一数据 + List needDelete = dbFlowTypeDTOList.stream().filter(dbSystemFlowTypeDTO -> + flowTypeDTOList.stream().noneMatch(dbSystemFlowTypeDTO::contentEquals)).toList(); - // 数据库中存在,入参中不存在,删除 - List needDelete = dbFlowTypeList.stream().filter(flowType -> !flowTypeList.contains(flowType)).distinct().toList(); if (CollUtil.isNotEmpty(needInsert)){ - doBatchSaveFlowTypeRelation(flowId, needInsert, baseIdList); + List flowTypeRelations = needInsert.stream().map(SystemFlowTypeDTO::toSystemFlowTypeRelation).toList(); + systemFlowTypeRelationService.saveBatch(flowTypeRelations); } if (CollUtil.isNotEmpty(needDelete)){ - systemFlowTypeRelationService.lambdaUpdate().in(SystemFlowTypeRelation::getFlowType, needDelete) - .eq(SystemFlowTypeRelation::getFlowId, flowId).remove(); + List needDeleteIds = needDelete.stream().map(SystemFlowTypeDTO::getId).filter(StrUtil::isNotEmpty).toList(); + systemFlowTypeRelationService.removeBatchByIds(needDeleteIds); } } diff --git a/know_sub_model/src/main/java/com/supervision/knowsub/dto/flow/SystemFlowTypeDTO.java b/know_sub_model/src/main/java/com/supervision/knowsub/dto/flow/SystemFlowTypeDTO.java new file mode 100644 index 0000000..909f168 --- /dev/null +++ b/know_sub_model/src/main/java/com/supervision/knowsub/dto/flow/SystemFlowTypeDTO.java @@ -0,0 +1,68 @@ +package com.supervision.knowsub.dto.flow; + +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; +import com.supervision.knowsub.model.SystemFlowTypeRelation; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.Tolerate; + +import java.util.Objects; + +/** + * 流程类型关联表 + */ +@Data +@Builder +public class SystemFlowTypeDTO { + + @Schema(description = "数据id") + private String id; + + @Schema(description = "流程类型id") + private String flowId; + + private Integer flowType; + + @Schema(description = "子库id") + private String baseId; + + @Tolerate + public SystemFlowTypeDTO() { + } + + + public static SystemFlowTypeDTO buildWithFlowTypeRelation(SystemFlowTypeRelation systemFlowTypeRelation){ + if (Objects.isNull(systemFlowTypeRelation)){ + return new SystemFlowTypeDTO(); + } + return SystemFlowTypeDTO.builder() + .id(systemFlowTypeRelation.getId()) + .flowId(systemFlowTypeRelation.getFlowId()) + .flowType(systemFlowTypeRelation.getFlowType()) + .baseId(systemFlowTypeRelation.getBaseId()) + .build(); + } + + public SystemFlowTypeRelation toSystemFlowTypeRelation(){ + SystemFlowTypeRelation flowTypeRelation = new SystemFlowTypeRelation(); + flowTypeRelation.setId(this.getId()); + flowTypeRelation.setFlowType(this.getFlowType()); + flowTypeRelation.setFlowId(this.getFlowId()); + flowTypeRelation.setBaseId(this.getBaseId()); + return flowTypeRelation; + } + + public boolean contentEquals(SystemFlowTypeDTO systemFlowTypeDTO) { + + if (StrUtil.isAllNotEmpty(this.getId(), systemFlowTypeDTO.getId())){ + return StrUtil.equals(this.getId(), systemFlowTypeDTO.getId()); + } + + return StrUtil.equals(this.getBaseId(), systemFlowTypeDTO.getBaseId()) + && NumberUtil.equals(this.getFlowType(), systemFlowTypeDTO.getFlowType()) + && StrUtil.equals(this.getFlowId(), systemFlowTypeDTO.getFlowId()); + + } +}