|
|
|
@ -10,18 +10,18 @@ import com.supervision.knowsub.model.SystemFlow;
|
|
|
|
|
import com.supervision.knowsub.model.SystemFlowBaseRelation;
|
|
|
|
|
import com.supervision.knowsub.model.SystemFlowTypeRelation;
|
|
|
|
|
import com.supervision.knowsub.service.*;
|
|
|
|
|
import com.supervision.knowsub.vo.flow.BaseResVo;
|
|
|
|
|
import com.supervision.knowsub.vo.flow.FlowInfoReqVo;
|
|
|
|
|
import com.supervision.knowsub.vo.flow.FlowInfoResVo;
|
|
|
|
|
import com.supervision.knowsub.vo.flow.*;
|
|
|
|
|
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.metadata.IIOMetadataFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
@ -34,8 +34,7 @@ public class FlowManageServiceImpl implements FlowManageService {
|
|
|
|
|
|
|
|
|
|
private final SystemFlowTypeRelationService systemFlowTypeRelationService;
|
|
|
|
|
|
|
|
|
|
private final SystemFlowRuleService systemFlowRuleService;
|
|
|
|
|
|
|
|
|
|
private final FlowRuleManageService flowRuleManageService;
|
|
|
|
|
|
|
|
|
|
private final ApplicationSubLibraryService applicationSubLibraryService;
|
|
|
|
|
|
|
|
|
@ -75,18 +74,34 @@ public class FlowManageServiceImpl implements FlowManageService {
|
|
|
|
|
}).toList();
|
|
|
|
|
systemFlowBaseRelationService.saveBatch(flowBaseRelationList);
|
|
|
|
|
|
|
|
|
|
List<SystemFlowTypeRelation> flowTypeRelationList = flowInfoReqVo.getFlowTypeList().stream().map(flowType -> baseIdList.stream().map(baseId -> {
|
|
|
|
|
doBatchSaveFlowTypeRelation(systemFlow.getId(), flowInfoReqVo.getFlowTypeList(), baseIdList);
|
|
|
|
|
|
|
|
|
|
flowRuleManageService.saveFlowRule(systemFlow.getId(), flowInfoReqVo.getNodeInfoList());
|
|
|
|
|
|
|
|
|
|
return systemFlow.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量保存流程类型关联表数据
|
|
|
|
|
* @param flowId 流程id
|
|
|
|
|
* @param flowTypeList 流程类型id集合
|
|
|
|
|
* @param baseIdList 子库id集合
|
|
|
|
|
*/
|
|
|
|
|
private void doBatchSaveFlowTypeRelation(String flowId,List<Integer> flowTypeList, List<String> baseIdList) {
|
|
|
|
|
|
|
|
|
|
List<SystemFlowTypeRelation> flowTypeRelationList = flowTypeList.stream().map(flowType -> baseIdList.stream()
|
|
|
|
|
.map(baseId -> {
|
|
|
|
|
SystemFlowTypeRelation flowTypeRelation = new SystemFlowTypeRelation();
|
|
|
|
|
flowTypeRelation.setFlowType(flowType);
|
|
|
|
|
flowTypeRelation.setBaseId(baseId);
|
|
|
|
|
flowTypeRelation.setFlowId(systemFlow.getId());
|
|
|
|
|
flowTypeRelation.setFlowId(flowId);
|
|
|
|
|
return flowTypeRelation;
|
|
|
|
|
}).toList()).flatMap(Collection::stream).toList();
|
|
|
|
|
systemFlowTypeRelationService.saveBatch(flowTypeRelationList);
|
|
|
|
|
|
|
|
|
|
return systemFlow.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> listUsedBaseIds(List<Integer> typeIds){
|
|
|
|
|
if (CollUtil.isEmpty(typeIds)){
|
|
|
|
@ -106,6 +121,107 @@ public class FlowManageServiceImpl implements FlowManageService {
|
|
|
|
|
@Override
|
|
|
|
|
public void updateFlow(FlowInfoReqVo flowInfoReqVo) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(flowInfoReqVo.getId(), "流程id不能为空");
|
|
|
|
|
assertBase(flowInfoReqVo);
|
|
|
|
|
|
|
|
|
|
SystemFlow dbSystem = systemFlowService.getById(flowInfoReqVo.getId());
|
|
|
|
|
Assert.notNull(dbSystem, "流程不存在");
|
|
|
|
|
|
|
|
|
|
// 一个子库最多对应一种流程类型
|
|
|
|
|
List<String> baseIdList = flowInfoReqVo.getBaseIdList();
|
|
|
|
|
if (CollUtil.isNotEmpty(baseIdList)){
|
|
|
|
|
List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery()
|
|
|
|
|
.in(SystemFlowTypeRelation::getBaseId, baseIdList).notIn(SystemFlowTypeRelation::getFlowId, flowInfoReqVo.getId()).list();
|
|
|
|
|
List<String> usedBaseIds = listUsedBaseIds(flowInfoReqVo.getFlowTypeList());
|
|
|
|
|
flowTypeRelationList.forEach(flowTypeRelation ->
|
|
|
|
|
Assert.isTrue(!usedBaseIds.contains(flowTypeRelation.getBaseId()), "该子库已存在流程类型"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新主表数据
|
|
|
|
|
doUpdateFlow(flowInfoReqVo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新流程
|
|
|
|
|
* @param flowInfoReqVo 更新流程数据
|
|
|
|
|
*/
|
|
|
|
|
private void doUpdateFlow(FlowInfoReqVo flowInfoReqVo) {
|
|
|
|
|
// 更新主表数据
|
|
|
|
|
SystemFlow systemFlow = new SystemFlow();
|
|
|
|
|
systemFlow.setId(flowInfoReqVo.getId());
|
|
|
|
|
systemFlow.setFlowName(flowInfoReqVo.getFlowName());
|
|
|
|
|
systemFlow.setRemark(flowInfoReqVo.getRemark());
|
|
|
|
|
systemFlowService.updateById(systemFlow);
|
|
|
|
|
|
|
|
|
|
// 更新关联表数据
|
|
|
|
|
updateFlowBaseRelation(flowInfoReqVo.getId(), flowInfoReqVo.getBaseIdList());
|
|
|
|
|
|
|
|
|
|
// 更新流程类型关联表数据
|
|
|
|
|
updateFlowTypeRelation(flowInfoReqVo.getId(), flowInfoReqVo.getFlowTypeList(), flowInfoReqVo.getBaseIdList());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新流程应用子库关联表
|
|
|
|
|
* 数据库中存在,参数集合中也存在,代表数据相等,跳过更新
|
|
|
|
|
* 数据库中存在,参数集合中不存在,代表删除
|
|
|
|
|
* 数据库中不存在,参数集合中存在,代表新增
|
|
|
|
|
* @param flowId 流程id
|
|
|
|
|
* @param baseIdList 应用子库id
|
|
|
|
|
*/
|
|
|
|
|
private void updateFlowBaseRelation(String flowId, List<String> baseIdList){
|
|
|
|
|
List<SystemFlowBaseRelation> dbFlowBaseRelationList = systemFlowBaseRelationService.lambdaQuery().eq(SystemFlowBaseRelation::getFlowId, flowId).list();
|
|
|
|
|
|
|
|
|
|
List<String> dbBaseIds = dbFlowBaseRelationList.stream().map(SystemFlowBaseRelation::getBaseId).toList();
|
|
|
|
|
// 数据库中不存在,入参中存在,新增
|
|
|
|
|
List<String> needInsert = baseIdList.stream().filter(baseId -> !dbBaseIds.contains(baseId)).toList();
|
|
|
|
|
|
|
|
|
|
// 数据库中存在,入参中不存在,删除
|
|
|
|
|
List<String> needDelete = dbBaseIds.stream().filter(baseId -> !baseIdList.contains(baseId)).toList();
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(needInsert)){
|
|
|
|
|
List<SystemFlowBaseRelation> baseRelationList = needInsert.stream().map(baseId -> {
|
|
|
|
|
SystemFlowBaseRelation flowBaseRelation = new SystemFlowBaseRelation();
|
|
|
|
|
flowBaseRelation.setBaseId(baseId);
|
|
|
|
|
flowBaseRelation.setFlowId(flowId);
|
|
|
|
|
return flowBaseRelation;
|
|
|
|
|
}).toList();
|
|
|
|
|
systemFlowBaseRelationService.saveBatch(baseRelationList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(needDelete)){
|
|
|
|
|
systemFlowBaseRelationService.lambdaUpdate().in(SystemFlowBaseRelation::getBaseId, needDelete)
|
|
|
|
|
.eq(SystemFlowBaseRelation::getFlowId, flowId).remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新流程类型关联表
|
|
|
|
|
* 数据库中存在,参数集合中也存在,代表数据相等,跳过更新
|
|
|
|
|
* 数据库中存在,参数集合中不存在,代表删除
|
|
|
|
|
* 数据库中不存在,参数集合中存在,代表新增
|
|
|
|
|
* @param flowId 流程id
|
|
|
|
|
* @param flowTypeList 流程类型
|
|
|
|
|
* @param baseIdList 应用子库id
|
|
|
|
|
*/
|
|
|
|
|
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<Integer> needDelete = dbFlowTypeList.stream().filter(flowType -> !flowTypeList.contains(flowType)).toList();
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(needInsert)){
|
|
|
|
|
doBatchSaveFlowTypeRelation(flowId, needInsert, baseIdList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(needDelete)){
|
|
|
|
|
systemFlowTypeRelationService.lambdaUpdate().in(SystemFlowTypeRelation::getFlowType, needDelete)
|
|
|
|
|
.eq(SystemFlowTypeRelation::getFlowId, flowId).remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -139,4 +255,30 @@ public class FlowManageServiceImpl implements FlowManageService {
|
|
|
|
|
return baseResVo;
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FlowDetailResVo getFlowDetail(String flowId) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(flowId, "流程id不能为空");
|
|
|
|
|
SystemFlow systemFlow = systemFlowService.getById(flowId);
|
|
|
|
|
Assert.notNull(systemFlow, "流程不存在");
|
|
|
|
|
|
|
|
|
|
FlowDetailResVo flowDetail = FlowDetailResVo.builder().id(systemFlow.getId()).flowName(systemFlow.getFlowName()).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<SystemFlowBaseRelation> flowBaseRelationList = systemFlowBaseRelationService.lambdaQuery().eq(SystemFlowBaseRelation::getId, flowId).list();
|
|
|
|
|
if (CollUtil.isNotEmpty(flowBaseRelationList)){
|
|
|
|
|
flowDetail.setSubLibraryIdList(flowBaseRelationList.stream().map(SystemFlowBaseRelation::getBaseId).toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery().eq(SystemFlowTypeRelation::getFlowId, flowId).list();
|
|
|
|
|
if (CollUtil.isNotEmpty(flowTypeRelationList)){
|
|
|
|
|
flowDetail.setFlowTypeIdList(
|
|
|
|
|
flowTypeRelationList.stream().map(SystemFlowTypeRelation::getFlowType).distinct().toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<NodeInfo> nodeInfos = flowRuleManageService.listFlowRule(flowId);
|
|
|
|
|
flowDetail.setNodeInfoList(nodeInfos);
|
|
|
|
|
return flowDetail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|