1. TaskMapper selectTaskHall 和 selectTaskHallByDept 方法: - 添加明细完善人、接收人、任务类型的关联查询 - 扩展搜索条件,支持搜索品牌、类目、平台、任务类型、发布人部门、一级需求人、一级需求部门、明细完善人、接收人、任务描述、产品条码等所有任务卡片信息 2. TaskService getCompletedTasks 方法: - 扩展搜索条件,使用 apply 方法添加自定义 SQL,支持搜索任务卡片的所有信息 3. TaskItemMapper 所有子任务查询方法: - selectAvailableItems、selectAvailableItemsByTaskTypes、selectInProgressItems、selectCompletedItems - 扩展搜索条件,支持搜索子任务卡片的所有信息,包括主任务和子任务的所有关联信息
332 lines
19 KiB
Java
332 lines
19 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.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<Task> {
|
|
|
|
/**
|
|
* 查询任务大厅(待接单的任务)
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT t.*, " +
|
|
" u.real_name AS publisher_name, " +
|
|
" d.dept_name AS publisher_dept_name, " +
|
|
" b.brand_name AS brand_name, " +
|
|
" c.category_name AS category_name, " +
|
|
" p.platform_name AS platform_name, " +
|
|
" approver.real_name AS current_approver_name, " +
|
|
" primary_user.real_name AS primary_publisher_name, " +
|
|
" primary_dept.dept_name AS primary_publisher_dept_name, " +
|
|
" detail_completer.real_name AS detail_completer_name, " +
|
|
" receiver.real_name AS receiver_name, " +
|
|
" dt.type_name AS task_type_name " +
|
|
"FROM task t " +
|
|
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
|
"LEFT JOIN sys_dept d ON t.publisher_dept_id = d.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 sys_user approver ON t.current_approver_id = approver.id " +
|
|
"LEFT JOIN sys_user primary_user ON t.primary_publisher_id = primary_user.id " +
|
|
"LEFT JOIN sys_dept primary_dept ON t.primary_publisher_dept_id = primary_dept.id " +
|
|
"LEFT JOIN sys_user detail_completer ON t.detail_completer_id = detail_completer.id " +
|
|
"LEFT JOIN sys_user receiver ON t.receiver_id = receiver.id " +
|
|
"LEFT JOIN task_type dt ON t.task_type_id = dt.id " +
|
|
"WHERE t.status = 'pending' AND t.approval_status = 'approved' AND t.deleted = 0 AND (t.is_pipeline = 0 OR t.is_pipeline IS NULL)" +
|
|
"<if test='taskTypeId != null'> AND t.task_type_id = #{taskTypeId}</if>" +
|
|
"<if test='demandTypeId != null'> AND t.demand_type_id = #{demandTypeId}</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='minScore != null'> AND t.score >= #{minScore}</if>" +
|
|
"<if test='maxScore != null'> AND t.score <= #{maxScore}</if>" +
|
|
"<if test='keyword != null and keyword != \"\"'> " +
|
|
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR t.task_no LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR t.remark LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(t.description, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(t.product_barcodes, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(d.dept_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}, '%') " +
|
|
" OR COALESCE(primary_user.real_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(primary_dept.dept_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(detail_completer.real_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(receiver.real_name, '') LIKE CONCAT('%', #{keyword}, '%'))" +
|
|
"</if>" +
|
|
"<if test='publisherName != null and publisherName != \"\"'> AND u.real_name LIKE CONCAT('%', #{publisherName}, '%')</if>" +
|
|
"<if test='timeRange != null and timeRange == \"today\"'> AND DATE(t.create_time) = CURDATE()</if>" +
|
|
"<if test='timeRange != null and timeRange == \"week\"'> AND t.create_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)</if>" +
|
|
"<if test='timeRange != null and timeRange == \"month\"'> AND t.create_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)</if>" +
|
|
"<choose>" +
|
|
" <when test='sortBy == \"score\"'> ORDER BY t.score DESC, t.create_time DESC</when>" +
|
|
" <when test='sortBy == \"deadline\"'> ORDER BY t.deadline ASC, t.create_time DESC</when>" +
|
|
" <when test='sortBy == \"hot\"'> ORDER BY t.score DESC, (SELECT COUNT(*) FROM task WHERE task_type_id = t.task_type_id AND status = 'pending') DESC, t.create_time DESC</when>" +
|
|
" <otherwise> ORDER BY t.create_time DESC</otherwise>" +
|
|
"</choose>" +
|
|
"</script>")
|
|
IPage<Task> selectTaskHall(Page<Task> 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("<script>" +
|
|
"SELECT t.*, " +
|
|
" u.real_name AS publisher_name, " +
|
|
" d.dept_name AS publisher_dept_name, " +
|
|
" b.brand_name AS brand_name, " +
|
|
" c.category_name AS category_name, " +
|
|
" p.platform_name AS platform_name, " +
|
|
" approver.real_name AS current_approver_name, " +
|
|
" primary_user.real_name AS primary_publisher_name, " +
|
|
" primary_dept.dept_name AS primary_publisher_dept_name, " +
|
|
" detail_completer.real_name AS detail_completer_name, " +
|
|
" receiver.real_name AS receiver_name, " +
|
|
" dt.type_name AS task_type_name " +
|
|
"FROM task t " +
|
|
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
|
"LEFT JOIN sys_dept d ON t.publisher_dept_id = d.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 sys_user approver ON t.current_approver_id = approver.id " +
|
|
"LEFT JOIN sys_user primary_user ON t.primary_publisher_id = primary_user.id " +
|
|
"LEFT JOIN sys_dept primary_dept ON t.primary_publisher_dept_id = primary_dept.id " +
|
|
"LEFT JOIN sys_user detail_completer ON t.detail_completer_id = detail_completer.id " +
|
|
"LEFT JOIN sys_user receiver ON t.receiver_id = receiver.id " +
|
|
"LEFT JOIN task_type dt ON t.task_type_id = dt.id " +
|
|
"WHERE t.status = 'pending' AND t.approval_status = 'approved' AND t.deleted = 0 AND (t.is_pipeline = 0 OR t.is_pipeline IS NULL)" +
|
|
"<if test='allowedTaskTypeIds != null and allowedTaskTypeIds.size() > 0'>" +
|
|
" AND t.task_type_id IN " +
|
|
" <foreach item='typeId' collection='allowedTaskTypeIds' open='(' separator=',' close=')'>" +
|
|
" #{typeId}" +
|
|
" </foreach>" +
|
|
"</if>" +
|
|
"<if test='taskTypeId != null'> AND t.task_type_id = #{taskTypeId}</if>" +
|
|
"<if test='demandTypeId != null'> AND t.demand_type_id = #{demandTypeId}</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='minScore != null'> AND t.score >= #{minScore}</if>" +
|
|
"<if test='maxScore != null'> AND t.score <= #{maxScore}</if>" +
|
|
"<if test='keyword != null and keyword != \"\"'> " +
|
|
" AND (t.title LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR t.task_no LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR t.spu_info LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR t.remark LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(t.description, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(t.product_barcodes, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR u.real_name LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(d.dept_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}, '%') " +
|
|
" OR COALESCE(primary_user.real_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(primary_dept.dept_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(detail_completer.real_name, '') LIKE CONCAT('%', #{keyword}, '%') " +
|
|
" OR COALESCE(receiver.real_name, '') LIKE CONCAT('%', #{keyword}, '%'))" +
|
|
"</if>" +
|
|
"<if test='publisherName != null and publisherName != \"\"'> AND u.real_name LIKE CONCAT('%', #{publisherName}, '%')</if>" +
|
|
"<if test='timeRange != null and timeRange == \"today\"'> AND DATE(t.create_time) = CURDATE()</if>" +
|
|
"<if test='timeRange != null and timeRange == \"week\"'> AND t.create_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)</if>" +
|
|
"<if test='timeRange != null and timeRange == \"month\"'> AND t.create_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)</if>" +
|
|
"<choose>" +
|
|
" <when test='sortBy == \"score\"'> ORDER BY t.score DESC, t.create_time DESC</when>" +
|
|
" <when test='sortBy == \"deadline\"'> ORDER BY t.deadline ASC, t.create_time DESC</when>" +
|
|
" <when test='sortBy == \"hot\"'> ORDER BY t.score DESC, (SELECT COUNT(*) FROM task WHERE task_type_id = t.task_type_id AND status = 'pending') DESC, t.create_time DESC</when>" +
|
|
" <otherwise> ORDER BY t.create_time DESC</otherwise>" +
|
|
"</choose>" +
|
|
"</script>")
|
|
IPage<Task> selectTaskHallByDept(Page<Task> 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<Long> allowedTaskTypeIds);
|
|
|
|
/**
|
|
* 查询我发布的任务
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT t.*, " +
|
|
" b.brand_name AS brandName, " +
|
|
" c.category_name AS categoryName, " +
|
|
" p.platform_name AS platformName, " +
|
|
" u.real_name AS publisherName, " +
|
|
" d.dept_name AS publisherDeptName, " +
|
|
" approver.real_name AS currentApproverName, " +
|
|
" primary_user.real_name AS primaryPublisherName, " +
|
|
" primary_dept.dept_name AS primaryPublisherDeptName " +
|
|
"FROM task t " +
|
|
"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 sys_user u ON t.publisher_id = u.id " +
|
|
"LEFT JOIN sys_dept d ON t.publisher_dept_id = d.id " +
|
|
"LEFT JOIN sys_user approver ON t.current_approver_id = approver.id " +
|
|
"LEFT JOIN sys_user primary_user ON t.primary_publisher_id = primary_user.id " +
|
|
"LEFT JOIN sys_dept primary_dept ON t.primary_publisher_dept_id = primary_dept.id " +
|
|
"WHERE t.publisher_id = #{userId} AND t.deleted = 0 " +
|
|
"<if test='status != null'> AND t.status = #{status}</if> " +
|
|
"ORDER BY t.create_time DESC" +
|
|
"</script>")
|
|
IPage<Task> selectMyPublishedTasks(Page<Task> page,
|
|
@Param("userId") Long userId,
|
|
@Param("status") String status);
|
|
|
|
/**
|
|
* 查询我接收的任务
|
|
* 包括:作为接收人的任务 或 作为一级需求任务明细完善人的任务
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT t.*, " +
|
|
" b.brand_name AS brandName, " +
|
|
" c.category_name AS categoryName, " +
|
|
" p.platform_name AS platformName, " +
|
|
" u.real_name AS publisherName, " +
|
|
" d.dept_name AS publisherDeptName, " +
|
|
" approver.real_name AS currentApproverName, " +
|
|
" primary_user.real_name AS primaryPublisherName, " +
|
|
" primary_dept.dept_name AS primaryPublisherDeptName " +
|
|
"FROM task t " +
|
|
"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 sys_user u ON t.publisher_id = u.id " +
|
|
"LEFT JOIN sys_dept d ON t.publisher_dept_id = d.id " +
|
|
"LEFT JOIN sys_user approver ON t.current_approver_id = approver.id " +
|
|
"LEFT JOIN sys_user primary_user ON t.primary_publisher_id = primary_user.id " +
|
|
"LEFT JOIN sys_dept primary_dept ON t.primary_publisher_dept_id = primary_dept.id " +
|
|
"WHERE (t.receiver_id = #{userId} OR t.detail_completer_id = #{userId}) AND t.deleted = 0 " +
|
|
"<if test='status != null'> AND t.status = #{status}</if> " +
|
|
"ORDER BY t.create_time DESC" +
|
|
"</script>")
|
|
IPage<Task> selectMyReceivedTasks(Page<Task> 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("<script>" +
|
|
"SELECT t.*, " +
|
|
" u.real_name AS publisherName, " +
|
|
" d.dept_name AS publisherDeptName, " +
|
|
" auditor.real_name AS auditorName " +
|
|
"FROM task t " +
|
|
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
|
"LEFT JOIN sys_dept d ON t.publisher_dept_id = d.id " +
|
|
"LEFT JOIN sys_user auditor ON t.auditor_id = auditor.id " +
|
|
"WHERE t.publisher_dept_id = #{deptId} AND t.deleted = 0 " +
|
|
"<if test='auditStatus != null and auditStatus != \"\"'> AND t.audit_status = #{auditStatus}</if> " +
|
|
"ORDER BY t.create_time DESC" +
|
|
"</script>")
|
|
IPage<Task> selectLeaderTaskPage(Page<Task> page,
|
|
@Param("deptId") Long deptId,
|
|
@Param("auditStatus") String auditStatus);
|
|
|
|
/**
|
|
* 查询接单部门负责人视图(部门成员接单的所有任务)
|
|
*/
|
|
@Select("<script>" +
|
|
"SELECT t.*, " +
|
|
" u.real_name AS publisherName, " +
|
|
" d.dept_name AS publisherDeptName, " +
|
|
" receiver.real_name AS receiverName " +
|
|
"FROM task t " +
|
|
"LEFT JOIN sys_user u ON t.publisher_id = u.id " +
|
|
"LEFT JOIN sys_dept d ON t.publisher_dept_id = d.id " +
|
|
"LEFT JOIN sys_user receiver ON t.receiver_id = receiver.id " +
|
|
"WHERE t.receiver_dept_id = #{deptId} AND t.deleted = 0 " +
|
|
"<if test='status != null and status != \"\"'> AND t.status = #{status}</if> " +
|
|
"ORDER BY t.create_time DESC" +
|
|
"</script>")
|
|
IPage<Task> selectDeptReceivingTaskPage(Page<Task> 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);
|
|
}
|
|
|