xiangpei
3 天以前 e85cd3fe826efe0baaa3fc09ea371467127c370c
business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
@@ -20,6 +20,7 @@
import com.ycl.common.enums.business.TaskStatusEnum;
import com.ycl.common.exception.CustomException;
import com.ycl.common.utils.SecurityUtils;
import com.ycl.constant.ProjectConstant;
import com.ycl.domain.dto.FlowCommentDto;
import com.ycl.domain.dto.FlowNextDto;
import com.ycl.domain.dto.FlowTaskDto;
@@ -73,6 +74,7 @@
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -109,6 +111,9 @@
    private final ProcessLogService processLogService;
    private final ApplicationEventPublisher publisher;
    private final ProjectProcessMapper projectProcessMapper;
    @Value("${targetIp}")
    private String targetIp;
    /**
     * 完成审核任务
@@ -1445,7 +1450,6 @@
    public AjaxResult currentFlowTaskForm(String taskId) {
        // 流程变量
        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
                .includeProcessVariables()
                .finished()
                .taskId(taskId)
                .orderByHistoricTaskInstanceStartTime()
@@ -1455,7 +1459,19 @@
            return AjaxResult.error("未找到该任务信息");
        }
        HistoricTaskInstance historicTaskInstance = hisTaskList.get(0);
        Map<String, Object> parameters = historicTaskInstance.getProcessVariables();
        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(),
@@ -1504,36 +1520,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, Boolean.TRUE);
        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, Boolean.TRUE);
            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.FALSE);
        // 判断前置任务是不是和当前任务为同一个executeId
        // 判断当前任务是否被挂起中
        String finalProcessInsId = processInsId;
@@ -1811,11 +1846,29 @@
                        for (JSONObject oldField : oldFields) {
                            JSONObject options = oldField.getJSONObject("options");
                            options.put("disabled", true);
                            // 处理文件上传ip问题
                            if ("file-upload".equals(oldField.get("type"))) {
                                options.put("uploadURL", String.format("http://%s:10076/common/upload", this.targetIp));
                            }
                        }
                    }
                    formJson.put(ProcessConstants.WIDGET_LIST, oldFields);
                    newP.put(ProcessConstants.TASK_FORM_KEY, formJson);
                    newP.remove(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY);
                    // 处理已经上传的文件的ip地址
                    for (String s : newP.keySet()) {
                        if (ProcessConstants.TASK_FORM_KEY.equals(s)) {
                            continue;
                        }
                        if (s.startsWith("fileupload")) {
                            List files = (List) newP.get(s);
                            for (Object file : files) {
                                LinkedHashMap<String, String> fileMap = (LinkedHashMap<String, String>) file;
                                String url = fileMap.get("url");
                                fileMap.put("url", url.replace("42.193.1.25", this.targetIp));
                            }
                        }
                    }
                    formDetailVO.setFormJsonObj(newP);
                }
                // TODO 暂时只处理用户任务上的表单