Files
lpt-be/src/main/resources/mapper/TasksMapper.xml
T

73 lines
3.8 KiB
XML
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.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.guo.learningprogresstracker.mapper.TasksMapper">
<resultMap id="BaseResultMap" type="com.guo.learningprogresstracker.entity.TaskEntity">
<id property="taskId" column="task_id" jdbcType="INTEGER"/>
<result property="taskName" column="task_name" jdbcType="VARCHAR"/>
<result property="materialUrl" column="material_url" jdbcType="VARCHAR"/>
<result property="urgency" column="urgency" jdbcType="INTEGER"/>
<result property="importance" column="importance" jdbcType="INTEGER"/>
<result property="contentDifficulty" column="content_difficulty" jdbcType="INTEGER"/>
<result property="futureValue" column="future_value" jdbcType="INTEGER"/>
<result property="subjectivePriority" column="subjective_priority" jdbcType="INTEGER"/>
<result property="calculatedPriority" column="calculated_priority" jdbcType="FLOAT"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="lastModifiedTime" column="last_modified_time" jdbcType="TIMESTAMP"/>
<result property="lastModifiedBy" column="last_modified_by" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
task_id,task_name,material_url,
urgency,importance,content_difficulty,
future_value,subjective_priority,calculated_priority,
created_time,created_by,last_modified_time,
last_modified_by
</sql>
<!--
按用户标签分页筛选任务(点标签即筛选):过滤下推到 SQL。
用 EXISTS 而不是 join markers:markers 的唯一键包含 marker_value,
而用户标签的 marker_value 为 NULL(MySQL 唯一键不约束 NULL),理论上可能有重复行;
EXISTS 天然去重,也避免分页 count 被 join 放大。
自定义 SQL 不会被 @TableLogic 追加条件,故显式写 deleted = 0;
租户条件由拦截器给外层 tasks 与子查询里的 markers 分别追加。
-->
<select id="selectPageByMarker" resultType="com.guo.learningprogresstracker.entity.TaskEntity">
SELECT t.*
FROM tasks t
WHERE t.deleted = 0
AND EXISTS (SELECT 1
FROM markers m
WHERE m.object_num = t.task_num
AND m.object_type = 'TASK'
AND m.kind = 'USER'
AND m.marker_name = #{markerName}
AND m.deleted = 0)
ORDER BY t.calculated_priority DESC, t.id DESC
</select>
<!--
权重保存后的批量重算:一条 CASE 更新一批任务,避免逐任务 updateById 变成 N 次往返。
自定义 SQL 不会被 @TableLogic 追加条件,故显式 deleted = 0;租户条件由拦截器追加。
device_info 为空时跳过,避免把已有设备信息清空(自动填充同样只在非 null 时写入)。
-->
<update id="updateCalculatedPriorities">
UPDATE tasks
SET calculated_priority = CASE id
<foreach collection="rows" item="row">
WHEN #{row.id} THEN #{row.calculatedPriority}
</foreach>
END,
last_modified_time = #{lastModifiedTime}
<if test="lastModifiedBy != null">, last_modified_by = #{lastModifiedBy}</if>
<if test="deviceInfo != null">, device_info = #{deviceInfo}</if>
WHERE id IN
<foreach collection="rows" item="row" open="(" separator="," close=")">#{row.id}</foreach>
AND deleted = 0
</update>
</mapper>