Pārlūkot izejas kodu

流程功能测试

wangliang 1 gadu atpakaļ
vecāks
revīzija
c963ce6b4f

+ 38 - 0
sop-business/src/main/java/com/qmth/sop/business/activiti/service/impl/ActivitiServiceImpl.java

@@ -38,6 +38,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
@@ -283,6 +284,16 @@ public class ActivitiServiceImpl implements ActivitiService {
                             }
                         }
                         taskService.complete(task.getId(), map);
+                        if (approve == FlowApprovePassEnum.START || approve == FlowApprovePassEnum.PASS) {
+                            List<Task> tasks = taskService.createTaskQuery().processInstanceId(processFlowId).list();
+                            if (!CollectionUtils.isEmpty(tasks)) {
+                                Set<String> approveIdSet = new LinkedHashSet<>();
+                                for (Task t : tasks) {
+                                    approveIdSet.add(t.getAssignee());
+                                }
+                                tfFlowLog.setPendApproveId(approveIdSet.toString().replaceAll("\\[", "").replaceAll("\\]", ""));
+                            }
+                        }
                     }
 //                    if (approve != FlowApprovePassEnum.DRAFT && approve != FlowApprovePassEnum.REJECT) {
 //                        taskService.complete(task.getId(), map);
@@ -387,6 +398,7 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param taskId
      */
     @Override
+    @Transactional
     public void taskApproverExchange(Long userId, Long taskId) {
         boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_EXCHANGE_PREFIX + taskId, taskId, SystemConstant.LOCK_FLOW_TIME_OUT);
         if (!lock) {
@@ -446,12 +458,38 @@ public class ActivitiServiceImpl implements ActivitiService {
      * @param flowId
      */
     @Override
+    @Transactional
     public void flowEnd(Long flowId) {
         boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_TASK_PREFIX + flowId, flowId, SystemConstant.LOCK_FLOW_TIME_OUT);
         if (!lock) {
             throw ExceptionResultEnum.ERROR.exception("正在终止中,请稍候再试!");
         }
         try {
+            TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, flowId));
+            Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程没有审批数据!"));
+
+            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
+            Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程没有实例数据!"));
+
+            FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
+            LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
+            List<Task> taskList = taskService.createTaskQuery().processInstanceId(String.valueOf(flowId)).list();
+            if (CollectionUtils.isEmpty(taskList)) {
+                throw ExceptionResultEnum.ERROR.exception("流程任务数据为空!");
+            }
+            FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(taskList.get(0).getTaskDefinitionKey())), FlowTaskResult.class);
+
+            TFFlowLog tfFlowLog = new TFFlowLog(null, Long.parseLong(taskList.get(0).getAssignee()), null,
+                    currFlowTaskResult.getSetup(), flowId,
+                    Long.parseLong(taskList.get(0).getId()), tfCustomFlowEntity.getId(), null);
+            tfFlowLog.setApproveOperation(FlowApproveOperationEnum.END);
+            tfFlowLog.setApproveRemark(taskList.get(0).getAssignee() + "终止流程");
+            tfFlowLogService.save(tfFlowLog);
+
+            tfFlowApprove.setStatus(FlowStatusEnum.END);
+            tfFlowApprove.setSetup(FlowApproveSetupEnum.END.getSetup());
+            tfFlowApproveService.updateById(tfFlowApprove);
+
             runtimeService.deleteProcessInstance(String.valueOf(flowId), "结束");
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);