fix: 修复部门负责人视角切换后任务卡片显示问题

This commit is contained in:
Your Name 2026-01-08 17:13:12 +08:00
parent 249b03cf99
commit 4d69910851
3 changed files with 112 additions and 61 deletions

View File

@ -58,13 +58,14 @@ public class TaskController {
public Result<IPage<Task>> getTaskList(
@Parameter(description = "任务状态") @RequestParam(required = false) String status,
@Parameter(description = "任务类型ID") @RequestParam(required = false) Long taskTypeId,
@Parameter(description = "发布者部门ID") @RequestParam(required = false) Long publisherDeptId,
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer pageSize) {
log.info("查询任务列表: status={}, taskTypeId={}, page={}, pageSize={}",
status, taskTypeId, page, pageSize);
log.info("查询任务列表: status={}, taskTypeId={}, publisherDeptId={}, page={}, pageSize={}",
status, taskTypeId, publisherDeptId, page, pageSize);
IPage<Task> taskPage = taskService.getTaskList(page, pageSize, status, taskTypeId);
IPage<Task> taskPage = taskService.getTaskList(page, pageSize, status, taskTypeId, publisherDeptId);
return Result.success(taskPage);
}
@ -174,15 +175,16 @@ public class TaskController {
@Parameter(description = "每页数量") @RequestParam(defaultValue = "12") Integer pageSize,
@Parameter(description = "关键词") @RequestParam(required = false) String keyword,
@Parameter(description = "排序方式") @RequestParam(required = false) String sortBy,
@Parameter(description = "发布者部门ID") @RequestParam(required = false) Long publisherDeptId,
@RequestHeader("Authorization") String authHeader) {
log.info("查询已完成任务: page={}, pageSize={}, keyword={}, sortBy={}",
page, pageSize, keyword, sortBy);
log.info("查询已完成任务: page={}, pageSize={}, keyword={}, sortBy={}, publisherDeptId={}",
page, pageSize, keyword, sortBy, publisherDeptId);
String token = jwtUtil.extractTokenFromHeader(authHeader);
Long userId = jwtUtil.getUserIdFromToken(token);
IPage<Task> taskPage = taskService.getCompletedTasks(page, pageSize, userId, keyword, sortBy);
IPage<Task> taskPage = taskService.getCompletedTasks(page, pageSize, userId, keyword, sortBy, publisherDeptId);
return Result.success(taskPage);
}

View File

@ -577,7 +577,7 @@ public class TaskService {
/**
* 获取任务列表
*/
public IPage<Task> getTaskList(Integer page, Integer pageSize, String status, Long taskTypeId) {
public IPage<Task> getTaskList(Integer page, Integer pageSize, String status, Long taskTypeId, Long publisherDeptId) {
Page<Task> pageParam = new Page<>(page, pageSize);
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
@ -591,6 +591,11 @@ public class TaskService {
wrapper.eq(Task::getTaskTypeId, taskTypeId);
}
// 根据发布者部门筛选(部门负责人视角切换时使用)
if (publisherDeptId != null) {
wrapper.eq(Task::getPublisherDeptId, publisherDeptId);
}
// 按更新时间倒序
wrapper.orderByDesc(Task::getUpdateTime);
@ -708,7 +713,7 @@ public class TaskService {
* - 管理员:看所有已完成任务
*/
public IPage<Task> getCompletedTasks(Integer page, Integer pageSize,
Long userId, String keyword, String sortBy) {
Long userId, String keyword, String sortBy, Long publisherDeptId) {
// 1. 获取用户信息和角色
User user = userService.getUserById(userId);
if (user == null) {
@ -734,8 +739,13 @@ public class TaskService {
// 状态必须是已完成
wrapper.eq(Task::getStatus, "completed");
// 3. 根据角色筛选数据范围
if (isAdmin) {
// 3. 如果指定了 publisherDeptId(部门负责人视角切换),优先使用
if (publisherDeptId != null) {
wrapper.eq(Task::getPublisherDeptId, publisherDeptId);
log.info("按发布者部门筛选已完成任务: publisherDeptId={}", publisherDeptId);
}
// 根据角色筛选数据范围
else if (isAdmin) {
// 管理员:查看所有
log.info("管理员查看所有已完成任务");
} else if (isDeptHead) {

View File

@ -12,7 +12,8 @@
<a-select
v-if="managedDepartments.length > 0"
v-model:value="currentDeptView"
style="width: 180px; margin-right: 12px;"
style="width: 140px; margin-right: 8px;"
size="middle"
@change="handleDeptViewChange"
>
<a-select-option :value="undefined">
@ -27,10 +28,11 @@
placeholder="选择月份"
format="YYYY-MM"
@change="handleMonthChange"
style="width: 150px; margin-right: 12px;"
style="width: 120px; margin-right: 8px;"
size="middle"
/>
<a-button type="primary" size="large" @click="handleCreateTask">
<Icon name="plus" size="sm" style="margin-right: 6px;" />
<a-button type="primary" size="middle" @click="handleCreateTask">
<Icon name="plus" size="xs" style="margin-right: 4px;" />
发起任务
</a-button>
</div>
@ -3069,7 +3071,36 @@ const loadCompletedTasks = async () => {
let allTasks: any[] = []
let totalCount = 0
if (isAdmin) {
// 优先判断是否是部门负责人切换视角
if (isDeptLeader && currentDeptView.value !== undefined) {
// 部门负责人切换到其他部门视角
console.log('已完成任务 - 部门负责人视角切换,部门ID:', currentDeptView.value, '部门类型:', currentDeptType)
if (currentDeptType === 'receiving') {
// 接单部门视角:看该部门成员完成的子任务
const response = await taskApi.getCompletedTaskItems(params)
if (response.data && response.data.records) {
allTasks = response.data.records.map((item: any) => ({
...mapTaskItemToTask(item),
status: 'completed'
}))
totalCount = response.data.total || 0
}
} else {
// 需求部门视角:看该部门发起的已完成任务
const response = await taskApi.getCompletedTasks({
...params,
publisherDeptId: currentDeptView.value
})
if (response.data && response.data.records) {
allTasks = response.data.records.map((task: any) => ({
...task,
isSubTask: false
}))
totalCount = response.data.total || 0
}
}
} else if (isAdmin) {
// 管理员:看到所有已完成任务(母任务和子任务)
const [taskResponse, itemResponse] = await Promise.all([
taskApi.getCompletedTasks(params),
@ -3094,8 +3125,8 @@ const loadCompletedTasks = async () => {
totalCount += itemResponse.data.total || 0
}
} else if (currentDeptType === 'demand') {
// 需求部门用户:看到自己发起的已完成的母任务
const response = await taskApi.getCompletedTasks(params)
// 需求部门普通用户:看到自己发起的已完成的母任务
const response = await taskApi.getCompletedTasks(params)
if (response.data && response.data.records) {
allTasks = response.data.records.map((task: any) => ({
...task,
@ -3103,18 +3134,8 @@ const loadCompletedTasks = async () => {
}))
totalCount = response.data.total || 0
}
} else if (isDeptLeader && currentDeptView.value !== undefined) {
// 部门负责人切换到其他部门视角:只看该部门的已完成子任务
const response = await taskApi.getCompletedTaskItems(params)
if (response.data && response.data.records) {
allTasks = response.data.records.map((item: any) => ({
...mapTaskItemToTask(item),
status: 'completed'
}))
totalCount = response.data.total || 0
}
} else {
// 接单部门用户:看到自己完成的子任务
// 接单部门普通用户:看到自己完成的子任务
const response = await taskApi.getCompletedTaskItems(params)
if (response.data && response.data.records) {
allTasks = response.data.records.map((item: any) => ({
@ -3967,32 +3988,64 @@ const loadInProgressTasks = async () => {
let totalCount = 0
// 根据部门类型决定加载哪些任务
if (isAdmin) {
// 优先判断是否是部门负责人切换视角
if (isDeptLeader && currentDeptView.value !== undefined) {
// 部门负责人切换到其他部门视角
console.log('部门负责人视角切换,部门ID:', currentDeptView.value, '部门类型:', currentDeptType)
if (currentDeptType === 'receiving') {
// 接单部门视角:看该部门成员的子任务
const itemResponse = await taskApi.getInProgressTaskItems(params)
if (itemResponse.data && itemResponse.data.records) {
const items = itemResponse.data.records.map((item: any) => mapTaskItemToTask(item))
allTasks = [...allTasks, ...items]
totalCount += itemResponse.data.total || 0
}
} else {
// 需求部门视角:看该部门发起的任务(通过 deptId 参数)
const taskResponse = await taskApi.getTasks({
...params,
publisherDeptId: currentDeptView.value // 按发布者部门过滤
})
if (taskResponse.data && taskResponse.data.records) {
const tasksWithInProgress = taskResponse.data.records.filter((task: any) => {
if (task.isPipeline === 1) {
return (task.subTaskInProgress || 0) > 0 || task.status === 'in_progress'
}
return task.status === 'in_progress'
})
allTasks = tasksWithInProgress.map((task: any) => ({
...task,
isSubTask: false
}))
totalCount = allTasks.length
}
}
} else if (isAdmin) {
// 管理员:看到所有任务(母任务和子任务)
const [taskResponse, itemResponse] = await Promise.all([
taskApi.getTasks(params),
taskApi.getInProgressTaskItems(params)
])
const [taskResponse, itemResponse] = await Promise.all([
taskApi.getTasks(params),
taskApi.getInProgressTaskItems(params)
])
// 处理普通任务
if (taskResponse.data && taskResponse.data.records) {
const tasks = taskResponse.data.records.map((task: any) => ({
...task,
// 处理普通任务
if (taskResponse.data && taskResponse.data.records) {
const tasks = taskResponse.data.records.map((task: any) => ({
...task,
isSubTask: false
}))
allTasks = [...allTasks, ...tasks]
totalCount += taskResponse.data.total || 0
}
}))
allTasks = [...allTasks, ...tasks]
totalCount += taskResponse.data.total || 0
}
// 处理子任务
if (itemResponse.data && itemResponse.data.records) {
// 处理子任务
if (itemResponse.data && itemResponse.data.records) {
const items = itemResponse.data.records.map((item: any) => mapTaskItemToTask(item))
allTasks = [...allTasks, ...items]
totalCount += itemResponse.data.total || 0
allTasks = [...allTasks, ...items]
totalCount += itemResponse.data.total || 0
}
} else if (currentDeptType === 'demand') {
// 需求部门用户:看自己发起的任务中有子任务在进行中的
// 调用 getMyTasks 获取自己发起的所有任务(包含子任务进度信息)
// 需求部门普通用户:看自己发起的任务中有子任务在进行中的
const taskResponse = await taskApi.getMyTasks({
role: 'publisher',
page: inProgressPagination.page,
@ -4000,32 +4053,18 @@ const loadInProgressTasks = async () => {
keyword: inProgressFilters.keyword
})
if (taskResponse.code === 200 && taskResponse.data && taskResponse.data.records) {
// 过滤出有子任务在进行中的任务
const tasksWithInProgress = taskResponse.data.records.filter((task: any) => {
// 流水线任务:检查是否有子任务在进行中
if (task.isPipeline === 1) {
return (task.subTaskInProgress || 0) > 0 || task.status === 'in_progress'
}
// 普通任务:状态为进行中
return task.status === 'in_progress'
})
allTasks = tasksWithInProgress.map((task: any) => ({
...task,
isSubTask: false
}))
// 由于是前端过滤,total 用过滤后的数量
totalCount = allTasks.length
}
} else if (isDeptLeader && currentDeptView.value !== undefined) {
// 部门负责人切换到其他部门视角:只看该部门的子任务
console.log('部门负责人视角切换,获取部门任务:', currentDeptView.value)
const itemResponse = await taskApi.getInProgressTaskItems(params)
if (itemResponse.data && itemResponse.data.records) {
const items = itemResponse.data.records.map((item: any) => mapTaskItemToTask(item))
allTasks = [...allTasks, ...items]
totalCount += itemResponse.data.total || 0
}
} else {
// 接单部门用户(设计师):看子任务卡片 + 直接分配给自己的普通任务
const [itemResponse, taskResponse] = await Promise.all([