From 1d3c3cdcf530621295701cca3d6ac7c4b1e862ce Mon Sep 17 00:00:00 2001 From: bob Date: Sun, 15 Jan 2023 21:06:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(hisTask)=20add=20allProcess=E3=80=81update?= =?UTF-8?q?VariablesSubmitDate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-common/pom.xml | 9 ++- .../controller/FlowTaskController.java | 12 ++++ .../vo/UpdateVariablesSubmitDateVo.java | 16 +++++ .../flowable/service/IFlowTaskService.java | 11 +++- .../service/impl/FlowTaskServiceImpl.java | 59 +++++++++++++++---- 5 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 ruoyi-flowable/src/main/java/com/ruoyi/flowable/domain/vo/UpdateVariablesSubmitDateVo.java diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 22cd72e..bcee698 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -52,7 +52,7 @@ org.apache.commons commons-lang3 - + com.fasterxml.jackson.core @@ -131,6 +131,11 @@ org.springframework.boot spring-boot-starter-test + + cn.hutool + hutool-all + 5.8.11 + - \ No newline at end of file + diff --git a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/controller/FlowTaskController.java b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/controller/FlowTaskController.java index 35fe130..5c275ef 100644 --- a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/controller/FlowTaskController.java +++ b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/controller/FlowTaskController.java @@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.flowable.domain.dto.FlowTaskDto; import com.ruoyi.flowable.domain.vo.FlowTaskVo; +import com.ruoyi.flowable.domain.vo.UpdateVariablesSubmitDateVo; import com.ruoyi.flowable.service.IFlowTaskService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -41,6 +42,12 @@ public class FlowTaskController { @ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize) { return flowTaskService.myProcess(pageNum, pageSize); } + @ApiOperation(value = "所有流程", response = FlowTaskDto.class) + @GetMapping(value = "/allProcess") + public AjaxResult allProcess(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum, + @ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize) { + return flowTaskService.allProcess(pageNum, pageSize); + } @ApiOperation(value = "取消申请", response = FlowTaskDto.class) @PostMapping(value = "/stopProcess") @@ -80,6 +87,11 @@ public class FlowTaskController { public AjaxResult processVariables(@ApiParam(value = "流程任务Id") @PathVariable(value = "taskId") String taskId) { return flowTaskService.processVariables(taskId); } + @ApiOperation(value = "更新流程变量提交时间", response = FlowTaskDto.class) + @PostMapping(value = "/updateVariablesSubmitDate") + public AjaxResult updateVariablesSubmitDate(@RequestBody UpdateVariablesSubmitDateVo vo) { + return flowTaskService.updateVariablesSubmitDate(vo.getProcessInstanceId(), vo.getSubmitDate()); + } @ApiOperation(value = "审批任务") @PostMapping(value = "/complete") diff --git a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/domain/vo/UpdateVariablesSubmitDateVo.java b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/domain/vo/UpdateVariablesSubmitDateVo.java new file mode 100644 index 0000000..2434916 --- /dev/null +++ b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/domain/vo/UpdateVariablesSubmitDateVo.java @@ -0,0 +1,16 @@ +package com.ruoyi.flowable.domain.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel("工作流任务相关--请求参数") +public class UpdateVariablesSubmitDateVo { + @ApiModelProperty("流程实例id") + private String processInstanceId; + + @ApiModelProperty("提交时间") + private String submitDate; + +} diff --git a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/IFlowTaskService.java b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/IFlowTaskService.java index 74035f4..a3de2a9 100644 --- a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/IFlowTaskService.java +++ b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/IFlowTaskService.java @@ -5,7 +5,6 @@ import com.ruoyi.flowable.domain.vo.FlowTaskVo; import org.flowable.task.api.Task; import java.io.InputStream; -import java.util.List; /** * @author XuanXuan @@ -87,6 +86,14 @@ public interface IFlowTaskService { */ AjaxResult myProcess(Integer pageNum, Integer pageSize); + /** + * 所有流程 + * @param pageNum + * @param pageSize + * @return + */ + AjaxResult allProcess(Integer pageNum, Integer pageSize); + /** * 取消申请 * @param flowTaskVo @@ -158,6 +165,8 @@ public interface IFlowTaskService { */ AjaxResult processVariables(String taskId); + AjaxResult updateVariablesSubmitDate(String processInstanceId,String submitDate); + /** * 获取下一节点 * @param flowTaskVo 任务 diff --git a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/impl/FlowTaskServiceImpl.java b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/impl/FlowTaskServiceImpl.java index 652b549..ff7b30d 100644 --- a/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/impl/FlowTaskServiceImpl.java +++ b/ruoyi-flowable/src/main/java/com/ruoyi/flowable/service/impl/FlowTaskServiceImpl.java @@ -1,16 +1,16 @@ package com.ruoyi.flowable.service.impl; -import com.alibaba.fastjson.JSONObject; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.collect.Lists; -import com.ruoyi.flowable.common.constant.ProcessConstants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.flowable.common.enums.FlowComment; import com.ruoyi.common.exception.CustomException; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.flowable.common.constant.ProcessConstants; +import com.ruoyi.flowable.common.enums.FlowComment; import com.ruoyi.flowable.domain.dto.FlowCommentDto; import com.ruoyi.flowable.domain.dto.FlowNextDto; import com.ruoyi.flowable.domain.dto.FlowTaskDto; @@ -22,25 +22,22 @@ import com.ruoyi.flowable.flow.FindNextNodeUtil; import com.ruoyi.flowable.flow.FlowableUtils; import com.ruoyi.flowable.service.IFlowTaskService; import com.ruoyi.flowable.service.ISysDeployFormService; -import com.ruoyi.system.domain.SysForm; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.flowable.bpmn.model.Process; import org.flowable.bpmn.model.*; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.api.FlowableObjectNotFoundException; -import org.flowable.common.engine.api.query.QueryProperty; import org.flowable.common.engine.impl.identity.Authentication; import org.flowable.engine.ProcessEngineConfiguration; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstanceQuery; -import org.flowable.engine.impl.ActivityInstanceQueryProperty; import org.flowable.engine.repository.ProcessDefinition; -import org.flowable.engine.runtime.ActivityInstance; import org.flowable.engine.runtime.Execution; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.task.Comment; @@ -413,12 +410,35 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask */ @Override public AjaxResult myProcess(Integer pageNum, Integer pageSize) { - Page page = new Page<>(); + Long userId = SecurityUtils.getLoginUser().getUser().getUserId(); HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() .startedBy(userId.toString()) .orderByProcessInstanceStartTime() .desc(); + return AjaxResult.success(buildFlowTask(pageNum, pageSize, historicProcessInstanceQuery)); + } + /** + * 所有流程 + * + * @param pageNum + * @param pageSize + * @return + */ + @Override + public AjaxResult allProcess(Integer pageNum, Integer pageSize) { +// 管理员才有权查询此接口 + + HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() + .orderByProcessInstanceStartTime() + .includeProcessVariables() + .desc(); + return AjaxResult.success(buildFlowTask(pageNum, pageSize, historicProcessInstanceQuery)); + } + + public Page buildFlowTask(Integer pageNum, Integer pageSize, HistoricProcessInstanceQuery historicProcessInstanceQuery) { + + Page page = new Page<>(); List historicProcessInstances = historicProcessInstanceQuery.listPage(pageSize * (pageNum - 1), pageSize); page.setTotal(historicProcessInstanceQuery.count()); List flowList = new ArrayList<>(); @@ -445,6 +465,12 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask flowTask.setProcDefVersion(pd.getVersion()); flowTask.setCategory(pd.getCategory()); flowTask.setProcDefVersion(pd.getVersion()); + if (MapUtils.isNotEmpty(hisIns.getProcessVariables()) + && hisIns.getProcessVariables().containsKey("submitDate") + && StringUtils.isNotBlank(MapUtils.getString(hisIns.getProcessVariables(), "submitDate"))) { + String submitDate = MapUtils.getString(hisIns.getProcessVariables(), "submitDate"); + flowTask.setCreateTime(DateUtil.parse(submitDate)); + } // 当前所处流程 todo: 本地启动放开以下注释 // List taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).list(); // if (CollectionUtils.isNotEmpty(taskList)) { @@ -456,7 +482,7 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask flowList.add(flowTask); } page.setRecords(flowList); - return AjaxResult.success(page); + return page; } /** @@ -889,6 +915,19 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask } } + @Override + public AjaxResult updateVariablesSubmitDate(String processInstanceId, String submitDate) { + if (StringUtils.isBlank(processInstanceId) || StringUtils.isBlank(submitDate)) { + return AjaxResult.error("更新提交时间失败,参数无效"); + } + Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).variableExists("submitDate").singleResult(); + if (Objects.isNull(execution)) { + return AjaxResult.error("更新提交时间失败,查询错误"); + } + runtimeService.setVariable(execution.getId(),"submitDate",submitDate); + return AjaxResult.success(); + } + /** * 获取下一节点 * @@ -986,4 +1025,4 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask return 0 + "秒"; } } -} \ No newline at end of file +}