fix bugs update-flow

release_1.0.0
xueqingkun 10 months ago
parent c81a637bbd
commit 9b8343c270

@ -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<Integer> flowTypeList,List<String> baseIdList){
List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery().eq(SystemFlowTypeRelation::getFlowId, flowId).list();
List<Integer> dbFlowTypeList = flowTypeRelationList.stream().map(SystemFlowTypeRelation::getFlowType).toList();
// 数据库中不存在,入参中存在,新增
List<Integer> needInsert = flowTypeList.stream().filter(flowType -> !dbFlowTypeList.contains(flowType)).toList();
// 从数据库中查询出来的数据
List<SystemFlowTypeDTO> dbFlowTypeDTOList = flowTypeRelationList.stream().map(SystemFlowTypeDTO::buildWithFlowTypeRelation).toList();
// 入参中的数据
List<SystemFlowTypeDTO> 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<SystemFlowTypeDTO> needInsert = flowTypeDTOList.stream().filter(systemFlowTypeDTO ->
dbFlowTypeDTOList.stream().noneMatch(dbSystemFlowTypeDTO ->
dbSystemFlowTypeDTO.contentEquals(systemFlowTypeDTO))
).toList();
// 数据库中存在,入参中不存在,删除 流程类型与子库id组合成唯一数据
List<SystemFlowTypeDTO> needDelete = dbFlowTypeDTOList.stream().filter(dbSystemFlowTypeDTO ->
flowTypeDTOList.stream().noneMatch(dbSystemFlowTypeDTO::contentEquals)).toList();
// 数据库中存在,入参中不存在,删除
List<Integer> needDelete = dbFlowTypeList.stream().filter(flowType -> !flowTypeList.contains(flowType)).distinct().toList();
if (CollUtil.isNotEmpty(needInsert)){
doBatchSaveFlowTypeRelation(flowId, needInsert, baseIdList);
List<SystemFlowTypeRelation> 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<String> needDeleteIds = needDelete.stream().map(SystemFlowTypeDTO::getId).filter(StrUtil::isNotEmpty).toList();
systemFlowTypeRelationService.removeBatchByIds(needDeleteIds);
}
}

@ -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());
}
}
Loading…
Cancel
Save