business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
@@ -1350,6 +1350,7 @@
                    .processInstanceId(procInsId)
                    .finished()
                    .list();
            listFinished = this.distinctHisActivity(listFinished);
            //扩展 获取这个流程实例的监控信息 key:TaskId value:实体类
            Map<String, ProcessCoding> processCodingMap = new LambdaQueryChainWrapper<>(processCodingMapper)
@@ -1413,6 +1414,27 @@
    }
    /**
     * 根据任务key去重历史任务,相同情况下取最新的一条
     *
     * @param hisTaskList
     * @return
     */
    private List<HistoricActivityInstance> distinctHisActivity(List<HistoricActivityInstance> hisTaskList) {
        Map<String, HistoricActivityInstance> uniqueTasks = new HashMap<>();
        for (HistoricActivityInstance task : hisTaskList) {
            String taskDefinitionKey = task.getActivityId();
            HistoricActivityInstance existingTask = uniqueTasks.get(taskDefinitionKey);
            // 如果任务key重复(可能被驳回过,重新提交导致key重复),取最近的一条
            if (existingTask == null || task.getStartTime().after(existingTask.getStartTime())) {
                uniqueTasks.put(taskDefinitionKey, task);
            }
        }
        // 最终去重后的任务列表
        return new ArrayList<>(uniqueTasks.values());
    }
    /**
     * 查询当前任务的表单数据
     *
     * @param taskId
@@ -1423,7 +1445,6 @@
    public AjaxResult currentFlowTaskForm(String taskId) {
        // 流程变量
        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
                .includeProcessVariables()
                .finished()
                .taskId(taskId)
                .orderByHistoricTaskInstanceStartTime()
@@ -1433,24 +1454,35 @@
            return AjaxResult.error("未找到该任务信息");
        }
        HistoricTaskInstance historicTaskInstance = hisTaskList.get(0);
        Map<String, Object> parameters = historicTaskInstance.getProcessVariables();
        String processInsId = historicTaskInstance.getProcessInstanceId();
        List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, historicTaskInstance.getFormKey(), historicTaskInstance.getName(), historicTaskInstance.getProcessDefinitionId(), historicTaskInstance.getTaskDefinitionKey(), Boolean.FALSE);
        // 判断前置任务是不是和当前任务为同一个executeId
        // 判断当前任务是否被挂起中
        String finalProcessInsId = processInsId;
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(historicTaskInstance.getProcessInstanceId()).singleResult();
        Map<String, Object> parameters = new HashMap<>();
        if (Objects.nonNull(processInstance)) {
            parameters = processInstance.getProcessVariables();
        } else {
            // 如果为空,表明流程已经结束
            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(historicTaskInstance.getProcessInstanceId()).singleResult();
            if (Objects.isNull(historicProcessInstance)) {
                throw new RuntimeException("流程不存在");
            }
            parameters = historicProcessInstance.getProcessVariables();
        }
        String processInsId = historicTaskInstance.getProcessInstanceId();
        List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters,
                historicTaskInstance.getFormKey(),
                historicTaskInstance.getName(),
                historicTaskInstance.getProcessDefinitionId(),
                historicTaskInstance.getTaskDefinitionKey(),
                Boolean.TRUE, Boolean.FALSE);
        String finalProcessInsId = processInsId;
        List<DoFormDetailVO> vos = beforeNodes.stream()
                .filter(FormDetailVO::getCurrent)
                .map(node -> {
                    if (node.getCurrent()) {
                        if (processLogService.taskIsHangup(taskId, finalProcessInsId)) {
                            node.setTaskStatus(TaskStatusEnum.HANGUP);
                        }
                    }
                    // 判断任务是否存在特殊操作(如跳过、转办等),需要在前端展示出来
                    ProcessLogQuery query = new ProcessLogQuery();
                    query.setTaskId(node.getTaskId());
                    query.setTaskId(taskId);
                    query.setProcessInsId(finalProcessInsId);
                    Result result = processLogService.projectProcessLogList(query);
                    List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data");
@@ -1458,6 +1490,16 @@
                    BeanUtils.copyProperties(node, vo);
                    if (CollectionUtils.isNotEmpty(logList)) {
                        vo.setEvents(logList);
                    }
                    // 根据日志判断当前任务的状态
                    if (logList.stream().anyMatch(log -> ProcessLogEventTypeEnum.FINISHED.equals(log.getEventType()))) {
                        vo.setTaskStatus(TaskStatusEnum.FINISHED);
                    } else if (logList.stream().anyMatch(log -> ProcessLogEventTypeEnum.JUMP.equals(log.getEventType()))) {
                        vo.setTaskStatus(TaskStatusEnum.JUMP);
                    } else if (processLogService.taskIsWait(taskId, processInsId)) {
                        vo.setTaskStatus(TaskStatusEnum.WAIT);
                    } else if (processLogService.taskIsHangup(taskId, processInsId)) {
                        vo.setTaskStatus(TaskStatusEnum.HANGUP);
                    }
                    return vo;
        }).collect(Collectors.toList());
@@ -1473,26 +1515,55 @@
    @Override
    public AjaxResult flowTaskForm(String taskId) throws Exception {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        // 流程变量
        Map<String, Object> parameters = new HashMap<>();
        List<FormDetailVO> beforeNodes = new ArrayList<>();
        // 1. 获取到变量信息,因为任务可能是运行中的也可能是历史任务
        String processInsId = "";
        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
                .includeProcessVariables()
                .finished()
                .taskId(taskId)
                .orderByHistoricTaskInstanceStartTime()
                .desc()
                .list();
        if (CollectionUtils.isNotEmpty(hisTaskList) && Objects.nonNull(hisTaskList.get(0))) {
            parameters = hisTaskList.get(0).getProcessVariables();
            processInsId = hisTaskList.get(0).getProcessInstanceId();
            beforeNodes = this.getBeforeNodeForm(parameters, hisTaskList.get(0).getFormKey(), hisTaskList.get(0).getName(), hisTaskList.get(0).getProcessDefinitionId(), hisTaskList.get(0).getTaskDefinitionKey(), Boolean.FALSE);
        String processDefId = "";
        String formKey = "";
        String taskName = "";
        String taskDefKey = "";
        if (Objects.isNull(task)) {
            List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
                    .finished()
                    .taskId(taskId)
                    .orderByHistoricTaskInstanceStartTime()
                    .desc()
                    .list();
            if (CollectionUtils.isEmpty(hisTaskList) || Objects.isNull(hisTaskList.get(0))) {
                return AjaxResult.error("任务不存在");
            }
            HistoricTaskInstance hisTask = hisTaskList.get(0);
            processInsId = hisTask.getProcessInstanceId();
            processDefId = hisTask.getProcessDefinitionId();
            formKey = hisTask.getFormKey();
            taskName = hisTask.getName();
            taskDefKey = hisTask.getTaskDefinitionKey();
        } else {
            parameters = taskService.getVariables(taskId);
            processInsId = task.getProcessInstanceId();
            beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE);
            processDefId = task.getProcessDefinitionId();
            formKey = task.getFormKey();
            taskName = task.getName();
            taskDefKey = task.getTaskDefinitionKey();
        }
        // 2. 获取流程变量
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult();
        Map<String, Object> parameters = new HashMap<>();
        if (Objects.nonNull(processInstance)) {
            parameters = processInstance.getProcessVariables();
        } else {
            // 如果为空,表明流程已经结束
            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult();
            if (Objects.isNull(historicProcessInstance)) {
                throw new RuntimeException("流程不存在");
            }
            parameters = historicProcessInstance.getProcessVariables();
        }
        List<FormDetailVO> beforeNodes = new ArrayList<>();
        beforeNodes = this.getBeforeNodeForm(parameters,
                formKey,
                taskName,
                processDefId,
                taskDefKey,
                Boolean.TRUE, Boolean.TRUE);
        // 判断前置任务是不是和当前任务为同一个executeId
        // 判断当前任务是否被挂起中
        String finalProcessInsId = processInsId;
@@ -1574,7 +1645,12 @@
            }
            HistoricTaskInstance hisTask = hisTasks.get(0);
            parameters = historicProcessInstance.getProcessVariables();
            List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE);
            List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters,
                    hisTask.getFormKey(),
                    hisTask.getName(),
                    hisTask.getProcessDefinitionId(),
                    hisTask.getTaskDefinitionKey(),
                    Boolean.TRUE, Boolean.TRUE);
            List<FormDetailVO> dataList = new ArrayList<>(2);
            Map<String, List<FormDetailVO>> map = new HashMap<>(2);
            beforeNodes.stream().forEach(node -> {
@@ -1631,7 +1707,12 @@
            Task task = taskService.createTaskQuery().taskId(taskId).processInstanceId(processInsId).singleResult();
            List<FormDetailVO> beforeNodes = new ArrayList<>();
            if (Objects.nonNull(task)) {
                beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.TRUE);
                beforeNodes = this.getBeforeNodeForm(parameters,
                        task.getFormKey(),
                        task.getName(),
                        task.getProcessDefinitionId(),
                        task.getTaskDefinitionKey(),
                        Boolean.TRUE, Boolean.TRUE);
            } else {
                List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery()
                        .taskId(taskId)
@@ -1644,7 +1725,12 @@
                    throw new RuntimeException("该任务不存在");
                }
                HistoricTaskInstance hisTask = hisTasks.get(0);
                beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE);
                beforeNodes = this.getBeforeNodeForm(parameters,
                        hisTask.getFormKey(),
                        hisTask.getName(),
                        hisTask.getProcessDefinitionId(),
                        hisTask.getTaskDefinitionKey(),
                        Boolean.TRUE, Boolean.TRUE);
            }
            List<FormDetailVO> dataList = new ArrayList<>(2);
            Map<String, List<FormDetailVO>> map = new HashMap<>(2);
@@ -1708,9 +1794,16 @@
     * @param taskName      任务
     * @param processDefId  流程定义id
     * @param processDefKey 流程实例id
     * @param disableInput 是否禁用已经有值的输入项
     * @return
     */
    private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters, String formKey, String taskName, String processDefId, String processDefKey, Boolean currentNeedData) {
    private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters,
                                                 String formKey,
                                                 String taskName,
                                                 String processDefId,
                                                 String processDefKey,
                                                 Boolean currentNeedData,
                                                 Boolean disableInput) {
        // 这里只需要查自身以及上一个节点(如果并行的有多个)的表单数据
        List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefInfo(processDefId, processDefKey, sysFormService, Boolean.TRUE);
@@ -1744,9 +1837,11 @@
                if(CollectionUtils.isNotEmpty(oldFields)) {
                    // 设置已填写的表单为禁用状态
                    for (JSONObject oldField : oldFields) {
                        JSONObject options = oldField.getJSONObject("options");
                        options.put("disabled", true);
                    if (disableInput) {
                        for (JSONObject oldField : oldFields) {
                            JSONObject options = oldField.getJSONObject("options");
                            options.put("disabled", true);
                        }
                    }
                    formJson.put(ProcessConstants.WIDGET_LIST, oldFields);
                    newP.put(ProcessConstants.TASK_FORM_KEY, formJson);