Your Name 9b849ccb40 feat: 优化子任务进度显示为时间线样式 + 修复需求者进行中任务显示
1. 将子任务进度从标签式改为时间线流程图样式,更直观展示任务流转进度
2. 修复需求部门用户在"进行中任务"页面看不到自己发起的任务的问题
3. 添加子任务状态辅助函数(状态类名、标签、状态文本)
4. 在MyTasksParams中添加keyword参数支持搜索
2026-01-07 15:38:59 +08:00

304 lines
14 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.designhub.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.designhub.entity.TaskItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.List;
/**
* 任务子项 Mapper 接口
*/
@Mapper
public interface TaskItemMapper extends BaseMapper<TaskItem> {
/**
* 查询可接单的子任务列表(带主任务信息)
*/
@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.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%'))" +
"</if> " +
"ORDER BY ti.create_time DESC" +
"</script>")
IPage<TaskItem> selectAvailableItems(Page<TaskItem> page,
@Param("taskTypeId") Long taskTypeId,
@Param("keyword") String keyword);
/**
* 查询进行中的子任务列表
* @param receiverId 接单人ID,null表示不按接单人过滤
* @param deptId 部门ID,用于部门负责人查看本部门所有任务
*/
@Select("<script>" +
"SELECT ti.*, " +
" t.title AS mainTaskTitle, " +
" t.pipeline_mode AS pipelineMode, " +
" t.spu_info AS spuInfo, " +
" t.task_sub_type AS taskSubType, " +
" t.attachment_url AS attachmentUrl, " +
" t.preview_image AS previewImage, " +
" b.brand_name AS brandName, " +
" c.category_name AS categoryName, " +
" p.platform_name AS platformName, " +
" dt.type_name AS taskTypeName, " +
" u.real_name AS publisherName, " +
" r.real_name AS receiverName, " +
" (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 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 " +
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
"LEFT JOIN sys_user r ON ti.receiver_id = r.id " +
"WHERE ti.status = 'in_progress' " +
" AND t.deleted = 0 " +
" <if test='receiverId != null'> AND ti.receiver_id = #{receiverId} </if>" +
" <if test='deptId != null'> AND ti.receiver_dept_id = #{deptId} </if>" +
" <if test='keyword != null and keyword != \"\"'> " +
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
" OR ti.item_no LIKE CONCAT('%', #{keyword}, '%'))" +
" </if>" +
"ORDER BY ti.update_time DESC" +
"</script>")
IPage<TaskItem> selectInProgressItems(Page<TaskItem> page,
@Param("receiverId") Long receiverId,
@Param("deptId") Long deptId,
@Param("keyword") String keyword);
/**
* 查询已完成的子任务列表
* @param receiverId 接单人ID,null表示不按接单人过滤
* @param deptId 部门ID,用于部门负责人查看本部门所有任务
* @param keyword 搜索关键词
*/
@Select("<script>" +
"SELECT ti.*, " +
" t.title AS mainTaskTitle, " +
" t.pipeline_mode AS pipelineMode, " +
" t.spu_info AS spuInfo, " +
" t.task_sub_type AS taskSubType, " +
" t.attachment_url AS attachmentUrl, " +
" t.preview_image AS previewImage, " +
" b.brand_name AS brandName, " +
" c.category_name AS categoryName, " +
" p.platform_name AS platformName, " +
" dt.type_name AS taskTypeName, " +
" u.real_name AS publisherName, " +
" r.real_name AS receiverName, " +
" (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 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 " +
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
"LEFT JOIN sys_user r ON ti.receiver_id = r.id " +
"WHERE ti.status = 'completed' " +
" AND t.deleted = 0 " +
" <if test='receiverId != null'> AND ti.receiver_id = #{receiverId} </if>" +
" <if test='deptId != null'> AND ti.receiver_dept_id = #{deptId} </if>" +
" <if test='keyword != null and keyword != \"\"'> " +
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
" OR ti.item_no LIKE CONCAT('%', #{keyword}, '%'))" +
" </if>" +
"ORDER BY ti.complete_time DESC" +
"</script>")
IPage<TaskItem> selectCompletedItems(Page<TaskItem> page,
@Param("receiverId") Long receiverId,
@Param("deptId") Long deptId,
@Param("keyword") String keyword);
/**
* 查询进行中的子任务列表(按多个部门ID过滤,用于部门负责人)
*/
@Select("<script>" +
"SELECT ti.*, " +
" t.title AS mainTaskTitle, " +
" t.pipeline_mode AS pipelineMode, " +
" t.spu_info AS spuInfo, " +
" t.task_sub_type AS taskSubType, " +
" t.attachment_url AS attachmentUrl, " +
" t.preview_image AS previewImage, " +
" b.brand_name AS brandName, " +
" c.category_name AS categoryName, " +
" p.platform_name AS platformName, " +
" dt.type_name AS taskTypeName, " +
" u.real_name AS publisherName, " +
" r.real_name AS receiverName, " +
" (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 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 " +
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
"LEFT JOIN sys_user r ON ti.receiver_id = r.id " +
"WHERE ti.status = 'in_progress' " +
" AND t.deleted = 0 " +
" AND ti.receiver_dept_id IN " +
" <foreach collection='deptIds' item='deptId' open='(' separator=',' close=')'>" +
" #{deptId}" +
" </foreach> " +
" <if test='keyword != null and keyword != \"\"'> " +
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
" OR ti.item_no LIKE CONCAT('%', #{keyword}, '%'))" +
" </if>" +
"ORDER BY ti.update_time DESC" +
"</script>")
IPage<TaskItem> selectInProgressItemsByDeptIds(Page<TaskItem> page,
@Param("deptIds") List<Long> deptIds,
@Param("keyword") String keyword);
/**
* 查询已完成的子任务列表(按多个部门ID过滤,用于部门负责人)
*/
@Select("<script>" +
"SELECT ti.*, " +
" t.title AS mainTaskTitle, " +
" t.pipeline_mode AS pipelineMode, " +
" t.spu_info AS spuInfo, " +
" t.task_sub_type AS taskSubType, " +
" t.attachment_url AS attachmentUrl, " +
" t.preview_image AS previewImage, " +
" b.brand_name AS brandName, " +
" c.category_name AS categoryName, " +
" p.platform_name AS platformName, " +
" dt.type_name AS taskTypeName, " +
" u.real_name AS publisherName, " +
" r.real_name AS receiverName, " +
" (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 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 " +
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
"LEFT JOIN sys_user r ON ti.receiver_id = r.id " +
"WHERE ti.status = 'completed' " +
" AND t.deleted = 0 " +
" AND ti.receiver_dept_id IN " +
" <foreach collection='deptIds' item='deptId' open='(' separator=',' close=')'>" +
" #{deptId}" +
" </foreach> " +
" <if test='keyword != null and keyword != \"\"'> " +
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
" OR ti.item_no LIKE CONCAT('%', #{keyword}, '%'))" +
" </if>" +
"ORDER BY ti.complete_time DESC" +
"</script>")
IPage<TaskItem> selectCompletedItemsByDeptIds(Page<TaskItem> page,
@Param("deptIds") List<Long> deptIds,
@Param("keyword") String keyword);
/**
* 根据任务ID查询所有子任务
*/
@Select("SELECT ti.*, " +
" dt.type_name AS taskTypeName " +
"FROM task_item ti " +
"LEFT JOIN task_type dt ON ti.task_type_id = dt.id " +
"WHERE ti.task_id = #{taskId} " +
"ORDER BY ti.sort_order ASC")
List<TaskItem> selectByTaskId(@Param("taskId") Long taskId);
/**
* 查询下一个待解锁的子任务(顺序流水线)
*/
@Select("SELECT * FROM task_item " +
"WHERE task_id = #{taskId} " +
" AND prev_item_id = #{prevItemId} " +
" AND status = 'locked' " +
" AND is_locked = 1 " +
"LIMIT 1")
TaskItem selectNextLockedItem(@Param("taskId") Long taskId,
@Param("prevItemId") Long prevItemId);
/**
* 抢单子任务(乐观锁)
*/
@Update("UPDATE task_item SET " +
"receiver_id = #{receiverId}, " +
"receiver_name = #{receiverName}, " +
"receiver_dept_id = #{receiverDeptId}, " +
"status = 'in_progress', " +
"update_time = NOW() " +
"WHERE id = #{itemId} " +
"AND status = 'pending' " +
"AND is_locked = 0 " +
"AND receiver_id IS NULL")
int grabItem(@Param("itemId") Long itemId,
@Param("receiverId") Long receiverId,
@Param("receiverName") String receiverName,
@Param("receiverDeptId") Long receiverDeptId);
/**
* 解锁子任务
*/
@Update("UPDATE task_item SET " +
"status = 'pending', " +
"is_locked = 0, " +
"update_time = NOW() " +
"WHERE id = #{itemId}")
int unlockItem(@Param("itemId") Long itemId);
/**
* 统计任务的完成子项数量
*/
@Select("SELECT COUNT(*) FROM task_item " +
"WHERE task_id = #{taskId} AND status = 'completed'")
int countCompletedItems(@Param("taskId") Long taskId);
/**
* 统计任务的总子项数量
*/
@Select("SELECT COUNT(*) FROM task_item WHERE task_id = #{taskId}")
int countTotalItems(@Param("taskId") Long taskId);
}