添加流程修改相关代码

release_1.0.0
xueqingkun 11 months ago
parent 35c4e1064c
commit b85c59cd6d

@ -3,7 +3,6 @@ package com.supervision.knowsub.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.supervision.knowsub.dto.flow.FlowBaseRelationTypeDTO;
import com.supervision.knowsub.exception.BusinessException; import com.supervision.knowsub.exception.BusinessException;
import com.supervision.knowsub.model.SystemBase; import com.supervision.knowsub.model.SystemBase;
import com.supervision.knowsub.model.SystemFlow; import com.supervision.knowsub.model.SystemFlow;
@ -11,17 +10,15 @@ import com.supervision.knowsub.model.SystemFlowBaseRelation;
import com.supervision.knowsub.model.SystemFlowTypeRelation; import com.supervision.knowsub.model.SystemFlowTypeRelation;
import com.supervision.knowsub.service.*; import com.supervision.knowsub.service.*;
import com.supervision.knowsub.vo.flow.*; import com.supervision.knowsub.vo.flow.*;
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.imageio.metadata.IIOMetadataFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
@ -46,11 +43,11 @@ public class FlowManageServiceImpl implements FlowManageService {
// 一个子库最多对应一种流程类型 // 一个子库最多对应一种流程类型
List<String> baseIdList = flowInfoReqVo.getBaseIdList(); List<String> baseIdList = flowInfoReqVo.getBaseIdList();
if (CollUtil.isNotEmpty(baseIdList)){ List<Integer> flowTypeList = flowInfoReqVo.getFlowTypeList();
if (CollUtil.isNotEmpty(baseIdList) & CollUtil.isNotEmpty(flowTypeList)){
List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery().in(SystemFlowTypeRelation::getBaseId, baseIdList).list(); List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery().in(SystemFlowTypeRelation::getBaseId, baseIdList).list();
List<String> usedBaseIds = listUsedBaseIds(flowInfoReqVo.getFlowTypeList());
flowTypeRelationList.forEach(flowTypeRelation -> flowTypeRelationList.forEach(flowTypeRelation ->
Assert.isTrue(!usedBaseIds.contains(flowTypeRelation.getBaseId()), "该子库已存在流程类型")); Assert.isTrue(!flowTypeList.contains(flowTypeRelation.getFlowType()), "该子库已存在流程类型"));
} }
// 保存数据 // 保存数据
@ -108,7 +105,7 @@ public class FlowManageServiceImpl implements FlowManageService {
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
return systemFlowTypeRelationService.lambdaQuery().in(SystemFlowTypeRelation::getFlowId, typeIds).list() return systemFlowTypeRelationService.lambdaQuery().in(SystemFlowTypeRelation::getFlowType, typeIds).list()
.stream().map(SystemFlowTypeRelation::getBaseId).distinct().toList(); .stream().map(SystemFlowTypeRelation::getBaseId).distinct().toList();
} }
@ -119,6 +116,7 @@ public class FlowManageServiceImpl implements FlowManageService {
Assert.notEmpty(flowInfoReqVo.getNodeInfoList()); Assert.notEmpty(flowInfoReqVo.getNodeInfoList());
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void updateFlow(FlowInfoReqVo flowInfoReqVo) { public void updateFlow(FlowInfoReqVo flowInfoReqVo) {
Assert.notEmpty(flowInfoReqVo.getId(), "流程id不能为空"); Assert.notEmpty(flowInfoReqVo.getId(), "流程id不能为空");
@ -129,12 +127,12 @@ public class FlowManageServiceImpl implements FlowManageService {
// 一个子库最多对应一种流程类型 // 一个子库最多对应一种流程类型
List<String> baseIdList = flowInfoReqVo.getBaseIdList(); List<String> baseIdList = flowInfoReqVo.getBaseIdList();
if (CollUtil.isNotEmpty(baseIdList)){ List<Integer> flowTypeList = flowInfoReqVo.getFlowTypeList();
if (CollUtil.isNotEmpty(baseIdList) && CollUtil.isNotEmpty(flowTypeList)){
List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery() List<SystemFlowTypeRelation> flowTypeRelationList = systemFlowTypeRelationService.lambdaQuery()
.in(SystemFlowTypeRelation::getBaseId, baseIdList).notIn(SystemFlowTypeRelation::getFlowId, flowInfoReqVo.getId()).list(); .in(SystemFlowTypeRelation::getBaseId, baseIdList).notIn(SystemFlowTypeRelation::getFlowId, flowInfoReqVo.getId()).list();
List<String> usedBaseIds = listUsedBaseIds(flowInfoReqVo.getFlowTypeList());
flowTypeRelationList.forEach(flowTypeRelation -> flowTypeRelationList.forEach(flowTypeRelation ->
Assert.isTrue(!usedBaseIds.contains(flowTypeRelation.getBaseId()), "该子库已存在流程类型")); Assert.isTrue(!flowTypeList.contains(flowTypeRelation.getFlowType()), "该子库已存在流程类型"));
} }
// 更新主表数据 // 更新主表数据
@ -159,6 +157,9 @@ public class FlowManageServiceImpl implements FlowManageService {
// 更新流程类型关联表数据 // 更新流程类型关联表数据
updateFlowTypeRelation(flowInfoReqVo.getId(), flowInfoReqVo.getFlowTypeList(), flowInfoReqVo.getBaseIdList()); updateFlowTypeRelation(flowInfoReqVo.getId(), flowInfoReqVo.getFlowTypeList(), flowInfoReqVo.getBaseIdList());
// 更新流程规则表数据
flowRuleManageService.updateFlowRule(flowInfoReqVo.getId(), flowInfoReqVo.getNodeInfoList());
} }
/** /**
@ -212,7 +213,7 @@ public class FlowManageServiceImpl implements FlowManageService {
List<Integer> needInsert = flowTypeList.stream().filter(flowType -> !dbFlowTypeList.contains(flowType)).toList(); List<Integer> needInsert = flowTypeList.stream().filter(flowType -> !dbFlowTypeList.contains(flowType)).toList();
// 数据库中存在,入参中不存在,删除 // 数据库中存在,入参中不存在,删除
List<Integer> needDelete = dbFlowTypeList.stream().filter(flowType -> !flowTypeList.contains(flowType)).toList(); List<Integer> needDelete = dbFlowTypeList.stream().filter(flowType -> !flowTypeList.contains(flowType)).distinct().toList();
if (CollUtil.isNotEmpty(needInsert)){ if (CollUtil.isNotEmpty(needInsert)){
doBatchSaveFlowTypeRelation(flowId, needInsert, baseIdList); doBatchSaveFlowTypeRelation(flowId, needInsert, baseIdList);
@ -263,10 +264,11 @@ public class FlowManageServiceImpl implements FlowManageService {
SystemFlow systemFlow = systemFlowService.getById(flowId); SystemFlow systemFlow = systemFlowService.getById(flowId);
Assert.notNull(systemFlow, "流程不存在"); Assert.notNull(systemFlow, "流程不存在");
FlowDetailResVo flowDetail = FlowDetailResVo.builder().id(systemFlow.getId()).flowName(systemFlow.getFlowName()).build(); FlowDetailResVo flowDetail = FlowDetailResVo.builder().id(systemFlow.getId())
.flowName(systemFlow.getFlowName()).remark(systemFlow.getRemark()).build();
List<SystemFlowBaseRelation> flowBaseRelationList = systemFlowBaseRelationService.lambdaQuery().eq(SystemFlowBaseRelation::getId, flowId).list(); List<SystemFlowBaseRelation> flowBaseRelationList = systemFlowBaseRelationService.lambdaQuery().eq(SystemFlowBaseRelation::getFlowId, flowId).list();
if (CollUtil.isNotEmpty(flowBaseRelationList)){ if (CollUtil.isNotEmpty(flowBaseRelationList)){
flowDetail.setSubLibraryIdList(flowBaseRelationList.stream().map(SystemFlowBaseRelation::getBaseId).toList()); flowDetail.setSubLibraryIdList(flowBaseRelationList.stream().map(SystemFlowBaseRelation::getBaseId).toList());
} }
@ -278,6 +280,7 @@ public class FlowManageServiceImpl implements FlowManageService {
} }
List<NodeInfo> nodeInfos = flowRuleManageService.listFlowRule(flowId); List<NodeInfo> nodeInfos = flowRuleManageService.listFlowRule(flowId);
nodeInfos.sort(Comparator.comparing(NodeInfo::getOrder));
flowDetail.setNodeInfoList(nodeInfos); flowDetail.setNodeInfoList(nodeInfos);
return flowDetail; return flowDetail;
} }

@ -65,9 +65,9 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
SystemFlowRule systemFlowRule = systemFlowRuleDTO.toSystemFlowRule(); SystemFlowRule systemFlowRule = systemFlowRuleDTO.toSystemFlowRule();
systemFlowRuleService.save(systemFlowRule); systemFlowRuleService.save(systemFlowRule);
List<SystemFlowRuleUser> systemFlowRuleUserList = systemFlowRuleDTO.toSystemFlowRuleUserList(); List<SystemFlowRuleUser> systemFlowRuleUserList = systemFlowRuleDTO.toSystemFlowRuleUserList();
if (CollUtil.isEmpty(systemFlowRuleUserList)){ if (CollUtil.isNotEmpty(systemFlowRuleUserList)){
for (SystemFlowRuleUser systemFlowRuleUser : systemFlowRuleUserList) { for (SystemFlowRuleUser systemFlowRuleUser : systemFlowRuleUserList) {
systemFlowRuleUser.setFlowId(systemFlowRule.getId()); systemFlowRuleUser.setRuleId(systemFlowRule.getId());
systemFlowRuleUserService.save(systemFlowRuleUser); systemFlowRuleUserService.save(systemFlowRuleUser);
} }
} }
@ -85,11 +85,11 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
for (SystemFlowRuleDTO systemFlowRuleDTO : systemFlowRuleDTOList) { for (SystemFlowRuleDTO systemFlowRuleDTO : systemFlowRuleDTOList) {
SystemFlowRule systemFlowRule = systemFlowRuleDTO.toSystemFlowRule(); SystemFlowRule systemFlowRule = systemFlowRuleDTO.toSystemFlowRule();
systemFlowRuleService.updateById(systemFlowRule); systemFlowRuleService.updateById(systemFlowRule);
systemFlowRuleUserService.lambdaUpdate().eq(SystemFlowRuleUser::getFlowId, systemFlowRuleDTO.getId()).remove(); systemFlowRuleUserService.lambdaUpdate().eq(SystemFlowRuleUser::getRuleId, systemFlowRuleDTO.getId()).remove();
List<SystemFlowRuleUser> systemFlowRuleUserList = systemFlowRuleDTO.toSystemFlowRuleUserList(); List<SystemFlowRuleUser> systemFlowRuleUserList = systemFlowRuleDTO.toSystemFlowRuleUserList();
if (CollUtil.isEmpty(systemFlowRuleUserList)){ if (CollUtil.isNotEmpty(systemFlowRuleUserList)){
for (SystemFlowRuleUser systemFlowRuleUser : systemFlowRuleUserList) { for (SystemFlowRuleUser systemFlowRuleUser : systemFlowRuleUserList) {
systemFlowRuleUser.setFlowId(systemFlowRule.getId()); systemFlowRuleUser.setRuleId(systemFlowRule.getId());
systemFlowRuleUserService.save(systemFlowRuleUser); systemFlowRuleUserService.save(systemFlowRuleUser);
} }
} }
@ -108,7 +108,6 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
List<String> flowRuleIdList = flowRuleList.stream().map(SystemFlowRule::getId).toList(); List<String> flowRuleIdList = flowRuleList.stream().map(SystemFlowRule::getId).toList();
Set<String> flowRuleIdSet = flowRuleList.stream().map(SystemFlowRule::getId).collect(Collectors.toSet()); Set<String> flowRuleIdSet = flowRuleList.stream().map(SystemFlowRule::getId).collect(Collectors.toSet());
FlowRuleDTOPair flowRuleDTOPair = pickInsertAndUpdateFlowRuleDTO(flowId, nodeInfoList, flowRuleIdSet); FlowRuleDTOPair flowRuleDTOPair = pickInsertAndUpdateFlowRuleDTO(flowId, nodeInfoList, flowRuleIdSet);
// 新增数据 // 新增数据
@ -117,7 +116,7 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
} }
// 更新数据 // 更新数据
if (CollUtil.isEmpty(flowRuleDTOPair.needUpdateRuleList())){ if (CollUtil.isNotEmpty(flowRuleDTOPair.needUpdateRuleList())){
updateFlowRule(flowRuleDTOPair.needUpdateRuleList()); updateFlowRule(flowRuleDTOPair.needUpdateRuleList());
} }
//如果数据库中存在,列表中不存在,则删除 //如果数据库中存在,列表中不存在,则删除
@ -125,10 +124,18 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
if (CollUtil.isNotEmpty(needDeleteRuleIdList)){ if (CollUtil.isNotEmpty(needDeleteRuleIdList)){
deleteFlowRuleByRuleIds(needDeleteRuleIdList); deleteFlowRuleByRuleIds(needDeleteRuleIdList);
} }
return false; return true;
} }
private static FlowRuleDTOPair pickInsertAndUpdateFlowRuleDTO(String flowId, List<NodeInfo> nodeInfoList, Set<String> flowRuleIdSet) {
/**
*
* @param flowId id
* @param nodeInfoList
* @param flowRuleIdSet
* @return
*/
private FlowRuleDTOPair pickInsertAndUpdateFlowRuleDTO(String flowId, List<NodeInfo> nodeInfoList, Set<String> flowRuleIdSet) {
List<SystemFlowRuleDTO> needUpdateRuleList = new ArrayList<>(); List<SystemFlowRuleDTO> needUpdateRuleList = new ArrayList<>();
List<SystemFlowRuleDTO> needAddRuleList = new ArrayList<>(); List<SystemFlowRuleDTO> needAddRuleList = new ArrayList<>();
int order = 0; int order = 0;
@ -155,12 +162,12 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
} }
List<SystemFlowRule> flowRuleList = systemFlowRuleService.lambdaQuery().eq(SystemFlowRule::getFlowId, flowId).list(); List<SystemFlowRule> flowRuleList = systemFlowRuleService.lambdaQuery().eq(SystemFlowRule::getFlowId, flowId).list();
if (CollUtil.isNotEmpty(flowRuleList)){ if (CollUtil.isEmpty(flowRuleList)){
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
List<NodeInfo> nodeInfoList = flowRuleList.stream().map(flowRule -> NodeInfo.builder() List<NodeInfo> nodeInfoList = flowRuleList.stream().map(flowRule -> NodeInfo.builder()
.NodeName(flowRule.getRuleName()).id(flowRule.getId()) .NodeName(flowRule.getRuleName()).id(flowRule.getId())
.order(flowRule.getRuleOrder()).build()).toList(); .order(flowRule.getRuleOrder()).build()).collect(Collectors.toList());
List<SystemFlowRuleUser> ruleUserList = systemFlowRuleUserService.lambdaQuery().in(SystemFlowRuleUser::getFlowId, flowId).list(); List<SystemFlowRuleUser> ruleUserList = systemFlowRuleUserService.lambdaQuery().in(SystemFlowRuleUser::getFlowId, flowId).list();
Map<String, List<SystemFlowRuleUser>> ruleUserGroupByRuleId = ruleUserList.stream().collect(Collectors.groupingBy(SystemFlowRuleUser::getRuleId)); Map<String, List<SystemFlowRuleUser>> ruleUserGroupByRuleId = ruleUserList.stream().collect(Collectors.groupingBy(SystemFlowRuleUser::getRuleId));
@ -176,10 +183,10 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
@Override @Override
public void deleteFlowRuleByRuleIds(List<String> ruleIdList) { public void deleteFlowRuleByRuleIds(List<String> ruleIdList) {
if (CollUtil.isEmpty(ruleIdList)){ if (CollUtil.isEmpty(ruleIdList)){
log.info("流程id为空不执行删除操作"); log.info("流程规则id为空不执行删除操作");
return; return;
} }
systemFlowRuleUserService.removeBatchByIds(ruleIdList); systemFlowRuleService.removeBatchByIds(ruleIdList);
systemFlowRuleUserService.lambdaUpdate().in(SystemFlowRuleUser::getRuleId, ruleIdList).remove(); systemFlowRuleUserService.lambdaUpdate().in(SystemFlowRuleUser::getRuleId, ruleIdList).remove();
} }

@ -1,20 +0,0 @@
package com.supervision.knowsub.dto.flow;
import lombok.Data;
import java.util.List;
/**
*
*/
@Data
public class FlowBaseRelationTypeDTO {
private String id;
private String flowId;
private String baseId;
private List<Integer> flowTypeList;
}

@ -40,7 +40,8 @@ public class SystemFlowRuleDTO {
SystemFlowRuleDTO systemFlowRuleDTO = new SystemFlowRuleDTO(); SystemFlowRuleDTO systemFlowRuleDTO = new SystemFlowRuleDTO();
systemFlowRuleDTO.setId(nodeInfo.getId()); systemFlowRuleDTO.setId(nodeInfo.getId());
systemFlowRuleDTO.setRuleName(nodeInfo.getNodeName()); systemFlowRuleDTO.setRuleName(nodeInfo.getNodeName());
systemFlowRuleDTO.setFlowId(flowId);
systemFlowRuleDTO.setRuleOrder(nodeInfo.getOrder());
List<SystemFlowRuleUser> ruleUserList = nodeInfo.getUserIdList().stream().map(userId -> { List<SystemFlowRuleUser> ruleUserList = nodeInfo.getUserIdList().stream().map(userId -> {
SystemFlowRuleUser flowRuleUser = new SystemFlowRuleUser(); SystemFlowRuleUser flowRuleUser = new SystemFlowRuleUser();
flowRuleUser.setFlowId(flowId); flowRuleUser.setFlowId(flowId);

@ -29,8 +29,9 @@
from ks_system_flow f from ks_system_flow f
left join ks_system_user u on f.create_user_id = u.id left join ks_system_user u on f.create_user_id = u.id
where where
1 = 1
<if test="flowName != null and flowName != ''"> <if test="flowName != null and flowName != ''">
f.flow_name like concat('%', #{flowName}, '%') and f.flow_name like concat('%', #{flowName}, '%')
</if> </if>
</select> </select>
</mapper> </mapper>

Loading…
Cancel
Save