|
@@ -3,8 +3,11 @@ package com.qmth.distributed.print.business.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.distributed.print.business.bean.flow.CustomFlowDto;
|
|
|
+import com.qmth.distributed.print.business.bean.flow.CustomFlowSaveDto;
|
|
|
import com.qmth.distributed.print.business.bean.result.*;
|
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
|
+import com.qmth.distributed.print.business.enums.CustomFlowDynamicBuildEnum;
|
|
|
import com.qmth.distributed.print.business.enums.CustomFlowTypeEnum;
|
|
|
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.FlowModelEnum;
|
|
@@ -15,6 +18,7 @@ import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
import com.qmth.teachcloud.common.entity.SysOrg;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.*;
|
|
|
+import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
|
import com.qmth.teachcloud.common.service.SysOrgService;
|
|
|
import com.qmth.teachcloud.common.service.SysUserService;
|
|
|
import com.qmth.teachcloud.common.util.RedisUtil;
|
|
@@ -103,6 +107,9 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
@Resource
|
|
|
TExamTaskFlowService tExamTaskFlowService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ CommonCacheService commonCacheService;
|
|
|
+
|
|
|
/**
|
|
|
* 注册流程
|
|
|
*
|
|
@@ -1399,70 +1406,112 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
/**
|
|
|
* 动态创建流程图
|
|
|
*
|
|
|
+ * @param customFlowSaveDto
|
|
|
* @param id
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@Override
|
|
|
- public void dynamicBuildBpmn(String id) throws IOException {
|
|
|
+ @Transactional
|
|
|
+ public void dynamicBuildBpmn(CustomFlowSaveDto customFlowSaveDto, String id) throws IOException {
|
|
|
+ BasicSchool basicSchool = commonCacheService.schoolCache(customFlowSaveDto.getSchoolId());
|
|
|
+
|
|
|
BpmnModel model = new BpmnModel();
|
|
|
Process process = new Process();
|
|
|
model.addProcess(process);
|
|
|
+ id = basicSchool.getCode() + "_" + id;
|
|
|
process.setId(id);
|
|
|
|
|
|
// 判断是否仅为一个节点任务
|
|
|
- List<String> taskList = new ArrayList<String>();
|
|
|
- taskList.add("报销申请");
|
|
|
-// taskList.add("主管审批");
|
|
|
-// taskList.add("经理审批");
|
|
|
-// taskList.add("总经理审批");
|
|
|
- //单节点任务
|
|
|
- if (taskList.size() == 1) {
|
|
|
- process.addFlowElement(createStartEvent());
|
|
|
- process.addFlowElement(createUserTask("task1", taskList.get(0), null));
|
|
|
- process.addFlowElement(createEndEvent());
|
|
|
- process.addFlowElement(createSequenceFlow("start", "task1", "", ""));
|
|
|
- process.addFlowElement(createSequenceFlow("task1", "end", "", ""));
|
|
|
- } else {
|
|
|
- // 多节点任务
|
|
|
- // 构造开始节点任务
|
|
|
- process.addFlowElement(createStartEvent());
|
|
|
- // 构造首个节点任务
|
|
|
- process.addFlowElement(createUserTask("task1", taskList.get(0), null));
|
|
|
- // 构造除去首尾节点的任务
|
|
|
- for (int i = 1; i < taskList.size() - 1; i++) {
|
|
|
- process.addFlowElement(createExclusiveGateway("createExclusiveGateway" + i));
|
|
|
- process.addFlowElement(createUserTask("task" + (i + 1), taskList.get(i), null));
|
|
|
- }
|
|
|
- // 构造尾节点任务
|
|
|
- process.addFlowElement(createExclusiveGateway("createExclusiveGateway" + (taskList.size() - 1)));
|
|
|
- process.addFlowElement(createUserTask("task" + taskList.size(), taskList.get(taskList.size() - 1), null));
|
|
|
- // 构造结束节点任务
|
|
|
- process.addFlowElement(createEndEvent());
|
|
|
-
|
|
|
- // 构造连线(加网关)
|
|
|
- process.addFlowElement(createSequenceFlow("start", "task1", "", ""));
|
|
|
- // 第一个节点任务到第二个百分百通过的,因此不存在网关
|
|
|
- process.addFlowElement(createSequenceFlow("task1", "task2", "", ""));
|
|
|
- for (int i = 1; i < taskList.size(); i++) {
|
|
|
- process.addFlowElement(createSequenceFlow("task" + (i + 1), "createExclusiveGateway" + i, "", ""));
|
|
|
- // 判断网关走向(同意则直接到下一节点即可,不同意需要判断回退层级,决定回退到哪个节点,returnLevel等于0,即回退到task1)
|
|
|
- // i等于几,即意味着回退的线路有几种可能,例如i等于1,即是task2,那么只能回退 到task1
|
|
|
- // 如果i等于2,即是task3,那么此时可以回退到task1和task2;returnLevel =1 ,即回退到task1,所以这里我是扩展了可以驳回到任意阶段节点任务
|
|
|
- for (int j = 1; j <= i; j++) {
|
|
|
- process.addFlowElement(createSequenceFlow("createExclusiveGateway" + i, "task" + j, "不通过",
|
|
|
- "${result == '0' && returnLevel== '" + j + "'}"));
|
|
|
- }
|
|
|
- // 操作结果为通过时,需要判断是否为最后一个节点任务,若是则直接到end
|
|
|
- if (i == taskList.size() - 1) {
|
|
|
- process.addFlowElement(
|
|
|
- createSequenceFlow("createExclusiveGateway" + i, "end", "通过", "${result == '1'} "));
|
|
|
-
|
|
|
- } else {
|
|
|
- process.addFlowElement(createSequenceFlow("createExclusiveGateway" + i, "task" + (i + 2), "通过",
|
|
|
- "${result == '1'}"));
|
|
|
- }
|
|
|
+// List<String> taskList = new ArrayList<String>();
|
|
|
+// taskList.add("报销申请");
|
|
|
+//// taskList.add("主管审批");
|
|
|
+//// taskList.add("经理审批");
|
|
|
+//// taskList.add("总经理审批");
|
|
|
+// //单节点任务
|
|
|
+// if (taskList.size() == 1) {
|
|
|
+// process.addFlowElement(createStartEvent());
|
|
|
+// process.addFlowElement(createUserTask("task1", taskList.get(0), null));
|
|
|
+// process.addFlowElement(createEndEvent());
|
|
|
+// process.addFlowElement(createSequenceFlow("start", "task1", "", ""));
|
|
|
+// process.addFlowElement(createSequenceFlow("task1", "end", "", ""));
|
|
|
+// } else {
|
|
|
+// // 多节点任务
|
|
|
+// // 构造开始节点任务
|
|
|
+// process.addFlowElement(createStartEvent());
|
|
|
+// // 构造首个节点任务
|
|
|
+// process.addFlowElement(createUserTask("task1", taskList.get(0), null));
|
|
|
+// // 构造除去首尾节点的任务
|
|
|
+// for (int i = 1; i < taskList.size() - 1; i++) {
|
|
|
+// process.addFlowElement(createExclusiveGateway("createExclusiveGateway" + i));
|
|
|
+// process.addFlowElement(createUserTask("task" + (i + 1), taskList.get(i), null));
|
|
|
+// }
|
|
|
+// // 构造尾节点任务
|
|
|
+// process.addFlowElement(createExclusiveGateway("createExclusiveGateway" + (taskList.size() - 1)));
|
|
|
+// process.addFlowElement(createUserTask("task" + taskList.size(), taskList.get(taskList.size() - 1), null));
|
|
|
+// // 构造结束节点任务
|
|
|
+// process.addFlowElement(createEndEvent());
|
|
|
+//
|
|
|
+// // 构造连线(加网关)
|
|
|
+// process.addFlowElement(createSequenceFlow("start", "task1", "", ""));
|
|
|
+// // 第一个节点任务到第二个百分百通过的,因此不存在网关
|
|
|
+// process.addFlowElement(createSequenceFlow("task1", "task2", "", ""));
|
|
|
+// for (int i = 1; i < taskList.size(); i++) {
|
|
|
+// process.addFlowElement(createSequenceFlow("task" + (i + 1), "createExclusiveGateway" + i, "", ""));
|
|
|
+// // 判断网关走向(同意则直接到下一节点即可,不同意需要判断回退层级,决定回退到哪个节点,returnLevel等于0,即回退到task1)
|
|
|
+// // i等于几,即意味着回退的线路有几种可能,例如i等于1,即是task2,那么只能回退 到task1
|
|
|
+// // 如果i等于2,即是task3,那么此时可以回退到task1和task2;returnLevel =1 ,即回退到task1,所以这里我是扩展了可以驳回到任意阶段节点任务
|
|
|
+// for (int j = 1; j <= i; j++) {
|
|
|
+// process.addFlowElement(createSequenceFlow("createExclusiveGateway" + i, "task" + j, "不通过",
|
|
|
+// "${result == '0' && returnLevel== '" + j + "'}"));
|
|
|
+// }
|
|
|
+// // 操作结果为通过时,需要判断是否为最后一个节点任务,若是则直接到end
|
|
|
+// if (i == taskList.size() - 1) {
|
|
|
+// process.addFlowElement(
|
|
|
+// createSequenceFlow("createExclusiveGateway" + i, "end", "通过", "${result == '1'} "));
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// process.addFlowElement(createSequenceFlow("createExclusiveGateway" + i, "task" + (i + 2), "通过",
|
|
|
+// "${result == '1'}"));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ List<CustomFlowDto> customFlowLists = customFlowSaveDto.getCustomFlowLists();
|
|
|
+ Map<CustomFlowTypeEnum, CustomFlowDto> customFlowTypeEnumCustomFlowDtoMap = new HashMap<>();
|
|
|
+ String firstProcessId = null, lastProcessId = null;
|
|
|
+ LinkedList processLinkedList = new LinkedList();
|
|
|
+ for (int i = 0; i < customFlowLists.size(); i++) {
|
|
|
+ CustomFlowDto customFlowDto = customFlowLists.get(i);
|
|
|
+ switch (customFlowDto.getType()) {
|
|
|
+ case START:
|
|
|
+ if (customFlowTypeEnumCustomFlowDtoMap.containsKey(CustomFlowTypeEnum.START)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("流程只能有一个开始节点!");
|
|
|
+ } else {
|
|
|
+ customFlowTypeEnumCustomFlowDtoMap.computeIfAbsent(CustomFlowTypeEnum.START, v -> customFlowDto);
|
|
|
+ }
|
|
|
+ process.addFlowElement(createStartEvent());
|
|
|
+ break;
|
|
|
+ case PROCESS:
|
|
|
+ if (Objects.isNull(firstProcessId)) {
|
|
|
+ firstProcessId = CustomFlowDynamicBuildEnum.USER_TASK.getId() + i;
|
|
|
+ }
|
|
|
+ lastProcessId = CustomFlowDynamicBuildEnum.USER_TASK.getId() + i;
|
|
|
+ process.addFlowElement(createUserTask(lastProcessId, customFlowDto.getContent(), null));
|
|
|
+ break;
|
|
|
+ case END:
|
|
|
+ if (customFlowTypeEnumCustomFlowDtoMap.containsKey(CustomFlowTypeEnum.END)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("流程只能有一个结束节点!");
|
|
|
+ } else {
|
|
|
+ customFlowTypeEnumCustomFlowDtoMap.computeIfAbsent(CustomFlowTypeEnum.END, v -> customFlowDto);
|
|
|
+ }
|
|
|
+ process.addFlowElement(createEndEvent());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ process.addFlowElement(createSequenceFlow(CustomFlowTypeEnum.START.name(), firstProcessId, "", ""));
|
|
|
+ process.addFlowElement(createSequenceFlow(lastProcessId, CustomFlowTypeEnum.END.name(), "", ""));
|
|
|
+
|
|
|
//生成图像信息
|
|
|
new BpmnAutoLayout(model).execute();
|
|
|
//部署流程
|
|
@@ -1474,11 +1523,11 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
InputStream processDiagram = repositoryService.getProcessDiagram(processInstance.getProcessDefinitionId());
|
|
|
FileUtils.copyInputStreamToFile(processDiagram, new File("target" + File.separator + id + "-multiple-process-diagram.png"));
|
|
|
|
|
|
- InputStream processBpmn = repositoryService.getResourceAsStream(deployment.getId(), id + "-dynamic-model.bpmn");
|
|
|
- FileUtils.copyInputStreamToFile(processBpmn, new File("target" + File.separator + id + "-multiple-process.bpmn20.xml"));
|
|
|
+// InputStream processBpmn = repositoryService.getResourceAsStream(deployment.getId(), id + "-dynamic-model.bpmn");
|
|
|
+// FileUtils.copyInputStreamToFile(processBpmn, new File("target" + File.separator + id + "-multiple-process.bpmn20.xml"));
|
|
|
|
|
|
- InputStream processBpmn1 = repositoryService.getResourceAsStream(deployment.getId(), id + "-dynamic-model.bpmn");
|
|
|
- FileUtils.copyInputStreamToFile(processBpmn1, new File("target" + File.separator + id + "-multiple-process.bpmn"));
|
|
|
+ InputStream processBpmn = repositoryService.getResourceAsStream(deployment.getId(), id + "-dynamic-model.bpmn");
|
|
|
+ FileUtils.copyInputStreamToFile(processBpmn, new File("target" + File.separator + id + "-multiple-process.bpmn"));
|
|
|
}
|
|
|
|
|
|
/**
|