fix: 修复需求部门进行中任务列表与顶部统计数量不一致

1. 后端新增 excludeStatuses 参数,支持排除指定状态查询
2. 前端需求部门负责人视角使用 excludeStatuses 排除 draft/completed/cancelled
3. 使用后端返回的 total 作为分页总数,确保分页正确
This commit is contained in:
Your Name 2026-01-16 16:00:32 +08:00
parent 0818db76b2
commit 130e0afcb2
3 changed files with 34 additions and 13 deletions

View File

@ -65,11 +65,12 @@ public class TaskController {
@Parameter(description = "发布者部门ID") @RequestParam(required = false) Long publisherDeptId,
@Parameter(description = "发布者部门ID列表(逗号分隔)") @RequestParam(required = false) String publisherDeptIds,
@Parameter(description = "接收部门ID") @RequestParam(required = false) Long receiverDeptId,
@Parameter(description = "排除的状态列表(逗号分隔,如 draft,completed,cancelled)") @RequestParam(required = false) String excludeStatuses,
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer pageSize) {
log.info("查询任务列表: status={}, taskTypeId={}, publisherDeptId={}, publisherDeptIds={}, receiverDeptId={}, page={}, pageSize={}",
status, taskTypeId, publisherDeptId, publisherDeptIds, receiverDeptId, page, pageSize);
log.info("查询任务列表: status={}, taskTypeId={}, publisherDeptId={}, publisherDeptIds={}, receiverDeptId={}, excludeStatuses={}, page={}, pageSize={}",
status, taskTypeId, publisherDeptId, publisherDeptIds, receiverDeptId, excludeStatuses, page, pageSize);
// 处理多个发布者部门ID
List<Long> publisherDeptIdList = null;
@ -81,7 +82,16 @@ public class TaskController {
.collect(Collectors.toList());
}
IPage<Task> taskPage = taskService.getTaskList(page, pageSize, status, taskTypeId, publisherDeptId, publisherDeptIdList, receiverDeptId);
// 处理排除状态列表
List<String> excludeStatusList = null;
if (excludeStatuses != null && !excludeStatuses.isEmpty()) {
excludeStatusList = Arrays.stream(excludeStatuses.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
}
IPage<Task> taskPage = taskService.getTaskList(page, pageSize, status, taskTypeId, publisherDeptId, publisherDeptIdList, receiverDeptId, excludeStatusList);
return Result.success(taskPage);
}

View File

@ -707,6 +707,14 @@ public class TaskService {
* 获取任务列表
*/
public IPage<Task> getTaskList(Integer page, Integer pageSize, String status, Long taskTypeId, Long publisherDeptId, List<Long> publisherDeptIds, Long receiverDeptId) {
return getTaskList(page, pageSize, status, taskTypeId, publisherDeptId, publisherDeptIds, receiverDeptId, null);
}
/**
* 获取任务列表(支持排除指定状态)
* @param excludeStatuses 要排除的状态列表(如 draft,completed,cancelled)
*/
public IPage<Task> getTaskList(Integer page, Integer pageSize, String status, Long taskTypeId, Long publisherDeptId, List<Long> publisherDeptIds, Long receiverDeptId, List<String> excludeStatuses) {
Page<Task> pageParam = new Page<>(page, pageSize);
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
@ -715,6 +723,12 @@ public class TaskService {
wrapper.eq(Task::getStatus, status);
}
// 🔥 排除指定状态(需求部门负责人查看"处理中"任务时使用)
if (excludeStatuses != null && !excludeStatuses.isEmpty()) {
wrapper.notIn(Task::getStatus, excludeStatuses);
log.info("排除状态: excludeStatuses={}", excludeStatuses);
}
// 根据任务类型筛选
if (taskTypeId != null) {
wrapper.eq(Task::getTaskTypeId, taskTypeId);

View File

@ -4521,24 +4521,21 @@ const loadInProgressTasks = async () => {
console.log('需求部门负责人查询的部门ID列表:', demandDeptIds)
// 需求部门负责人:不传递status参数,查询所有非草稿的任务
// 需求部门负责人:查询所有处理中的任务(排除 draft、completed、cancelled)
const { status: _, ...paramsWithoutStatus } = params
const taskResponse = await taskApi.getTasks({
...paramsWithoutStatus,
publisherDeptIds: demandDeptIds.join(',') // 按多个发布者部门过滤
publisherDeptIds: demandDeptIds.join(','), // 按多个发布者部门过滤
excludeStatuses: 'draft,completed,cancelled' // 🔥 后端排除指定状态
})
if (taskResponse.data && taskResponse.data.records) {
// 需求部门负责人:显示所有已发布且未完成的任务(pending、in_progress、review等)
const tasksWithInProgress = taskResponse.data.records.filter((task: any) => {
// 排除草稿和已完成的任务
const excludeStatuses = ['draft', 'completed', 'cancelled']
return !excludeStatuses.includes(task.status)
})
allTasks = tasksWithInProgress.map((task: any) => ({
// 需求部门负责人:显示所有处理中的任务(后端已过滤)
allTasks = taskResponse.data.records.map((task: any) => ({
...task,
isSubTask: false
}))
totalCount = allTasks.length
// 🔥 使用后端返回的总数,确保分页正确
totalCount = taskResponse.data.total || allTasks.length
}
}
}