Просмотр исходного кода

新增自定义流程属性-转他人审批

wangliang 3 лет назад
Родитель
Сommit
4846020929

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TFFlowApprove.java

@@ -57,6 +57,9 @@ public class TFFlowApprove extends BaseEntity implements Serializable {
     @TableField(value = "approve_max_setup", updateStrategy = FieldStrategy.IGNORED)
     private Integer approveMaxSetup;
 
+    @ApiModelProperty(value = "流程转办")
+    private String transferAssignee;
+
     public TFFlowApprove() {
 
     }
@@ -72,6 +75,14 @@ public class TFFlowApprove extends BaseEntity implements Serializable {
         this.setup = FlowApproveSetupEnum.SUBMIT.getSetup();
     }
 
+    public String getTransferAssignee() {
+        return transferAssignee;
+    }
+
+    public void setTransferAssignee(String transferAssignee) {
+        this.transferAssignee = transferAssignee;
+    }
+
     public Integer getApproveSetup() {
         return approveSetup;
     }

+ 8 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TFCustomFlowService.java

@@ -23,4 +23,12 @@ public interface TFCustomFlowService extends IService<TFCustomFlow> {
      * @return
      */
     Integer findMaxVersion(Long schoolId, Long orgId, TFCustomTypeEnum type);
+
+    /**
+     * 根据流程id查找
+     *
+     * @param flowId
+     * @return
+     */
+    TFCustomFlow findByFlowId(Long flowId);
 }

+ 51 - 48
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ActivitiServiceImpl.java

@@ -330,8 +330,6 @@ public class ActivitiServiceImpl implements ActivitiService {
             Long flowId = SystemConstant.convertIdToLong(processInstanceId);
             ExamTask examTask = examTaskService.findByFlowId(flowId);
 
-//            String processDefinitionId = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();
-//            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinitionId);
             //获取当前流程节点
             String currActivityId = task.getTaskDefinitionKey();
             BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
@@ -344,14 +342,15 @@ public class ActivitiServiceImpl implements ActivitiService {
             Map<String, Object> objectMap = new HashMap<>();
             TFFlowLog tfFlowLog = null;
 
-            QueryWrapper<TFCustomFlow> tfCustomFlowQueryWrapper = new QueryWrapper<>();
-            tfCustomFlowQueryWrapper.lambda().eq(TFCustomFlow::getFlowId, flowId);
-            TFCustomFlow tfCustomFlow = tfCustomFlowService.getOne(tfCustomFlowQueryWrapper);
+            TFCustomFlow tfCustomFlow = tfCustomFlowService.findByFlowId(flowId);
             Map<String, Object> flowProcessVarMap = this.getFlowProcessVarMap(tfCustomFlow);
 
             String remark = null;
             FlowTaskResult currFlowTaskResult = null, nextFlowTaskResult = null;
             Map<String, CustomFlowVarDto> agginessMap = (Map<String, CustomFlowVarDto>) flowProcessVarMap.get(SystemConstant.AGGINESS_MAP);
+            if (Objects.nonNull(tfFlowApprove.getTransferAssignee())) {
+                agginessMap = JacksonUtil.readJson(tfFlowApprove.getTransferAssignee(), Map.class);
+            }
             Gson gson = new Gson();
             Integer nrOfCompletedInstances = null, nrOfInstances = null;
             boolean multiInstance = false;
@@ -1009,60 +1008,64 @@ public class ActivitiServiceImpl implements ActivitiService {
             throw ExceptionResultEnum.ERROR.exception("流程已结束或已终止");
         }
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-//        List<Long> ids = null;
-//        String variableName = null;
-        switch (tfFlowApprove.getSetup()) {
-            case 1:
-            case 4:
-                if (Objects.nonNull(task) && Objects.nonNull(task.getAssignee()) && Objects.equals(task.getAssignee(), userId)) {
-                    throw ExceptionResultEnum.ERROR.exception("不能转给自己");
-                }
-                break;
-            case 2:
-            case 3:
-            case 5:
-                if (Objects.nonNull(task) && Objects.nonNull(task.getAssignee()) && Objects.equals(task.getAssignee(), userId)) {
-                    throw ExceptionResultEnum.ERROR.exception("不能转给自己");
-                } else {
-                    Task taskUser = taskService.createTaskQuery().taskId(taskId).taskCandidateUser(userId).singleResult();
-                    if (Objects.nonNull(taskUser)) {
-                        throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限,无需流转");
-                    }
-                }
-//                if (tfFlowApprove.getSetup() == FlowGdykdxApproveSetupEnum.PRIMARY_APPROVE.getSetup()) {
-//                    ids = (List<Long>) taskService.getVariable(taskId, SystemConstant.APPROVE_DIRECTOR_USER_IDS);
-//                    variableName = SystemConstant.APPROVE_DIRECTOR_USER_IDS;
-//                } else {
-//                    ids = (List<Long>) taskService.getVariable(taskId, SystemConstant.APPROVE_PRESIDENT_USER_IDS);
-//                    variableName = SystemConstant.APPROVE_PRESIDENT_USER_IDS;
-//                }
-                break;
-            default:
-                break;
+        if (Objects.nonNull(task) && Objects.nonNull(task.getAssignee()) && Objects.equals(task.getAssignee(), userId)) {
+            throw ExceptionResultEnum.ERROR.exception("不能转给自己");
+        }
+        Task taskUser = taskService.createTaskQuery().taskId(taskId).taskAssignee(userId).singleResult();
+        if (Objects.nonNull(taskUser)) {
+            throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限,无需流转");
         }
-        taskService.deleteCandidateUser(taskId, String.valueOf(sysUser.getId()));
-        taskService.addCandidateUser(taskId, userId);
-//        if (Objects.nonNull(ids) && ids.size() > 0) {
-//            ids.remove(sysUser.getId());
-//            ids.add(Long.parseLong(userId));
-//            taskService.setVariable(taskId, variableName, ids);
-//        }
-        ExamTask examTask = examTaskService.findByFlowId(SystemConstant.convertIdToLong(flowId));
 
         //获取当前流程节点
         String currActivityId = task.getTaskDefinitionKey();
         BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
         FlowNode currFlow = (FlowNode) bpmnModel.getMainProcess().getFlowElement(currActivityId);
+        UserTask userTask = null;
+        if (currFlow instanceof UserTask) {
+            userTask = (UserTask) currFlow;
+        }
+        Integer nrOfCompletedInstances = null, nrOfInstances = null;
+        boolean multiInstance = false;
+        if (currFlow.getBehavior() instanceof MultiInstanceActivityBehavior) {
+            nrOfCompletedInstances = (Integer) taskService.getVariable(task.getId(), DefaultInstanceConvertToMultiInstance.NR_OF_COMPLETED_INSTANCES);
+            nrOfInstances = (Integer) taskService.getVariable(task.getId(), DefaultInstanceConvertToMultiInstance.NR_OF_INSTANCES);
+            multiInstance = true;
+        }
+
+        TFCustomFlow tfCustomFlow = tfCustomFlowService.findByFlowId(tfFlowApprove.getFlowId());
+        Map<String, Object> flowProcessVarMap = this.getFlowProcessVarMap(tfCustomFlow);
+        Map<String, CustomFlowVarDto> agginessMap = (Map<String, CustomFlowVarDto>) flowProcessVarMap.get(SystemConstant.AGGINESS_MAP);
+        if (Objects.nonNull(tfFlowApprove.getTransferAssignee())) {
+            agginessMap = JacksonUtil.readJson(tfFlowApprove.getTransferAssignee(), Map.class);
+        }
 
+        Gson gson = new Gson();
+        CustomFlowVarDto customFlowVarDto = gson.fromJson(gson.toJson(agginessMap.get(userTask.getId())), CustomFlowVarDto.class);
+        if (customFlowVarDto.getApproveIds().size() == 1) {
+            customFlowVarDto.setApproveIds(new ArrayList<>(Arrays.asList(userId)));
+        } else {
+            if (multiInstance && Objects.nonNull(nrOfCompletedInstances)) {
+                List<String> approveIds = customFlowVarDto.getApproveIds();
+                approveIds.remove(nrOfCompletedInstances.intValue());
+                approveIds.add(nrOfCompletedInstances.intValue(), userId);
+            }
+        }
+
+        agginessMap.put(userTask.getId(), customFlowVarDto);
+        taskService.setAssignee(taskId, userId);
+
+        tfFlowApprove.setTransferAssignee(JacksonUtil.parseJson(agginessMap));
+        tfFlowApproveService.updateById(tfFlowApprove);
+
+        ExamTask examTask = examTaskService.findByFlowId(SystemConstant.convertIdToLong(flowId));
         SysUser exchangeUser = sysUserService.getById(userId);
         //流程流水日志
         TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getSchoolId(), sysUser.getOrgId(), examTask.getFlowId(), examTask.getId(), sysUser.getId(), sysUser.getRealName() + "转" + exchangeUser.getRealName() + "审批", FlowApproveOperationEnum.EXCHANGE, sysUser.getId(), String.valueOf(exchangeUser.getId()));
-        if (currFlow instanceof UserTask) {
-            UserTask userTask = (UserTask) currFlow;
-            FlowApproveSetupEnum setupEnum = FlowApproveSetupEnum.convertToInstance(userTask.getId());
-            tfFlowLog.setApproveSetup(setupEnum.getSetup());
-            taskService.setVariable(taskId, SystemConstant.APPROVE_EXCHANGE_USER_ID + setupEnum.getId(), String.valueOf(exchangeUser.getId()));
+        if (multiInstance) {
+            tfFlowLog.setPendApproveId(customFlowVarDto.getApproveIds().subList(nrOfCompletedInstances, nrOfInstances).toString().replaceAll("\\[", "").replaceAll("\\]", ""));
         }
+
+        tfFlowLog.setApproveSetup(tfFlowApprove.getSetup());
         tfFlowLogService.save(tfFlowLog);
         return true;
     }

+ 14 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TFCustomFlowServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.distributed.print.business.entity.TFCustomFlow;
 import com.qmth.distributed.print.business.enums.TFCustomTypeEnum;
@@ -36,4 +37,17 @@ public class TFCustomFlowServiceImpl extends ServiceImpl<TFCustomFlowMapper, TFC
     public Integer findMaxVersion(Long schoolId, Long orgId, TFCustomTypeEnum type) {
         return tfCustomFlowMapper.findMaxVersion(schoolId, orgId, Objects.nonNull(type) ? type.name() : null);
     }
+
+    /**
+     * 根据流程id查找
+     *
+     * @param flowId
+     * @return
+     */
+    @Override
+    public TFCustomFlow findByFlowId(Long flowId) {
+        QueryWrapper<TFCustomFlow> tfCustomFlowQueryWrapper = new QueryWrapper<>();
+        tfCustomFlowQueryWrapper.lambda().eq(TFCustomFlow::getFlowId, flowId);
+        return this.getOne(tfCustomFlowQueryWrapper);
+    }
 }