fix: 修复可接任务筛选接单部门时子任务未正确过滤的问题
1. TaskItemController 增加 filterDeptId 参数 2. TaskItemService 增加按接单部门筛选逻辑 3. TaskItemMapper 增加 selectAvailableItemsByTaskTypes 方法
This commit is contained in:
parent
b845cf52a5
commit
ff371a6665
@ -53,9 +53,10 @@ public class TaskItemController {
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@Parameter(description = "任务类型ID") @RequestParam(required = false) Long taskTypeId,
|
||||
@Parameter(description = "搜索关键词") @RequestParam(required = false) String keyword) {
|
||||
@Parameter(description = "搜索关键词") @RequestParam(required = false) String keyword,
|
||||
@Parameter(description = "筛选可接单部门ID") @RequestParam(required = false) Long filterDeptId) {
|
||||
|
||||
IPage<TaskItem> items = taskItemService.getAvailableItems(page, pageSize, taskTypeId, keyword);
|
||||
IPage<TaskItem> items = taskItemService.getAvailableItems(page, pageSize, taskTypeId, keyword, filterDeptId);
|
||||
return Result.success(items);
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,55 @@ public interface TaskItemMapper extends BaseMapper<TaskItem> {
|
||||
@Param("taskTypeId") Long taskTypeId,
|
||||
@Param("keyword") String keyword);
|
||||
|
||||
/**
|
||||
* 查询可接单的子任务列表(按任务类型ID列表筛选,用于接单部门筛选功能)
|
||||
*/
|
||||
@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, " +
|
||||
" u.real_name AS publisherName, " +
|
||||
" 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 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='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 u.real_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> selectAvailableItemsByTaskTypes(Page<TaskItem> page,
|
||||
@Param("taskTypeId") Long taskTypeId,
|
||||
@Param("keyword") String keyword,
|
||||
@Param("allowedTaskTypeIds") List<Long> allowedTaskTypeIds);
|
||||
|
||||
/**
|
||||
* 查询进行中的子任务列表
|
||||
* @param receiverId 接单人ID,null表示不按接单人过滤
|
||||
|
||||
@ -50,8 +50,57 @@ public class TaskItemService {
|
||||
* 获取可接单的子任务列表
|
||||
*/
|
||||
public IPage<TaskItem> getAvailableItems(Integer page, Integer pageSize, Long taskTypeId, String keyword) {
|
||||
return getAvailableItems(page, pageSize, taskTypeId, keyword, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可接单的子任务列表(支持按接单部门筛选)
|
||||
* @param filterDeptId 筛选可接单部门ID(可选)
|
||||
*/
|
||||
public IPage<TaskItem> getAvailableItems(Integer page, Integer pageSize, Long taskTypeId, String keyword, Long filterDeptId) {
|
||||
Page<TaskItem> pageParam = new Page<>(page, pageSize);
|
||||
return taskItemMapper.selectAvailableItems(pageParam, taskTypeId, keyword);
|
||||
|
||||
// 如果没有指定筛选部门,直接查询
|
||||
if (filterDeptId == null) {
|
||||
return taskItemMapper.selectAvailableItems(pageParam, taskTypeId, keyword);
|
||||
}
|
||||
|
||||
// 获取该部门可接单的任务类型ID列表
|
||||
List<com.designhub.entity.DemandType> allDemandTypes = demandTypeMapper.selectList(null);
|
||||
Map<Long, com.designhub.entity.DemandType> demandTypeMap = allDemandTypes.stream()
|
||||
.collect(java.util.stream.Collectors.toMap(com.designhub.entity.DemandType::getId, dt -> dt));
|
||||
|
||||
List<Long> filterDeptAllowedTypeIds = allDemandTypes.stream()
|
||||
.filter(dt -> {
|
||||
String allowedDepts = dt.getAllowedDeptIds();
|
||||
if ((allowedDepts == null || allowedDepts.isEmpty()) && dt.getParentId() != null) {
|
||||
com.designhub.entity.DemandType parentType = demandTypeMap.get(dt.getParentId());
|
||||
if (parentType != null) {
|
||||
allowedDepts = parentType.getAllowedDeptIds();
|
||||
}
|
||||
}
|
||||
// 只筛选明确指定了该部门的任务类型
|
||||
if (allowedDepts == null || allowedDepts.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String[] deptIds = allowedDepts.split(",");
|
||||
for (String deptId : deptIds) {
|
||||
if (deptId.trim().equals(String.valueOf(filterDeptId))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.map(com.designhub.entity.DemandType::getId)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
// 如果没有找到匹配的任务类型,返回空结果
|
||||
if (filterDeptAllowedTypeIds.isEmpty()) {
|
||||
return new Page<>(page, pageSize);
|
||||
}
|
||||
|
||||
// 查询并筛选
|
||||
return taskItemMapper.selectAvailableItemsByTaskTypes(pageParam, taskTypeId, keyword, filterDeptAllowedTypeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user