178 lines
7.2 KiB
Java
178 lines
7.2 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, " +
|
|
" 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 demand_type dt ON ti.task_type_id = dt.id " +
|
|
"WHERE ti.status = 'pending' AND ti.is_locked = 0 AND t.deleted = 0 " +
|
|
"<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);
|
|
|
|
/**
|
|
* 查询进行中的子任务列表(按接单人)
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT ti.*, " +
|
|
" t.title AS mainTaskTitle, " +
|
|
" t.pipeline_mode AS pipelineMode, " +
|
|
" 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, " +
|
|
" (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 demand_type dt ON ti.task_type_id = dt.id " +
|
|
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
|
"WHERE ti.receiver_id = #{receiverId} " +
|
|
" AND ti.status = 'in_progress' " +
|
|
" AND t.deleted = 0 " +
|
|
"ORDER BY ti.update_time DESC" +
|
|
"</script>")
|
|
IPage<TaskItem> selectInProgressItems(Page<TaskItem> page,
|
|
@Param("receiverId") Long receiverId);
|
|
|
|
/**
|
|
* 查询已完成的子任务列表(按接单人)
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT ti.*, " +
|
|
" t.title AS mainTaskTitle, " +
|
|
" t.pipeline_mode AS pipelineMode, " +
|
|
" 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, " +
|
|
" (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 demand_type dt ON ti.task_type_id = dt.id " +
|
|
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
|
"WHERE ti.receiver_id = #{receiverId} " +
|
|
" AND ti.status = 'completed' " +
|
|
" AND t.deleted = 0 " +
|
|
"ORDER BY ti.complete_time DESC" +
|
|
"</script>")
|
|
IPage<TaskItem> selectCompletedItems(Page<TaskItem> page,
|
|
@Param("receiverId") Long receiverId);
|
|
|
|
/**
|
|
* 根据任务ID查询所有子任务
|
|
*/
|
|
@Select("SELECT ti.*, " +
|
|
" dt.type_name AS taskTypeName " +
|
|
"FROM task_item ti " +
|
|
"LEFT JOIN demand_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}, " +
|
|
"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);
|
|
|
|
/**
|
|
* 解锁子任务
|
|
*/
|
|
@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);
|
|
}
|