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.Task; 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 TaskMapper extends BaseMapper { /** * 查询任务大厅(待接单的任务) */ @Select("") IPage selectTaskHall(Page page, @Param("taskTypeId") Long taskTypeId, @Param("demandTypeId") Long demandTypeId, @Param("brandId") Long brandId, @Param("categoryId") Long categoryId, @Param("platformId") Long platformId, @Param("taskSubType") String taskSubType, @Param("minScore") Integer minScore, @Param("maxScore") Integer maxScore, @Param("keyword") String keyword, @Param("publisherName") String publisherName, @Param("timeRange") String timeRange, @Param("sortBy") String sortBy); /** * 查询任务大厅(按部门筛选) */ @Select("") IPage selectTaskHallByDept(Page page, @Param("taskTypeId") Long taskTypeId, @Param("demandTypeId") Long demandTypeId, @Param("brandId") Long brandId, @Param("categoryId") Long categoryId, @Param("platformId") Long platformId, @Param("taskSubType") String taskSubType, @Param("minScore") Integer minScore, @Param("maxScore") Integer maxScore, @Param("keyword") String keyword, @Param("publisherName") String publisherName, @Param("timeRange") String timeRange, @Param("sortBy") String sortBy, @Param("allowedTaskTypeIds") List allowedTaskTypeIds); /** * 查询我发布的任务 */ @Select("") IPage selectMyPublishedTasks(Page page, @Param("userId") Long userId, @Param("status") String status); /** * 查询我接收的任务 * 包括:作为接收人的任务 或 作为一级需求任务明细完善人的任务 */ @Select("") IPage selectMyReceivedTasks(Page page, @Param("userId") Long userId, @Param("status") String status); /** * 根据任务编号查询 */ @Select("SELECT * FROM task WHERE task_no = #{taskNo} AND deleted = 0") Task selectByTaskNo(@Param("taskNo") String taskNo); /** * 查询设计师当前进行中的任务数量 */ @Select("SELECT COUNT(*) FROM task WHERE receiver_id = #{designerId} " + "AND status IN ('in_progress', 'review') AND deleted = 0") int countInProgressTasks(@Param("designerId") Long designerId); /** * 抢单时基于条件更新任务,避免并发 */ @Update("UPDATE task SET " + "receiver_id = #{receiverId}, " + "receiver_dept_id = #{receiverDeptId}, " + "status = 'in_progress', " + "start_time = #{startTime}, " + "actual_start_time = #{startTime}, " + "deadline = CASE WHEN #{deadline} IS NOT NULL THEN #{deadline} ELSE deadline END, " + "update_time = NOW() " + "WHERE id = #{taskId} " + "AND deleted = 0 " + "AND status = 'pending' " + "AND release_type = 'recruitment' " + "AND receiver_id IS NULL") int grabTask(@Param("taskId") Long taskId, @Param("receiverId") Long receiverId, @Param("receiverDeptId") Long receiverDeptId, @Param("startTime") LocalDateTime startTime, @Param("deadline") LocalDateTime deadline); /** * 查询需求部门负责人的任务列表(部门内所有成员发起的任务) */ @Select("") IPage selectLeaderTaskPage(Page page, @Param("deptId") Long deptId, @Param("auditStatus") String auditStatus); /** * 查询接单部门负责人视图(部门成员接单的所有任务) */ @Select("") IPage selectDeptReceivingTaskPage(Page page, @Param("deptId") Long deptId, @Param("status") String status); /** * 查询设计师进行中的子任务数量 */ @Select("SELECT COUNT(*) FROM task_item WHERE receiver_id = #{receiverId} " + "AND status = 'in_progress' AND is_locked = 0") Long countSubTasksByReceiverId(@Param("receiverId") Long receiverId); }