fix: 待办任务只查询当前用户所属任务

rf
tony 2022-12-26 11:38:34 +08:00
parent 59935dd2f2
commit 8c393c4f44
5 changed files with 95 additions and 40 deletions

View File

@ -2,6 +2,7 @@ package com.ruoyi.flowable.controller;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.flowable.domain.dto.FlowTaskDto; import com.ruoyi.flowable.domain.dto.FlowTaskDto;
import com.ruoyi.flowable.domain.vo.FlowQueryVo;
import com.ruoyi.flowable.domain.vo.FlowTaskVo; import com.ruoyi.flowable.domain.vo.FlowTaskVo;
import com.ruoyi.flowable.service.IFlowTaskService; import com.ruoyi.flowable.service.IFlowTaskService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -35,9 +36,8 @@ public class FlowTaskController {
@ApiOperation(value = "我发起的流程", response = FlowTaskDto.class) @ApiOperation(value = "我发起的流程", response = FlowTaskDto.class)
@GetMapping(value = "/myProcess") @GetMapping(value = "/myProcess")
public AjaxResult myProcess(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum, public AjaxResult myProcess(FlowQueryVo queryVo) {
@ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize) { return flowTaskService.myProcess(queryVo);
return flowTaskService.myProcess(pageNum, pageSize);
} }
@ApiOperation(value = "取消申请", response = FlowTaskDto.class) @ApiOperation(value = "取消申请", response = FlowTaskDto.class)
@ -54,16 +54,14 @@ public class FlowTaskController {
@ApiOperation(value = "获取待办列表", response = FlowTaskDto.class) @ApiOperation(value = "获取待办列表", response = FlowTaskDto.class)
@GetMapping(value = "/todoList") @GetMapping(value = "/todoList")
public AjaxResult todoList(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum, public AjaxResult todoList(FlowQueryVo queryVo) {
@ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize) { return flowTaskService.todoList(queryVo);
return flowTaskService.todoList(pageNum, pageSize);
} }
@ApiOperation(value = "获取已办任务", response = FlowTaskDto.class) @ApiOperation(value = "获取已办任务", response = FlowTaskDto.class)
@GetMapping(value = "/finishedList") @GetMapping(value = "/finishedList")
public AjaxResult finishedList(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum, public AjaxResult finishedList(FlowQueryVo queryVo) {
@ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize) { return flowTaskService.finishedList(queryVo);
return flowTaskService.finishedList(pageNum, pageSize);
} }

View File

@ -0,0 +1,36 @@
package com.ruoyi.flowable.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* <p><p>
*
* @author XuanXuan
* @date 2021-04-03
*/
@Data
@ApiModel("工作流任务相关--请求参数")
public class FlowQueryVo {
@ApiModelProperty("流程名称")
private String name;
@ApiModelProperty("开始时间")
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
@ApiModelProperty("当前页码")
private Integer pageNum;
@ApiModelProperty("每页条数")
private Integer pageSize;
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.flowable.service; package com.ruoyi.flowable.service;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.flowable.domain.vo.FlowQueryVo;
import com.ruoyi.flowable.domain.vo.FlowTaskVo; import com.ruoyi.flowable.domain.vo.FlowTaskVo;
import org.flowable.task.api.Task; import org.flowable.task.api.Task;
@ -81,11 +82,10 @@ public interface IFlowTaskService {
/** /**
* *
* @param pageNum * @param queryVo
* @param pageSize
* @return * @return
*/ */
AjaxResult myProcess(Integer pageNum, Integer pageSize); AjaxResult myProcess(FlowQueryVo queryVo);
/** /**
* *
@ -105,21 +105,19 @@ public interface IFlowTaskService {
/** /**
* *
* *
* @param pageNum * @param queryVo
* @param pageSize
* @return * @return
*/ */
AjaxResult todoList(Integer pageNum, Integer pageSize); AjaxResult todoList(FlowQueryVo queryVo);
/** /**
* *
* *
* @param pageNum * @param queryVo
* @param pageSize
* @return * @return
*/ */
AjaxResult finishedList(Integer pageNum, Integer pageSize); AjaxResult finishedList(FlowQueryVo queryVo);
/** /**
* *

View File

@ -18,6 +18,7 @@ import com.ruoyi.flowable.domain.dto.FlowCommentDto;
import com.ruoyi.flowable.domain.dto.FlowNextDto; import com.ruoyi.flowable.domain.dto.FlowNextDto;
import com.ruoyi.flowable.domain.dto.FlowTaskDto; import com.ruoyi.flowable.domain.dto.FlowTaskDto;
import com.ruoyi.flowable.domain.dto.FlowViewerDto; import com.ruoyi.flowable.domain.dto.FlowViewerDto;
import com.ruoyi.flowable.domain.vo.FlowQueryVo;
import com.ruoyi.flowable.domain.vo.FlowTaskVo; import com.ruoyi.flowable.domain.vo.FlowTaskVo;
import com.ruoyi.flowable.factory.FlowServiceFactory; import com.ruoyi.flowable.factory.FlowServiceFactory;
import com.ruoyi.flowable.flow.CustomProcessDiagramGenerator; import com.ruoyi.flowable.flow.CustomProcessDiagramGenerator;
@ -459,19 +460,18 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
/** /**
* *
* *
* @param pageNum * @param queryVo
* @param pageSize
* @return * @return
*/ */
@Override @Override
public AjaxResult myProcess(Integer pageNum, Integer pageSize) { public AjaxResult myProcess(FlowQueryVo queryVo) {
Page<FlowTaskDto> page = new Page<>(); Page<FlowTaskDto> page = new Page<>();
Long userId = SecurityUtils.getLoginUser().getUser().getUserId(); Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery() HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery()
.startedBy(userId.toString()) .startedBy(userId.toString())
.orderByProcessInstanceStartTime() .orderByProcessInstanceStartTime()
.desc(); .desc();
List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.listPage(pageSize * (pageNum - 1), pageSize); List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.listPage(queryVo.getPageSize() * (queryVo.getPageNum() - 1), queryVo.getPageSize());
page.setTotal(historicProcessInstanceQuery.count()); page.setTotal(historicProcessInstanceQuery.count());
List<FlowTaskDto> flowList = new ArrayList<>(); List<FlowTaskDto> flowList = new ArrayList<>();
for (HistoricProcessInstance hisIns : historicProcessInstances) { for (HistoricProcessInstance hisIns : historicProcessInstances) {
@ -616,23 +616,27 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
/** /**
* *
* *
* @param pageNum * @param queryVo
* @param pageSize
* @return * @return
*/ */
@Override @Override
public AjaxResult todoList(Integer pageNum, Integer pageSize) { public AjaxResult todoList(FlowQueryVo queryVo) {
Page<FlowTaskDto> page = new Page<>(); Page<FlowTaskDto> page = new Page<>();
// 只查看自己的数据 // 只查看自己的数据
SysUser sysUser = SecurityUtils.getLoginUser().getUser(); SysUser sysUser = SecurityUtils.getLoginUser().getUser();
Long userId = sysUser.getUserId();
TaskQuery taskQuery = taskService.createTaskQuery() TaskQuery taskQuery = taskService.createTaskQuery()
.active() .active()
.includeProcessVariables() .includeProcessVariables()
.taskCandidateOrAssigned(userId.toString()) .taskCandidateGroupIn(sysUser.getRoles().stream().map(role -> role.getRoleId().toString()).collect(Collectors.toList()))
.taskCandidateOrAssigned(sysUser.getUserId().toString())
.orderByTaskCreateTime().desc(); .orderByTaskCreateTime().desc();
// TODO 传入名称查询不到数据?
// if (StringUtils.isNotBlank(queryVo.getName())){
// taskQuery.processDefinitionNameLike(queryVo.getName());
// }
page.setTotal(taskQuery.count()); page.setTotal(taskQuery.count());
List<Task> taskList = taskQuery.listPage(pageSize * (pageNum - 1), pageSize); List<Task> taskList = taskQuery.listPage(queryVo.getPageSize() * (queryVo.getPageNum() - 1), queryVo.getPageSize());
List<FlowTaskDto> flowList = new ArrayList<>(); List<FlowTaskDto> flowList = new ArrayList<>();
for (Task task : taskList) { for (Task task : taskList) {
FlowTaskDto flowTask = new FlowTaskDto(); FlowTaskDto flowTask = new FlowTaskDto();
@ -671,12 +675,11 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
/** /**
* *
* *
* @param pageNum * @param queryVo
* @param pageSize
* @return * @return
*/ */
@Override @Override
public AjaxResult finishedList(Integer pageNum, Integer pageSize) { public AjaxResult finishedList(FlowQueryVo queryVo) {
Page<FlowTaskDto> page = new Page<>(); Page<FlowTaskDto> page = new Page<>();
Long userId = SecurityUtils.getLoginUser().getUser().getUserId(); Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery() HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
@ -685,7 +688,7 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
.taskAssignee(userId.toString()) .taskAssignee(userId.toString())
.orderByHistoricTaskInstanceEndTime() .orderByHistoricTaskInstanceEndTime()
.desc(); .desc();
List<HistoricTaskInstance> historicTaskInstanceList = taskInstanceQuery.listPage(pageSize * (pageNum - 1), pageSize); List<HistoricTaskInstance> historicTaskInstanceList = taskInstanceQuery.listPage(queryVo.getPageSize() * (queryVo.getPageNum() - 1), queryVo.getPageSize());
List<FlowTaskDto> hisTaskList = new ArrayList<>(); List<FlowTaskDto> hisTaskList = new ArrayList<>();
for (HistoricTaskInstance histTask : historicTaskInstanceList) { for (HistoricTaskInstance histTask : historicTaskInstanceList) {
FlowTaskDto flowTask = new FlowTaskDto(); FlowTaskDto flowTask = new FlowTaskDto();
@ -721,9 +724,6 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
} }
page.setTotal(taskInstanceQuery.count()); page.setTotal(taskInstanceQuery.count());
page.setRecords(hisTaskList); page.setRecords(hisTaskList);
// Map<String, Object> result = new HashMap<>();
// result.put("result",page);
// result.put("finished",true);
return AjaxResult.success(page); return AjaxResult.success(page);
} }
@ -1091,7 +1091,7 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
@Override @Override
public AjaxResult flowTaskForm(String taskId) throws Exception { public AjaxResult flowTaskForm(String taskId) throws Exception {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("formKeyExist",false); result.put("formKeyExist", false);
Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId()); BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
@ -1122,15 +1122,15 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask
oldVariables.put("fields", oldFields); oldVariables.put("fields", oldFields);
oldVariables.put("disabled", false); oldVariables.put("disabled", false);
oldVariables.put("formBtns", true); oldVariables.put("formBtns", true);
result.put("formData",oldVariables); result.put("formData", oldVariables);
result.put("formKeyExist",true); result.put("formKeyExist", true);
return AjaxResult.success("", result); return AjaxResult.success("", result);
} else { } else {
result.put("formData",parameters.get("variables")); result.put("formData", parameters.get("variables"));
return AjaxResult.success("", result); return AjaxResult.success("", result);
} }
} else { } else {
result.put("formData",parameters.get("variables")); result.put("formData", parameters.get("variables"));
return AjaxResult.success("", result); return AjaxResult.success("", result);
} }
} }

View File

@ -0,0 +1,23 @@
//package com.ruoyi.framework.config;
//
//import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
//import com.ruoyi.common.utils.DateUtils;
//import org.apache.commons.lang3.StringUtils;
//
//import java.util.Date;
//
///**
// * 自定义 p6spy sql输出格式
// *
// */
//public class P6spySqlFormatConfig implements MessageFormattingStrategy {
//
// /**
// * 过滤掉定时任务的 SQL
// */
// @Override
// public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
// return StringUtils.isNotBlank(sql) ? DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date())
// + " | 耗时 " + elapsed + " ms | SQL 语句:" + StringUtils.LF + sql.replaceAll("[\\s]+", StringUtils.SPACE) + ";" : "";
// }
//}