fuliqi
2025-01-13 16d4c2e94790188c59dac9f22bfc65354f634527
审核提交注入流转条件字段
2个文件已修改
67 ■■■■■ 已修改文件
flowable/src/main/java/com/ycl/service/common/TaskCommonService.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
@@ -43,9 +43,9 @@
    /**
     * 通过当前节点定义key,获取其上一个节点的信息,如果前面是并行的会返回多个(包含当前节点)
     *
     * @param processDefId 流程定义id
     * @param currentNodeDefId 当前节点定义id
     * @param sysFormService 表单服务层
     * @param processDefId        流程定义id
     * @param currentNodeDefId    当前节点定义id
     * @param sysFormService      表单服务层
     * @param needInitCurrentForm 是否需要初始化当前节点的表单数据,一般查询已完成的任务详情需要
     * @return
     */
@@ -82,11 +82,11 @@
        // 获取当前节点的输入
        List<FormDetailVO> defKeys = new ArrayList<>(2);
        FormDetailVO formDetailVO = new FormDetailVO();
        formDetailVO.setCurrent(Boolean.TRUE);
        formDetailVO.setBeforeNodeDefId(currentElement.getId());
        formDetailVO.setBeforeNodeName(currentElement.getName());
        if (StringUtils.hasText(currentElement.getFormKey())) {
            FormDetailVO formDetailVO = new FormDetailVO();
            formDetailVO.setBeforeNodeDefId(currentElement.getId());
            formDetailVO.setBeforeNodeName(currentElement.getName());
            formDetailVO.setCurrent(Boolean.TRUE);
            if (needInitCurrentForm) {
                SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(currentElement.getFormKey()));
@@ -95,12 +95,10 @@
                }
                Map<String, Object> data = new HashMap<>(1);
                data.put(ProcessConstants.TASK_FORM_KEY, JSONObject.parseObject(sysForm.getFormContent()));
                formDetailVO.setFormJsonObj(data);
            }
            defKeys.add(formDetailVO);
        }
        defKeys.add(formDetailVO);
        this.beforeNodeInfo(currentElement, defKeys);
        return defKeys;
@@ -161,7 +159,7 @@
    private void beforeNodeInfo(FlowElement currentElement, List<FormDetailVO> defKeys) {
        if (currentElement instanceof UserTask) {
            UserTask userTask = (UserTask) currentElement;
            if (! CollectionUtils.isEmpty(userTask.getIncomingFlows())) {
            if (!CollectionUtils.isEmpty(userTask.getIncomingFlows())) {
                for (SequenceFlow incomingFlow : userTask.getIncomingFlows()) {
                    if (incomingFlow.getSourceFlowElement() instanceof UserTask) {
                        FormDetailVO formDetailVO = new FormDetailVO();
@@ -173,9 +171,9 @@
                    }
                }
            }
        } else if (currentElement instanceof Gateway ){
        } else if (currentElement instanceof Gateway) {
            Gateway gateway = (Gateway) currentElement;
            if (! CollectionUtils.isEmpty(gateway.getIncomingFlows())) {
            if (!CollectionUtils.isEmpty(gateway.getIncomingFlows())) {
                for (SequenceFlow incomingFlow : gateway.getIncomingFlows()) {
                    if (incomingFlow.getSourceFlowElement() instanceof UserTask) {
                        FormDetailVO formDetailVO = new FormDetailVO();
@@ -194,7 +192,7 @@
    /**
     * 获取当前节点的上一节点id,不反悔当前节点信息,如果前面是并行,那么会返回多个
     *
     * @param processDefId 流程定义id
     * @param processDefId     流程定义id
     * @param currentNodeDefId 当前节点定义id
     * @return
     */
@@ -253,7 +251,7 @@
            } else {
                // 否则先查本身的属性有不有:需要审核 的属性,没有也是递归child
                if (extensionElement.getAttributes().get("name").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_NEED_AUDITING_TEXT.equals(attribute.getValue()))
                    && extensionElement.getAttributes().get("value").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_NEED_AUDITING_VALUE.equals(attribute.getValue()))
                        && extensionElement.getAttributes().get("value").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_NEED_AUDITING_VALUE.equals(attribute.getValue()))
                ) {
                    return Boolean.TRUE;
                } else {
@@ -269,10 +267,10 @@
     * 驳回任务
     *
     * @param rejectedTaskDefKey 被驳回的任务key
     * @param rejectTaskDefKey 执行驳回操作所在的任务key
     * @param processInsId 流程实例id
     * @param taskId 当前任务id
     * @param msg 审核意见
     * @param rejectTaskDefKey   执行驳回操作所在的任务key
     * @param processInsId       流程实例id
     * @param taskId             当前任务id
     * @param msg                审核意见
     */
    public void reject(String rejectedTaskDefKey, String rejectTaskDefKey, String processInsId, String taskId, String msg) {
        // 驳回的核心api:runtimeService.createChangeActivityStateBuilder().moveXXX 的api,可以设置从当前节点移动到目标节点
@@ -289,13 +287,11 @@
        // 设置两条评论
        List<HistoricTaskInstance> rejectedTaskList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInsId).taskDefinitionKey(rejectedTaskDefKey).orderByHistoricTaskInstanceStartTime().desc().list();
        String msg1 = "驳回了:【" + rejectedTaskList.get(0).getName() + "】,驳回原因:";
        taskService.addComment(taskId, processInsId,  FlowComment.REJECT.getType(), msg1 + msg);
        taskService.addComment(taskId, processInsId, FlowComment.REJECT.getType(), msg1 + msg);
        // TODO 直接使用这个api好像有问题
        runtimeService.createChangeActivityStateBuilder().processInstanceId(processInsId).moveActivityIdTo(rejectTaskDefKey, rejectedTaskDefKey).changeState();
        runtimeService.createChangeActivityStateBuilder().processInstanceId(processInsId).moveExecutionToActivityId(rejectTaskDefKey, rejectedTaskDefKey).changeState();
    }
}
flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
@@ -9,6 +9,7 @@
import com.ycl.common.constant.ProcessConstants;
import com.ycl.common.core.domain.AjaxResult;
import com.ycl.common.core.domain.entity.SysDept;
import com.ycl.common.core.domain.entity.SysDictData;
import com.ycl.common.core.domain.entity.SysRole;
import com.ycl.common.core.domain.entity.SysUser;
import com.ycl.common.enums.FlowComment;
@@ -33,9 +34,7 @@
import com.ycl.service.ISysDeployFormService;
import com.ycl.service.ISysFormService;
import com.ycl.service.common.TaskCommonService;
import com.ycl.system.service.ISysDeptService;
import com.ycl.system.service.ISysRoleService;
import com.ycl.system.service.ISysUserService;
import com.ycl.system.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -90,6 +89,7 @@
    private final ISysUserService sysUserService;
    private final ISysRoleService sysRoleService;
    private final ISysDeptService sysDeptService;
    private final ISysDictTypeService sysDictDService;
    private final ISysDeployFormService sysInstanceFormService;
    private final ISysFormService sysFormService;
    private final TaskCommonService taskCommonService;
@@ -134,12 +134,22 @@
        if (Objects.isNull(task)) {
            return AjaxResult.error("任务不存在");
        }
        Map<String, Object> processVariables = new HashMap<>();
        //查出字典中需要注入的字段信息
        List<String> dictList = sysDictDService.selectDictDataByType("flow_variables").stream().map(SysDictData::getDictValue).collect(Collectors.toList());
        Map<String, Object> newV = new HashMap<>(2);
        if (!org.springframework.util.CollectionUtils.isEmpty(variables)) {
            for (String key : variables.keySet()) {
                newV.put(task.getTaskDefinitionKey() + "&" + key, variables.get(key));
                //字典里有就放入流程变量中
                if (!CollectionUtils.isEmpty(dictList) && dictList.contains(key)) {
                    processVariables.put(key,variables.get(key));
                }
            }
        }
        //添加流程变量
        if(!processVariables.isEmpty()) taskService.setVariables(taskId,processVariables);
        taskService.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "完成提交");
        // 判断当前任务是不是转办过的
        Boolean delegation = flowLogService.taskDelegation(task.getProcessInstanceId(), task.getId());
@@ -865,18 +875,19 @@
                    flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis()));
                    //扩展 判断是否超时
                    ProcessCoding processCoding = processCodingMap.get(histIns.getTaskId());
                    if(processCoding!=null){
                    if (processCoding != null) {
                        //通过耗时判断是否是代办节点
                        //如果任务是代办节点
                        if (flowTask.getDuration() == null) {
                            if(RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus())){
                            if (RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus())) {
                                flowTask.setOvertime(processCoding.getStatus());
                            }
                        }else {
                        } else {
                            //如果任务节点属于历史节点
                            if(RED.equals(processCoding.getStatus())){
                            if (RED.equals(processCoding.getStatus())) {
                                flowTask.setOvertime(processCoding.getStatus());
                            };
                            }
                            ;
                        }
                    }
                    // 获取意见评论内容