562 lines
31 KiB
Java
562 lines
31 KiB
Java
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, " +
|
||
" 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='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> " +
|
||
"ORDER BY ti.create_time DESC" +
|
||
"</script>")
|
||
IPage<TaskItem> selectAvailableItems(Page<TaskItem> page,
|
||
@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, " +
|
||
" 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='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> selectAvailableItemsByTaskTypes(Page<TaskItem> page,
|
||
@Param("taskTypeId") Long taskTypeId,
|
||
@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> " +
|
||
"<if test='visibleReceiverDeptIds != null and visibleReceiverDeptIds.size() > 0'> " +
|
||
" AND (ti.receiver_dept_id IS NULL OR ti.receiver_dept_id IN " +
|
||
" <foreach collection='visibleReceiverDeptIds' item='deptId' open='(' separator=',' close=')'>" +
|
||
" #{deptId}" +
|
||
" </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("visibleReceiverDeptIds") List<Long> visibleReceiverDeptIds);
|
||
|
||
/**
|
||
* 查询进行中的子任务列表
|
||
* @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, " +
|
||
" t.is_primary_task AS isPrimaryTask, " +
|
||
" 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, " +
|
||
" pp.real_name AS primaryPublisherName, " +
|
||
" ppd.dept_name AS primaryPublisherDeptName, " +
|
||
" dc.real_name AS detailCompleterName, " +
|
||
" 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 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 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.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(r.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>" +
|
||
"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, " +
|
||
" t.is_primary_task AS isPrimaryTask, " +
|
||
" 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, " +
|
||
" pp.real_name AS primaryPublisherName, " +
|
||
" ppd.dept_name AS primaryPublisherDeptName, " +
|
||
" dc.real_name AS detailCompleterName, " +
|
||
" 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 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 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.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(r.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>" +
|
||
"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, " +
|
||
" t.is_primary_task AS isPrimaryTask, " +
|
||
" 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, " +
|
||
" pp.real_name AS primaryPublisherName, " +
|
||
" ppd.dept_name AS primaryPublisherDeptName, " +
|
||
" dc.real_name AS detailCompleterName, " +
|
||
" 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 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 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.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(r.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>" +
|
||
"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, " +
|
||
" t.is_primary_task AS isPrimaryTask, " +
|
||
" 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, " +
|
||
" pp.real_name AS primaryPublisherName, " +
|
||
" ppd.dept_name AS primaryPublisherDeptName, " +
|
||
" dc.real_name AS detailCompleterName, " +
|
||
" 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 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 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.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(r.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>" +
|
||
"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', " +
|
||
"claim_time = NOW(), " +
|
||
"deadline = CASE WHEN #{deadline} IS NOT NULL THEN #{deadline} ELSE deadline END, " +
|
||
"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,
|
||
@Param("deadline") LocalDateTime deadline);
|
||
|
||
/**
|
||
* 指定任务接单(用于已预先指定设计师的任务)
|
||
* 只有被指定的设计师才能接单
|
||
* 🔥 修复:增加 receiver_name 更新,确保接单记录完整
|
||
*/
|
||
@Update("UPDATE task_item SET " +
|
||
"status = 'in_progress', " +
|
||
"receiver_name = #{receiverName}, " +
|
||
"claim_time = NOW(), " +
|
||
"deadline = CASE WHEN #{deadline} IS NOT NULL THEN #{deadline} ELSE deadline END, " +
|
||
"update_time = NOW() " +
|
||
"WHERE id = #{itemId} " +
|
||
"AND status = 'pending' " +
|
||
"AND is_locked = 0 " +
|
||
"AND receiver_id = #{receiverId}")
|
||
int grabAssignedItem(@Param("itemId") Long itemId,
|
||
@Param("receiverId") Long receiverId,
|
||
@Param("receiverName") String receiverName,
|
||
@Param("deadline") LocalDateTime deadline);
|
||
|
||
/**
|
||
* 解锁子任务
|
||
*/
|
||
@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);
|
||
}
|