refactor(SQL分层): 剩余 85 条注解 SQL 全量迁进 mapper XML,等价性改由 MyBatis 自己判
96 条语句现在全在 src/main/resources/mapper/<模块>/ 下,注解侧 SQL 归零;判据从"基线清单"
改成完成态(逐接口必须为 0 + XML 语句总数 96 + 反向钉:XML 有则注解必须无)。
搬法上踩实了一个坑:注解参数是 Java 表达式("…" + CLIENT_MODULE_TYPES + "…"),
用只认字面量的抽取器搬家会把常量整段吞掉——上一轮生成的 26 份 XML 里因此出现
IN ()、AS status 前面没有表达式(MySQL 语法错),<script> 形态还被多转义一次变成 &lt;。
更糟的是当时"搬迁前快照"与 XML 由同一个抽取器产出,两边一起错所以逐字比对全绿,
抓到现场的是既有的语义用例(TaskCenter 15 条 + 店铺查重那条断 <> 的)。
所以 MigratedSqlEquivalenceTest 改成:账本存注解原文,Java 侧现场用
getDefaultScriptingLanguageInstance().createSqlSource 编译原文,与 XML 解析出的
MappedStatement 各渲染一遍 BoundSql 对撞(空参数 + foreach 喂满 2 元素各一次),
转义对不对由 MyBatis 判定而不是由生成器判定;账本自己再钉 <script>/<if> 成对、不许出现 IN ()。
resultType 那一支不变:期望值由接口签名反射反推,66 条分母钉住。
取数入口跟着换:6 支原本读 @Select 注解的守卫(TaskCenter/Dedupe/店铺查重/通知保留/
鉴权形状/后台扩权)改走 MapperXmlSupport,断言内容一字未动;后台扩权那条"不许有 wrapper
投影"从全文 doesNotContain(".select(") 改成只扫可执行行——接口里现在只剩签名,
而 javadoc 正写着"别用 selectList(.select(...))",全文判会被自己的注释喂饱。
隔离树全量 4059 例 0 红(基线 4054,+5 为新增等价性与 XML 用例)。这批要生效得随下一版 jar 发版。
This commit is contained in:
-86
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.imagevideo.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -14,39 +13,6 @@ import java.util.Map;
|
||||
@Mapper
|
||||
public interface ImageVideoAdminTaskMapper {
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT t.id, t.user_id, t.status, t.request_json, t.submit_response_json, t.result_json,
|
||||
t.video_urls_json, t.debug_url, t.archived_videos_json, t.archive_status,
|
||||
t.archive_error, t.archive_attempt_count,
|
||||
DATE_FORMAT(t.archived_at, '%Y-%m-%d %H:%i:%s') AS archived_at,
|
||||
t.error_message, t.coze_execute_id, t.coze_status,
|
||||
DATE_FORMAT(t.submitted_at, '%Y-%m-%d %H:%i:%s') AS submitted_at,
|
||||
DATE_FORMAT(t.completed_at, '%Y-%m-%d %H:%i:%s') AS completed_at,
|
||||
u.username,
|
||||
COALESCE((
|
||||
SELECT GROUP_CONCAT(DISTINCT g.group_name ORDER BY g.id SEPARATOR '、')
|
||||
FROM biz_shop_manage_group g
|
||||
LEFT JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id
|
||||
WHERE g.created_by_id = t.user_id OR g.user_id = t.user_id OR gm.user_id = t.user_id
|
||||
), '') AS group_name
|
||||
FROM biz_image_video_async_task t
|
||||
LEFT JOIN users u ON u.id = t.user_id
|
||||
WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'
|
||||
AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
<if test="userId != null"> AND t.user_id = #{userId}</if>
|
||||
<if test="userIds != null"> AND t.user_id IN
|
||||
<foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>
|
||||
</if>
|
||||
<if test="username != null and username != ''"> AND u.username LIKE CONCAT('%', #{username}, '%')</if>
|
||||
<if test="status != null and status != ''"> AND t.status = #{status}</if>
|
||||
<if test="executeId != null and executeId != ''"> AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%')</if>
|
||||
<if test="submittedFrom != null"> AND t.submitted_at >= #{submittedFrom}</if>
|
||||
<if test="submittedTo != null"> AND t.submitted_at <= #{submittedTo}</if>
|
||||
ORDER BY t.submitted_at DESC, t.id DESC
|
||||
LIMIT #{limit} OFFSET #{offset}
|
||||
</script>
|
||||
""")
|
||||
List<Map<String, Object>> selectAdminTaskPage(
|
||||
@Param("userId") Long userId,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@@ -58,24 +24,6 @@ public interface ImageVideoAdminTaskMapper {
|
||||
@Param("limit") int limit,
|
||||
@Param("offset") int offset);
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT COUNT(*) AS total
|
||||
FROM biz_image_video_async_task t
|
||||
LEFT JOIN users u ON u.id = t.user_id
|
||||
WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'
|
||||
AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
<if test="userId != null"> AND t.user_id = #{userId}</if>
|
||||
<if test="userIds != null"> AND t.user_id IN
|
||||
<foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>
|
||||
</if>
|
||||
<if test="username != null and username != ''"> AND u.username LIKE CONCAT('%', #{username}, '%')</if>
|
||||
<if test="status != null and status != ''"> AND t.status = #{status}</if>
|
||||
<if test="executeId != null and executeId != ''"> AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%')</if>
|
||||
<if test="submittedFrom != null"> AND t.submitted_at >= #{submittedFrom}</if>
|
||||
<if test="submittedTo != null"> AND t.submitted_at <= #{submittedTo}</if>
|
||||
</script>
|
||||
""")
|
||||
Long countAdminTaskPage(
|
||||
@Param("userId") Long userId,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@@ -85,41 +33,7 @@ public interface ImageVideoAdminTaskMapper {
|
||||
@Param("submittedFrom") LocalDateTime submittedFrom,
|
||||
@Param("submittedTo") LocalDateTime submittedTo);
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT t.id, t.user_id, t.video_urls_json, t.archived_videos_json
|
||||
FROM biz_image_video_async_task t
|
||||
WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'
|
||||
AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
AND t.id IN
|
||||
<foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
|
||||
#{taskId}
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
List<Map<String, Object>> selectAdminZipRows(@Param("taskIds") List<Long> taskIds);
|
||||
|
||||
@Select("""
|
||||
SELECT t.id, t.user_id, t.status, t.request_json, t.submit_response_json, t.result_json,
|
||||
t.video_urls_json, t.debug_url, t.archived_videos_json, t.archive_status,
|
||||
t.archive_error, t.archive_attempt_count,
|
||||
DATE_FORMAT(t.archived_at, '%Y-%m-%d %H:%i:%s') AS archived_at,
|
||||
t.error_message, t.coze_execute_id, t.coze_status,
|
||||
DATE_FORMAT(t.submitted_at, '%Y-%m-%d %H:%i:%s') AS submitted_at,
|
||||
DATE_FORMAT(t.completed_at, '%Y-%m-%d %H:%i:%s') AS completed_at,
|
||||
u.username,
|
||||
COALESCE((
|
||||
SELECT GROUP_CONCAT(DISTINCT g.group_name ORDER BY g.id SEPARATOR '、')
|
||||
FROM biz_shop_manage_group g
|
||||
LEFT JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id
|
||||
WHERE g.created_by_id = t.user_id OR g.user_id = t.user_id OR gm.user_id = t.user_id
|
||||
), '') AS group_name
|
||||
FROM biz_image_video_async_task t
|
||||
LEFT JOIN users u ON u.id = t.user_id
|
||||
WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'
|
||||
AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
AND t.id = #{taskId}
|
||||
LIMIT 1
|
||||
""")
|
||||
Map<String, Object> selectAdminTaskDetail(@Param("taskId") Long taskId);
|
||||
}
|
||||
|
||||
-16
@@ -4,29 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.imagevideo.model.entity.ImageVideoAsyncTaskEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
@Mapper
|
||||
public interface ImageVideoAsyncTaskMapper extends BaseMapper<ImageVideoAsyncTaskEntity> {
|
||||
|
||||
@Update("UPDATE biz_image_video_async_task "
|
||||
+ "SET status = 'RUNNING', owner_instance_id = CASE "
|
||||
+ "WHEN owner_instance_id IS NULL OR owner_instance_id = '' THEN #{ownerInstanceId} "
|
||||
+ "ELSE owner_instance_id END, updated_at = NOW(), attempt_count = attempt_count + 1 "
|
||||
+ "WHERE id = #{taskId} AND status = 'PENDING' "
|
||||
+ "AND (owner_instance_id = #{ownerInstanceId} OR owner_instance_id IS NULL OR owner_instance_id = '')")
|
||||
int claimPending(@Param("taskId") Long taskId, @Param("ownerInstanceId") String ownerInstanceId);
|
||||
|
||||
@Update("UPDATE biz_image_video_async_task "
|
||||
+ "SET status = 'POLLING', owner_instance_id = CASE "
|
||||
+ "WHEN owner_instance_id IS NULL OR owner_instance_id = '' THEN #{ownerInstanceId} "
|
||||
+ "ELSE owner_instance_id END, updated_at = NOW(), attempt_count = attempt_count + 1 "
|
||||
+ "WHERE id = #{taskId} AND status = 'WAITING' "
|
||||
+ "AND (owner_instance_id = #{ownerInstanceId} OR owner_instance_id IS NULL OR owner_instance_id = '')")
|
||||
int claimWaiting(@Param("taskId") Long taskId, @Param("ownerInstanceId") String ownerInstanceId);
|
||||
|
||||
@Update("UPDATE biz_image_video_async_task SET status = 'WAITING', updated_at = NOW() "
|
||||
+ "WHERE status = 'POLLING' "
|
||||
+ "AND (owner_instance_id = #{ownerInstanceId} OR owner_instance_id IS NULL OR owner_instance_id = '')")
|
||||
int requeuePollingTasks(@Param("ownerInstanceId") String ownerInstanceId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user