添加流程创建相关代码

release_1.0.0
xueqingkun 8 months ago
parent 8443e627a8
commit 09af8bc295

@ -1,14 +1,11 @@
package com.supervision.knowsub.controller.system;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.supervision.knowsub.service.ApplicationSubLibraryService;
import com.supervision.knowsub.service.FlowManageService;
import com.supervision.knowsub.vo.flow.BaseResVo;
import com.supervision.knowsub.vo.flow.FlowDetailResVo;
import com.supervision.knowsub.vo.flow.FlowInfoReqVo;
import com.supervision.knowsub.vo.flow.FlowInfoResVo;
import com.supervision.knowsub.vo.sublibrary.SubLibraryReqVo;
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -63,4 +60,11 @@ public class FlowManageController {
return flowManageService.optionalBaseList(flowType);
}
@Operation(summary = "查询流程详情")
@GetMapping("/getFlowDetail")
public FlowDetailResVo getFlowDetail(@Parameter(name = "flowId",description = "流程id") @RequestParam("flowId") String flowId) {
return flowManageService.getFlowDetail(flowId);
}
}

@ -2,6 +2,7 @@ package com.supervision.knowsub.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.supervision.knowsub.vo.flow.BaseResVo;
import com.supervision.knowsub.vo.flow.FlowDetailResVo;
import com.supervision.knowsub.vo.flow.FlowInfoReqVo;
import com.supervision.knowsub.vo.flow.FlowInfoResVo;
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
@ -46,4 +47,11 @@ public interface FlowManageService {
* @return
*/
List<BaseResVo> optionalBaseList(List<Integer> flowType);
/**
*
* @param flowId id
* @return
*/
FlowDetailResVo getFlowDetail(String flowId);
}

@ -1,6 +1,12 @@
package com.supervision.knowsub.service;
import com.supervision.knowsub.vo.flow.NodeInfo;
import java.util.List;
public interface FlowRuleManageService {
boolean saveFlowRule(String flowId, String ruleId, String userId);
boolean saveFlowRule(String flowId, List<NodeInfo> nodeInfoList);
List<NodeInfo> listFlowRule(String flowId);
}

@ -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;
}
}

@ -1,13 +1,24 @@
package com.supervision.knowsub.service.impl;
import com.supervision.knowsub.service.FileInfoService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.supervision.knowsub.model.SystemFlowRule;
import com.supervision.knowsub.model.SystemFlowRuleUser;
import com.supervision.knowsub.service.FlowRuleManageService;
import com.supervision.knowsub.service.SystemFlowRuleService;
import com.supervision.knowsub.service.SystemFlowRuleUserService;
import com.supervision.knowsub.vo.flow.NodeInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.sql.Struct;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Slf4j
@RequiredArgsConstructor
@ -19,7 +30,53 @@ public class FlowRuleManageServiceImpl implements FlowRuleManageService {
@Override
public boolean saveFlowRule(String flowId, String ruleId, String userId) {
return false;
public boolean saveFlowRule(String flowId, List<NodeInfo> nodeInfoList) {
Assert.notEmpty(flowId, "流程id不能为空");
Assert.notEmpty(nodeInfoList, "节点信息不能为空");
int i = 0;
for (NodeInfo nodeInfo : nodeInfoList) {
SystemFlowRule flowRule = new SystemFlowRule();
flowRule.setFlowId(flowId);
flowRule.setRuleName(nodeInfo.getNodeName());
flowRule.setRuleOrder(i++);
systemFlowRuleService.save(flowRule);
systemFlowRuleUserService.saveBatch(nodeInfo.getUserIdList().stream().map(userId -> {
SystemFlowRuleUser flowRuleUser = new SystemFlowRuleUser();
flowRuleUser.setFlowId(flowId);
flowRuleUser.setRuleId(flowRule.getId());
flowRuleUser.setUserId(userId);
return flowRuleUser;
}).toList());
}
return true;
}
@Override
public List<NodeInfo> listFlowRule(String flowId) {
if (StrUtil.isEmpty(flowId)){
return CollUtil.newArrayList();
}
List<SystemFlowRule> flowRuleList = systemFlowRuleService.lambdaQuery().eq(SystemFlowRule::getFlowId, flowId).list();
if (CollUtil.isNotEmpty(flowRuleList)){
return CollUtil.newArrayList();
}
List<NodeInfo> nodeInfoList = flowRuleList.stream().map(flowRule -> NodeInfo.builder()
.NodeName(flowRule.getRuleName()).id(flowRule.getId())
.order(flowRule.getRuleOrder()).build()).toList();
List<SystemFlowRuleUser> ruleUserList = systemFlowRuleUserService.lambdaQuery().in(SystemFlowRuleUser::getFlowId, flowId).list();
Map<String, List<SystemFlowRuleUser>> ruleUserGroupByRuleId = ruleUserList.stream().collect(Collectors.groupingBy(SystemFlowRuleUser::getRuleId));
nodeInfoList.forEach(nodeInfo -> {
List<SystemFlowRuleUser> ruleUserListByRuleId = ruleUserGroupByRuleId.get(nodeInfo.getId());
if (CollUtil.isNotEmpty(ruleUserListByRuleId)){
nodeInfo.setUserIdList(ruleUserListByRuleId.stream().map(SystemFlowRuleUser::getUserId).toList());
}
});
return nodeInfoList;
}
}

@ -1,4 +0,0 @@
package com.supervision.knowsub.dto.flow;
public class FlowRoleInfo {
}

@ -1,9 +1,9 @@
package com.supervision.knowsub.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.knowsub.mapper.KnowledgeFlowTodoMapper;
import com.supervision.knowsub.model.KnowledgeFlowTodo;
import com.supervision.knowsub.service.KnowledgeFlowTodoService;
import com.supervision.knowsub.mapper.KnowledgeFlowTodoMapper;
import org.springframework.stereotype.Service;
/**

@ -1,11 +1,16 @@
package com.supervision.knowsub.vo.flow;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;
import java.util.List;
/**
*
*/
@Data
@Builder
public class FlowDetailResVo {
private String id;
@ -14,5 +19,13 @@ public class FlowDetailResVo {
private String remark;
// private
private List<String> subLibraryIdList;
private List<Integer> flowTypeIdList;
private List<NodeInfo> nodeInfoList;
@Tolerate
public FlowDetailResVo() {
}
}

@ -8,6 +8,9 @@ import java.util.List;
@Data
public class FlowInfoReqVo {
@Schema(description = "流程id")
private String id;
@Schema(description = "流程名称")
private String flowName;

@ -1,11 +1,14 @@
package com.supervision.knowsub.vo.flow;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;
import java.util.List;
@Data
@Builder
public class NodeInfo {
@Schema(description = "节点id")
@ -16,4 +19,11 @@ public class NodeInfo {
@Schema(description = "节点用户id列表")
private List<String> userIdList;
@Schema(description = "节点顺序")
private Integer order;
@Tolerate
public NodeInfo() {
}
}

Loading…
Cancel
Save