zxl
2025-03-02 42a7552b9c8603aeab7f0785eb05270dfbeb0bd3
flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson2.JSONObject;
import com.ycl.common.constant.ProcessConstants;
import com.ycl.common.core.domain.entity.SysDictData;
import com.ycl.common.core.domain.entity.SysUser;
import com.ycl.common.enums.FlowComment;
import com.ycl.common.enums.business.TaskStatusEnum;
@@ -10,6 +11,8 @@
import com.ycl.domain.vo.FormDetailVO;
import com.ycl.flow.FindNextNodeUtil;
import com.ycl.service.ISysFormService;
import com.ycl.system.service.ISysDictDataService;
import com.ycl.system.service.ISysDictTypeService;
import com.ycl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.flowable.bpmn.model.*;
@@ -44,6 +47,7 @@
    private final TaskService taskService;
    private final HistoryService historyService;
    private final ISysUserService sysUserService;
    private final ISysDictTypeService sysDictDService;
    /**
     * 通过当前节点定义key,获取其上一个节点的信息,如果前面是并行的会返回多个(包含当前节点)
@@ -85,7 +89,7 @@
            throw new RuntimeException("未找到该任务的流程定义节点");
        }
        // 获取当前节点的输入
        // 获取当前节点的信息
        List<FormDetailVO> defKeys = new ArrayList<>(2);
        FormDetailVO formDetailVO = new FormDetailVO();
        formDetailVO.setCurrent(Boolean.TRUE);
@@ -103,6 +107,10 @@
                formDetailVO.setFormJsonObj(data);
            }
        }
        formDetailVO.setCanJump(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_JUMP_TEXT));
        formDetailVO.setCanWait(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_WAIT_TEXT));
        formDetailVO.setCanHangup(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_HANGUP_TEXT));
        formDetailVO.setUserTask(currentElement);
        defKeys.add(formDetailVO);
        this.beforeNodeInfo(currentElement, defKeys);
@@ -170,6 +178,9 @@
                        FormDetailVO formDetailVO = new FormDetailVO();
                        formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
                        formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
                        formDetailVO.setCanJump(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_JUMP_TEXT));
                        formDetailVO.setCanWait(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_WAIT_TEXT));
                        formDetailVO.setUserTask((UserTask) incomingFlow.getSourceFlowElement());
                        defKeys.add(formDetailVO);
                    } else {
                        beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
@@ -184,6 +195,9 @@
                        FormDetailVO formDetailVO = new FormDetailVO();
                        formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
                        formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
                        formDetailVO.setCanJump(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_JUMP_TEXT));
                        formDetailVO.setCanWait(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_WAIT_TEXT));
                        formDetailVO.setUserTask((UserTask) incomingFlow.getSourceFlowElement());
                        defKeys.add(formDetailVO);
                    } else {
                        beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
@@ -195,7 +209,7 @@
    /**
     * 获取当前节点的上一节点id,不反悔当前节点信息,如果前面是并行,那么会返回多个
     * 获取当前节点的上一节点id,不返回当前节点信息,如果前面是并行,那么会返回多个
     *
     * @param processDefId     流程定义id
     * @param currentNodeDefId 当前节点定义id
@@ -241,30 +255,29 @@
    /**
     * 检查任务节点是否配置了:需要审核  的扩展属性
     * 检查任务节点是否配置了某个的扩展属性
     *
     * @param extensionElements 扩展列表
     * @return
     */
    public Boolean checkTaskNeedAuditing(List<ExtensionElement> extensionElements) {
    public Boolean checkHasExeProperty(List<ExtensionElement> extensionElements, String exePropertyName) {
        if (CollectionUtils.isEmpty(extensionElements)) {
            return Boolean.FALSE;
        }
        for (ExtensionElement extensionElement : extensionElements) {
        return extensionElements.stream().anyMatch(extensionElement -> {
            if (CollectionUtils.isEmpty(extensionElement.getAttributes())) { // 如果本身没有属性,则递归child
                return checkTaskNeedAuditing(extensionElement.getChildElements().get("property"));
                return checkHasExeProperty(extensionElement.getChildElements().get("property"), exePropertyName);
            } 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()))
                // 否则先查本身的属性有不有,没有也是递归child
                if (extensionElement.getAttributes().get("name").stream().anyMatch(attribute -> exePropertyName.equals(attribute.getValue()))
                        && extensionElement.getAttributes().get("value").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_VALUE.equals(attribute.getValue()))
                ) {
                    return Boolean.TRUE;
                } else {
                    return checkTaskNeedAuditing(extensionElement.getChildElements().get("property"));
                    return checkHasExeProperty(extensionElement.getChildElements().get("property"), exePropertyName);
                }
            }
        }
        return Boolean.FALSE;
        });
    }
@@ -317,4 +330,28 @@
        return roleIds;
    }
    /**
     * 处理流程中的变量
     *
     * @param variables
     * @param taskDefKey
     * @return
     */
    public Map<String, Object> handleVar(Map<String, Object> variables, String taskDefKey) {
        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(taskDefKey + "&" + key, variables.get(key));
                //字典里有就放入流程变量中
                if (!org.apache.commons.collections4.CollectionUtils.isEmpty(dictList) && dictList.contains(key)) {
                    processVariables.put(key,variables.get(key));
                }
            }
        }
        return processVariables;
    }
}