fix: 子任务列表支持品牌、类目、平台等筛选条件

- 后端TaskItemController添加brandId/categoryId/platformId/taskSubType参数
- 后端TaskItemMapper添加selectAvailableItemsWithFilters方法
- 前端task.ts更新getAvailableTaskItems参数类型
This commit is contained in:
Your Name 2026-01-30 14:56:16 +08:00
parent d9d8663823
commit 4c28716ab5
4 changed files with 103 additions and 4 deletions

View File

@ -57,9 +57,13 @@ public class TaskItemController {
@Parameter(description = "搜索关键词") @RequestParam(required = false) String keyword,
@Parameter(description = "筛选可接单部门ID") @RequestParam(required = false) Long filterDeptId,
@Parameter(description = "排序方式: oldest(最早优先)/latest(最新优先,默认)") @RequestParam(defaultValue = "latest") String sortBy,
@Parameter(description = "是否包含排队中的任务") @RequestParam(defaultValue = "true") Boolean includeQueuing) {
@Parameter(description = "是否包含排队中的任务") @RequestParam(defaultValue = "true") Boolean includeQueuing,
@Parameter(description = "品牌ID") @RequestParam(required = false) Long brandId,
@Parameter(description = "类目ID") @RequestParam(required = false) Long categoryId,
@Parameter(description = "平台ID") @RequestParam(required = false) Long platformId,
@Parameter(description = "需求类型") @RequestParam(required = false) String taskSubType) {
IPage<TaskItem> items = taskItemService.getAvailableItems(page, pageSize, taskTypeId, keyword, filterDeptId, sortBy, includeQueuing);
IPage<TaskItem> items = taskItemService.getAvailableItems(page, pageSize, taskTypeId, keyword, filterDeptId, sortBy, includeQueuing, brandId, categoryId, platformId, taskSubType);
return Result.success(items);
}

View File

@ -141,6 +141,79 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
@Param("keyword") String keyword,
@Param("allowedTaskTypeIds") List<Long> allowedTaskTypeIds);
/**
* 查询可接单的子任务列表(完整筛选版本,支持品牌、类目、平台等筛选)
*/
@Select("<script>" +
"SELECT ti.*, " +
" t.title AS mainTaskTitle, " +
" t.pipeline_mode AS pipelineMode, " +
" t.brand_id, " +
" t.category_id, " +
" t.platform_id, " +
" t.spu_info AS spuInfo, " +
" t.task_sub_type AS taskSubType, " +
" t.attachment_url AS attachmentUrl, " +
" t.preview_image AS previewImage, " +
" t.is_primary_task AS isPrimaryTask, " +
" u.real_name AS publisherName, " +
" pp.real_name AS primaryPublisherName, " +
" ppd.dept_name AS primaryPublisherDeptName, " +
" dc.real_name AS detailCompleterName, " +
" b.brand_name AS brandName, " +
" c.category_name AS categoryName, " +
" p.platform_name AS platformName, " +
" dt.type_name AS taskTypeName, " +
" (SELECT COUNT(*) FROM task_item WHERE task_id = ti.task_id) AS totalItems " +
"FROM task_item ti " +
"LEFT JOIN task t ON ti.task_id = t.id " +
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
"LEFT JOIN sys_user pp ON t.primary_publisher_id = pp.id " +
"LEFT JOIN sys_dept ppd ON t.primary_publisher_dept_id = ppd.id " +
"LEFT JOIN sys_user dc ON t.detail_completer_id = dc.id " +
"LEFT JOIN brand b ON t.brand_id = b.id " +
"LEFT JOIN category c ON t.category_id = c.id " +
"LEFT JOIN platform p ON t.platform_id = p.id " +
"LEFT JOIN task_type dt ON ti.task_type_id = dt.id " +
"WHERE ti.status = 'pending' AND ti.is_locked = 0 AND t.deleted = 0 AND t.approval_status = 'approved' " +
"<if test='taskTypeId != null'> AND ti.task_type_id = #{taskTypeId}</if> " +
"<if test='brandId != null'> AND t.brand_id = #{brandId}</if> " +
"<if test='categoryId != null'> AND t.category_id = #{categoryId}</if> " +
"<if test='platformId != null'> AND t.platform_id = #{platformId}</if> " +
"<if test='taskSubType != null and taskSubType != \"\"'> AND t.task_sub_type = #{taskSubType}</if> " +
"<if test='keyword != null and keyword != \"\"'> " +
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
" OR t.task_no LIKE CONCAT('%', #{keyword}, '%') " +
" OR ti.item_no LIKE CONCAT('%', #{keyword}, '%') " +
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(t.remark, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(t.product_barcodes, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(pp.real_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(ppd.dept_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(dc.real_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(b.brand_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(c.category_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(p.platform_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
" OR COALESCE(dt.type_name, '') LIKE CONCAT('%', #{keyword}, '%'))" +
"</if> " +
"<if test='allowedTaskTypeIds != null and allowedTaskTypeIds.size() > 0'> " +
" AND ti.task_type_id IN " +
" <foreach collection='allowedTaskTypeIds' item='typeId' open='(' separator=',' close=')'>" +
" #{typeId}" +
" </foreach> " +
"</if> " +
"ORDER BY ti.create_time DESC" +
"</script>")
IPage<TaskItem> selectAvailableItemsWithFilters(Page<TaskItem> page,
@Param("taskTypeId") Long taskTypeId,
@Param("keyword") String keyword,
@Param("brandId") Long brandId,
@Param("categoryId") Long categoryId,
@Param("platformId") Long platformId,
@Param("taskSubType") String taskSubType,
@Param("allowedTaskTypeIds") List<Long> allowedTaskTypeIds);
/**
* 查询进行中的子任务列表
* @param receiverId 接单人ID,null表示不按接单人过滤

View File

@ -73,12 +73,28 @@ public class TaskItemService {
*/
public IPage<TaskItem> getAvailableItems(Integer page, Integer pageSize, Long taskTypeId, String keyword,
Long filterDeptId, String sortBy, Boolean includeQueuing) {
return getAvailableItems(page, pageSize, taskTypeId, keyword, filterDeptId, sortBy, includeQueuing, null, null, null, null);
}
/**
* 获取可接单的子任务列表(完整版,支持所有筛选条件)
* @param filterDeptId 筛选可接单部门ID(可选)
* @param sortBy 排序方式:oldest(最早优先) / latest(最新优先,默认)
* @param includeQueuing 是否包含排队中的任务
* @param brandId 品牌ID筛选
* @param categoryId 类目ID筛选
* @param platformId 平台ID筛选
* @param taskSubType 需求类型筛选
*/
public IPage<TaskItem> getAvailableItems(Integer page, Integer pageSize, Long taskTypeId, String keyword,
Long filterDeptId, String sortBy, Boolean includeQueuing,
Long brandId, Long categoryId, Long platformId, String taskSubType) {
Page<TaskItem> pageParam = new Page<>(page, pageSize);
IPage<TaskItem> result;
// 如果没有指定筛选部门,直接查询
if (filterDeptId == null) {
result = taskItemMapper.selectAvailableItems(pageParam, taskTypeId, keyword);
result = taskItemMapper.selectAvailableItemsWithFilters(pageParam, taskTypeId, keyword, brandId, categoryId, platformId, taskSubType, null);
} else {
// 🔥 获取筛选部门及其所有子部门的ID列表
Set<Long> filterDeptAndChildIds = getDeptAndChildIds(filterDeptId);
@ -127,7 +143,7 @@ public class TaskItemService {
}
// 查询并筛选
result = taskItemMapper.selectAvailableItemsByTaskTypes(pageParam, taskTypeId, keyword, filterDeptAllowedTypeIds);
result = taskItemMapper.selectAvailableItemsWithFilters(pageParam, taskTypeId, keyword, brandId, categoryId, platformId, taskSubType, filterDeptAllowedTypeIds);
}
// 🔥 填充排队状态信息

View File

@ -418,6 +418,12 @@ export const getAvailableTaskItems = (params: {
pageSize?: number
taskTypeId?: number
keyword?: string
brandId?: number
categoryId?: number
platformId?: number
taskSubType?: string
filterDeptId?: number
sortBy?: string
}) => {
return request.get<any>('/tasks/items/available', { params })
}