Pārlūkot izejas kodu

新增自定义流程属性-新增默认节点

wangliang 3 gadi atpakaļ
vecāks
revīzija
1d34247141

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TFCustomFlow.java

@@ -72,13 +72,14 @@ public class TFCustomFlow extends BaseEntity implements Serializable {
 
     }
 
-    public TFCustomFlow(Long schoolId, Long orgId, String name, TFCustomTypeEnum type, Boolean publish, String objectData, Long userId) {
+    public TFCustomFlow(Long schoolId, Long orgId, String name, TFCustomTypeEnum type, Boolean publish, String objectData, Long userId, String flowKey) {
         this.schoolId = schoolId;
         this.orgId = orgId;
         this.name = name;
         this.type = type;
         this.publish = publish;
         this.objectData = objectData;
+        this.flowKey = flowKey;
         insertInfo(userId);
     }
 

+ 4 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ActivitiServiceImpl.java

@@ -222,6 +222,9 @@ public class ActivitiServiceImpl implements ActivitiService {
             e.printStackTrace();
         }
         map.computeIfAbsent(SystemConstant.FLOW_START, v -> true);
+        map.computeIfAbsent(SystemConstant.PROCESS_DEFINITION_ID, v -> processInstance.getProcessDefinitionId());
+        map.computeIfAbsent(SystemConstant.FLOW_ID, v -> processInstance.getProcessInstanceId());
+        map.remove(SystemConstant.MODEL);
         return processInstance;
     }
 
@@ -1493,7 +1496,7 @@ public class ActivitiServiceImpl implements ActivitiService {
                     process.addFlowElement(createStartEvent());
                     //默认在开始节点后新增一个审批节点
                     multiWorkFlow.createDefaultUserTask(customFlowDto, flowTaskLink, DefaultInstanceConvertToMultiInstance.DEFAULT_USER_TASK);
-                    flowProcessVarMap.computeIfAbsent(SystemConstant.APPROVE_ID, v -> sysUser.getId());
+                    flowProcessVarMap.computeIfAbsent(SystemConstant.APPROVE_ID, v -> "");
                     process.addFlowElement(createUserTask(CustomFlowDynamicBuildEnum.USER_TASK.getId() + DefaultInstanceConvertToMultiInstance.DEFAULT_USER_TASK, Objects.nonNull(flowTaskLink.getLast().getTask().getContent()) && !Objects.equals(flowTaskLink.getLast().getTask().getContent(), "") ? flowTaskLink.getLast().getTask().getContent() : DefaultInstanceConvertToMultiInstance.DEFAULT_USER_TASK_NAME, DefaultInstanceConvertToMultiInstance.APPROVE_ID_EXP));
                     break;
                 case PROCESS://过程节点

+ 29 - 9
distributed-print/src/main/java/com/qmth/distributed/print/api/TFCustomFlowController.java

@@ -15,19 +15,15 @@ import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.util.*;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.*;
+import org.activiti.engine.TaskService;
+import org.activiti.engine.task.Task;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
@@ -84,7 +80,7 @@ public class TFCustomFlowController {
         }
         try {
             Integer dbVersion = tfCustomFlowService.findMaxVersion(customFlowSaveDto.getSchoolId(), customFlowSaveDto.getOrgId(), customFlowSaveDto.getType());
-            TFCustomFlow tfCustomFlow = new TFCustomFlow(customFlowSaveDto.getSchoolId(), customFlowSaveDto.getOrgId(), customFlowSaveDto.getName(), customFlowSaveDto.getType(), customFlowSaveDto.getPublish(), JacksonUtil.parseJson(customFlowSaveDto.getCustomFlowLists()), sysUser.getId());
+            TFCustomFlow tfCustomFlow = new TFCustomFlow(customFlowSaveDto.getSchoolId(), customFlowSaveDto.getOrgId(), customFlowSaveDto.getName(), customFlowSaveDto.getType(), customFlowSaveDto.getPublish(), JacksonUtil.parseJson(customFlowSaveDto.getCustomFlowLists()), sysUser.getId(), flowBpmnId);
             AtomicInteger atomicInteger = null;
             if (Objects.isNull(dbVersion)) {//新增
                 atomicInteger = new AtomicInteger(1);
@@ -99,6 +95,9 @@ public class TFCustomFlowController {
             if (Objects.nonNull(map.get(SystemConstant.FLOW_START))) {
                 tfCustomFlow.setStart((Boolean) map.get(SystemConstant.FLOW_START));
             }
+            if (Objects.nonNull(map.get(SystemConstant.PROCESS_DEFINITION_ID))) {
+                tfCustomFlow.setActFlowId((String) map.get(SystemConstant.PROCESS_DEFINITION_ID));
+            }
             tfCustomFlowService.save(tfCustomFlow);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
@@ -112,4 +111,25 @@ public class TFCustomFlowController {
         }
         return ResultUtil.ok(true);
     }
+
+    @Resource
+    TaskService taskService;
+
+    @ApiOperation(value = "测试启动流程")
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
+    @RequestMapping(value = "/testStart", method = RequestMethod.POST)
+    @Transactional
+    public Result testStart(@ApiParam(value = "流程id", required = true) @RequestParam String id) {
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        TFCustomFlow tfCustomFlow = tfCustomFlowService.getById(SystemConstant.convertIdToLong(id));
+        Map<String, Object> map = JacksonUtil.readJson(tfCustomFlow.getFlowProcessVar(), Map.class);
+        Task task = taskService.createTaskQuery().processInstanceId(String.valueOf(map.get(SystemConstant.FLOW_ID))).singleResult();
+        task.setAssignee(String.valueOf(sysUser.getId()));
+        taskService.saveTask(task);
+        Map<String, Object> flowProcessVarMap = (Map<String, Object>) map.get(SystemConstant.FLOW_PROCESS_VAR_MAP);
+        flowProcessVarMap.put(SystemConstant.APPROVE_ID, sysUser.getId());
+        tfCustomFlow.setFlowProcessVar(JacksonUtil.parseJson(map));
+        tfCustomFlowService.updateById(tfCustomFlow);
+        return ResultUtil.ok(true);
+    }
 }

+ 1 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -59,6 +59,7 @@ public class SystemConstant {
     public static final String MODEL = "model";
     public static final String FLOW_PROCESS_VAR_MAP = "flowProcessVarMap";
     public static final String FLOW_START = "start";
+    public static final String PROCESS_DEFINITION_ID = "processDefinitionId";
     public static final String FILE = "file";
     public static final String SIZE = "size";
     public static final String HTML_PREFIX = ".html";