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:
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -20,12 +19,6 @@ public interface AdminUserMapper extends BaseMapper<AdminUserEntity> {
|
||||
* 遍历时解引用即 NPE,而这里正是每次登录与每个鉴权请求都要走的读出口。MIN 忽略 NULL,
|
||||
* 无行时结果集仍是单行单列,直接映射成 null。</p>
|
||||
*/
|
||||
@Select("""
|
||||
SELECT MIN(expires_at)
|
||||
FROM users
|
||||
WHERE role = 'company_super_admin'
|
||||
AND company_id = #{companyId}
|
||||
""")
|
||||
LocalDateTime selectCompanySuperAdminEarliestExpiry(@Param("companyId") Long companyId);
|
||||
|
||||
/**
|
||||
@@ -38,17 +31,5 @@ public interface AdminUserMapper extends BaseMapper<AdminUserEntity> {
|
||||
* 残留授权行会让账号"进得了后台、菜单树却是空的"——入口门与 {@code getUserColumnPermissions}
|
||||
* 的下发集要用同一个公司口径,否则两处各判一次就留下静默死链。</p>
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT COUNT(1)
|
||||
FROM user_column_permission ucp
|
||||
JOIN columns cm ON cm.id = ucp.column_id
|
||||
WHERE ucp.user_id = #{userId}
|
||||
AND cm.menu_type = 'admin'
|
||||
<if test="companyId != null">
|
||||
AND cm.company_id = #{companyId}
|
||||
</if>
|
||||
</script>
|
||||
""")
|
||||
Long countAdminMenuGrants(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
||||
}
|
||||
|
||||
-125
@@ -4,164 +4,39 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.common.model.entity.ShopManageGroupEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ShopManageGroupMapper extends BaseMapper<ShopManageGroupEntity> {
|
||||
|
||||
@Select("""
|
||||
SELECT DISTINCT accessible_group_id
|
||||
FROM (
|
||||
SELECT g.id AS accessible_group_id
|
||||
FROM biz_shop_manage_group g
|
||||
WHERE g.created_by_id = #{operatorId}
|
||||
OR g.user_id = #{operatorId}
|
||||
UNION
|
||||
SELECT gm.group_id AS accessible_group_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
WHERE gm.user_id = #{operatorId}
|
||||
UNION
|
||||
SELECT g2.id AS accessible_group_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
INNER JOIN biz_shop_manage_group g1 ON g1.id = gm.group_id
|
||||
INNER JOIN biz_shop_manage_group g2
|
||||
ON g2.created_by_id = COALESCE(g1.created_by_id, g1.user_id)
|
||||
OR g2.user_id = COALESCE(g1.created_by_id, g1.user_id)
|
||||
WHERE gm.user_id = #{operatorId}
|
||||
AND COALESCE(g1.created_by_id, g1.user_id) IS NOT NULL
|
||||
UNION
|
||||
SELECT member_groups.id AS accessible_group_id
|
||||
FROM biz_shop_manage_group leader_group
|
||||
INNER JOIN biz_shop_manage_group_member direct_member ON direct_member.group_id = leader_group.id
|
||||
INNER JOIN biz_shop_manage_group member_groups
|
||||
ON member_groups.created_by_id = direct_member.user_id
|
||||
OR member_groups.user_id = direct_member.user_id
|
||||
WHERE leader_group.created_by_id = #{operatorId}
|
||||
OR leader_group.user_id = #{operatorId}
|
||||
) accessible_groups
|
||||
WHERE accessible_group_id IS NOT NULL
|
||||
ORDER BY accessible_group_id ASC
|
||||
""")
|
||||
List<Long> selectAccessibleGroupIds(@Param("operatorId") Long operatorId);
|
||||
|
||||
@Select("""
|
||||
SELECT DISTINCT visible_user_id
|
||||
FROM (
|
||||
SELECT #{operatorId} AS visible_user_id
|
||||
UNION
|
||||
SELECT direct_member.user_id AS visible_user_id
|
||||
FROM biz_shop_manage_group leader_group
|
||||
INNER JOIN biz_shop_manage_group_member direct_member ON direct_member.group_id = leader_group.id
|
||||
WHERE leader_group.created_by_id = #{operatorId}
|
||||
OR leader_group.user_id = #{operatorId}
|
||||
UNION
|
||||
SELECT COALESCE(direct_group.created_by_id, direct_group.user_id) AS visible_user_id
|
||||
FROM biz_shop_manage_group_member membership
|
||||
INNER JOIN biz_shop_manage_group direct_group ON direct_group.id = membership.group_id
|
||||
WHERE membership.user_id = #{operatorId}
|
||||
AND COALESCE(direct_group.created_by_id, direct_group.user_id) IS NOT NULL
|
||||
) visible_users
|
||||
WHERE visible_user_id IS NOT NULL
|
||||
ORDER BY visible_user_id ASC
|
||||
""")
|
||||
List<Long> selectAccessibleCreatorUserIds(@Param("operatorId") Long operatorId);
|
||||
|
||||
@Select("""
|
||||
SELECT DISTINCT gm.user_id
|
||||
FROM biz_shop_manage_group g
|
||||
INNER JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id
|
||||
INNER JOIN users u ON u.id = gm.user_id
|
||||
WHERE g.created_by_id = #{operatorId}
|
||||
OR g.user_id = #{operatorId}
|
||||
ORDER BY gm.user_id ASC
|
||||
""")
|
||||
List<Long> selectManagedMemberUserIds(@Param("operatorId") Long operatorId);
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT DISTINCT visible_user_id
|
||||
FROM (
|
||||
SELECT COALESCE(g.created_by_id, g.user_id) AS visible_user_id
|
||||
FROM biz_shop_manage_group g
|
||||
WHERE g.id IN
|
||||
<foreach collection='groupIds' item='groupId' open='(' separator=',' close=')'>
|
||||
#{groupId}
|
||||
</foreach>
|
||||
UNION
|
||||
SELECT gm.user_id AS visible_user_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
WHERE gm.group_id IN
|
||||
<foreach collection='groupIds' item='groupId' open='(' separator=',' close=')'>
|
||||
#{groupId}
|
||||
</foreach>
|
||||
) visible_users
|
||||
WHERE visible_user_id IS NOT NULL
|
||||
ORDER BY visible_user_id ASC
|
||||
</script>
|
||||
""")
|
||||
List<Long> selectUserIdsByGroupIds(@Param("groupIds") List<Long> groupIds);
|
||||
|
||||
/**
|
||||
* 批量查用户所属分组名:分组归属按「分组的创建人(created_by_id/user_id) = 用户的创建人」判定,
|
||||
* 即主管名下的子账户归入该主管创建的分组(成员表 biz_shop_manage_group_member 生产上基本未使用)。
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT u.id AS userId, g.group_name AS groupName
|
||||
FROM users u
|
||||
INNER JOIN biz_shop_manage_group g
|
||||
ON g.created_by_id = u.created_by_id OR g.user_id = u.created_by_id
|
||||
WHERE u.created_by_id IS NOT NULL
|
||||
AND u.id IN
|
||||
<foreach collection='userIds' item='userId' open='(' separator=',' close=')'>
|
||||
#{userId}
|
||||
</foreach>
|
||||
ORDER BY g.id ASC
|
||||
</script>
|
||||
""")
|
||||
List<com.nanri.aiimage.modules.shopkey.model.dto.UserGroupRef> selectGroupNamesByUserIds(
|
||||
@Param("userIds") List<Long> userIds);
|
||||
|
||||
/** 某分组下的用户:该分组创建人(组长)本人 + 其名下子账户。 */
|
||||
@Select("""
|
||||
SELECT u.id AS userId
|
||||
FROM users u
|
||||
INNER JOIN biz_shop_manage_group g ON g.id = #{groupId}
|
||||
WHERE u.id = COALESCE(g.created_by_id, g.user_id)
|
||||
OR u.created_by_id = COALESCE(g.created_by_id, g.user_id)
|
||||
ORDER BY u.id ASC
|
||||
""")
|
||||
List<Long> selectUserIdsByGroupId(@Param("groupId") Long groupId);
|
||||
|
||||
/** 某人作为组长(创建人)的分组(密钥管理等按组隔离场景用)。 */
|
||||
@Select("""
|
||||
SELECT g.id AS id, g.group_name AS groupName
|
||||
FROM biz_shop_manage_group g
|
||||
WHERE g.created_by_id = #{operatorId} OR g.user_id = #{operatorId}
|
||||
ORDER BY g.id ASC
|
||||
""")
|
||||
List<ShopManageGroupEntity> selectLedGroups(@Param("operatorId") Long operatorId);
|
||||
|
||||
/**
|
||||
* 某用户所属分组(成员表)的组长 id 集合(到期级联用,AccountExpiryService)。
|
||||
* 与数据可见范围同源:组长的旧字段 user_id 与新字段 created_by_id 都算(COALESCE 取新优先旧兜底)。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT DISTINCT COALESCE(g.created_by_id, g.user_id) AS leader_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
INNER JOIN biz_shop_manage_group g ON g.id = gm.group_id
|
||||
WHERE gm.user_id = #{userId}
|
||||
AND COALESCE(g.created_by_id, g.user_id) IS NOT NULL
|
||||
""")
|
||||
List<Long> selectLeaderIdsByMemberUserId(@Param("userId") Long userId);
|
||||
|
||||
/** 全部分组(超管筛选项用)。 */
|
||||
@Select("""
|
||||
SELECT g.id AS id, g.group_name AS groupName
|
||||
FROM biz_shop_manage_group g
|
||||
ORDER BY g.id ASC
|
||||
""")
|
||||
List<ShopManageGroupEntity> selectAllGroups();
|
||||
}
|
||||
|
||||
-8
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.brand.model.entity.BrandCrawlTaskEntity;
|
||||
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;
|
||||
@@ -21,13 +20,6 @@ public interface BrandCrawlTaskMapper extends BaseMapper<BrandCrawlTaskEntity> {
|
||||
* 时间线用 updated_at,与 BrandTaskStaleRepairSpiImpl 的陈旧判定同款口径,
|
||||
* 可命中 V120 的 idx_brand_crawl_task_status_updated(status, updated_at) 索引。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT id FROM brand_crawl_tasks
|
||||
WHERE status IN ('success', 'failed', 'cancelled')
|
||||
AND updated_at < #{cutoff}
|
||||
ORDER BY id ASC
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
List<Long> selectExpiredTerminalTaskIds(@Param("cutoff") LocalDateTime cutoff,
|
||||
@Param("batchSize") int batchSize);
|
||||
}
|
||||
|
||||
-12
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.collectdata.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.collectdata.model.entity.CollectDataItemEntity;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -11,16 +10,5 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface CollectDataItemMapper extends BaseMapper<CollectDataItemEntity> {
|
||||
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT INTO biz_collect_data_item
|
||||
(task_id, row_index, source_file_key, source_filename, keyword, status_value, extra_json, created_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.taskId}, #{row.rowIndex}, #{row.sourceFileKey}, #{row.sourceFilename},
|
||||
#{row.keyword}, #{row.statusValue}, #{row.extraJson}, #{row.createdAt})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int insertBatch(@Param("rows") List<CollectDataItemEntity> rows);
|
||||
}
|
||||
|
||||
-13
@@ -2,10 +2,8 @@ package com.nanri.aiimage.modules.dedupe.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.dedupe.model.entity.DedupeTotalDataEntity;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,7 +12,6 @@ import java.util.StringJoiner;
|
||||
@Mapper
|
||||
public interface DedupeTotalDataMapper extends BaseMapper<DedupeTotalDataEntity> {
|
||||
|
||||
@Select("SELECT data_value FROM biz_dedupe_total_data")
|
||||
List<String> selectAllDataValues();
|
||||
|
||||
@SelectProvider(type = SqlProvider.class, method = "selectExistingDataValues")
|
||||
@@ -25,16 +22,6 @@ public interface DedupeTotalDataMapper extends BaseMapper<DedupeTotalDataEntity>
|
||||
* index remains the final concurrency guard when another request inserts
|
||||
* the same value between the pre-check and this statement.
|
||||
*/
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT IGNORE INTO biz_dedupe_total_data
|
||||
(data_value, country, group_id, uploader_user_id, uploader_username, company_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.dataValue}, #{row.country}, #{row.groupId}, #{row.uploaderUserId}, #{row.uploaderUsername}, #{row.companyId})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int insertBatchIgnore(@Param("rows") List<DedupeTotalDataEntity> rows);
|
||||
|
||||
class SqlProvider {
|
||||
|
||||
-6
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.devicelog.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.devicelog.model.entity.DeviceLogFileEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -17,10 +16,5 @@ public interface DeviceLogFileMapper extends BaseMapper<DeviceLogFileEntity> {
|
||||
* <p>只删 {@code log_date} 早于 cutoff 的行:这条线正好是查询侧可见窗口的边界,
|
||||
* 即"早已看不见、只剩占位"的行,删掉不影响任何读取路径。
|
||||
*/
|
||||
@Delete("""
|
||||
DELETE FROM device_log_file
|
||||
WHERE log_date < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteOlderThanBatch(@Param("cutoff") LocalDate cutoff, @Param("batchSize") int batchSize);
|
||||
}
|
||||
|
||||
-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);
|
||||
}
|
||||
|
||||
-11
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.invalidasin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.invalidasin.model.entity.InvalidAsinDataEntity;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -25,15 +24,5 @@ public interface InvalidAsinDataMapper extends BaseMapper<InvalidAsinDataEntity>
|
||||
* 不告诉 MyBatis 类型它会抛 "Error setting null parameter",而调用方把异常吞成 log.warn,
|
||||
* 于是整批黑名单静默丢掉。</p>
|
||||
*/
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT IGNORE INTO biz_invalid_asin_data
|
||||
(data_value, brand, record_source, uploader_user_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.dataValue}, #{row.brand}, #{row.recordSource}, #{row.uploaderUserId,jdbcType=BIGINT})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int insertBatchIgnore(@Param("rows") List<InvalidAsinDataEntity> rows);
|
||||
}
|
||||
|
||||
-11
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.notification.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.notification.model.entity.UserNotificationEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -17,18 +16,8 @@ public interface UserNotificationMapper extends BaseMapper<UserNotificationEntit
|
||||
* <p>两条都按 {@code created_at < cutoff} 走建表即有的 {@code idx_created_at}:保留窗口外的行
|
||||
* 几乎全部命中删除条件,索引 range 扫前 N 行就能凑满一批,因此不必再为 read_at 补组合索引。
|
||||
*/
|
||||
@Delete("""
|
||||
DELETE FROM biz_user_notification
|
||||
WHERE read_at IS NOT NULL AND created_at < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteReadBeforeBatch(@Param("cutoff") LocalDateTime cutoff, @Param("batchSize") int batchSize);
|
||||
|
||||
/** 分批删除保留期外的<b>未读</b>通知(与已读同一条时间线)。 */
|
||||
@Delete("""
|
||||
DELETE FROM biz_user_notification
|
||||
WHERE read_at IS NULL AND created_at < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteUnreadBeforeBatch(@Param("cutoff") LocalDateTime cutoff, @Param("batchSize") int batchSize);
|
||||
}
|
||||
|
||||
-19
@@ -1,45 +1,26 @@
|
||||
package com.nanri.aiimage.modules.permission.mapper;
|
||||
|
||||
import com.nanri.aiimage.modules.permission.model.entity.UserColumnPermissionEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserColumnPermissionMapper {
|
||||
|
||||
@Insert("INSERT INTO user_column_permission (user_id, column_id) VALUES (#{userId}, #{columnId})")
|
||||
int insert(UserColumnPermissionEntity entity);
|
||||
|
||||
@Select("SELECT user_id, column_id FROM user_column_permission WHERE user_id = #{userId}")
|
||||
List<UserColumnPermissionEntity> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select("SELECT user_id, column_id FROM user_column_permission WHERE column_id = #{columnId}")
|
||||
List<UserColumnPermissionEntity> selectByColumnId(@Param("columnId") Long columnId);
|
||||
|
||||
@Select("SELECT COUNT(*) FROM user_column_permission WHERE user_id = #{userId} AND column_id = #{columnId}")
|
||||
Long countByUserIdAndColumnId(@Param("userId") Long userId, @Param("columnId") Long columnId);
|
||||
|
||||
@Delete("DELETE FROM user_column_permission WHERE user_id = #{userId}")
|
||||
int deleteByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Delete("DELETE FROM user_column_permission WHERE column_id = #{columnId}")
|
||||
int deleteByColumnId(@Param("columnId") Long columnId);
|
||||
|
||||
@Delete("""
|
||||
<script>
|
||||
DELETE FROM user_column_permission
|
||||
WHERE user_id = #{userId}
|
||||
AND column_id IN
|
||||
<foreach collection="columnIds" item="columnId" open="(" separator="," close=")">
|
||||
#{columnId}
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int deleteByUserIdAndColumnIds(@Param("userId") Long userId,
|
||||
@Param("columnIds") List<Long> columnIds);
|
||||
}
|
||||
|
||||
-7
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.pricetrack.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.pricetrack.model.entity.PriceTrackLoopRunEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -19,11 +18,5 @@ public interface PriceTrackLoopRunMapper extends BaseMapper<PriceTrackLoopRunEnt
|
||||
* created_at),口径与改造前完全一致):原来这个表达式直接写在 WHERE 里不可走索引,
|
||||
* 每条 DELETE 都要全表扫描并对扫过的行加锁,而 (status, cleanup_at) 索引已就位。
|
||||
*/
|
||||
@Delete("""
|
||||
DELETE FROM biz_price_track_loop_run
|
||||
WHERE status IN ('SUCCESS', 'FAILED', 'STOPPED')
|
||||
AND cleanup_at < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteFinishedBefore(@Param("cutoff") LocalDateTime cutoff, @Param("batchSize") int batchSize);
|
||||
}
|
||||
-14
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.publish.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.publish.model.entity.PublishItemEntity;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -11,18 +10,5 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface PublishItemMapper extends BaseMapper<PublishItemEntity> {
|
||||
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT INTO biz_publish_item
|
||||
(task_id, file_id, row_index, source_id, asin, country, brand, price_value,
|
||||
status_value, sync_status, sync_countries, created_at, updated_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.taskId}, #{row.fileId}, #{row.rowIndex}, #{row.sourceId}, #{row.asin},
|
||||
#{row.country}, #{row.brand}, #{row.priceValue}, #{row.statusValue},
|
||||
#{row.syncStatus}, #{row.syncCountries}, #{row.createdAt}, #{row.updatedAt})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int insertBatch(@Param("rows") List<PublishItemEntity> rows);
|
||||
}
|
||||
|
||||
-12
@@ -6,7 +6,6 @@ import com.nanri.aiimage.modules.shopdatacrawl.model.dto.ShopDataCrawlAdminGroup
|
||||
import com.nanri.aiimage.modules.shopdatacrawl.model.dto.ShopDataCrawlAdminRow;
|
||||
import com.nanri.aiimage.modules.shopdatacrawl.model.dto.ShopDataCrawlDownloadRowDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
|
||||
import java.util.List;
|
||||
@@ -47,20 +46,9 @@ public interface ShopDataCrawlAdminTasksMapper {
|
||||
List<ShopDataCrawlDownloadRowDto> selectDownloadRows(Map<String, Object> p);
|
||||
|
||||
/** 按每日累计档 id 取单行(下载/删除用)。 */
|
||||
@Select("""
|
||||
SELECT df.id AS resultId, df.latest_task_id AS taskId, df.user_id AS userId,
|
||||
df.shop_name AS sourceFilename, df.result_filename AS resultFilename,
|
||||
df.result_file_url AS resultFileUrl
|
||||
FROM biz_shop_data_crawl_daily_file df
|
||||
WHERE df.id = #{dailyFileId}
|
||||
""")
|
||||
ShopDataCrawlDownloadRowDto selectDownloadRowById(@org.apache.ibatis.annotations.Param("dailyFileId") Long dailyFileId);
|
||||
|
||||
/** 某一累计对象 key 还被多少 daily_file 行引用。 */
|
||||
@Select("""
|
||||
SELECT COUNT(1) FROM biz_shop_data_crawl_daily_file
|
||||
WHERE result_file_url = #{objectKey}
|
||||
""")
|
||||
long countDailyFileObjectReferences(@org.apache.ibatis.annotations.Param("objectKey") String objectKey);
|
||||
|
||||
class SqlProvider {
|
||||
|
||||
-28
@@ -2,8 +2,6 @@ package com.nanri.aiimage.modules.shopdatacrawl.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.shopdatacrawl.model.entity.ShopDataCrawlItemEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -13,10 +11,6 @@ import java.util.List;
|
||||
public interface ShopDataCrawlItemMapper extends BaseMapper<ShopDataCrawlItemEntity> {
|
||||
|
||||
/** 删除某店某批次(每日快照替换语义:先删后插)。 */
|
||||
@Delete("""
|
||||
DELETE FROM biz_shop_data_crawl_item
|
||||
WHERE shop_name = #{shopName} AND business_date = #{businessDate}
|
||||
""")
|
||||
int deleteBatch(@Param("shopName") String shopName, @Param("businessDate") java.time.LocalDate businessDate);
|
||||
|
||||
/**
|
||||
@@ -26,18 +20,9 @@ public interface ShopDataCrawlItemMapper extends BaseMapper<ShopDataCrawlItemEnt
|
||||
* 撞款扫描只读每店最新批次,历史批次仅用于追溯,过期即可删;分批删避免长事务与大范围行锁,
|
||||
* 走 idx_shop_data_crawl_item_biz_date 范围扫描。
|
||||
*/
|
||||
@Delete("""
|
||||
DELETE FROM biz_shop_data_crawl_item
|
||||
WHERE business_date < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteOlderThanBatch(@Param("cutoff") java.time.LocalDate cutoff, @Param("batchSize") int batchSize);
|
||||
|
||||
/** 删除归属某累计档的全部明细行(管理端真删店铺数据记录时清理,避免留下悬空引用)。 */
|
||||
@Delete("""
|
||||
DELETE FROM biz_shop_data_crawl_item
|
||||
WHERE daily_file_id = #{dailyFileId}
|
||||
""")
|
||||
int deleteByDailyFileId(@Param("dailyFileId") Long dailyFileId);
|
||||
|
||||
/**
|
||||
@@ -47,18 +32,5 @@ public interface ShopDataCrawlItemMapper extends BaseMapper<ShopDataCrawlItemEnt
|
||||
* 此前逐行 insert 会产生同数量网络往返并全部持在一个事务里,是采集落库耗时与主从延迟的主要来源。
|
||||
* 刻意不写 created_at:该列有 DB 默认值 CURRENT_TIMESTAMP,显式传 null 会覆盖掉默认值。
|
||||
*/
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT INTO biz_shop_data_crawl_item
|
||||
(shop_id, shop_name, group_name, business_date, country, asin, brand, price,
|
||||
item_date, units_sold, item_json, result_id, task_id, daily_file_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.shopId}, #{row.shopName}, #{row.groupName}, #{row.businessDate}, #{row.country},
|
||||
#{row.asin}, #{row.brand}, #{row.price}, #{row.itemDate}, #{row.unitsSold},
|
||||
#{row.itemJson}, #{row.resultId}, #{row.taskId}, #{row.dailyFileId})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int insertBatch(@Param("rows") List<ShopDataCrawlItemEntity> rows);
|
||||
}
|
||||
|
||||
-14
@@ -4,10 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ScanLightRowDto;
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ScanFullRowDto;
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.model.entity.ShopDataDuplicateScanEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -15,27 +13,15 @@ import java.time.LocalDateTime;
|
||||
public interface ShopDataDuplicateScanMapper extends BaseMapper<ShopDataDuplicateScanEntity> {
|
||||
|
||||
/** 轻量判活:仅取最新 SUCCESS 行 id/created_at,避免每次请求读大 payload。 */
|
||||
@Select("SELECT id, created_at AS createdAt FROM shop_data_duplicate_scan "
|
||||
+ "WHERE status = 'SUCCESS' ORDER BY id DESC LIMIT 1")
|
||||
ScanLightRowDto selectLatestLightRow();
|
||||
|
||||
/** 全量读取最新 SUCCESS 行(含 summary/payload 反序列化)。 */
|
||||
@Select("SELECT id, summary_json AS summaryJson, payload_json AS payloadJson, "
|
||||
+ "created_at AS createdAt FROM shop_data_duplicate_scan "
|
||||
+ "WHERE status = 'SUCCESS' ORDER BY id DESC LIMIT 1")
|
||||
ScanFullRowDto selectLatestFullRow();
|
||||
|
||||
/** 第 N 新的行 id(offset 从 0 计);行数不足时返回 null,供保留清理计算保护线。 */
|
||||
@Select("SELECT id FROM shop_data_duplicate_scan ORDER BY id DESC LIMIT 1 OFFSET #{offset}")
|
||||
Long selectNthNewestId(@Param("offset") int offset);
|
||||
|
||||
/** 分批删除保留期外、且早于保护线的历史扫描行。 */
|
||||
@Delete("""
|
||||
DELETE FROM shop_data_duplicate_scan
|
||||
WHERE created_at < #{cutoff}
|
||||
AND id < #{protectFromId}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteOlderThanBatch(@Param("cutoff") LocalDateTime cutoff,
|
||||
@Param("protectFromId") long protectFromId,
|
||||
@Param("batchSize") int batchSize);
|
||||
|
||||
-45
@@ -4,7 +4,6 @@ import com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopDailyFileMigra
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopLatestItemRowDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
@@ -20,7 +19,6 @@ public interface ShopDuplicateCheckItemMapper {
|
||||
* 全量店铺名(去重,走 idx_shop_data_crawl_item_shop_date 的索引扫描,不读行数据)。
|
||||
* 撞款扫描按店逐批取数用,避免一次性把全部明细拉进堆。
|
||||
*/
|
||||
@Select("SELECT DISTINCT shop_name FROM biz_shop_data_crawl_item")
|
||||
List<String> selectDistinctShopNames();
|
||||
|
||||
/**
|
||||
@@ -28,57 +26,14 @@ public interface ShopDuplicateCheckItemMapper {
|
||||
* 内层 MAX(business_date) 走 (shop_name, business_date) 索引(松散索引扫描),
|
||||
* 外层按索引前缀取该批次,只读目标店的行,不再全表 GROUP BY + JOIN。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT i.shop_name AS shopName,
|
||||
i.country AS country,
|
||||
i.asin AS asin,
|
||||
i.item_date AS itemDate,
|
||||
i.price AS price,
|
||||
i.brand AS brand
|
||||
FROM biz_shop_data_crawl_item i
|
||||
WHERE i.shop_name = #{shopName}
|
||||
AND i.business_date = (
|
||||
SELECT MAX(business_date) FROM biz_shop_data_crawl_item WHERE shop_name = #{shopName}
|
||||
)
|
||||
""")
|
||||
List<ShopLatestItemRowDto> selectLatestItemsByShop(@Param("shopName") String shopName);
|
||||
|
||||
/** 幂等判定:该店该日是否已有明细批次。 */
|
||||
@Select("""
|
||||
SELECT COUNT(1) FROM biz_shop_data_crawl_item
|
||||
WHERE shop_name = #{shopName} AND business_date = #{businessDate}
|
||||
""")
|
||||
long countShopBatch(@Param("shopName") String shopName, @Param("businessDate") LocalDate businessDate);
|
||||
|
||||
/** 存量迁移数据源:每店最新已补偿 daily_file(join 最新结果行拿店名/文件地址)。 */
|
||||
@Select("""
|
||||
SELECT ranked.daily_file_id AS dailyFileId,
|
||||
ranked.business_date AS businessDate,
|
||||
ranked.latest_result_id AS latestResultId,
|
||||
fr.source_filename AS shopName,
|
||||
fr.result_file_url AS resultFileUrl,
|
||||
fr.task_id AS taskId
|
||||
FROM (
|
||||
SELECT df.id AS daily_file_id,
|
||||
df.business_date,
|
||||
df.latest_result_id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY df.shop_key
|
||||
ORDER BY df.business_date DESC, df.id DESC) AS row_no
|
||||
FROM biz_shop_data_crawl_daily_file df
|
||||
WHERE df.compensation_done = 1
|
||||
) ranked
|
||||
JOIN biz_file_result fr ON fr.id = ranked.latest_result_id
|
||||
WHERE ranked.row_no = 1
|
||||
AND fr.module_type = 'SHOP_DATA_CRAWL'
|
||||
""")
|
||||
List<ShopDailyFileMigrationDto> selectLegacyMigrationFiles();
|
||||
|
||||
/** 取每日成员行(row_payload 快照 JSON),无 payload 时返回 null。 */
|
||||
@Select("""
|
||||
SELECT row_payload FROM biz_shop_data_crawl_daily_member
|
||||
WHERE daily_file_id = #{dailyFileId} AND result_id = #{resultId}
|
||||
LIMIT 1
|
||||
""")
|
||||
String selectMemberPayload(@Param("dailyFileId") Long dailyFileId, @Param("resultId") Long resultId);
|
||||
}
|
||||
|
||||
-70
@@ -4,7 +4,6 @@ import com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopGroupLabelDto;
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopSourceRowDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,81 +19,21 @@ public interface ShopDuplicateCheckSourceMapper {
|
||||
* 每家店铺最新一条 biz_file_result 行(shop 最新累计结果文件,含该店全部国家/记录)。
|
||||
* 结果文件 URL 非空即参与,不要求 task/result 成功(与 Python 语义一致)。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT ranked.result_id AS resultId,
|
||||
ranked.shop_name AS shopName,
|
||||
ranked.result_file_url AS resultFileUrl,
|
||||
ranked.result_file_size AS resultFileSize,
|
||||
ranked.request_json AS requestJson,
|
||||
ranked.country_codes_json AS countryCodesJson
|
||||
FROM (
|
||||
SELECT r.id AS result_id,
|
||||
r.source_filename AS shop_name,
|
||||
r.result_file_url,
|
||||
r.result_file_size,
|
||||
t.request_json,
|
||||
df.country_codes_json,
|
||||
COALESCE(df.last_success_at, df.updated_at, t.finished_at,
|
||||
t.updated_at, t.created_at) AS latest_file_updated_at,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY TRIM(COALESCE(r.source_filename, ''))
|
||||
ORDER BY COALESCE(df.last_success_at, df.updated_at,
|
||||
t.finished_at, t.updated_at, t.created_at) DESC,
|
||||
r.id DESC) AS row_no
|
||||
FROM biz_file_result r
|
||||
JOIN biz_file_task t ON t.id = r.task_id
|
||||
LEFT JOIN biz_shop_data_crawl_daily_file df ON df.latest_result_id = r.id
|
||||
WHERE r.module_type = 'SHOP_DATA_CRAWL'
|
||||
AND t.module_type = 'SHOP_DATA_CRAWL'
|
||||
AND TRIM(COALESCE(r.result_file_url, '')) <> ''
|
||||
) ranked
|
||||
WHERE ranked.row_no = 1
|
||||
ORDER BY ranked.latest_file_updated_at DESC, ranked.result_id DESC
|
||||
""")
|
||||
List<ShopSourceRowDto> selectLatestResultRows();
|
||||
|
||||
/** 店铺 → 分组名(g.group_name 优先,多分组用「、」连接;店铺名 trim 精确匹配)。 */
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT TRIM(sm.shop_name) AS shopName,
|
||||
GROUP_CONCAT(DISTINCT COALESCE(NULLIF(g.group_name, ''), NULLIF(sm.group_name, ''))
|
||||
ORDER BY sm.id SEPARATOR '、') AS groupName
|
||||
FROM biz_shop_manage sm
|
||||
LEFT JOIN biz_shop_manage_group g ON g.id = sm.group_id
|
||||
WHERE TRIM(sm.shop_name) IN
|
||||
<foreach collection='shopNames' item='name' open='(' separator=',' close=')'>#{name}</foreach>
|
||||
GROUP BY TRIM(sm.shop_name)
|
||||
</script>
|
||||
""")
|
||||
List<ShopGroupLabelDto> selectGroupLabels(@Param("shopNames") List<String> shopNames);
|
||||
|
||||
/**
|
||||
* 全量店铺名+分组标签(biz_shop_manage 全集):扫描基线对齐店铺表——
|
||||
* 无结果文件的店以空态(0 记录)参与扫描,保证撞款控制台超管可见全部分组店铺。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT TRIM(sm.shop_name) AS shopName,
|
||||
GROUP_CONCAT(DISTINCT COALESCE(NULLIF(g.group_name, ''), NULLIF(sm.group_name, ''))
|
||||
ORDER BY sm.id SEPARATOR '、') AS groupName
|
||||
FROM biz_shop_manage sm
|
||||
LEFT JOIN biz_shop_manage_group g ON g.id = sm.group_id
|
||||
WHERE TRIM(COALESCE(sm.shop_name, '')) <> ''
|
||||
GROUP BY TRIM(sm.shop_name)
|
||||
""")
|
||||
List<ShopGroupLabelDto> selectAllShopLabels();
|
||||
|
||||
/**
|
||||
* 主管(admin 角色)可管店铺:自己创建或指派给自己的分组(created_by_id=me OR user_id=me)
|
||||
* 下的店铺名,trim 后去重。无分组时返回空集合(什么都看不到),与 Python 语义一致。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT DISTINCT TRIM(sm.shop_name) AS shopName
|
||||
FROM biz_shop_manage sm
|
||||
WHERE sm.group_id IN (
|
||||
SELECT id FROM biz_shop_manage_group
|
||||
WHERE created_by_id = #{operatorId} OR user_id = #{operatorId}
|
||||
)
|
||||
""")
|
||||
List<String> selectManagedShopNames(@Param("operatorId") Long operatorId);
|
||||
|
||||
/**
|
||||
@@ -107,14 +46,5 @@ public interface ShopDuplicateCheckSourceMapper {
|
||||
*
|
||||
* <p>空成员集不在这条 SQL 里兜:IN () 是语法错,调用方必须在 memberIds 为空时直接给空集合。</p>
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT DISTINCT TRIM(sm.shop_name)
|
||||
FROM biz_shop_manage sm
|
||||
WHERE TRIM(COALESCE(sm.shop_name, '')) <> ''
|
||||
AND sm.created_by_id IN
|
||||
<foreach collection="memberIds" item="mid" open="(" separator="," close=")">#{mid}</foreach>
|
||||
</script>
|
||||
""")
|
||||
List<String> selectShopNamesOwnedBy(@Param("memberIds") List<Long> memberIds);
|
||||
}
|
||||
|
||||
-35
@@ -4,8 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.QueryAsinEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -13,43 +11,10 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface QueryAsinMapper extends BaseMapper<QueryAsinEntity> {
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT id, group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es, created_at, updated_at
|
||||
FROM biz_query_asin
|
||||
WHERE group_id IN
|
||||
<foreach collection="groupIds" item="groupId" open="(" separator="," close=")">
|
||||
#{groupId}
|
||||
</foreach>
|
||||
AND shop_name IN
|
||||
<foreach collection="shopNames" item="shopName" open="(" separator="," close=")">
|
||||
#{shopName}
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
List<QueryAsinEntity> selectByGroupIdsAndShopNames(@Param("groupIds") Collection<Long> groupIds,
|
||||
@Param("shopNames") Collection<String> shopNames);
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT id, group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es, created_at, updated_at
|
||||
FROM biz_query_asin
|
||||
WHERE shop_name IN
|
||||
<foreach collection="shopNames" item="shopName" open="(" separator="," close=")">
|
||||
#{shopName}
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
List<QueryAsinEntity> selectByShopNames(@Param("shopNames") Collection<String> shopNames);
|
||||
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT INTO biz_query_asin (group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.groupId}, #{row.shopName}, #{row.asinDe}, #{row.asinUk}, #{row.asinFr}, #{row.asinIt}, #{row.asinEs})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
int insertBatch(@Param("rows") List<QueryAsinEntity> rows);
|
||||
}
|
||||
|
||||
-2
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.softwareversion.model.entity.SoftwareVersionEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
@Mapper
|
||||
public interface SoftwareVersionMapper extends BaseMapper<SoftwareVersionEntity> {
|
||||
@@ -17,6 +16,5 @@ public interface SoftwareVersionMapper extends BaseMapper<SoftwareVersionEntity>
|
||||
* 零标记的中间态,而本方法要在 MinIO 上传流程之后调用,不值得为 62 行的表
|
||||
* 拉一个事务、还要为此绕开 Spring 自调用不走代理的问题。
|
||||
*/
|
||||
@Update("UPDATE web_config SET is_latest = (id = #{id})")
|
||||
int markLatestById(@Param("id") Long id);
|
||||
}
|
||||
|
||||
-11
@@ -5,7 +5,6 @@ import com.nanri.aiimage.modules.task.model.dto.TaskRowsVersionDto;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,16 +19,6 @@ public interface FileResultMapper extends BaseMapper<FileResultEntity> {
|
||||
* 前端据 (latestRowAt, rowCount) 判断该任务的行数据是否变化,未变就不必再拉带行明细的重型 batch。
|
||||
* GROUP BY 走 (task_id) 索引,每任务一行。
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT task_id AS taskId, MAX(updated_at) AS latestRowAt, COUNT(*) AS rowCount
|
||||
FROM biz_file_result
|
||||
WHERE module_type = #{moduleType}
|
||||
AND task_id IN
|
||||
<foreach item="taskId" collection="taskIds" open="(" separator="," close=")">#{taskId}</foreach>
|
||||
GROUP BY task_id
|
||||
</script>
|
||||
""")
|
||||
List<TaskRowsVersionDto> selectRowsUpdatedAtByTaskIds(@Param("moduleType") String moduleType,
|
||||
@Param("taskIds") List<Long> taskIds);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
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;
|
||||
@@ -23,14 +22,6 @@ public interface FileTaskMapper extends BaseMapper<FileTaskEntity> {
|
||||
* 且能命中 V120 的 idx_biz_file_task_status_updated(status, updated_at) 索引,避免每轮全表扫描。
|
||||
* 注意不要在这里包 COALESCE(finished_at, updated_at):表达式会让该索引失效。
|
||||
*/
|
||||
@Select("""
|
||||
SELECT id FROM biz_file_task
|
||||
WHERE module_type = #{moduleType}
|
||||
AND status IN ('SUCCESS', 'FAILED', 'CANCELLED', 'CANCELED')
|
||||
AND updated_at < #{cutoff}
|
||||
ORDER BY id ASC
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
List<Long> selectExpiredTerminalTaskIds(@Param("moduleType") String moduleType,
|
||||
@Param("cutoff") LocalDateTime cutoff,
|
||||
@Param("batchSize") int batchSize);
|
||||
|
||||
-22
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.task.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskResultItemEntity;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -15,26 +14,5 @@ public interface TaskResultItemMapper extends BaseMapper<TaskResultItemEntity> {
|
||||
* 按唯一键 uk_task_scope_item (task_id, module_type, scope_hash, item_key)
|
||||
* 批量 upsert:命中唯一键时更新行内容(含 id 保留),否则插入。
|
||||
*/
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT INTO biz_task_result_item
|
||||
(task_id, module_type, result_id, scope_key, scope_hash, item_key, asin, status,
|
||||
payload_json, payload_hash, created_at, updated_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.taskId}, #{row.moduleType}, #{row.resultId}, #{row.scopeKey}, #{row.scopeHash},
|
||||
#{row.itemKey}, #{row.asin}, #{row.status}, #{row.payloadJson}, #{row.payloadHash},
|
||||
#{row.createdAt}, #{row.updatedAt})
|
||||
</foreach>
|
||||
ON DUPLICATE KEY UPDATE
|
||||
result_id = VALUES(result_id),
|
||||
scope_key = VALUES(scope_key),
|
||||
asin = VALUES(asin),
|
||||
status = VALUES(status),
|
||||
payload_json = VALUES(payload_json),
|
||||
payload_hash = VALUES(payload_hash),
|
||||
updated_at = VALUES(updated_at)
|
||||
</script>
|
||||
""")
|
||||
int upsertBatch(@Param("rows") List<TaskResultItemEntity> rows);
|
||||
}
|
||||
|
||||
-11
@@ -5,7 +5,6 @@ import com.nanri.aiimage.modules.task.model.dto.TaskScopeLastChunkDto;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskScopeStateEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,15 +19,5 @@ public interface TaskScopeStateMapper extends BaseMapper<TaskScopeStateEntity> {
|
||||
* HAVING 过滤掉全 NULL 的组:从未上报的任务不出现在结果里,调用方据此跳过(不判死)。
|
||||
* GROUP BY 走 uk_task_scope 的 task_id 前缀。
|
||||
*/
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT task_id AS taskId, MAX(last_chunk_at) AS lastChunkAt
|
||||
FROM biz_task_scope_state
|
||||
WHERE task_id IN
|
||||
<foreach item="taskId" collection="taskIds" open="(" separator="," close=")">#{taskId}</foreach>
|
||||
GROUP BY task_id
|
||||
HAVING MAX(last_chunk_at) IS NOT NULL
|
||||
</script>
|
||||
""")
|
||||
List<TaskScopeLastChunkDto> selectLastChunkAtByTaskIds(@Param("taskIds") List<Long> taskIds);
|
||||
}
|
||||
|
||||
-134
@@ -10,7 +10,6 @@ import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterTaskRow;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterUserRow;
|
||||
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;
|
||||
@@ -108,59 +107,15 @@ public interface TaskCenterQueryMapper {
|
||||
String USER_SCOPE_S = "<if test='userIds != null'> AND s.created_by_id IN"
|
||||
+ " <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>";
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT COUNT(*) FROM ("
|
||||
+ " SELECT t.id FROM biz_file_task t"
|
||||
+ " WHERE t.module_type IN (" + CLIENT_MODULE_TYPES + ")"
|
||||
+ " AND t.status IN (" + ACTIVE_STATUSES + ")"
|
||||
+ USER_SCOPE_T
|
||||
+ " UNION ALL"
|
||||
+ " SELECT b.id FROM brand_crawl_tasks b"
|
||||
+ " WHERE b.status IN (" + BRAND_ACTIVE_STATUSES + ")"
|
||||
+ USER_SCOPE_B
|
||||
+ ") u"
|
||||
+ "</script>")
|
||||
long countRunningTasks(@Param("userIds") List<Long> userIds);
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT COUNT(*) FROM ("
|
||||
+ " SELECT t.id FROM biz_file_task t"
|
||||
+ " WHERE t.module_type IN (" + CLIENT_MODULE_TYPES + ")"
|
||||
+ " AND t.status IN (" + ACTIVE_STATUSES + ")"
|
||||
+ " AND t.updated_at < #{idleBefore}"
|
||||
+ USER_SCOPE_T
|
||||
+ " UNION ALL"
|
||||
+ " SELECT b.id FROM brand_crawl_tasks b"
|
||||
+ " WHERE b.status IN (" + BRAND_ACTIVE_STATUSES + ")"
|
||||
+ " AND b.updated_at < #{idleBefore}"
|
||||
+ USER_SCOPE_B
|
||||
+ ") u"
|
||||
+ "</script>")
|
||||
long countStuckTasks(@Param("userIds") List<Long> userIds,
|
||||
@Param("idleBefore") LocalDateTime idleBefore);
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT COUNT(*) FROM ("
|
||||
+ " SELECT t.id FROM biz_file_task t"
|
||||
+ " WHERE t.module_type IN (" + CLIENT_MODULE_TYPES + ")"
|
||||
+ " AND t.status IN (" + TERMINAL_STATUSES + ")"
|
||||
+ " AND COALESCE(t.finished_at, t.updated_at) >= #{since}"
|
||||
+ USER_SCOPE_T
|
||||
+ " UNION ALL"
|
||||
+ " SELECT b.id FROM brand_crawl_tasks b"
|
||||
+ " WHERE b.status IN (" + BRAND_TERMINAL_STATUSES + ")"
|
||||
+ " AND b.updated_at >= #{since}"
|
||||
+ USER_SCOPE_B
|
||||
+ ") u"
|
||||
+ "</script>")
|
||||
long countFinishedTasksSince(@Param("userIds") List<Long> userIds,
|
||||
@Param("since") LocalDateTime since);
|
||||
|
||||
/** 总店铺:店铺库(biz_shop_manage)在可见账号下的数量。 */
|
||||
@Select("<script>"
|
||||
+ "SELECT COUNT(*) FROM biz_shop_manage s WHERE 1 = 1"
|
||||
+ USER_SCOPE_S
|
||||
+ "</script>")
|
||||
long countShops(@Param("userIds") List<Long> userIds);
|
||||
|
||||
/**
|
||||
@@ -169,11 +124,6 @@ public interface TaskCenterQueryMapper {
|
||||
* <p>biz_shop_manage 里带 account/password/zn_username,这一列之外的都不能出,
|
||||
* 由 {@code TaskCenterQueryMapperSqlTest.shopOptionsAreDistinctNamesWithoutCredentialColumns} 守住。</p>
|
||||
*/
|
||||
@Select("<script>"
|
||||
+ "SELECT DISTINCT s.shop_name FROM biz_shop_manage s WHERE 1 = 1"
|
||||
+ USER_SCOPE_S
|
||||
+ " ORDER BY s.shop_name LIMIT 2000"
|
||||
+ "</script>")
|
||||
List<String> selectShopNames(@Param("userIds") List<Long> userIds);
|
||||
|
||||
/** 状态归一化:CANCELED 并入 CANCELLED(历史脏值),前端只认一套。 */
|
||||
@@ -265,11 +215,6 @@ public interface TaskCenterQueryMapper {
|
||||
+ USER_SCOPE_B
|
||||
+ ")";
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT m.* FROM " + TASK_LIST_ROWS + " m"
|
||||
+ " ORDER BY m.createdAt DESC, m.id DESC"
|
||||
+ " LIMIT #{limit} OFFSET #{offset}"
|
||||
+ "</script>")
|
||||
List<TaskCenterTaskRow> selectTaskPage(@Param("userIds") List<Long> userIds,
|
||||
@Param("moduleType") String moduleType,
|
||||
@Param("statuses") List<String> statuses,
|
||||
@@ -279,9 +224,6 @@ public interface TaskCenterQueryMapper {
|
||||
@Param("limit") long limit,
|
||||
@Param("offset") long offset);
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT COUNT(*) FROM " + TASK_LIST_ROWS + " m"
|
||||
+ "</script>")
|
||||
long countTaskPage(@Param("userIds") List<Long> userIds,
|
||||
@Param("moduleType") String moduleType,
|
||||
@Param("statuses") List<String> statuses,
|
||||
@@ -290,43 +232,21 @@ public interface TaskCenterQueryMapper {
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
/** 店铺面板的原料:当前全部进行中任务(超管口径下上限 500,截断由服务层显式提示)。 */
|
||||
@Select("<script>"
|
||||
+ "SELECT m.* FROM " + ACTIVE_TASK_ROWS + " m"
|
||||
+ " ORDER BY m.createdAt DESC, m.id DESC"
|
||||
+ " LIMIT #{limit}"
|
||||
+ "</script>")
|
||||
List<TaskCenterTaskRow> selectActiveTasks(@Param("userIds") List<Long> userIds,
|
||||
@Param("limit") long limit);
|
||||
|
||||
/** 账号名筛选 → 用户号(与可见账号集合求交由服务层负责)。 */
|
||||
@Select("SELECT id FROM users WHERE username LIKE CONCAT('%', #{keyword}, '%') LIMIT 500")
|
||||
List<Long> selectUserIdsByUsername(@Param("keyword") String keyword);
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT id AS userId, username FROM users WHERE id IN"
|
||||
+ " <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach>"
|
||||
+ "</script>")
|
||||
List<TaskCenterUserRow> selectUsernames(@Param("userIds") List<Long> userIds);
|
||||
|
||||
/** 设备展示名(详情里保留「跑在哪台机」;列表与面板不再按设备装配)。 */
|
||||
@Select("<script>"
|
||||
+ "SELECT d.device_id AS deviceId, MAX(d.device_name) AS deviceName"
|
||||
+ " FROM device_log_file d WHERE d.device_id IN"
|
||||
+ " <foreach collection='deviceIds' item='did' open='(' separator=',' close=')'>#{did}</foreach>"
|
||||
+ " GROUP BY d.device_id"
|
||||
+ "</script>")
|
||||
List<TaskCenterDeviceRow> selectDeviceNames(@Param("deviceIds") List<String> deviceIds);
|
||||
|
||||
/** 品牌任务在列表/详情里的任务号前缀(task_no = brand-<id>)。 */
|
||||
String BRAND_TASK_NO_PREFIX = "brand-";
|
||||
|
||||
/** 店铺来源一:上架结果文件(shop_name)。 */
|
||||
@Select("<script>"
|
||||
+ "SELECT p.task_id AS taskId, p.shop_name AS shop FROM biz_publish_file p"
|
||||
+ " WHERE p.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>"
|
||||
+ " AND p.shop_name IS NOT NULL AND p.shop_name != ''"
|
||||
+ " GROUP BY p.task_id, p.shop_name"
|
||||
+ "</script>")
|
||||
List<TaskCenterShopRow> selectPublishShops(@Param("taskIds") List<Long> taskIds);
|
||||
|
||||
/**
|
||||
@@ -336,24 +256,9 @@ public interface TaskCenterQueryMapper {
|
||||
* <p>JOIN 回 biz_file_task 而不是靠调用方保证:店铺面板传进来的是两表混合 id,
|
||||
* 品牌任务 id 与 biz id 会撞号,白名单必须先由 biz 行筛掉。</p>
|
||||
*/
|
||||
@Select("<script>"
|
||||
+ "SELECT f.task_id AS taskId, f.source_filename AS shop FROM biz_file_result f"
|
||||
+ " JOIN biz_file_task ft ON ft.id = f.task_id"
|
||||
+ " AND ft.module_type IN (" + FILE_RESULT_SHOP_MODULES + ")"
|
||||
+ " WHERE f.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>"
|
||||
+ " AND f.source_filename IS NOT NULL AND f.source_filename != ''"
|
||||
+ " GROUP BY f.task_id, f.source_filename"
|
||||
+ "</script>")
|
||||
List<TaskCenterShopRow> selectFileResultShops(@Param("taskIds") List<Long> taskIds);
|
||||
|
||||
/** 进度快照(只用于「当前处理」与进度列,不作为店铺来源)。按 (taskId, moduleType) 由服务层匹配。 */
|
||||
@Select("<script>"
|
||||
+ "SELECT s.task_id AS taskId, s.module_type AS moduleType, s.total_count AS totalCount,"
|
||||
+ " s.success_count AS successCount, s.failed_count AS failedCount, s.pending_count AS pendingCount,"
|
||||
+ " s.current_scope_key AS currentScopeKey, s.message AS message"
|
||||
+ " FROM biz_task_progress_snapshot s"
|
||||
+ " WHERE s.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>"
|
||||
+ "</script>")
|
||||
List<TaskCenterSnapshotRow> selectSnapshots(@Param("taskIds") List<Long> taskIds);
|
||||
|
||||
/**
|
||||
@@ -362,15 +267,6 @@ public interface TaskCenterQueryMapper {
|
||||
*
|
||||
* <p>列是原生 JSON 类型,缺键只会得到 NULL(服务层按「无进度」读),不会让整页查询报错。</p>
|
||||
*/
|
||||
@Select("<script>"
|
||||
+ "SELECT t.id AS taskId,"
|
||||
+ " JSON_UNQUOTE(JSON_EXTRACT(t.result_json, '$.totalRows')) AS totalRows,"
|
||||
+ " JSON_UNQUOTE(JSON_EXTRACT(t.result_json, '$.processedRows')) AS processedRows"
|
||||
+ " FROM biz_file_task t"
|
||||
+ " WHERE t.id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>"
|
||||
+ " AND UPPER(t.module_type) = 'COLLECT_DATA'"
|
||||
+ " AND t.result_json IS NOT NULL"
|
||||
+ "</script>")
|
||||
List<TaskCenterCollectStatsRow> selectCollectDataKeywordStats(@Param("taskIds") List<Long> taskIds);
|
||||
|
||||
/**
|
||||
@@ -392,47 +288,17 @@ public interface TaskCenterQueryMapper {
|
||||
+ "NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.filters.countryCodes')), ''), 'null')"
|
||||
+ ")";
|
||||
|
||||
@Select("<script>"
|
||||
+ "SELECT t.id AS taskId, " + COUNTRY_PATHS + " AS country"
|
||||
+ " FROM biz_file_task t"
|
||||
+ " WHERE t.id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>"
|
||||
+ "</script>")
|
||||
List<TaskCenterCountryRow> selectTaskCountries(@Param("taskIds") List<Long> taskIds);
|
||||
|
||||
/** 详情:按任务号取单行(只认 12 个客户端模块,其余模块不在看板范围)。 */
|
||||
@Select("SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType,"
|
||||
+ " " + STATUS_T + " AS status, t.user_id AS userId, t.device_id AS deviceId,"
|
||||
+ " t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt,"
|
||||
+ " t.source_file_count AS totalCount, t.success_file_count AS successCount,"
|
||||
+ " t.failed_file_count AS failedCount, 0 AS brand, t.error_message AS errorMessage"
|
||||
+ " FROM biz_file_task t"
|
||||
+ " WHERE t.task_no = #{taskNo} AND t.module_type IN (" + CLIENT_MODULE_TYPES + ")"
|
||||
+ " LIMIT 1")
|
||||
TaskCenterTaskRow selectTaskByTaskNo(@Param("taskNo") String taskNo);
|
||||
|
||||
/** 详情:品牌任务行(task_no = brand-<id>,这里按 id 取)。 */
|
||||
@Select("SELECT b.id AS id, CONCAT('" + BRAND_TASK_NO_PREFIX + "', b.id) AS taskNo, 'BRAND' AS moduleType,"
|
||||
+ " " + STATUS_B + " AS status, b.user_id AS userId, b.device_id AS deviceId,"
|
||||
+ " b.created_at AS createdAt,"
|
||||
+ " CASE WHEN b.status IN (" + BRAND_TERMINAL_STATUSES + ") THEN b.updated_at END AS finishedAt,"
|
||||
+ " b.updated_at AS updatedAt, b.progress_total AS totalCount, b.progress_current AS successCount,"
|
||||
+ " 0 AS failedCount, 1 AS brand, b.error_message AS errorMessage"
|
||||
+ " FROM brand_crawl_tasks b WHERE b.id = #{id}")
|
||||
TaskCenterTaskRow selectBrandTaskById(@Param("id") Long id);
|
||||
|
||||
/** 详情分组明细(上架):按店铺聚合文件数 + 成功/失败文件数,最多的排前面。 */
|
||||
@Select("SELECT p.shop_name AS scopeKey, COUNT(*) AS total,"
|
||||
+ " SUM(UPPER(p.status) = 'SUCCESS') AS success, SUM(UPPER(p.status) = 'FAILED') AS failed"
|
||||
+ " FROM biz_publish_file p"
|
||||
+ " WHERE p.task_id = #{taskId} AND p.shop_name IS NOT NULL AND p.shop_name != ''"
|
||||
+ " GROUP BY p.shop_name ORDER BY COUNT(*) DESC, p.shop_name LIMIT 200")
|
||||
List<TaskCenterShopStatRow> selectPublishShopStats(@Param("taskId") Long taskId);
|
||||
|
||||
/** 详情分组明细(其余模块):按任务结果分组 scope_key 聚合条目数。 */
|
||||
@Select("SELECT i.scope_key AS scopeKey, COUNT(*) AS total,"
|
||||
+ " SUM(UPPER(i.status) = 'SUCCESS') AS success, SUM(UPPER(i.status) = 'FAILED') AS failed"
|
||||
+ " FROM biz_task_result_item i"
|
||||
+ " WHERE i.task_id = #{taskId} AND i.scope_key IS NOT NULL AND i.scope_key != ''"
|
||||
+ " GROUP BY i.scope_key ORDER BY COUNT(*) DESC, i.scope_key LIMIT 200")
|
||||
List<TaskCenterShopStatRow> selectResultItemShopStats(@Param("taskId") Long taskId);
|
||||
}
|
||||
|
||||
-12
@@ -2,8 +2,6 @@ package com.nanri.aiimage.modules.usersecret.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.usersecret.model.entity.UserSecretUsageEntity;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -16,21 +14,11 @@ public interface UserSecretUsageMapper extends BaseMapper<UserSecretUsageEntity>
|
||||
* 按唯一键 uk_user_module_date 原子累加计次:命中则 call_count 自增,否则插入。
|
||||
* 并发下无需应用层加锁(引擎层唯一键冲突转更新)。
|
||||
*/
|
||||
@Insert("""
|
||||
INSERT INTO biz_user_secret_usage_daily (user_id, module_key, business_date, call_count, created_at, updated_at)
|
||||
VALUES (#{userId}, #{moduleKey}, #{businessDate}, #{count}, NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE call_count = call_count + #{count}, updated_at = NOW()
|
||||
""")
|
||||
int increment(@Param("userId") Long userId,
|
||||
@Param("moduleKey") String moduleKey,
|
||||
@Param("businessDate") LocalDate businessDate,
|
||||
@Param("count") int count);
|
||||
|
||||
/** 分批删除保留期外的用量日统计行(该表此前只增不删)。 */
|
||||
@Delete("""
|
||||
DELETE FROM biz_user_secret_usage_daily
|
||||
WHERE business_date < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
""")
|
||||
int deleteBefore(@Param("cutoff") LocalDate cutoff, @Param("batchSize") int batchSize);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.brand.mapper.BrandCrawlTaskMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="selectExpiredTerminalTaskIds" resultType="long">
|
||||
SELECT id FROM brand_crawl_tasks
|
||||
WHERE status IN ('success', 'failed', 'cancelled')
|
||||
AND updated_at < #{cutoff}
|
||||
ORDER BY id ASC
|
||||
LIMIT #{batchSize}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.collectdata.mapper.CollectDataItemMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO biz_collect_data_item
|
||||
(task_id, row_index, source_file_key, source_filename, keyword, status_value, extra_json, created_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.taskId}, #{row.rowIndex}, #{row.sourceFileKey}, #{row.sourceFilename},
|
||||
#{row.keyword}, #{row.statusValue}, #{row.extraJson}, #{row.createdAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.common.mapper.AdminUserMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="countAdminMenuGrants" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM user_column_permission ucp
|
||||
JOIN columns cm ON cm.id = ucp.column_id
|
||||
WHERE ucp.user_id = #{userId}
|
||||
AND cm.menu_type = 'admin'
|
||||
<if test="companyId != null">
|
||||
AND cm.company_id = #{companyId}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectCompanySuperAdminEarliestExpiry" resultType="java.time.LocalDateTime">
|
||||
SELECT MIN(expires_at)
|
||||
FROM users
|
||||
WHERE role = 'company_super_admin'
|
||||
AND company_id = #{companyId}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.common.mapper.ShopManageGroupMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="selectAccessibleCreatorUserIds" resultType="long">
|
||||
SELECT DISTINCT visible_user_id
|
||||
FROM (
|
||||
SELECT #{operatorId} AS visible_user_id
|
||||
UNION
|
||||
SELECT direct_member.user_id AS visible_user_id
|
||||
FROM biz_shop_manage_group leader_group
|
||||
INNER JOIN biz_shop_manage_group_member direct_member ON direct_member.group_id = leader_group.id
|
||||
WHERE leader_group.created_by_id = #{operatorId}
|
||||
OR leader_group.user_id = #{operatorId}
|
||||
UNION
|
||||
SELECT COALESCE(direct_group.created_by_id, direct_group.user_id) AS visible_user_id
|
||||
FROM biz_shop_manage_group_member membership
|
||||
INNER JOIN biz_shop_manage_group direct_group ON direct_group.id = membership.group_id
|
||||
WHERE membership.user_id = #{operatorId}
|
||||
AND COALESCE(direct_group.created_by_id, direct_group.user_id) IS NOT NULL
|
||||
) visible_users
|
||||
WHERE visible_user_id IS NOT NULL
|
||||
ORDER BY visible_user_id ASC
|
||||
</select>
|
||||
<select id="selectAccessibleGroupIds" resultType="long">
|
||||
SELECT DISTINCT accessible_group_id
|
||||
FROM (
|
||||
SELECT g.id AS accessible_group_id
|
||||
FROM biz_shop_manage_group g
|
||||
WHERE g.created_by_id = #{operatorId}
|
||||
OR g.user_id = #{operatorId}
|
||||
UNION
|
||||
SELECT gm.group_id AS accessible_group_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
WHERE gm.user_id = #{operatorId}
|
||||
UNION
|
||||
SELECT g2.id AS accessible_group_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
INNER JOIN biz_shop_manage_group g1 ON g1.id = gm.group_id
|
||||
INNER JOIN biz_shop_manage_group g2
|
||||
ON g2.created_by_id = COALESCE(g1.created_by_id, g1.user_id)
|
||||
OR g2.user_id = COALESCE(g1.created_by_id, g1.user_id)
|
||||
WHERE gm.user_id = #{operatorId}
|
||||
AND COALESCE(g1.created_by_id, g1.user_id) IS NOT NULL
|
||||
UNION
|
||||
SELECT member_groups.id AS accessible_group_id
|
||||
FROM biz_shop_manage_group leader_group
|
||||
INNER JOIN biz_shop_manage_group_member direct_member ON direct_member.group_id = leader_group.id
|
||||
INNER JOIN biz_shop_manage_group member_groups
|
||||
ON member_groups.created_by_id = direct_member.user_id
|
||||
OR member_groups.user_id = direct_member.user_id
|
||||
WHERE leader_group.created_by_id = #{operatorId}
|
||||
OR leader_group.user_id = #{operatorId}
|
||||
) accessible_groups
|
||||
WHERE accessible_group_id IS NOT NULL
|
||||
ORDER BY accessible_group_id ASC
|
||||
</select>
|
||||
<select id="selectAllGroups" resultType="com.nanri.aiimage.common.model.entity.ShopManageGroupEntity">
|
||||
SELECT g.id AS id, g.group_name AS groupName
|
||||
FROM biz_shop_manage_group g
|
||||
ORDER BY g.id ASC
|
||||
</select>
|
||||
<select id="selectGroupNamesByUserIds" resultType="com.nanri.aiimage.modules.shopkey.model.dto.UserGroupRef">
|
||||
SELECT u.id AS userId, g.group_name AS groupName
|
||||
FROM users u
|
||||
INNER JOIN biz_shop_manage_group g
|
||||
ON g.created_by_id = u.created_by_id OR g.user_id = u.created_by_id
|
||||
WHERE u.created_by_id IS NOT NULL
|
||||
AND u.id IN
|
||||
<foreach collection='userIds' item='userId' open='(' separator=',' close=')'>
|
||||
#{userId}
|
||||
</foreach>
|
||||
ORDER BY g.id ASC
|
||||
</select>
|
||||
<select id="selectLeaderIdsByMemberUserId" resultType="long">
|
||||
SELECT DISTINCT COALESCE(g.created_by_id, g.user_id) AS leader_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
INNER JOIN biz_shop_manage_group g ON g.id = gm.group_id
|
||||
WHERE gm.user_id = #{userId}
|
||||
AND COALESCE(g.created_by_id, g.user_id) IS NOT NULL
|
||||
</select>
|
||||
<select id="selectLedGroups" resultType="com.nanri.aiimage.common.model.entity.ShopManageGroupEntity">
|
||||
SELECT g.id AS id, g.group_name AS groupName
|
||||
FROM biz_shop_manage_group g
|
||||
WHERE g.created_by_id = #{operatorId} OR g.user_id = #{operatorId}
|
||||
ORDER BY g.id ASC
|
||||
</select>
|
||||
<select id="selectManagedMemberUserIds" resultType="long">
|
||||
SELECT DISTINCT gm.user_id
|
||||
FROM biz_shop_manage_group g
|
||||
INNER JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id
|
||||
INNER JOIN users u ON u.id = gm.user_id
|
||||
WHERE g.created_by_id = #{operatorId}
|
||||
OR g.user_id = #{operatorId}
|
||||
ORDER BY gm.user_id ASC
|
||||
</select>
|
||||
<select id="selectUserIdsByGroupId" resultType="long">
|
||||
SELECT u.id AS userId
|
||||
FROM users u
|
||||
INNER JOIN biz_shop_manage_group g ON g.id = #{groupId}
|
||||
WHERE u.id = COALESCE(g.created_by_id, g.user_id)
|
||||
OR u.created_by_id = COALESCE(g.created_by_id, g.user_id)
|
||||
ORDER BY u.id ASC
|
||||
</select>
|
||||
<select id="selectUserIdsByGroupIds" resultType="long">
|
||||
SELECT DISTINCT visible_user_id
|
||||
FROM (
|
||||
SELECT COALESCE(g.created_by_id, g.user_id) AS visible_user_id
|
||||
FROM biz_shop_manage_group g
|
||||
WHERE g.id IN
|
||||
<foreach collection='groupIds' item='groupId' open='(' separator=',' close=')'>
|
||||
#{groupId}
|
||||
</foreach>
|
||||
UNION
|
||||
SELECT gm.user_id AS visible_user_id
|
||||
FROM biz_shop_manage_group_member gm
|
||||
WHERE gm.group_id IN
|
||||
<foreach collection='groupIds' item='groupId' open='(' separator=',' close=')'>
|
||||
#{groupId}
|
||||
</foreach>
|
||||
) visible_users
|
||||
WHERE visible_user_id IS NOT NULL
|
||||
ORDER BY visible_user_id ASC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.dedupe.mapper.DedupeTotalDataMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<insert id="insertBatchIgnore">
|
||||
INSERT IGNORE INTO biz_dedupe_total_data
|
||||
(data_value, country, group_id, uploader_user_id, uploader_username, company_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.dataValue}, #{row.country}, #{row.groupId}, #{row.uploaderUserId}, #{row.uploaderUsername}, #{row.companyId})
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="selectAllDataValues" resultType="string">
|
||||
SELECT data_value FROM biz_dedupe_total_data
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.devicelog.mapper.DeviceLogFileMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<delete id="deleteOlderThanBatch">
|
||||
DELETE FROM device_log_file
|
||||
WHERE log_date < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.imagevideo.mapper.ImageVideoAdminTaskMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="countAdminTaskPage" resultType="long">
|
||||
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>
|
||||
</select>
|
||||
<select id="selectAdminTaskDetail" resultType="map">
|
||||
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 &gt;= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
AND t.id = #{taskId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectAdminTaskPage" resultType="map">
|
||||
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}
|
||||
</select>
|
||||
<select id="selectAdminZipRows" resultType="map">
|
||||
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>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.imagevideo.mapper.ImageVideoAsyncTaskMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<update id="claimPending">
|
||||
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 = '')
|
||||
</update>
|
||||
<update id="claimWaiting">
|
||||
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 = '')
|
||||
</update>
|
||||
<update id="requeuePollingTasks">
|
||||
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 = '')
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.invalidasin.mapper.InvalidAsinDataMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<insert id="insertBatchIgnore">
|
||||
INSERT IGNORE INTO biz_invalid_asin_data
|
||||
(data_value, brand, record_source, uploader_user_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.dataValue}, #{row.brand}, #{row.recordSource}, #{row.uploaderUserId,jdbcType=BIGINT})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.notification.mapper.UserNotificationMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<delete id="deleteReadBeforeBatch">
|
||||
DELETE FROM biz_user_notification
|
||||
WHERE read_at IS NOT NULL AND created_at < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
<delete id="deleteUnreadBeforeBatch">
|
||||
DELETE FROM biz_user_notification
|
||||
WHERE read_at IS NULL AND created_at < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.permission.mapper.UserColumnPermissionMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="countByUserIdAndColumnId" resultType="long">
|
||||
SELECT COUNT(*) FROM user_column_permission WHERE user_id = #{userId} AND column_id = #{columnId}
|
||||
</select>
|
||||
<delete id="deleteByColumnId">
|
||||
DELETE FROM user_column_permission WHERE column_id = #{columnId}
|
||||
</delete>
|
||||
<delete id="deleteByUserId">
|
||||
DELETE FROM user_column_permission WHERE user_id = #{userId}
|
||||
</delete>
|
||||
<delete id="deleteByUserIdAndColumnIds">
|
||||
DELETE FROM user_column_permission
|
||||
WHERE user_id = #{userId}
|
||||
AND column_id IN
|
||||
<foreach collection="columnIds" item="columnId" open="(" separator="," close=")">
|
||||
#{columnId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<insert id="insert">
|
||||
INSERT INTO user_column_permission (user_id, column_id) VALUES (#{userId}, #{columnId})
|
||||
</insert>
|
||||
<select id="selectByColumnId" resultType="com.nanri.aiimage.modules.permission.model.entity.UserColumnPermissionEntity">
|
||||
SELECT user_id, column_id FROM user_column_permission WHERE column_id = #{columnId}
|
||||
</select>
|
||||
<select id="selectByUserId" resultType="com.nanri.aiimage.modules.permission.model.entity.UserColumnPermissionEntity">
|
||||
SELECT user_id, column_id FROM user_column_permission WHERE user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.pricetrack.mapper.PriceTrackLoopRunMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<delete id="deleteFinishedBefore">
|
||||
DELETE FROM biz_price_track_loop_run
|
||||
WHERE status IN ('SUCCESS', 'FAILED', 'STOPPED')
|
||||
AND cleanup_at < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.publish.mapper.PublishItemMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO biz_publish_item
|
||||
(task_id, file_id, row_index, source_id, asin, country, brand, price_value,
|
||||
status_value, sync_status, sync_countries, created_at, updated_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.taskId}, #{row.fileId}, #{row.rowIndex}, #{row.sourceId}, #{row.asin},
|
||||
#{row.country}, #{row.brand}, #{row.priceValue}, #{row.statusValue},
|
||||
#{row.syncStatus}, #{row.syncCountries}, #{row.createdAt}, #{row.updatedAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.shopdatacrawl.mapper.ShopDataCrawlAdminTasksMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="countDailyFileObjectReferences" resultType="long">
|
||||
SELECT COUNT(1) FROM biz_shop_data_crawl_daily_file
|
||||
WHERE result_file_url = #{objectKey}
|
||||
</select>
|
||||
<select id="selectDownloadRowById" resultType="com.nanri.aiimage.modules.shopdatacrawl.model.dto.ShopDataCrawlDownloadRowDto">
|
||||
SELECT df.id AS resultId, df.latest_task_id AS taskId, df.user_id AS userId,
|
||||
df.shop_name AS sourceFilename, df.result_filename AS resultFilename,
|
||||
df.result_file_url AS resultFileUrl
|
||||
FROM biz_shop_data_crawl_daily_file df
|
||||
WHERE df.id = #{dailyFileId}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.shopdatacrawl.mapper.ShopDataCrawlItemMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<delete id="deleteBatch">
|
||||
DELETE FROM biz_shop_data_crawl_item
|
||||
WHERE shop_name = #{shopName} AND business_date = #{businessDate}
|
||||
</delete>
|
||||
<delete id="deleteByDailyFileId">
|
||||
DELETE FROM biz_shop_data_crawl_item
|
||||
WHERE daily_file_id = #{dailyFileId}
|
||||
</delete>
|
||||
<delete id="deleteOlderThanBatch">
|
||||
DELETE FROM biz_shop_data_crawl_item
|
||||
WHERE business_date < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO biz_shop_data_crawl_item
|
||||
(shop_id, shop_name, group_name, business_date, country, asin, brand, price,
|
||||
item_date, units_sold, item_json, result_id, task_id, daily_file_id)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.shopId}, #{row.shopName}, #{row.groupName}, #{row.businessDate}, #{row.country},
|
||||
#{row.asin}, #{row.brand}, #{row.price}, #{row.itemDate}, #{row.unitsSold},
|
||||
#{row.itemJson}, #{row.resultId}, #{row.taskId}, #{row.dailyFileId})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.shopduplicatecheck.mapper.ShopDataDuplicateScanMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<delete id="deleteOlderThanBatch">
|
||||
DELETE FROM shop_data_duplicate_scan
|
||||
WHERE created_at < #{cutoff}
|
||||
AND id < #{protectFromId}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
<select id="selectLatestFullRow" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ScanFullRowDto">
|
||||
SELECT id, summary_json AS summaryJson, payload_json AS payloadJson, created_at AS createdAt FROM shop_data_duplicate_scan WHERE status = 'SUCCESS' ORDER BY id DESC LIMIT 1
|
||||
</select>
|
||||
<select id="selectLatestLightRow" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ScanLightRowDto">
|
||||
SELECT id, created_at AS createdAt FROM shop_data_duplicate_scan WHERE status = 'SUCCESS' ORDER BY id DESC LIMIT 1
|
||||
</select>
|
||||
<select id="selectNthNewestId" resultType="long">
|
||||
SELECT id FROM shop_data_duplicate_scan ORDER BY id DESC LIMIT 1 OFFSET #{offset}
|
||||
</select>
|
||||
</mapper>
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.shopduplicatecheck.mapper.ShopDuplicateCheckItemMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="countShopBatch" resultType="long">
|
||||
SELECT COUNT(1) FROM biz_shop_data_crawl_item
|
||||
WHERE shop_name = #{shopName} AND business_date = #{businessDate}
|
||||
</select>
|
||||
<select id="selectDistinctShopNames" resultType="string">
|
||||
SELECT DISTINCT shop_name FROM biz_shop_data_crawl_item
|
||||
</select>
|
||||
<select id="selectLatestItemsByShop" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopLatestItemRowDto">
|
||||
SELECT i.shop_name AS shopName,
|
||||
i.country AS country,
|
||||
i.asin AS asin,
|
||||
i.item_date AS itemDate,
|
||||
i.price AS price,
|
||||
i.brand AS brand
|
||||
FROM biz_shop_data_crawl_item i
|
||||
WHERE i.shop_name = #{shopName}
|
||||
AND i.business_date = (
|
||||
SELECT MAX(business_date) FROM biz_shop_data_crawl_item WHERE shop_name = #{shopName}
|
||||
)
|
||||
</select>
|
||||
<select id="selectLegacyMigrationFiles" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopDailyFileMigrationDto">
|
||||
SELECT ranked.daily_file_id AS dailyFileId,
|
||||
ranked.business_date AS businessDate,
|
||||
ranked.latest_result_id AS latestResultId,
|
||||
fr.source_filename AS shopName,
|
||||
fr.result_file_url AS resultFileUrl,
|
||||
fr.task_id AS taskId
|
||||
FROM (
|
||||
SELECT df.id AS daily_file_id,
|
||||
df.business_date,
|
||||
df.latest_result_id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY df.shop_key
|
||||
ORDER BY df.business_date DESC, df.id DESC) AS row_no
|
||||
FROM biz_shop_data_crawl_daily_file df
|
||||
WHERE df.compensation_done = 1
|
||||
) ranked
|
||||
JOIN biz_file_result fr ON fr.id = ranked.latest_result_id
|
||||
WHERE ranked.row_no = 1
|
||||
AND fr.module_type = 'SHOP_DATA_CRAWL'
|
||||
</select>
|
||||
<select id="selectMemberPayload" resultType="string">
|
||||
SELECT row_payload FROM biz_shop_data_crawl_daily_member
|
||||
WHERE daily_file_id = #{dailyFileId} AND result_id = #{resultId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.shopduplicatecheck.mapper.ShopDuplicateCheckSourceMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="selectAllShopLabels" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopGroupLabelDto">
|
||||
SELECT TRIM(sm.shop_name) AS shopName,
|
||||
GROUP_CONCAT(DISTINCT COALESCE(NULLIF(g.group_name, ''), NULLIF(sm.group_name, ''))
|
||||
ORDER BY sm.id SEPARATOR '、') AS groupName
|
||||
FROM biz_shop_manage sm
|
||||
LEFT JOIN biz_shop_manage_group g ON g.id = sm.group_id
|
||||
WHERE TRIM(COALESCE(sm.shop_name, '')) <> ''
|
||||
GROUP BY TRIM(sm.shop_name)
|
||||
</select>
|
||||
<select id="selectGroupLabels" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopGroupLabelDto">
|
||||
SELECT TRIM(sm.shop_name) AS shopName,
|
||||
GROUP_CONCAT(DISTINCT COALESCE(NULLIF(g.group_name, ''), NULLIF(sm.group_name, ''))
|
||||
ORDER BY sm.id SEPARATOR '、') AS groupName
|
||||
FROM biz_shop_manage sm
|
||||
LEFT JOIN biz_shop_manage_group g ON g.id = sm.group_id
|
||||
WHERE TRIM(sm.shop_name) IN
|
||||
<foreach collection='shopNames' item='name' open='(' separator=',' close=')'>#{name}</foreach>
|
||||
GROUP BY TRIM(sm.shop_name)
|
||||
</select>
|
||||
<select id="selectLatestResultRows" resultType="com.nanri.aiimage.modules.shopduplicatecheck.model.dto.ShopSourceRowDto">
|
||||
SELECT ranked.result_id AS resultId,
|
||||
ranked.shop_name AS shopName,
|
||||
ranked.result_file_url AS resultFileUrl,
|
||||
ranked.result_file_size AS resultFileSize,
|
||||
ranked.request_json AS requestJson,
|
||||
ranked.country_codes_json AS countryCodesJson
|
||||
FROM (
|
||||
SELECT r.id AS result_id,
|
||||
r.source_filename AS shop_name,
|
||||
r.result_file_url,
|
||||
r.result_file_size,
|
||||
t.request_json,
|
||||
df.country_codes_json,
|
||||
COALESCE(df.last_success_at, df.updated_at, t.finished_at,
|
||||
t.updated_at, t.created_at) AS latest_file_updated_at,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY TRIM(COALESCE(r.source_filename, ''))
|
||||
ORDER BY COALESCE(df.last_success_at, df.updated_at,
|
||||
t.finished_at, t.updated_at, t.created_at) DESC,
|
||||
r.id DESC) AS row_no
|
||||
FROM biz_file_result r
|
||||
JOIN biz_file_task t ON t.id = r.task_id
|
||||
LEFT JOIN biz_shop_data_crawl_daily_file df ON df.latest_result_id = r.id
|
||||
WHERE r.module_type = 'SHOP_DATA_CRAWL'
|
||||
AND t.module_type = 'SHOP_DATA_CRAWL'
|
||||
AND TRIM(COALESCE(r.result_file_url, '')) <> ''
|
||||
) ranked
|
||||
WHERE ranked.row_no = 1
|
||||
ORDER BY ranked.latest_file_updated_at DESC, ranked.result_id DESC
|
||||
</select>
|
||||
<select id="selectManagedShopNames" resultType="string">
|
||||
SELECT DISTINCT TRIM(sm.shop_name) AS shopName
|
||||
FROM biz_shop_manage sm
|
||||
WHERE sm.group_id IN (
|
||||
SELECT id FROM biz_shop_manage_group
|
||||
WHERE created_by_id = #{operatorId} OR user_id = #{operatorId}
|
||||
)
|
||||
</select>
|
||||
<select id="selectShopNamesOwnedBy" resultType="string">
|
||||
SELECT DISTINCT TRIM(sm.shop_name)
|
||||
FROM biz_shop_manage sm
|
||||
WHERE TRIM(COALESCE(sm.shop_name, '')) <> ''
|
||||
AND sm.created_by_id IN
|
||||
<foreach collection="memberIds" item="mid" open="(" separator="," close=")">#{mid}</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.shopkey.mapper.QueryAsinMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO biz_query_asin (group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.groupId}, #{row.shopName}, #{row.asinDe}, #{row.asinUk}, #{row.asinFr}, #{row.asinIt}, #{row.asinEs})
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="selectByGroupIdsAndShopNames" resultType="com.nanri.aiimage.modules.shopkey.model.entity.QueryAsinEntity">
|
||||
SELECT id, group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es, created_at, updated_at
|
||||
FROM biz_query_asin
|
||||
WHERE group_id IN
|
||||
<foreach collection="groupIds" item="groupId" open="(" separator="," close=")">
|
||||
#{groupId}
|
||||
</foreach>
|
||||
AND shop_name IN
|
||||
<foreach collection="shopNames" item="shopName" open="(" separator="," close=")">
|
||||
#{shopName}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="selectByShopNames" resultType="com.nanri.aiimage.modules.shopkey.model.entity.QueryAsinEntity">
|
||||
SELECT id, group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es, created_at, updated_at
|
||||
FROM biz_query_asin
|
||||
WHERE shop_name IN
|
||||
<foreach collection="shopNames" item="shopName" open="(" separator="," close=")">
|
||||
#{shopName}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.softwareversion.mapper.SoftwareVersionMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<update id="markLatestById">
|
||||
UPDATE web_config SET is_latest = (id = #{id})
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.task.mapper.FileResultMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="selectRowsUpdatedAtByTaskIds" resultType="com.nanri.aiimage.modules.task.model.dto.TaskRowsVersionDto">
|
||||
SELECT task_id AS taskId, MAX(updated_at) AS latestRowAt, COUNT(*) AS rowCount
|
||||
FROM biz_file_result
|
||||
WHERE module_type = #{moduleType}
|
||||
AND task_id IN
|
||||
<foreach item="taskId" collection="taskIds" open="(" separator="," close=")">#{taskId}</foreach>
|
||||
GROUP BY task_id
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.task.mapper.FileTaskMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="selectExpiredTerminalTaskIds" resultType="long">
|
||||
SELECT id FROM biz_file_task
|
||||
WHERE module_type = #{moduleType}
|
||||
AND status IN ('SUCCESS', 'FAILED', 'CANCELLED', 'CANCELED')
|
||||
AND updated_at < #{cutoff}
|
||||
ORDER BY id ASC
|
||||
LIMIT #{batchSize}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.task.mapper.TaskResultItemMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<insert id="upsertBatch">
|
||||
INSERT INTO biz_task_result_item
|
||||
(task_id, module_type, result_id, scope_key, scope_hash, item_key, asin, status,
|
||||
payload_json, payload_hash, created_at, updated_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.taskId}, #{row.moduleType}, #{row.resultId}, #{row.scopeKey}, #{row.scopeHash},
|
||||
#{row.itemKey}, #{row.asin}, #{row.status}, #{row.payloadJson}, #{row.payloadHash},
|
||||
#{row.createdAt}, #{row.updatedAt})
|
||||
</foreach>
|
||||
ON DUPLICATE KEY UPDATE
|
||||
result_id = VALUES(result_id),
|
||||
scope_key = VALUES(scope_key),
|
||||
asin = VALUES(asin),
|
||||
status = VALUES(status),
|
||||
payload_json = VALUES(payload_json),
|
||||
payload_hash = VALUES(payload_hash),
|
||||
updated_at = VALUES(updated_at)
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="selectLastChunkAtByTaskIds" resultType="com.nanri.aiimage.modules.task.model.dto.TaskScopeLastChunkDto">
|
||||
SELECT task_id AS taskId, MAX(last_chunk_at) AS lastChunkAt
|
||||
FROM biz_task_scope_state
|
||||
WHERE task_id IN
|
||||
<foreach item="taskId" collection="taskIds" open="(" separator="," close=")">#{taskId}</foreach>
|
||||
GROUP BY task_id
|
||||
HAVING MAX(last_chunk_at) IS NOT NULL
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.taskcenter.mapper.TaskCenterQueryMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<select id="countFinishedTasksSince" resultType="long">
|
||||
SELECT COUNT(*) FROM ( SELECT t.id FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('CANCELED','CANCELLED','FAILED','SUCCESS') AND COALESCE(t.finished_at, t.updated_at) >= #{since}<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id FROM brand_crawl_tasks b WHERE b.status IN ('cancelled','failed','success') AND b.updated_at >= #{since}<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) u
|
||||
</select>
|
||||
<select id="countRunningTasks" resultType="long">
|
||||
SELECT COUNT(*) FROM ( SELECT t.id FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('PENDING','RUNNING','SCHEDULED')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id FROM brand_crawl_tasks b WHERE b.status IN ('pending','running')<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) u
|
||||
</select>
|
||||
<select id="countShops" resultType="long">
|
||||
SELECT COUNT(*) FROM biz_shop_manage s WHERE 1 = 1<if test='userIds != null'> AND s.created_by_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>
|
||||
</select>
|
||||
<select id="countStuckTasks" resultType="long">
|
||||
SELECT COUNT(*) FROM ( SELECT t.id FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('PENDING','RUNNING','SCHEDULED') AND t.updated_at < #{idleBefore}<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id FROM brand_crawl_tasks b WHERE b.status IN ('pending','running') AND b.updated_at < #{idleBefore}<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) u
|
||||
</select>
|
||||
<select id="countTaskPage" resultType="long">
|
||||
SELECT COUNT(*) FROM (SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND UPPER(t.module_type) = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND t.created_at >= #{startTime}</if><if test='endTime != null'> AND t.created_at <= #{endTime}</if><if test='shop != null'> AND (EXISTS (SELECT 1 FROM biz_publish_file p WHERE p.task_id = t.id AND LOWER(TRIM(p.shop_name)) = LOWER(TRIM(#{shop}))) OR (t.module_type IN ('PATROL_DELETE','PRICE_TRACK','PRODUCT_RISK_RESOLVE','QUERY_ASIN','SHOP_DATA_CRAWL','SHOP_MATCH') AND EXISTS (SELECT 1 FROM biz_file_result f WHERE f.task_id = t.id AND LOWER(TRIM(f.source_filename)) = LOWER(TRIM(#{shop})))))</if> UNION ALL SELECT b.id, CONCAT('brand-', b.id), 'BRAND', CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END, b.user_id, b.device_id, b.created_at, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END, b.updated_at, b.progress_total, b.progress_current, 0, 1 FROM brand_crawl_tasks b WHERE 1 = 1<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND 'BRAND' = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND b.created_at >= #{startTime}</if><if test='endTime != null'> AND b.created_at <= #{endTime}</if><if test='shop != null'> AND 1 = 0</if>) m
|
||||
</select>
|
||||
<select id="selectActiveTasks" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterTaskRow">
|
||||
SELECT m.* FROM (SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('PENDING','RUNNING','SCHEDULED')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id, CONCAT('brand-', b.id), 'BRAND', CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END, b.user_id, b.device_id, b.created_at, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END, b.updated_at, b.progress_total, b.progress_current, 0, 1 FROM brand_crawl_tasks b WHERE b.status IN ('pending','running')<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) m ORDER BY m.createdAt DESC, m.id DESC LIMIT #{limit}
|
||||
</select>
|
||||
<select id="selectBrandTaskById" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterTaskRow">
|
||||
SELECT b.id AS id, CONCAT('brand-', b.id) AS taskNo, 'BRAND' AS moduleType, CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END AS status, b.user_id AS userId, b.device_id AS deviceId, b.created_at AS createdAt, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END AS finishedAt, b.updated_at AS updatedAt, b.progress_total AS totalCount, b.progress_current AS successCount, 0 AS failedCount, 1 AS brand, b.error_message AS errorMessage FROM brand_crawl_tasks b WHERE b.id = #{id}
|
||||
</select>
|
||||
<select id="selectCollectDataKeywordStats" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterCollectStatsRow">
|
||||
SELECT t.id AS taskId, JSON_UNQUOTE(JSON_EXTRACT(t.result_json, '$.totalRows')) AS totalRows, JSON_UNQUOTE(JSON_EXTRACT(t.result_json, '$.processedRows')) AS processedRows FROM biz_file_task t WHERE t.id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach> AND UPPER(t.module_type) = 'COLLECT_DATA' AND t.result_json IS NOT NULL
|
||||
</select>
|
||||
<select id="selectDeviceNames" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterDeviceRow">
|
||||
SELECT d.device_id AS deviceId, MAX(d.device_name) AS deviceName FROM device_log_file d WHERE d.device_id IN <foreach collection='deviceIds' item='did' open='(' separator=',' close=')'>#{did}</foreach> GROUP BY d.device_id
|
||||
</select>
|
||||
<select id="selectFileResultShops" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterShopRow">
|
||||
SELECT f.task_id AS taskId, f.source_filename AS shop FROM biz_file_result f JOIN biz_file_task ft ON ft.id = f.task_id AND ft.module_type IN ('PATROL_DELETE','PRICE_TRACK','PRODUCT_RISK_RESOLVE','QUERY_ASIN','SHOP_DATA_CRAWL','SHOP_MATCH') WHERE f.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach> AND f.source_filename IS NOT NULL AND f.source_filename != '' GROUP BY f.task_id, f.source_filename
|
||||
</select>
|
||||
<select id="selectPublishShopStats" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterShopStatRow">
|
||||
SELECT p.shop_name AS scopeKey, COUNT(*) AS total, SUM(UPPER(p.status) = 'SUCCESS') AS success, SUM(UPPER(p.status) = 'FAILED') AS failed FROM biz_publish_file p WHERE p.task_id = #{taskId} AND p.shop_name IS NOT NULL AND p.shop_name != '' GROUP BY p.shop_name ORDER BY COUNT(*) DESC, p.shop_name LIMIT 200
|
||||
</select>
|
||||
<select id="selectPublishShops" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterShopRow">
|
||||
SELECT p.task_id AS taskId, p.shop_name AS shop FROM biz_publish_file p WHERE p.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach> AND p.shop_name IS NOT NULL AND p.shop_name != '' GROUP BY p.task_id, p.shop_name
|
||||
</select>
|
||||
<select id="selectResultItemShopStats" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterShopStatRow">
|
||||
SELECT i.scope_key AS scopeKey, COUNT(*) AS total, SUM(UPPER(i.status) = 'SUCCESS') AS success, SUM(UPPER(i.status) = 'FAILED') AS failed FROM biz_task_result_item i WHERE i.task_id = #{taskId} AND i.scope_key IS NOT NULL AND i.scope_key != '' GROUP BY i.scope_key ORDER BY COUNT(*) DESC, i.scope_key LIMIT 200
|
||||
</select>
|
||||
<select id="selectShopNames" resultType="string">
|
||||
SELECT DISTINCT s.shop_name FROM biz_shop_manage s WHERE 1 = 1<if test='userIds != null'> AND s.created_by_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> ORDER BY s.shop_name LIMIT 2000
|
||||
</select>
|
||||
<select id="selectSnapshots" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterSnapshotRow">
|
||||
SELECT s.task_id AS taskId, s.module_type AS moduleType, s.total_count AS totalCount, s.success_count AS successCount, s.failed_count AS failedCount, s.pending_count AS pendingCount, s.current_scope_key AS currentScopeKey, s.message AS message FROM biz_task_progress_snapshot s WHERE s.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>
|
||||
</select>
|
||||
<select id="selectTaskByTaskNo" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterTaskRow">
|
||||
SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand, t.error_message AS errorMessage FROM biz_file_task t WHERE t.task_no = #{taskNo} AND t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') LIMIT 1
|
||||
</select>
|
||||
<select id="selectTaskCountries" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterCountryRow">
|
||||
SELECT t.id AS taskId, COALESCE(NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.filters.countryCode')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.countryCode')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.country')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.publish_country')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.countryCodes')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.country_codes')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.filters.countryCodes')), ''), 'null')) AS country FROM biz_file_task t WHERE t.id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>
|
||||
</select>
|
||||
<select id="selectTaskPage" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterTaskRow">
|
||||
SELECT m.* FROM (SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND UPPER(t.module_type) = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND t.created_at >= #{startTime}</if><if test='endTime != null'> AND t.created_at <= #{endTime}</if><if test='shop != null'> AND (EXISTS (SELECT 1 FROM biz_publish_file p WHERE p.task_id = t.id AND LOWER(TRIM(p.shop_name)) = LOWER(TRIM(#{shop}))) OR (t.module_type IN ('PATROL_DELETE','PRICE_TRACK','PRODUCT_RISK_RESOLVE','QUERY_ASIN','SHOP_DATA_CRAWL','SHOP_MATCH') AND EXISTS (SELECT 1 FROM biz_file_result f WHERE f.task_id = t.id AND LOWER(TRIM(f.source_filename)) = LOWER(TRIM(#{shop})))))</if> UNION ALL SELECT b.id, CONCAT('brand-', b.id), 'BRAND', CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END, b.user_id, b.device_id, b.created_at, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END, b.updated_at, b.progress_total, b.progress_current, 0, 1 FROM brand_crawl_tasks b WHERE 1 = 1<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND 'BRAND' = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND b.created_at >= #{startTime}</if><if test='endTime != null'> AND b.created_at <= #{endTime}</if><if test='shop != null'> AND 1 = 0</if>) m ORDER BY m.createdAt DESC, m.id DESC LIMIT #{limit} OFFSET #{offset}
|
||||
</select>
|
||||
<select id="selectUserIdsByUsername" resultType="long">
|
||||
SELECT id FROM users WHERE username LIKE CONCAT('%', #{keyword}, '%') LIMIT 500
|
||||
</select>
|
||||
<select id="selectUsernames" resultType="com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterUserRow">
|
||||
SELECT id AS userId, username FROM users WHERE id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.usersecret.mapper.UserSecretUsageMapper">
|
||||
<!-- 由注解 SQL 平移而来,SQL 文本未改写;语句 id 与接口方法名逐字一致。
|
||||
等价性由 MigratedSqlEquivalenceTest 按搬迁前的 fixture 逐条比对。 -->
|
||||
<delete id="deleteBefore">
|
||||
DELETE FROM biz_user_secret_usage_daily
|
||||
WHERE business_date < #{cutoff}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
<insert id="increment">
|
||||
INSERT INTO biz_user_secret_usage_daily (user_id, module_key, business_date, call_count, created_at, updated_at)
|
||||
VALUES (#{userId}, #{moduleKey}, #{businessDate}, #{count}, NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE call_count = call_count + #{count}, updated_at = NOW()
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,410 @@
|
||||
package com.nanri.aiimage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 注解 SQL 平移到 mapper XML 的等价性守卫。
|
||||
*
|
||||
* <p>基准是<b>搬迁前注解的原文</b>({@code src/test/resources/sql-layering/migrated-statements.tsv},
|
||||
* 85 条),而且比对发生在 <b>MyBatis 解析之后</b>:把注解原文现场交给
|
||||
* {@code LanguageDriver.createSqlSource}(注解当年就是走这条路进 MyBatis 的),
|
||||
* 与 XML 解析出来的 {@code MappedStatement} 各渲染一遍 {@code BoundSql} 再对撞。
|
||||
* 这样"元素体该怎么转义"由 MyBatis 判定,不由生成脚本判定——
|
||||
* 上一轮正是拿生成器的输出当基准,同一个解析器错两遍,85 条"逐字相等"全绿而 SQL 已经残缺。
|
||||
*
|
||||
* <p>渲染用两组参数各对撞一次:空参数(所有 {@code <if>} 走 false 支)与把
|
||||
* {@code <foreach collection>} 喂满 2 个元素(动态支展开成 {@code ?,?})。
|
||||
* 两边同抛异常也算一致,但必须是同一异常类型与同一消息,不许一边过一边炸。
|
||||
*
|
||||
* <p>第二支管 {@code resultType}:期望类型由反射从接口签名反推,不由生成脚本算,
|
||||
* 避免"生成时解错、断言时照着错的对"。
|
||||
*/
|
||||
class MigratedSqlEquivalenceTest {
|
||||
|
||||
private static final String FIXTURE = "sql-layering/migrated-statements.tsv";
|
||||
private static final int LEDGER_ROWS = 85;
|
||||
private static final int LEDGER_SELECTS = 60;
|
||||
/** 全部 mapper XML 里的 select 总数:账本 60 + TaskImageCache 5 + AsinResultCache 1。 */
|
||||
private static final int XML_SELECT_TOTAL = 66;
|
||||
|
||||
/** 账本 5 列:接口 / 方法 / @Select 种类 / 是否含常量插值 / 注解原文(Java 反转义后那条串)。 */
|
||||
private static final int LEDGER_COLUMNS = 5;
|
||||
private static final int BASELINE_COL = 4;
|
||||
|
||||
private static final Pattern STATEMENT = Pattern.compile(
|
||||
"(?is)<(select|insert|update|delete)\\s+id=\"([A-Za-z0-9_]+)\"([^>]*)>(.*?)</\\1>");
|
||||
private static final Pattern RESULT_TYPE = Pattern.compile("resultType=\"([^\"]+)\"");
|
||||
private static final Pattern FOREACH_COLLECTION = Pattern.compile("collection=[\"'](\\w+)[\"']");
|
||||
private static final Pattern TEST_NAME = Pattern.compile("test=[\"']([^\"']*)[\"']");
|
||||
private static final Pattern HASH_PARAM = Pattern.compile("#\\{\\s*([A-Za-z_]\\w*)");
|
||||
/** OGNL 里的字面量与方法名不是参数名,喂值进去会让两边同时以错误告终。 */
|
||||
private static final Set<String> OGNL_WORDS =
|
||||
Set.of("null", "true", "false", "and", "or", "not", "size", "isEmpty", "equals", "length");
|
||||
|
||||
@Test
|
||||
void ledgerItselfIsTheExpectedShape() throws IOException {
|
||||
List<String[]> rows = readLedger();
|
||||
assertEquals(LEDGER_ROWS, rows.size(), "fixture 行数变了——它是搬迁前的快照,不该跟着代码漂");
|
||||
assertEquals(LEDGER_SELECTS, rows.stream().filter(r -> "Select".equals(r[2])).count(),
|
||||
"fixture 里的 Select 条数与基线不符(读侧账本 = 60)");
|
||||
assertEquals(LEDGER_ROWS - LEDGER_SELECTS,
|
||||
rows.stream().filter(r -> !"Select".equals(r[2])).count(),
|
||||
"写侧条数对不上(25 = Insert+Update+Delete)");
|
||||
assertTrue(rows.stream().allMatch(r -> !r[1].isEmpty() && !r[BASELINE_COL].isEmpty()),
|
||||
"fixture 有空方法名或空 SQL,说明抽取器漏了形状");
|
||||
// 基准得是「整条注解串」:半截 <script> 外壳说明抽取被截断(上一轮就是把常量与标签吃了)
|
||||
assertTrue(rows.stream().allMatch(r ->
|
||||
r[BASELINE_COL].startsWith("<script>") == r[BASELINE_COL].contains("</script>")),
|
||||
"有基准行的 <script> 外壳不成对——抽取时注解表达式被截断了");
|
||||
assertTrue(rows.stream().allMatch(r ->
|
||||
r[BASELINE_COL].contains("<if") == r[BASELINE_COL].contains("</if>")),
|
||||
"有基准行的 <if> 不成对——常量插值没展开");
|
||||
assertTrue(rows.stream().noneMatch(r -> r[BASELINE_COL].contains("IN ()")),
|
||||
"有基准行出现空的 IN (),说明 foreach/常量被吞了");
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyMigratedStatementRendersTheSameSqlAsTheAnnotationDid() throws Exception {
|
||||
Map<String, String> baselines = new LinkedHashMap<>();
|
||||
Map<String, String> kinds = new LinkedHashMap<>();
|
||||
for (String[] row : readLedger()) {
|
||||
baselines.put(row[0] + "#" + row[1], unescapeJava(row[4]));
|
||||
kinds.put(row[0] + "#" + row[1], row[2].toLowerCase());
|
||||
}
|
||||
List<String> problems = new ArrayList<>();
|
||||
int checked = 0;
|
||||
for (Path xml : mapperXmls()) {
|
||||
String iface = stem(xml);
|
||||
if (!baselines.keySet().stream().anyMatch(k -> k.startsWith(iface + "#"))) {
|
||||
continue; // TaskImageCache / AsinResultCache 由各自用例钉,不在这本账里
|
||||
}
|
||||
Class<?> mapperClass = Class.forName(namespaceOf(xml));
|
||||
MybatisConfiguration configuration = parseInto(xml, new MybatisConfiguration());
|
||||
Matcher m = STATEMENT.matcher(read(xml));
|
||||
while (m.find()) {
|
||||
String key = iface + "#" + m.group(2);
|
||||
String baseline = baselines.get(key);
|
||||
if (baseline == null) {
|
||||
problems.add(key + " 在基准账本里没有对应注解(XML 多出一条语句)");
|
||||
continue;
|
||||
}
|
||||
checked++;
|
||||
if (!kinds.get(key).equals(m.group(1))) {
|
||||
problems.add(key + " 注解是 @" + kinds.get(key) + ",XML 用了 <" + m.group(1) + ">");
|
||||
continue;
|
||||
}
|
||||
MappedStatement fromXml =
|
||||
configuration.getMappedStatement(mapperClass.getName() + "." + m.group(2));
|
||||
// 注解当年就是走这条驱动进 MyBatis 的(MapperAnnotationBuilder 用的正是默认脚本语言),
|
||||
// 所以这里拿它现场编译基准串,等价性由 MyBatis 判定而不是由生成脚本判定。
|
||||
SqlSource fromAnnotation = configuration.getDefaultScriptingLanguageInstance()
|
||||
.createSqlSource(configuration, baseline, Object.class);
|
||||
for (Map<String, Object> params : renderParams(baseline)) {
|
||||
String where = key + "(" + params.get("_case") + ")";
|
||||
compare(fromXml.getBoundSql(params), fromAnnotation.getBoundSql(params), where, problems);
|
||||
}
|
||||
}
|
||||
}
|
||||
int checkedRows = checked;
|
||||
assertEquals(LEDGER_ROWS, checkedRows,
|
||||
() -> "只比对了 " + checkedRows + " 条,其余没在 XML 里落地(应为 " + LEDGER_ROWS + " 条)");
|
||||
assertTrue(problems.isEmpty(),
|
||||
() -> "这些语句搬完之后 MyBatis 渲染出的 SQL 与注解时不同(" + problems.size() + " 处):"
|
||||
+ System.lineSeparator() + String.join(System.lineSeparator(), problems));
|
||||
}
|
||||
|
||||
/** 两边各渲染一次:都出 SQL 就逐字比,都抛就比异常,一边过一边炸必须算问题。 */
|
||||
private static void compare(BoundSql a, BoundSql b, String where, List<String> problems) {
|
||||
String sqlA, sqlB;
|
||||
try {
|
||||
sqlA = normalize(a.getSql());
|
||||
} catch (RuntimeException e) {
|
||||
problems.add(where + " XML 侧渲染就抛:" + e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sqlB = normalize(b.getSql());
|
||||
} catch (RuntimeException e) {
|
||||
problems.add(where + " 注解侧渲染抛 " + e.getClass().getSimpleName()
|
||||
+ " 而 XML 侧正常出 SQL: " + sqlA);
|
||||
return;
|
||||
}
|
||||
if (!sqlA.equals(sqlB)) {
|
||||
problems.add(where + System.lineSeparator()
|
||||
+ " 注解渲染: " + sqlB + System.lineSeparator()
|
||||
+ " XML 渲染 : " + sqlA);
|
||||
return;
|
||||
}
|
||||
if (a.getParameterMappings().size() != b.getParameterMappings().size()) {
|
||||
problems.add(where + " 占位符数不同:注解 " + b.getParameterMappings().size()
|
||||
+ " vs XML " + a.getParameterMappings().size() + " —— " + sqlA);
|
||||
}
|
||||
}
|
||||
|
||||
/** 空参数走所有 <if> 的 false 支;再喂满 foreach 走动态支。两支都要两边一致。 */
|
||||
private static List<Map<String, Object>> renderParams(String baseline) {
|
||||
Map<String, Object> full = new HashMap<>();
|
||||
Set<String> collections = new java.util.LinkedHashSet<>();
|
||||
Matcher fc = FOREACH_COLLECTION.matcher(baseline);
|
||||
while (fc.find()) {
|
||||
collections.add(fc.group(1));
|
||||
}
|
||||
Set<String> names = new java.util.LinkedHashSet<>(collections);
|
||||
Matcher t = TEST_NAME.matcher(baseline);
|
||||
while (t.find()) {
|
||||
Matcher word = Pattern.compile("\\w+").matcher(t.group(1));
|
||||
while (word.find()) {
|
||||
String w = word.group();
|
||||
if (!OGNL_WORDS.contains(w)) {
|
||||
names.add(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
Matcher h = HASH_PARAM.matcher(baseline);
|
||||
while (h.find()) {
|
||||
names.add(h.group(1));
|
||||
}
|
||||
for (String name : names) {
|
||||
full.put(name, collections.contains(name) ? List.of("a", "b") : "v");
|
||||
}
|
||||
return List.of(Map.of("_case", "空参数"), Map.of("_case", "带参数"))
|
||||
.stream().map(marker -> {
|
||||
Map<String, Object> params =
|
||||
new HashMap<>("_case".equals(marker.get("_case")) ? Map.of() : full);
|
||||
params.putAll(marker);
|
||||
return params;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/** resultType 必须与接口方法签名一致;期望值由反射算,不用生成脚本的结论。 */
|
||||
@Test
|
||||
void everySelectKeepsTheReturnTypeItsAnnotationHad() throws Exception {
|
||||
List<String> problems = new ArrayList<>();
|
||||
int checked = 0;
|
||||
for (Path xml : mapperXmls()) {
|
||||
String text = read(xml);
|
||||
Matcher ns = Pattern.compile("namespace=\"([^\"]+)\"").matcher(text);
|
||||
if (!ns.find()) {
|
||||
problems.add(xml + " 缺 namespace");
|
||||
continue;
|
||||
}
|
||||
Class<?> iface = Class.forName(ns.group(1));
|
||||
MybatisConfiguration configuration = parseInto(xml, new MybatisConfiguration());
|
||||
Matcher m = STATEMENT.matcher(text);
|
||||
while (m.find()) {
|
||||
if (!"select".equals(m.group(1))) {
|
||||
continue;
|
||||
}
|
||||
String method = m.group(2);
|
||||
checked++;
|
||||
MappedStatement statement =
|
||||
configuration.getMappedStatement(iface.getName() + "." + method);
|
||||
Class<?> resolved = statement.getResultMaps().get(0).getType();
|
||||
Matcher attrs = RESULT_TYPE.matcher(m.group(3));
|
||||
String declared = attrs.find() ? attrs.group(1) : null;
|
||||
if (declared == null) {
|
||||
problems.add(iface.getSimpleName() + "#" + method + " 的 <select> 没写 resultType");
|
||||
continue;
|
||||
}
|
||||
Class<?> expected = expectedType(iface, method);
|
||||
if (expected == null) {
|
||||
problems.add(iface.getSimpleName() + "#" + method + " 找不到接口方法签名");
|
||||
} else if (!compatible(expected, resolved)) {
|
||||
problems.add(iface.getSimpleName() + "#" + method
|
||||
+ " resultType=" + declared + " 解析成 " + resolved.getName()
|
||||
+ ",而方法签名要的是 " + expected.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
int checkedSelects = checked;
|
||||
assertTrue(problems.isEmpty(), () -> "resultType 与接口签名不一致(" + problems.size() + " 条):"
|
||||
+ System.lineSeparator() + String.join(System.lineSeparator(), problems));
|
||||
// 这支扫的是全部 mapper XML,所以分母比账本大:本轮 60 + TaskImageCache 5 + AsinResultCache 1
|
||||
assertEquals(XML_SELECT_TOTAL, checkedSelects,
|
||||
() -> "只检查了 " + checkedSelects + " 条 select,应为 " + XML_SELECT_TOTAL
|
||||
+ " 条(正则或 XML 漂了)");
|
||||
}
|
||||
|
||||
/** 只把 XML 解析进配置:XMLMapperBuilder 会顺带按 namespace 绑上接口。 */
|
||||
private static MybatisConfiguration parseInto(Path xml, MybatisConfiguration configuration)
|
||||
throws IOException {
|
||||
try (InputStream in = Files.newInputStream(xml)) {
|
||||
new XMLMapperBuilder(in, configuration, xml.toString(),
|
||||
configuration.getSqlFragments()).parse();
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private static Class<?> expectedType(Class<?> iface, String method) {
|
||||
for (Method m : iface.getDeclaredMethods()) {
|
||||
if (!m.getName().equals(method)) {
|
||||
continue;
|
||||
}
|
||||
return unwrap(m.getGenericReturnType());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** List<X> / Set<X> / Collection<X> 取 X;byte[] 原样;泛型数组元素再解一层。 */
|
||||
private static Class<?> unwrap(Type type) {
|
||||
if (type instanceof ParameterizedType pt) {
|
||||
Type raw = pt.getRawType();
|
||||
if (raw instanceof Class<?> c && (c == List.class || c == java.util.Set.class
|
||||
|| c == java.util.Collection.class || c == Iterable.class)) {
|
||||
return unwrap(pt.getActualTypeArguments()[0]);
|
||||
}
|
||||
return (Class<?>) raw;
|
||||
}
|
||||
if (type instanceof GenericArrayType ga) {
|
||||
Class<?> component = unwrap(ga.getGenericComponentType());
|
||||
if (component == byte.class) {
|
||||
return byte[].class;
|
||||
}
|
||||
return java.lang.reflect.Array.newInstance(component, 0).getClass();
|
||||
}
|
||||
if (type instanceof Class<?> c) {
|
||||
if (c == long.class) {
|
||||
return Long.class;
|
||||
}
|
||||
if (c == int.class) {
|
||||
return Integer.class;
|
||||
}
|
||||
if (c == boolean.class) {
|
||||
return Boolean.class;
|
||||
}
|
||||
if (c == double.class) {
|
||||
return Double.class;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
private static boolean compatible(Class<?> expected, Class<?> resolved) {
|
||||
if (expected == resolved) {
|
||||
return true;
|
||||
}
|
||||
if (Map.class.isAssignableFrom(expected)) {
|
||||
return Map.class.isAssignableFrom(resolved);
|
||||
}
|
||||
return resolved != null && expected.isAssignableFrom(resolved);
|
||||
}
|
||||
|
||||
private static List<String[]> readLedger() throws IOException {
|
||||
try (InputStream in = Resources.getResourceAsStream(FIXTURE)) {
|
||||
String text = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
List<String[]> rows = new ArrayList<>();
|
||||
for (String line : text.split("\n")) {
|
||||
if (line.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
String[] cols = line.split("\t", -1);
|
||||
if (cols.length != 5) {
|
||||
throw new IllegalStateException("fixture 列数不对: " + line.substring(0,
|
||||
Math.min(80, line.length())));
|
||||
}
|
||||
rows.add(cols);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Path> mapperXmls() throws IOException {
|
||||
Path dir = moduleRoot().resolve("src/main/resources/mapper");
|
||||
if (!Files.isDirectory(dir)) {
|
||||
fail("找不到 " + dir + " —— 本用例依赖以 backend-java 为工作目录运行");
|
||||
}
|
||||
try (Stream<Path> walk = Files.walk(dir)) {
|
||||
return walk.filter(p -> p.getFileName().toString().endsWith(".xml"))
|
||||
.sorted().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
private static String namespaceOf(Path xml) {
|
||||
Matcher m = Pattern.compile("namespace=\"([^\"]+)\"").matcher(read(xml));
|
||||
if (!m.find()) {
|
||||
throw new IllegalStateException(xml + " 缺 namespace");
|
||||
}
|
||||
return m.group(1);
|
||||
}
|
||||
|
||||
/** tsv 里的基准行是 Java 转义过的(一行一条),还原成注解当年真正的那个字符串。 */
|
||||
private static String unescapeJava(String s) {
|
||||
StringBuilder out = new StringBuilder(s.length());
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\' && i + 1 < s.length()) {
|
||||
char n = s.charAt(++i);
|
||||
switch (n) {
|
||||
case 'n' -> out.append('\n');
|
||||
case 't' -> out.append('\t');
|
||||
case 'r' -> out.append('\r');
|
||||
case '\\' -> out.append('\\');
|
||||
default -> out.append(n);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
out.append(c);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static String normalize(String text) {
|
||||
return text.replaceAll("\\s+", " ").trim();
|
||||
}
|
||||
|
||||
private static String read(Path path) {
|
||||
try {
|
||||
return Files.readString(path, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("读取失败: " + path, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String stem(Path path) {
|
||||
String name = path.getFileName().toString();
|
||||
return name.substring(0, name.length() - 4);
|
||||
}
|
||||
|
||||
private static Path moduleRoot() {
|
||||
Path here = Path.of("").toAbsolutePath();
|
||||
if (Files.isDirectory(here.resolve("src/main/java"))) {
|
||||
return here;
|
||||
}
|
||||
Path nested = here.resolve("backend-java");
|
||||
if (Files.isDirectory(nested.resolve("src/main/java"))) {
|
||||
return nested;
|
||||
}
|
||||
throw new IllegalStateException("无法定位 backend-java 模块目录(cwd=" + here + ")");
|
||||
}
|
||||
}
|
||||
@@ -44,16 +44,23 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
*/
|
||||
class SqlLayeringConventionTest {
|
||||
|
||||
/** 写 SQL(@Insert/@Update/@Delete)在注解里的现状清单:文件名 → 条数。只许减,不许加。 */
|
||||
private static final Map<String, Integer> WRITE_SQL_BASELINE = writeSqlBaseline();
|
||||
/**
|
||||
* 注解里的写 SQL 清单。<b>2026-10-08 全量迁完后为空</b>:任何一条重新出现都直接红,
|
||||
* 新 SQL 一律写进 {@code src/main/resources/mapper/<模块>/<Name>Mapper.xml}。
|
||||
*/
|
||||
private static final Map<String, Integer> WRITE_SQL_BASELINE = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* 读侧注解 SQL 的逐接口清单(2026-10-08 实测 65 条 / 16 个接口,迁走 TaskImageCacheMapper 后 60 / 15)。
|
||||
* 注解里的读 SQL 清单,同样在 2026-10-08 迁完归零。
|
||||
*
|
||||
* <p>为什么从"总数 + 文件数"两个标量改成逐接口:标量守恒的是**和**,A 接口减一条、
|
||||
* B 接口加一条时两个标量都不动,闸门照样绿——档 B 口径下这等于没有闸门。
|
||||
* <p>保留逐接口形态(而不是退回一个"总数 0")是有原因的:以前钉"总数 + 文件数"两个标量时,
|
||||
* A 接口加一条配 B 接口减一条两个标量都不动,闸门形同虚设;逐接口清单在迁移期就是账本,
|
||||
* 迁完后它继续保证"不许在某个接口里悄悄攒回来"。
|
||||
*/
|
||||
private static final Map<String, Integer> SELECT_SQL_BASELINE = selectSqlBaseline();
|
||||
private static final Map<String, Integer> SELECT_SQL_BASELINE = new LinkedHashMap<>();
|
||||
|
||||
/** 迁移完成态的分母:XML 里应有的语句总数(85 本轮 + 9 TaskImageCache + 2 AsinResultCache)。 */
|
||||
private static final int XML_STATEMENT_TOTAL = 96;
|
||||
|
||||
/**
|
||||
* wrapper 里夹带函数级 SQL 的现状("这不是简单单表"的证据),文件名 → 条数:
|
||||
@@ -62,65 +69,24 @@ class SqlLayeringConventionTest {
|
||||
private static final Map<String, Integer> RAW_SQL_IN_WRAPPERS_BASELINE = rawSqlInWrappersBaseline();
|
||||
|
||||
/**
|
||||
* 其中"复杂"的写 SQL(注解正文含动态标签)——Wrapper 表达不了(批量/INSERT…SELECT/upsert),
|
||||
* 按约定应迁到 XML。这是待迁 backlog,不是许可名单:迁走一条要同时从这里划掉。
|
||||
* 注解里带动态标签的写 SQL 待迁清单。<b>2026-10-08 已清空</b>——
|
||||
* {@code <foreach>}/{@code <if>} 这类 Wrapper 表达不了的语句现在只在 XML 里。
|
||||
* 再往注解里塞动态标签,{@link #noNewComplexWriteSqlInAnnotations} 直接红。
|
||||
*/
|
||||
private static final List<String> COMPLEX_WRITE_SQL_BACKLOG = List.of(
|
||||
"CollectDataItemMapper", "DedupeTotalDataMapper", "InvalidAsinDataMapper",
|
||||
"UserColumnPermissionMapper", "PublishItemMapper", "ShopDataCrawlItemMapper",
|
||||
"QueryAsinMapper", "TaskResultItemMapper");
|
||||
private static final List<String> COMPLEX_WRITE_SQL_BACKLOG = List.of();
|
||||
|
||||
/** 唯一没有实体可走的 mapper:连 wrapper 的入口都没有,所以只能写裸 SQL。 */
|
||||
private static final List<String> MAPPERS_WITHOUT_ENTITY = List.of("UserColumnPermissionMapper");
|
||||
|
||||
/** 已经迁到 XML 的:反向钉住"不许再用注解把 SQL 写回来"(注解 + XML 同名会让启动期抛重复语句)。 */
|
||||
private static final List<String> MIGRATED_TO_XML = List.of("AsinResultCacheMapper", "TaskImageCacheMapper");
|
||||
/**
|
||||
* "带写 SQL 又不继承 BaseMapper" 的豁免名单,同样已清空:SQL 进了 XML 之后,
|
||||
* 接口继不继承实体都不影响语句落地,这条只用来拦"新 mapper 一上来就写裸注解 SQL"。
|
||||
*/
|
||||
private static final List<String> MAPPERS_WITHOUT_ENTITY = List.of();
|
||||
|
||||
private static final Pattern WRITE_ANNOTATION = Pattern.compile("@(Insert|Update|Delete)\\(");
|
||||
private static final Pattern SELECT_ANNOTATION = Pattern.compile("@Select\\(");
|
||||
private static final Pattern WRITE_ANNOTATION_BODY =
|
||||
Pattern.compile("@(Insert|Update|Delete)\\(\\s*\"\"\"(.*?)\"\"\"", Pattern.DOTALL);
|
||||
|
||||
private static Map<String, Integer> writeSqlBaseline() {
|
||||
Map<String, Integer> baseline = new LinkedHashMap<>();
|
||||
baseline.put("CollectDataItemMapper", 1);
|
||||
baseline.put("DedupeTotalDataMapper", 1);
|
||||
baseline.put("DeviceLogFileMapper", 1);
|
||||
baseline.put("ImageVideoAsyncTaskMapper", 3);
|
||||
baseline.put("InvalidAsinDataMapper", 1);
|
||||
baseline.put("UserNotificationMapper", 2);
|
||||
baseline.put("UserColumnPermissionMapper", 4);
|
||||
baseline.put("PriceTrackLoopRunMapper", 1);
|
||||
baseline.put("PublishItemMapper", 1);
|
||||
baseline.put("ShopDataCrawlItemMapper", 4);
|
||||
baseline.put("ShopDataDuplicateScanMapper", 1);
|
||||
baseline.put("QueryAsinMapper", 1);
|
||||
baseline.put("SoftwareVersionMapper", 1);
|
||||
baseline.put("TaskResultItemMapper", 1);
|
||||
baseline.put("UserSecretUsageMapper", 2);
|
||||
return baseline;
|
||||
}
|
||||
|
||||
/** 读侧基线:TaskImageCacheMapper 的 5 条已在 mapper/task/TaskImageCacheMapper.xml 里。 */
|
||||
private static Map<String, Integer> selectSqlBaseline() {
|
||||
Map<String, Integer> baseline = new LinkedHashMap<>();
|
||||
baseline.put("TaskCenterQueryMapper", 20);
|
||||
baseline.put("ShopManageGroupMapper", 9);
|
||||
baseline.put("ShopDuplicateCheckItemMapper", 5);
|
||||
baseline.put("ShopDuplicateCheckSourceMapper", 5);
|
||||
baseline.put("ImageVideoAdminTaskMapper", 4);
|
||||
baseline.put("UserColumnPermissionMapper", 3);
|
||||
baseline.put("ShopDataDuplicateScanMapper", 3);
|
||||
baseline.put("AdminUserMapper", 2);
|
||||
baseline.put("ShopDataCrawlAdminTasksMapper", 2);
|
||||
baseline.put("QueryAsinMapper", 2);
|
||||
baseline.put("BrandCrawlTaskMapper", 1);
|
||||
baseline.put("DedupeTotalDataMapper", 1);
|
||||
baseline.put("FileResultMapper", 1);
|
||||
baseline.put("FileTaskMapper", 1);
|
||||
baseline.put("TaskScopeStateMapper", 1);
|
||||
return baseline;
|
||||
}
|
||||
private static final Pattern STATEMENT_ID =
|
||||
Pattern.compile("<(?:select|insert|update|delete)\\s+id=\"[^\"]+\"");
|
||||
|
||||
private static Map<String, Integer> rawSqlInWrappersBaseline() {
|
||||
Map<String, Integer> baseline = new LinkedHashMap<>();
|
||||
@@ -147,17 +113,17 @@ class SqlLayeringConventionTest {
|
||||
actualSelects.put(stem(file), read);
|
||||
}
|
||||
}
|
||||
assertEquals(WRITE_SQL_BASELINE, actual, () -> "注解里的写 SQL 清单变了。" + System.lineSeparator()
|
||||
+ " 新增 → 写进 src/main/resources/mapper/<模块>/<Name>Mapper.xml;"
|
||||
+ "简单单表才用 BaseMapper/实体(wrapper)。" + System.lineSeparator()
|
||||
+ " 迁走 → 把这一项从 WRITE_SQL_BASELINE 里减掉,让减法出现在 diff 上。");
|
||||
assertFalse(actual.isEmpty(), "清单为空说明本用例没扫到任何 mapper,判据本身坏了");
|
||||
assertEquals(SELECT_SQL_BASELINE, actualSelects, () -> "注解里的 @Select 逐接口清单变了(读侧同样 XML 优先)。"
|
||||
assertEquals(WRITE_SQL_BASELINE, actual, () -> "注解里又出现了写 SQL(基线已归零)。" + System.lineSeparator()
|
||||
+ " 新 SQL → 写进 src/main/resources/mapper/<模块>/<Name>Mapper.xml;"
|
||||
+ "简单单表才用 BaseMapper/实体(wrapper)。当前实测:" + actual);
|
||||
assertEquals(SELECT_SQL_BASELINE, actualSelects, () -> "注解里又出现了 @Select(基线已归零)。"
|
||||
+ System.lineSeparator()
|
||||
+ " 迁一条就从这里划掉一条;A 接口减一条配 B 接口加一条在这种钉法下会直接红。"
|
||||
+ System.lineSeparator()
|
||||
+ " 当前实测:" + actualSelects);
|
||||
assertFalse(actualSelects.isEmpty(), "读侧清单为空说明正则或目录坏了——恒绿的闸门比没有闸门更糟");
|
||||
+ " A 接口加一条配 B 接口减一条在这种逐接口钉法下会直接红。当前实测:" + actualSelects);
|
||||
// 归零之后不能拿"清单为空"当自证,分母改由扫描面本身提供
|
||||
int scanned = mappers().size();
|
||||
assertTrue(scanned >= 60,
|
||||
() -> "只扫到 " + scanned + " 个 *Mapper.java,多半是目录或工作目录坏了——"
|
||||
+ "扫描面塌了的话上面两个 assertEquals(空表) 就成了恒绿");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,19 +186,26 @@ class SqlLayeringConventionTest {
|
||||
"复杂写 SQL 的待迁清单变了:迁走一条就同时从 COMPLEX_WRITE_SQL_BACKLOG 划掉");
|
||||
}
|
||||
|
||||
/**
|
||||
* 反向钉:每扫到一份 mapper XML,它的同名接口就不许再留注解 SQL 或 {@code <script>} 残留。
|
||||
* 名单由 {@code src/main/resources/mapper} 扫出来,不是手写的——多一份 XML 就自动进守卫,
|
||||
* 少一份也不会让这条用例悄悄变绿。
|
||||
*/
|
||||
@Test
|
||||
void everyMigratedMapperHasNoAnnotatedSqlLeft() {
|
||||
for (String name : MIGRATED_TO_XML) {
|
||||
void everyMigratedMapperHasNoAnnotatedSqlLeft() throws IOException {
|
||||
List<Path> xmls = xmlFiles();
|
||||
assertFalse(xmls.isEmpty(), "一份 XML 都没扫到,这条守卫就是恒绿的");
|
||||
for (Path xml : xmls) {
|
||||
String name = stem(xml);
|
||||
Path file = findMapperInterface(name);
|
||||
String text = stripComments(read(file));
|
||||
assertFalse(count(WRITE_ANNOTATION, text) > 0,
|
||||
() -> name + " 已迁到 XML,注解里却又出现写 SQL:同名会让 MyBatis 启动期抛重复语句");
|
||||
assertFalse(count(SELECT_ANNOTATION, text) > 0,
|
||||
() -> name + " 已迁到 XML,注解里却又出现 @Select:" + name);
|
||||
int writes = count(WRITE_ANNOTATION, text);
|
||||
int selects = count(SELECT_ANNOTATION, text);
|
||||
assertTrue(writes == 0 && selects == 0,
|
||||
() -> name + " 的语句已在 " + xml.getFileName() + " 里,注解却又出现 "
|
||||
+ writes + " 条写 SQL / " + selects + " 条 @Select:同名会让 MyBatis 启动期抛重复语句");
|
||||
assertFalse(text.contains("<script>"),
|
||||
() -> name + " 的注解里还留着 <script>:迁移只做了一半,调用时会报 no statement");
|
||||
assertTrue(xmlFiles().stream().anyMatch(x -> stem(x).equals(name)),
|
||||
() -> name + " 声称已迁 XML,但 src/main/resources/mapper 下没有同名文件");
|
||||
() -> name + " 的注解里还留着 <script>:迁移只做了一半,调用时才报 no statement");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,25 +245,23 @@ class SqlLayeringConventionTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 这条是给"逐文件清单"这次改动自证的:以前钉的是总数 65 + 文件数 16 两个标量,
|
||||
* 于是 A 接口加一条、B 接口减一条就能让两个标量双双不动而绕过闸门。
|
||||
* 这里在内存里造出那次搬家——总和仍是基线总和,清单必须不等。
|
||||
* 迁移完成态的分母。归零之后,"注解为空"本身证明不了任何东西(扫描面塌了也空),
|
||||
* 所以把账本搬到 XML 一侧:语句总数必须是 96(本轮平移 85 + TaskImageCache 9 + AsinResultCache 2),
|
||||
* 少一条就是搬运中丢了语句,多一条就是有人加了语句没记账。
|
||||
*/
|
||||
@Test
|
||||
void thePerFileLedgerCatchesWhatTheScalarsCouldNot() {
|
||||
int baselineTotal = SELECT_SQL_BASELINE.values().stream().mapToInt(Integer::intValue).sum();
|
||||
assertTrue(baselineTotal > 0, "基线本身是空的,下面的断言就是恒真");
|
||||
|
||||
Map<String, Integer> moved = new LinkedHashMap<>(SELECT_SQL_BASELINE);
|
||||
moved.merge("ShopManageGroupMapper", 1, Integer::sum);
|
||||
moved.merge("ShopDuplicateCheckItemMapper", -1, Integer::sum);
|
||||
|
||||
assertEquals(baselineTotal, moved.values().stream().mapToInt(Integer::intValue).sum(),
|
||||
"这次搬家必须让总数不变,否则它证明不了标量钉法的失明");
|
||||
assertEquals(SELECT_SQL_BASELINE.size(), moved.size(),
|
||||
"这次搬家必须让文件数也不变");
|
||||
assertFalse(SELECT_SQL_BASELINE.equals(moved),
|
||||
"逐文件清单没看见这次搬家——说明它退化成了标量比较");
|
||||
void migratedStatementsLandInXmlWithoutLoss() throws IOException {
|
||||
List<Path> xmls = xmlFiles();
|
||||
int xmlCount = xmls.size();
|
||||
assertTrue(xmlCount >= 28, () -> "只扫到 " + xmlCount + " 份 mapper XML,目录不对或文件被挪走");
|
||||
int statements = 0;
|
||||
for (Path xml : xmls) {
|
||||
statements += count(STATEMENT_ID, read(xml));
|
||||
}
|
||||
int counted = statements;
|
||||
assertEquals(XML_STATEMENT_TOTAL, counted,
|
||||
() -> "mapper XML 里数到 " + counted + " 条语句,账本 " + XML_STATEMENT_TOTAL
|
||||
+ "(分布在 " + xmlCount + " 份文件)—— 迁移漏了,或加了没记账");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+11
-6
@@ -3,6 +3,9 @@ package com.nanri.aiimage.common.security;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.testutil.MapperXmlSupport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -76,13 +79,15 @@ class AuthChainQueryShapeTest {
|
||||
assertThat(service).doesNotContain("selectList(");
|
||||
|
||||
String mapper = read(sourceNamed("AdminUserMapper.java"));
|
||||
Matcher method = Pattern.compile(
|
||||
"LocalDateTime selectCompanySuperAdminEarliestExpiry\\([\\s\\S]{0,400}").matcher(mapper);
|
||||
assertThat(method.find()).as("mapper 里那个标量方法还在").isTrue();
|
||||
assertThat(mapper).contains("MIN(expires_at)");
|
||||
assertThat(mapper).contains("LocalDateTime selectCompanySuperAdminEarliestExpiry(");
|
||||
// 2026-10-08 SQL 迁进 mapper XML:断言内容一字未动,取文本的入口换到语句体本身。
|
||||
// 顺带去掉原来那个「方法名起 400 字符」的定宽窗口——它会截错,也会因上面多一行注释而失明。
|
||||
String sql = MapperXmlSupport.statementBody(AdminUserMapper.class,
|
||||
"selectCompanySuperAdminEarliestExpiry");
|
||||
assertThat(sql).contains("MIN(expires_at)");
|
||||
// 判据必须仍锁死在"本公司 + 公司超管",扩到全站会把别家的到期算进这家
|
||||
assertThat(mapper).contains("role = 'company_super_admin'");
|
||||
assertThat(mapper).contains("company_id = #{companyId}");
|
||||
assertThat(sql).contains("role = 'company_super_admin'");
|
||||
assertThat(sql).contains("company_id = #{companyId}");
|
||||
}
|
||||
|
||||
private static List<Path> scannedSources() throws IOException {
|
||||
|
||||
+16
-7
@@ -3,6 +3,9 @@ package com.nanri.aiimage.common.security;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.testutil.MapperXmlSupport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -214,14 +217,20 @@ class ConsoleWideningGuardrailTest {
|
||||
String mapper = read(mainSource("common/mapper/AdminUserMapper.java"));
|
||||
int at = mapper.indexOf("Long countAdminMenuGrants(");
|
||||
assertThat(at).as("入口探针方法还在").isGreaterThan(0);
|
||||
String head = mapper.substring(Math.max(0, at - 400), at);
|
||||
assertThat(head).contains("SELECT COUNT(1)");
|
||||
assertThat(head).doesNotContain(".select(");
|
||||
// 探针必须仍限定本公司:否则别家公司的授权能给这条账号开门
|
||||
assertThat(head).contains("cm.company_id");
|
||||
assertThat(head).contains("ucp.user_id = #{userId}");
|
||||
assertThat(head).contains("cm.menu_type = 'admin'");
|
||||
assertThat(mapper.substring(at)).contains("@Param(\"companyId\")");
|
||||
// 2026-10-08 SQL 迁进 mapper XML:断言内容一字未动,只把取文本的入口换到语句体本身,
|
||||
// 顺带去掉"方法名前 400 字符"那个定宽窗口(会截错,也会因注释变长而失明)。
|
||||
String sql = MapperXmlSupport.statementBody(AdminUserMapper.class, "countAdminMenuGrants");
|
||||
assertThat(sql).contains("SELECT COUNT(1)");
|
||||
// 探针必须仍限定本公司:否则别家公司的授权能给这条账号开门
|
||||
assertThat(sql).contains("cm.company_id");
|
||||
assertThat(sql).contains("ucp.user_id = #{userId}");
|
||||
assertThat(sql).contains("cm.menu_type = 'admin'");
|
||||
// 接口侧不许出现 wrapper 投影写法。SQL 搬进 XML 后接口只剩签名与 javadoc,
|
||||
// 而 javadoc 里就写着「别用 selectList(.select(columnId))」这段教训——只扫可执行行,
|
||||
// 否则这条断言会被自己的注释喂饱(注释越长越像"有问题",那不是它该管的事)。
|
||||
assertThat(executableLinesContaining(mapper, ".select("))
|
||||
.as("mapper 源码读到了(上面 indexOf 已证),这里必须是零命中").isEmpty();
|
||||
}
|
||||
|
||||
/** 自检:扫描面与两个分母都必须是实打实的非空,且页面门/豁免恰好铺满入口门清单。 */
|
||||
|
||||
+6
-9
@@ -1,14 +1,12 @@
|
||||
package com.nanri.aiimage.modules.dedupe.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.nanri.aiimage.modules.dedupe.model.entity.DedupeTotalDataEntity;
|
||||
import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
|
||||
import com.nanri.aiimage.testutil.MapperXmlSupport;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -22,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
* <p>为什么必须单独有一支:服务层测试用 mock 捕获的是实体对象,看不到最终 SQL——本表写侧
|
||||
* 靠的是注解里的列清单(不是 MyBatis-Plus 的实体字段推导),把 {@code company_id} 从清单里漏掉
|
||||
* 或把 {@code #{row.companyId}} 写成 {@code ${...}} 都是"SQL 变了而 service 测试照样绿"。
|
||||
* 走 {@code MapperAnnotationBuilder} 解析注解、向真 {@code BoundSql} 断言,
|
||||
* 走真 {@code XMLMapperBuilder} 解析 mapper XML、向真 {@code BoundSql} 断言,
|
||||
* 口径照抄 {@code ShopDataDuplicateCheckCompanyScopeTest#boundSqlFor}。</p>
|
||||
*/
|
||||
class DedupeTotalDataMapperSqlTest {
|
||||
@@ -46,11 +44,10 @@ class DedupeTotalDataMapperSqlTest {
|
||||
}
|
||||
|
||||
private static BoundSql boundSqlFor(int rowCount) throws Exception {
|
||||
Method method = DedupeTotalDataMapper.class.getMethod("insertBatchIgnore", List.class);
|
||||
String script = String.join(" ", method.getAnnotation(org.apache.ibatis.annotations.Insert.class).value());
|
||||
assertTrue(script.contains("company_id"), "注解原文应含 company_id(生成 SQL 才可能含): " + script);
|
||||
Configuration configuration = new MybatisConfiguration();
|
||||
new MapperAnnotationBuilder(configuration, DedupeTotalDataMapper.class).parse();
|
||||
// SQL 已从注解迁到 mapper XML(档 B 口径),原文与语句都要从 XML 那侧取
|
||||
String script = MapperXmlSupport.statementBody(DedupeTotalDataMapper.class, "insertBatchIgnore");
|
||||
assertTrue(script.contains("company_id"), "XML 语句体应含 company_id(生成 SQL 才可能含): " + script);
|
||||
Configuration configuration = MapperXmlSupport.configurationWith(DedupeTotalDataMapper.class);
|
||||
MappedStatement statement = configuration.getMappedStatement(
|
||||
DedupeTotalDataMapper.class.getName() + ".insertBatchIgnore");
|
||||
List<DedupeTotalDataEntity> rows = new java.util.ArrayList<>(rowCount);
|
||||
|
||||
+6
-8
@@ -3,10 +3,11 @@ package com.nanri.aiimage.modules.notification.service;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.config.NotificationProperties;
|
||||
import com.nanri.aiimage.modules.notification.mapper.UserNotificationMapper;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import com.nanri.aiimage.testutil.MapperXmlSupport;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -153,13 +154,10 @@ class NotificationRetentionServiceTest {
|
||||
|
||||
private static String deleteSqlOf(String methodName) {
|
||||
try {
|
||||
Delete delete = UserNotificationMapper.class
|
||||
.getMethod(methodName, LocalDateTime.class, int.class)
|
||||
.getAnnotation(Delete.class);
|
||||
assertThat(delete).as("%s 上的 @Delete 注解", methodName).isNotNull();
|
||||
return String.join(" ", delete.value());
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new AssertionError(ex);
|
||||
// SQL 已在 mapper XML 里(档 B 口径),取原文的入口跟着换到 XML 侧
|
||||
return MapperXmlSupport.statementBody(UserNotificationMapper.class, methodName);
|
||||
} catch (IOException | RuntimeException ex) {
|
||||
throw new AssertionError(methodName + " 的 DELETE 语句在 mapper XML 里取不到", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-11
@@ -8,16 +8,13 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.TestFixtures;
|
||||
import com.nanri.aiimage.modules.shopduplicatecheck.mapper.ShopDuplicateCheckSourceMapper;
|
||||
import java.lang.reflect.Method;
|
||||
import com.nanri.aiimage.testutil.MapperXmlSupport;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
@@ -166,13 +163,9 @@ class ShopDataDuplicateCheckCompanyScopeTest {
|
||||
}
|
||||
|
||||
private static BoundSql boundSqlFor(List<Long> memberIds) throws Exception {
|
||||
Method method = ShopDuplicateCheckSourceMapper.class
|
||||
.getMethod("selectShopNamesOwnedBy", List.class);
|
||||
String script = String.join(" ", method.getAnnotation(Select.class).value());
|
||||
Configuration configuration = new MybatisConfiguration();
|
||||
// 走注解构建器的同一条路径:把这条语句注册进 configuration,再向它要 BoundSql
|
||||
new MapperAnnotationBuilder(configuration, ShopDuplicateCheckSourceMapper.class)
|
||||
.parse();
|
||||
// SQL 已迁进 mapper XML:addMapper()/MapperAnnotationBuilder 都拿不到它,
|
||||
// 必须用 MapperXmlSupport 把接口与同名 XML 一起装进配置。
|
||||
Configuration configuration = MapperXmlSupport.configurationWith(ShopDuplicateCheckSourceMapper.class);
|
||||
MappedStatement statement = configuration.getMappedStatement(
|
||||
ShopDuplicateCheckSourceMapper.class.getName() + ".selectShopNamesOwnedBy");
|
||||
return statement.getBoundSql(Map.of("memberIds", memberIds));
|
||||
|
||||
+6
-3
@@ -1,11 +1,13 @@
|
||||
package com.nanri.aiimage.modules.taskcenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.nanri.aiimage.testutil.MapperXmlSupport;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -28,9 +30,10 @@ class TaskCenterQueryMapperSqlTest {
|
||||
private static MybatisConfiguration configuration;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
configuration = new MybatisConfiguration();
|
||||
configuration.addMapper(TaskCenterQueryMapper.class);
|
||||
static void setUp() throws IOException {
|
||||
// 2026-10-08 SQL 迁进 mapper XML:addMapper() 只会装 BaseMapper 的内置方法,
|
||||
// 自定义语句必须由 MapperXmlSupport 把同名 XML 一起装进来。
|
||||
configuration = MapperXmlSupport.configurationWith(TaskCenterQueryMapper.class);
|
||||
}
|
||||
|
||||
private static BoundSql render(String method, Map<String, Object> params) {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.nanri.aiimage.testutil;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 给"钉 SQL 形状"的用例用的取数通道:SQL 已从注解搬进 mapper XML(档 B 口径,2026-10-08),
|
||||
* 所以这类用例不能再靠 {@code method.getAnnotation(Select.class).value()} 或只
|
||||
* {@code addMapper()} 拿语句——那两条路现在分别给出 NPE 和"语句不存在"。
|
||||
*
|
||||
* <p>注意 {@code addMapper()} 自己不会加载我们这份 XML:MyBatis 只按
|
||||
* {@code com/…/mapper/XxxMapper.xml} 这个同名路径去找,而我们的语句在
|
||||
* {@code src/main/resources/mapper/<模块>/XxxMapper.xml}(由 {@code mybatis-plus.mapper-locations}
|
||||
* 在运行期扫进来)。所以这里显式把两份都装进同一个 Configuration。
|
||||
*/
|
||||
public final class MapperXmlSupport {
|
||||
|
||||
private static final Pattern STATEMENT = Pattern.compile(
|
||||
"(?is)<(select|insert|update|delete)\\s+id=\"%s\"[^>]*>(.*?)</\\1>");
|
||||
|
||||
private MapperXmlSupport() {
|
||||
}
|
||||
|
||||
/** 装好接口(BaseMapper 的内置方法)与同名 XML(自定义语句)的配置,供取 BoundSql。 */
|
||||
public static MybatisConfiguration configurationWith(Class<?> mapper) throws IOException {
|
||||
MybatisConfiguration configuration = new MybatisConfiguration();
|
||||
configuration.addMapper(mapper);
|
||||
Path xml = xmlOf(mapper);
|
||||
try (InputStream in = Files.newInputStream(xml)) {
|
||||
new XMLMapperBuilder(in, configuration, xml.toString(),
|
||||
configuration.getSqlFragments()).parse();
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/** 取某条语句在 XML 里的原文(实体已还原),断言比较符/转义是否落地时用这支。 */
|
||||
public static String statementBody(Class<?> mapper, String method) throws IOException {
|
||||
Matcher m = Pattern.compile(String.format(STATEMENT.pattern(), Pattern.quote(method)))
|
||||
.matcher(read(xmlOf(mapper)));
|
||||
if (!m.find()) {
|
||||
throw new IllegalStateException(mapper.getSimpleName() + "#" + method
|
||||
+ " 在 " + xmlOf(mapper) + " 里没有语句");
|
||||
}
|
||||
return unescape(m.group(2));
|
||||
}
|
||||
|
||||
private static Path xmlOf(Class<?> mapper) throws IOException {
|
||||
String wanted = mapper.getSimpleName() + ".xml";
|
||||
List<Path> hits;
|
||||
Path dir = moduleRoot().resolve("src/main/resources/mapper");
|
||||
if (!Files.isDirectory(dir)) {
|
||||
throw new IllegalStateException("找不到 " + dir + " —— 本 helper 依赖以 backend-java 为工作目录运行");
|
||||
}
|
||||
try (Stream<Path> walk = Files.walk(dir)) {
|
||||
hits = walk.filter(p -> p.getFileName().toString().equals(wanted)).collect(Collectors.toList());
|
||||
}
|
||||
if (hits.isEmpty()) {
|
||||
throw new IllegalStateException(mapper.getSimpleName() + " 没有对应的 mapper XML:"
|
||||
+ "SQL 若还在注解里就不该走这支,若在 XML 里请检查文件名与接口名是否逐字一致");
|
||||
}
|
||||
if (hits.size() > 1) {
|
||||
throw new IllegalStateException("同名 mapper XML 有 " + hits.size() + " 份:" + hits);
|
||||
}
|
||||
return hits.get(0);
|
||||
}
|
||||
|
||||
private static String unescape(String text) {
|
||||
return text.replace("<", "<").replace(">", ">").replace("&", "&");
|
||||
}
|
||||
|
||||
private static String read(Path path) throws IOException {
|
||||
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static Path moduleRoot() {
|
||||
Path here = Path.of("").toAbsolutePath();
|
||||
if (Files.isDirectory(here.resolve("src/main/java"))) {
|
||||
return here;
|
||||
}
|
||||
Path nested = here.resolve("backend-java");
|
||||
if (Files.isDirectory(nested.resolve("src/main/java"))) {
|
||||
return nested;
|
||||
}
|
||||
throw new IllegalStateException("无法定位 backend-java 模块目录(cwd=" + here + ")");
|
||||
}
|
||||
|
||||
/** 供 Resources 走类路径取主资源(target/classes 在测试类路径上)。 */
|
||||
public static InputStream classpathResource(String path) throws IOException {
|
||||
return Resources.getResourceAsStream(path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
AdminUserMapper countAdminMenuGrants Select PURE <script>\nSELECT COUNT(1)\nFROM user_column_permission ucp\nJOIN columns cm ON cm.id = ucp.column_id\nWHERE ucp.user_id = #{userId}\n AND cm.menu_type = 'admin'\n<if test="companyId != null">\n AND cm.company_id = #{companyId}\n</if>\n</script>
|
||||
AdminUserMapper selectCompanySuperAdminEarliestExpiry Select PURE SELECT MIN(expires_at)\nFROM users\nWHERE role = 'company_super_admin'\n AND company_id = #{companyId}
|
||||
BrandCrawlTaskMapper selectExpiredTerminalTaskIds Select PURE SELECT id FROM brand_crawl_tasks\nWHERE status IN ('success', 'failed', 'cancelled')\n AND updated_at < #{cutoff}\nORDER BY id ASC\nLIMIT #{batchSize}
|
||||
CollectDataItemMapper insertBatch Insert PURE <script>\nINSERT INTO biz_collect_data_item\n (task_id, row_index, source_file_key, source_filename, keyword, status_value, extra_json, created_at)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.taskId}, #{row.rowIndex}, #{row.sourceFileKey}, #{row.sourceFilename},\n #{row.keyword}, #{row.statusValue}, #{row.extraJson}, #{row.createdAt})\n</foreach>\n</script>
|
||||
DedupeTotalDataMapper insertBatchIgnore Insert PURE <script>\nINSERT IGNORE INTO biz_dedupe_total_data\n (data_value, country, group_id, uploader_user_id, uploader_username, company_id)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.dataValue}, #{row.country}, #{row.groupId}, #{row.uploaderUserId}, #{row.uploaderUsername}, #{row.companyId})\n</foreach>\n</script>
|
||||
DedupeTotalDataMapper selectAllDataValues Select PURE SELECT data_value FROM biz_dedupe_total_data
|
||||
DeviceLogFileMapper deleteOlderThanBatch Delete PURE DELETE FROM device_log_file\nWHERE log_date < #{cutoff}\nLIMIT #{batchSize}
|
||||
FileResultMapper selectRowsUpdatedAtByTaskIds Select PURE <script>\nSELECT task_id AS taskId, MAX(updated_at) AS latestRowAt, COUNT(*) AS rowCount\nFROM biz_file_result\nWHERE module_type = #{moduleType}\n AND task_id IN\n <foreach item="taskId" collection="taskIds" open="(" separator="," close=")">#{taskId}</foreach>\nGROUP BY task_id\n</script>
|
||||
FileTaskMapper selectExpiredTerminalTaskIds Select PURE SELECT id FROM biz_file_task\nWHERE module_type = #{moduleType}\n AND status IN ('SUCCESS', 'FAILED', 'CANCELLED', 'CANCELED')\n AND updated_at < #{cutoff}\nORDER BY id ASC\nLIMIT #{batchSize}
|
||||
ImageVideoAdminTaskMapper countAdminTaskPage Select PURE <script>\nSELECT COUNT(*) AS total\nFROM biz_image_video_async_task t\nLEFT JOIN users u ON u.id = t.user_id\nWHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'\n AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)\n<if test="userId != null"> AND t.user_id = #{userId}</if>\n<if test="userIds != null"> AND t.user_id IN\n <foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>\n</if>\n<if test="username != null and username != ''"> AND u.username LIKE CONCAT('%', #{username}, '%')</if>\n<if test="status != null and status != ''"> AND t.status = #{status}</if>\n<if test="executeId != null and executeId != ''"> AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%')</if>\n<if test="submittedFrom != null"> AND t.submitted_at >= #{submittedFrom}</if>\n<if test="submittedTo != null"> AND t.submitted_at <= #{submittedTo}</if>\n</script>
|
||||
ImageVideoAdminTaskMapper selectAdminTaskDetail Select PURE SELECT t.id, t.user_id, t.status, t.request_json, t.submit_response_json, t.result_json,\n t.video_urls_json, t.debug_url, t.archived_videos_json, t.archive_status,\n t.archive_error, t.archive_attempt_count,\n DATE_FORMAT(t.archived_at, '%Y-%m-%d %H:%i:%s') AS archived_at,\n t.error_message, t.coze_execute_id, t.coze_status,\n DATE_FORMAT(t.submitted_at, '%Y-%m-%d %H:%i:%s') AS submitted_at,\n DATE_FORMAT(t.completed_at, '%Y-%m-%d %H:%i:%s') AS completed_at,\n u.username,\n COALESCE((\n SELECT GROUP_CONCAT(DISTINCT g.group_name ORDER BY g.id SEPARATOR '、')\n FROM biz_shop_manage_group g\n LEFT JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id\n WHERE g.created_by_id = t.user_id OR g.user_id = t.user_id OR gm.user_id = t.user_id\n ), '') AS group_name\nFROM biz_image_video_async_task t\nLEFT JOIN users u ON u.id = t.user_id\nWHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'\n AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)\n AND t.id = #{taskId}\nLIMIT 1
|
||||
ImageVideoAdminTaskMapper selectAdminTaskPage Select PURE <script>\nSELECT t.id, t.user_id, t.status, t.request_json, t.submit_response_json, t.result_json,\n t.video_urls_json, t.debug_url, t.archived_videos_json, t.archive_status,\n t.archive_error, t.archive_attempt_count,\n DATE_FORMAT(t.archived_at, '%Y-%m-%d %H:%i:%s') AS archived_at,\n t.error_message, t.coze_execute_id, t.coze_status,\n DATE_FORMAT(t.submitted_at, '%Y-%m-%d %H:%i:%s') AS submitted_at,\n DATE_FORMAT(t.completed_at, '%Y-%m-%d %H:%i:%s') AS completed_at,\n u.username,\n COALESCE((\n SELECT GROUP_CONCAT(DISTINCT g.group_name ORDER BY g.id SEPARATOR '、')\n FROM biz_shop_manage_group g\n LEFT JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id\n WHERE g.created_by_id = t.user_id OR g.user_id = t.user_id OR gm.user_id = t.user_id\n ), '') AS group_name\nFROM biz_image_video_async_task t\nLEFT JOIN users u ON u.id = t.user_id\nWHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'\n AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)\n<if test="userId != null"> AND t.user_id = #{userId}</if>\n<if test="userIds != null"> AND t.user_id IN\n <foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>\n</if>\n<if test="username != null and username != ''"> AND u.username LIKE CONCAT('%', #{username}, '%')</if>\n<if test="status != null and status != ''"> AND t.status = #{status}</if>\n<if test="executeId != null and executeId != ''"> AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%')</if>\n<if test="submittedFrom != null"> AND t.submitted_at >= #{submittedFrom}</if>\n<if test="submittedTo != null"> AND t.submitted_at <= #{submittedTo}</if>\nORDER BY t.submitted_at DESC, t.id DESC\nLIMIT #{limit} OFFSET #{offset}\n</script>
|
||||
ImageVideoAdminTaskMapper selectAdminZipRows Select PURE <script>\nSELECT t.id, t.user_id, t.video_urls_json, t.archived_videos_json\nFROM biz_image_video_async_task t\nWHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'\n AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)\n AND t.id IN\n<foreach collection="taskIds" item="taskId" open="(" separator="," close=")">\n #{taskId}\n</foreach>\n</script>
|
||||
ImageVideoAsyncTaskMapper claimPending Update PURE 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 = '')
|
||||
ImageVideoAsyncTaskMapper claimWaiting Update PURE 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 = '')
|
||||
ImageVideoAsyncTaskMapper requeuePollingTasks Update PURE 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 = '')
|
||||
InvalidAsinDataMapper insertBatchIgnore Insert PURE <script>\nINSERT IGNORE INTO biz_invalid_asin_data\n (data_value, brand, record_source, uploader_user_id)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.dataValue}, #{row.brand}, #{row.recordSource}, #{row.uploaderUserId,jdbcType=BIGINT})\n</foreach>\n</script>
|
||||
PriceTrackLoopRunMapper deleteFinishedBefore Delete PURE DELETE FROM biz_price_track_loop_run\nWHERE status IN ('SUCCESS', 'FAILED', 'STOPPED')\n AND cleanup_at < #{cutoff}\nLIMIT #{batchSize}
|
||||
PublishItemMapper insertBatch Insert PURE <script>\nINSERT INTO biz_publish_item\n (task_id, file_id, row_index, source_id, asin, country, brand, price_value,\n status_value, sync_status, sync_countries, created_at, updated_at)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.taskId}, #{row.fileId}, #{row.rowIndex}, #{row.sourceId}, #{row.asin},\n #{row.country}, #{row.brand}, #{row.priceValue}, #{row.statusValue},\n #{row.syncStatus}, #{row.syncCountries}, #{row.createdAt}, #{row.updatedAt})\n</foreach>\n</script>
|
||||
QueryAsinMapper insertBatch Insert PURE <script>\nINSERT INTO biz_query_asin (group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.groupId}, #{row.shopName}, #{row.asinDe}, #{row.asinUk}, #{row.asinFr}, #{row.asinIt}, #{row.asinEs})\n</foreach>\n</script>
|
||||
QueryAsinMapper selectByGroupIdsAndShopNames Select PURE <script>\nSELECT id, group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es, created_at, updated_at\nFROM biz_query_asin\nWHERE group_id IN\n<foreach collection="groupIds" item="groupId" open="(" separator="," close=")">\n #{groupId}\n</foreach>\nAND shop_name IN\n<foreach collection="shopNames" item="shopName" open="(" separator="," close=")">\n #{shopName}\n</foreach>\n</script>
|
||||
QueryAsinMapper selectByShopNames Select PURE <script>\nSELECT id, group_id, shop_name, asin_de, asin_uk, asin_fr, asin_it, asin_es, created_at, updated_at\nFROM biz_query_asin\nWHERE shop_name IN\n<foreach collection="shopNames" item="shopName" open="(" separator="," close=")">\n #{shopName}\n</foreach>\n</script>
|
||||
ShopDataCrawlAdminTasksMapper countDailyFileObjectReferences Select PURE SELECT COUNT(1) FROM biz_shop_data_crawl_daily_file\nWHERE result_file_url = #{objectKey}
|
||||
ShopDataCrawlAdminTasksMapper selectDownloadRowById Select PURE SELECT df.id AS resultId, df.latest_task_id AS taskId, df.user_id AS userId,\n df.shop_name AS sourceFilename, df.result_filename AS resultFilename,\n df.result_file_url AS resultFileUrl\nFROM biz_shop_data_crawl_daily_file df\nWHERE df.id = #{dailyFileId}
|
||||
ShopDataCrawlItemMapper deleteBatch Delete PURE DELETE FROM biz_shop_data_crawl_item\nWHERE shop_name = #{shopName} AND business_date = #{businessDate}
|
||||
ShopDataCrawlItemMapper deleteByDailyFileId Delete PURE DELETE FROM biz_shop_data_crawl_item\nWHERE daily_file_id = #{dailyFileId}
|
||||
ShopDataCrawlItemMapper deleteOlderThanBatch Delete PURE DELETE FROM biz_shop_data_crawl_item\nWHERE business_date < #{cutoff}\nLIMIT #{batchSize}
|
||||
ShopDataCrawlItemMapper insertBatch Insert PURE <script>\nINSERT INTO biz_shop_data_crawl_item\n (shop_id, shop_name, group_name, business_date, country, asin, brand, price,\n item_date, units_sold, item_json, result_id, task_id, daily_file_id)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.shopId}, #{row.shopName}, #{row.groupName}, #{row.businessDate}, #{row.country},\n #{row.asin}, #{row.brand}, #{row.price}, #{row.itemDate}, #{row.unitsSold},\n #{row.itemJson}, #{row.resultId}, #{row.taskId}, #{row.dailyFileId})\n</foreach>\n</script>
|
||||
ShopDataDuplicateScanMapper deleteOlderThanBatch Delete PURE DELETE FROM shop_data_duplicate_scan\nWHERE created_at < #{cutoff}\n AND id < #{protectFromId}\nLIMIT #{batchSize}
|
||||
ShopDataDuplicateScanMapper selectLatestFullRow Select PURE SELECT id, summary_json AS summaryJson, payload_json AS payloadJson, created_at AS createdAt FROM shop_data_duplicate_scan WHERE status = 'SUCCESS' ORDER BY id DESC LIMIT 1
|
||||
ShopDataDuplicateScanMapper selectLatestLightRow Select PURE SELECT id, created_at AS createdAt FROM shop_data_duplicate_scan WHERE status = 'SUCCESS' ORDER BY id DESC LIMIT 1
|
||||
ShopDataDuplicateScanMapper selectNthNewestId Select PURE SELECT id FROM shop_data_duplicate_scan ORDER BY id DESC LIMIT 1 OFFSET #{offset}
|
||||
ShopDuplicateCheckItemMapper countShopBatch Select PURE SELECT COUNT(1) FROM biz_shop_data_crawl_item\nWHERE shop_name = #{shopName} AND business_date = #{businessDate}
|
||||
ShopDuplicateCheckItemMapper selectDistinctShopNames Select PURE SELECT DISTINCT shop_name FROM biz_shop_data_crawl_item
|
||||
ShopDuplicateCheckItemMapper selectLatestItemsByShop Select PURE SELECT i.shop_name AS shopName,\n i.country AS country,\n i.asin AS asin,\n i.item_date AS itemDate,\n i.price AS price,\n i.brand AS brand\nFROM biz_shop_data_crawl_item i\nWHERE i.shop_name = #{shopName}\n AND i.business_date = (\n SELECT MAX(business_date) FROM biz_shop_data_crawl_item WHERE shop_name = #{shopName}\n )
|
||||
ShopDuplicateCheckItemMapper selectLegacyMigrationFiles Select PURE SELECT ranked.daily_file_id AS dailyFileId,\n ranked.business_date AS businessDate,\n ranked.latest_result_id AS latestResultId,\n fr.source_filename AS shopName,\n fr.result_file_url AS resultFileUrl,\n fr.task_id AS taskId\nFROM (\n SELECT df.id AS daily_file_id,\n df.business_date,\n df.latest_result_id,\n ROW_NUMBER() OVER (\n PARTITION BY df.shop_key\n ORDER BY df.business_date DESC, df.id DESC) AS row_no\n FROM biz_shop_data_crawl_daily_file df\n WHERE df.compensation_done = 1\n) ranked\nJOIN biz_file_result fr ON fr.id = ranked.latest_result_id\nWHERE ranked.row_no = 1\n AND fr.module_type = 'SHOP_DATA_CRAWL'
|
||||
ShopDuplicateCheckItemMapper selectMemberPayload Select PURE SELECT row_payload FROM biz_shop_data_crawl_daily_member\nWHERE daily_file_id = #{dailyFileId} AND result_id = #{resultId}\nLIMIT 1
|
||||
ShopDuplicateCheckSourceMapper selectAllShopLabels Select PURE SELECT TRIM(sm.shop_name) AS shopName,\n GROUP_CONCAT(DISTINCT COALESCE(NULLIF(g.group_name, ''), NULLIF(sm.group_name, ''))\n ORDER BY sm.id SEPARATOR '、') AS groupName\nFROM biz_shop_manage sm\nLEFT JOIN biz_shop_manage_group g ON g.id = sm.group_id\nWHERE TRIM(COALESCE(sm.shop_name, '')) <> ''\nGROUP BY TRIM(sm.shop_name)
|
||||
ShopDuplicateCheckSourceMapper selectGroupLabels Select PURE <script>\nSELECT TRIM(sm.shop_name) AS shopName,\n GROUP_CONCAT(DISTINCT COALESCE(NULLIF(g.group_name, ''), NULLIF(sm.group_name, ''))\n ORDER BY sm.id SEPARATOR '、') AS groupName\nFROM biz_shop_manage sm\nLEFT JOIN biz_shop_manage_group g ON g.id = sm.group_id\nWHERE TRIM(sm.shop_name) IN\n<foreach collection='shopNames' item='name' open='(' separator=',' close=')'>#{name}</foreach>\nGROUP BY TRIM(sm.shop_name)\n</script>
|
||||
ShopDuplicateCheckSourceMapper selectLatestResultRows Select PURE SELECT ranked.result_id AS resultId,\n ranked.shop_name AS shopName,\n ranked.result_file_url AS resultFileUrl,\n ranked.result_file_size AS resultFileSize,\n ranked.request_json AS requestJson,\n ranked.country_codes_json AS countryCodesJson\nFROM (\n SELECT r.id AS result_id,\n r.source_filename AS shop_name,\n r.result_file_url,\n r.result_file_size,\n t.request_json,\n df.country_codes_json,\n COALESCE(df.last_success_at, df.updated_at, t.finished_at,\n t.updated_at, t.created_at) AS latest_file_updated_at,\n ROW_NUMBER() OVER (\n PARTITION BY TRIM(COALESCE(r.source_filename, ''))\n ORDER BY COALESCE(df.last_success_at, df.updated_at,\n t.finished_at, t.updated_at, t.created_at) DESC,\n r.id DESC) AS row_no\n FROM biz_file_result r\n JOIN biz_file_task t ON t.id = r.task_id\n LEFT JOIN biz_shop_data_crawl_daily_file df ON df.latest_result_id = r.id\n WHERE r.module_type = 'SHOP_DATA_CRAWL'\n AND t.module_type = 'SHOP_DATA_CRAWL'\n AND TRIM(COALESCE(r.result_file_url, '')) <> ''\n) ranked\nWHERE ranked.row_no = 1\nORDER BY ranked.latest_file_updated_at DESC, ranked.result_id DESC
|
||||
ShopDuplicateCheckSourceMapper selectManagedShopNames Select PURE SELECT DISTINCT TRIM(sm.shop_name) AS shopName\nFROM biz_shop_manage sm\nWHERE sm.group_id IN (\n SELECT id FROM biz_shop_manage_group\n WHERE created_by_id = #{operatorId} OR user_id = #{operatorId}\n)
|
||||
ShopDuplicateCheckSourceMapper selectShopNamesOwnedBy Select PURE <script>\nSELECT DISTINCT TRIM(sm.shop_name)\nFROM biz_shop_manage sm\nWHERE TRIM(COALESCE(sm.shop_name, '')) <> ''\n AND sm.created_by_id IN\n <foreach collection="memberIds" item="mid" open="(" separator="," close=")">#{mid}</foreach>\n</script>
|
||||
ShopManageGroupMapper selectAccessibleCreatorUserIds Select PURE SELECT DISTINCT visible_user_id\nFROM (\n SELECT #{operatorId} AS visible_user_id\n UNION\n SELECT direct_member.user_id AS visible_user_id\n FROM biz_shop_manage_group leader_group\n INNER JOIN biz_shop_manage_group_member direct_member ON direct_member.group_id = leader_group.id\n WHERE leader_group.created_by_id = #{operatorId}\n OR leader_group.user_id = #{operatorId}\n UNION\n SELECT COALESCE(direct_group.created_by_id, direct_group.user_id) AS visible_user_id\n FROM biz_shop_manage_group_member membership\n INNER JOIN biz_shop_manage_group direct_group ON direct_group.id = membership.group_id\n WHERE membership.user_id = #{operatorId}\n AND COALESCE(direct_group.created_by_id, direct_group.user_id) IS NOT NULL\n) visible_users\nWHERE visible_user_id IS NOT NULL\nORDER BY visible_user_id ASC
|
||||
ShopManageGroupMapper selectAccessibleGroupIds Select PURE SELECT DISTINCT accessible_group_id\nFROM (\n SELECT g.id AS accessible_group_id\n FROM biz_shop_manage_group g\n WHERE g.created_by_id = #{operatorId}\n OR g.user_id = #{operatorId}\n UNION\n SELECT gm.group_id AS accessible_group_id\n FROM biz_shop_manage_group_member gm\n WHERE gm.user_id = #{operatorId}\n UNION\n SELECT g2.id AS accessible_group_id\n FROM biz_shop_manage_group_member gm\n INNER JOIN biz_shop_manage_group g1 ON g1.id = gm.group_id\n INNER JOIN biz_shop_manage_group g2\n ON g2.created_by_id = COALESCE(g1.created_by_id, g1.user_id)\n OR g2.user_id = COALESCE(g1.created_by_id, g1.user_id)\n WHERE gm.user_id = #{operatorId}\n AND COALESCE(g1.created_by_id, g1.user_id) IS NOT NULL\n UNION\n SELECT member_groups.id AS accessible_group_id\n FROM biz_shop_manage_group leader_group\n INNER JOIN biz_shop_manage_group_member direct_member ON direct_member.group_id = leader_group.id\n INNER JOIN biz_shop_manage_group member_groups\n ON member_groups.created_by_id = direct_member.user_id\n OR member_groups.user_id = direct_member.user_id\n WHERE leader_group.created_by_id = #{operatorId}\n OR leader_group.user_id = #{operatorId}\n) accessible_groups\nWHERE accessible_group_id IS NOT NULL\nORDER BY accessible_group_id ASC
|
||||
ShopManageGroupMapper selectAllGroups Select PURE SELECT g.id AS id, g.group_name AS groupName\nFROM biz_shop_manage_group g\nORDER BY g.id ASC
|
||||
ShopManageGroupMapper selectGroupNamesByUserIds Select PURE <script>\nSELECT u.id AS userId, g.group_name AS groupName\nFROM users u\nINNER JOIN biz_shop_manage_group g\n ON g.created_by_id = u.created_by_id OR g.user_id = u.created_by_id\nWHERE u.created_by_id IS NOT NULL\n AND u.id IN\n<foreach collection='userIds' item='userId' open='(' separator=',' close=')'>\n #{userId}\n</foreach>\nORDER BY g.id ASC\n</script>
|
||||
ShopManageGroupMapper selectLeaderIdsByMemberUserId Select PURE SELECT DISTINCT COALESCE(g.created_by_id, g.user_id) AS leader_id\nFROM biz_shop_manage_group_member gm\nINNER JOIN biz_shop_manage_group g ON g.id = gm.group_id\nWHERE gm.user_id = #{userId}\n AND COALESCE(g.created_by_id, g.user_id) IS NOT NULL
|
||||
ShopManageGroupMapper selectLedGroups Select PURE SELECT g.id AS id, g.group_name AS groupName\nFROM biz_shop_manage_group g\nWHERE g.created_by_id = #{operatorId} OR g.user_id = #{operatorId}\nORDER BY g.id ASC
|
||||
ShopManageGroupMapper selectManagedMemberUserIds Select PURE SELECT DISTINCT gm.user_id\nFROM biz_shop_manage_group g\nINNER JOIN biz_shop_manage_group_member gm ON gm.group_id = g.id\nINNER JOIN users u ON u.id = gm.user_id\nWHERE g.created_by_id = #{operatorId}\n OR g.user_id = #{operatorId}\nORDER BY gm.user_id ASC
|
||||
ShopManageGroupMapper selectUserIdsByGroupId Select PURE SELECT u.id AS userId\nFROM users u\nINNER JOIN biz_shop_manage_group g ON g.id = #{groupId}\nWHERE u.id = COALESCE(g.created_by_id, g.user_id)\n OR u.created_by_id = COALESCE(g.created_by_id, g.user_id)\nORDER BY u.id ASC
|
||||
ShopManageGroupMapper selectUserIdsByGroupIds Select PURE <script>\nSELECT DISTINCT visible_user_id\nFROM (\n SELECT COALESCE(g.created_by_id, g.user_id) AS visible_user_id\n FROM biz_shop_manage_group g\n WHERE g.id IN\n <foreach collection='groupIds' item='groupId' open='(' separator=',' close=')'>\n #{groupId}\n </foreach>\n UNION\n SELECT gm.user_id AS visible_user_id\n FROM biz_shop_manage_group_member gm\n WHERE gm.group_id IN\n <foreach collection='groupIds' item='groupId' open='(' separator=',' close=')'>\n #{groupId}\n </foreach>\n) visible_users\nWHERE visible_user_id IS NOT NULL\nORDER BY visible_user_id ASC\n</script>
|
||||
SoftwareVersionMapper markLatestById Update PURE UPDATE web_config SET is_latest = (id = #{id})
|
||||
TaskCenterQueryMapper countFinishedTasksSince Select CONST <script>SELECT COUNT(*) FROM ( SELECT t.id FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('CANCELED','CANCELLED','FAILED','SUCCESS') AND COALESCE(t.finished_at, t.updated_at) >= #{since}<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id FROM brand_crawl_tasks b WHERE b.status IN ('cancelled','failed','success') AND b.updated_at >= #{since}<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) u</script>
|
||||
TaskCenterQueryMapper countRunningTasks Select CONST <script>SELECT COUNT(*) FROM ( SELECT t.id FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('PENDING','RUNNING','SCHEDULED')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id FROM brand_crawl_tasks b WHERE b.status IN ('pending','running')<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) u</script>
|
||||
TaskCenterQueryMapper countShops Select CONST <script>SELECT COUNT(*) FROM biz_shop_manage s WHERE 1 = 1<if test='userIds != null'> AND s.created_by_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if></script>
|
||||
TaskCenterQueryMapper countStuckTasks Select CONST <script>SELECT COUNT(*) FROM ( SELECT t.id FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('PENDING','RUNNING','SCHEDULED') AND t.updated_at < #{idleBefore}<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id FROM brand_crawl_tasks b WHERE b.status IN ('pending','running') AND b.updated_at < #{idleBefore}<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) u</script>
|
||||
TaskCenterQueryMapper countTaskPage Select CONST <script>SELECT COUNT(*) FROM (SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND UPPER(t.module_type) = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND t.created_at >= #{startTime}</if><if test='endTime != null'> AND t.created_at <= #{endTime}</if><if test='shop != null'> AND (EXISTS (SELECT 1 FROM biz_publish_file p WHERE p.task_id = t.id AND LOWER(TRIM(p.shop_name)) = LOWER(TRIM(#{shop}))) OR (t.module_type IN ('PATROL_DELETE','PRICE_TRACK','PRODUCT_RISK_RESOLVE','QUERY_ASIN','SHOP_DATA_CRAWL','SHOP_MATCH') AND EXISTS (SELECT 1 FROM biz_file_result f WHERE f.task_id = t.id AND LOWER(TRIM(f.source_filename)) = LOWER(TRIM(#{shop})))))</if> UNION ALL SELECT b.id, CONCAT('brand-', b.id), 'BRAND', CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END, b.user_id, b.device_id, b.created_at, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END, b.updated_at, b.progress_total, b.progress_current, 0, 1 FROM brand_crawl_tasks b WHERE 1 = 1<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND 'BRAND' = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND b.created_at >= #{startTime}</if><if test='endTime != null'> AND b.created_at <= #{endTime}</if><if test='shop != null'> AND 1 = 0</if>) m</script>
|
||||
TaskCenterQueryMapper selectActiveTasks Select CONST <script>SELECT m.* FROM (SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') AND t.status IN ('PENDING','RUNNING','SCHEDULED')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> UNION ALL SELECT b.id, CONCAT('brand-', b.id), 'BRAND', CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END, b.user_id, b.device_id, b.created_at, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END, b.updated_at, b.progress_total, b.progress_current, 0, 1 FROM brand_crawl_tasks b WHERE b.status IN ('pending','running')<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if>) m ORDER BY m.createdAt DESC, m.id DESC LIMIT #{limit}</script>
|
||||
TaskCenterQueryMapper selectBrandTaskById Select CONST SELECT b.id AS id, CONCAT('brand-', b.id) AS taskNo, 'BRAND' AS moduleType, CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END AS status, b.user_id AS userId, b.device_id AS deviceId, b.created_at AS createdAt, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END AS finishedAt, b.updated_at AS updatedAt, b.progress_total AS totalCount, b.progress_current AS successCount, 0 AS failedCount, 1 AS brand, b.error_message AS errorMessage FROM brand_crawl_tasks b WHERE b.id = #{id}
|
||||
TaskCenterQueryMapper selectCollectDataKeywordStats Select PURE <script>SELECT t.id AS taskId, JSON_UNQUOTE(JSON_EXTRACT(t.result_json, '$.totalRows')) AS totalRows, JSON_UNQUOTE(JSON_EXTRACT(t.result_json, '$.processedRows')) AS processedRows FROM biz_file_task t WHERE t.id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach> AND UPPER(t.module_type) = 'COLLECT_DATA' AND t.result_json IS NOT NULL</script>
|
||||
TaskCenterQueryMapper selectDeviceNames Select PURE <script>SELECT d.device_id AS deviceId, MAX(d.device_name) AS deviceName FROM device_log_file d WHERE d.device_id IN <foreach collection='deviceIds' item='did' open='(' separator=',' close=')'>#{did}</foreach> GROUP BY d.device_id</script>
|
||||
TaskCenterQueryMapper selectFileResultShops Select CONST <script>SELECT f.task_id AS taskId, f.source_filename AS shop FROM biz_file_result f JOIN biz_file_task ft ON ft.id = f.task_id AND ft.module_type IN ('PATROL_DELETE','PRICE_TRACK','PRODUCT_RISK_RESOLVE','QUERY_ASIN','SHOP_DATA_CRAWL','SHOP_MATCH') WHERE f.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach> AND f.source_filename IS NOT NULL AND f.source_filename != '' GROUP BY f.task_id, f.source_filename</script>
|
||||
TaskCenterQueryMapper selectPublishShopStats Select PURE SELECT p.shop_name AS scopeKey, COUNT(*) AS total, SUM(UPPER(p.status) = 'SUCCESS') AS success, SUM(UPPER(p.status) = 'FAILED') AS failed FROM biz_publish_file p WHERE p.task_id = #{taskId} AND p.shop_name IS NOT NULL AND p.shop_name != '' GROUP BY p.shop_name ORDER BY COUNT(*) DESC, p.shop_name LIMIT 200
|
||||
TaskCenterQueryMapper selectPublishShops Select PURE <script>SELECT p.task_id AS taskId, p.shop_name AS shop FROM biz_publish_file p WHERE p.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach> AND p.shop_name IS NOT NULL AND p.shop_name != '' GROUP BY p.task_id, p.shop_name</script>
|
||||
TaskCenterQueryMapper selectResultItemShopStats Select PURE SELECT i.scope_key AS scopeKey, COUNT(*) AS total, SUM(UPPER(i.status) = 'SUCCESS') AS success, SUM(UPPER(i.status) = 'FAILED') AS failed FROM biz_task_result_item i WHERE i.task_id = #{taskId} AND i.scope_key IS NOT NULL AND i.scope_key != '' GROUP BY i.scope_key ORDER BY COUNT(*) DESC, i.scope_key LIMIT 200
|
||||
TaskCenterQueryMapper selectShopNames Select CONST <script>SELECT DISTINCT s.shop_name FROM biz_shop_manage s WHERE 1 = 1<if test='userIds != null'> AND s.created_by_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if> ORDER BY s.shop_name LIMIT 2000</script>
|
||||
TaskCenterQueryMapper selectSnapshots Select PURE <script>SELECT s.task_id AS taskId, s.module_type AS moduleType, s.total_count AS totalCount, s.success_count AS successCount, s.failed_count AS failedCount, s.pending_count AS pendingCount, s.current_scope_key AS currentScopeKey, s.message AS message FROM biz_task_progress_snapshot s WHERE s.task_id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach></script>
|
||||
TaskCenterQueryMapper selectTaskByTaskNo Select CONST SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand, t.error_message AS errorMessage FROM biz_file_task t WHERE t.task_no = #{taskNo} AND t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL') LIMIT 1
|
||||
TaskCenterQueryMapper selectTaskCountries Select CONST <script>SELECT t.id AS taskId, COALESCE(NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.filters.countryCode')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.countryCode')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.country')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.publish_country')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.countryCodes')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.country_codes')), ''), 'null'),NULLIF(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(t.request_json, '$.filters.countryCodes')), ''), 'null')) AS country FROM biz_file_task t WHERE t.id IN <foreach collection='taskIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach></script>
|
||||
TaskCenterQueryMapper selectTaskPage Select CONST <script>SELECT m.* FROM (SELECT t.id AS id, t.task_no AS taskNo, UPPER(t.module_type) AS moduleType, CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END AS status, t.user_id AS userId, t.device_id AS deviceId, t.created_at AS createdAt, t.finished_at AS finishedAt, t.updated_at AS updatedAt, t.source_file_count AS totalCount, t.success_file_count AS successCount, t.failed_file_count AS failedCount, 0 AS brand FROM biz_file_task t WHERE t.module_type IN ('PUBLISH','DELETE_BRAND','PRODUCT_RISK_RESOLVE','PRICE_TRACK','SHOP_MATCH','PATROL_DELETE','QUERY_ASIN','WITHDRAW','APPEARANCE_PATENT','SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL')<if test='userIds != null'> AND t.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND UPPER(t.module_type) = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(t.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(t.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND t.created_at >= #{startTime}</if><if test='endTime != null'> AND t.created_at <= #{endTime}</if><if test='shop != null'> AND (EXISTS (SELECT 1 FROM biz_publish_file p WHERE p.task_id = t.id AND LOWER(TRIM(p.shop_name)) = LOWER(TRIM(#{shop}))) OR (t.module_type IN ('PATROL_DELETE','PRICE_TRACK','PRODUCT_RISK_RESOLVE','QUERY_ASIN','SHOP_DATA_CRAWL','SHOP_MATCH') AND EXISTS (SELECT 1 FROM biz_file_result f WHERE f.task_id = t.id AND LOWER(TRIM(f.source_filename)) = LOWER(TRIM(#{shop})))))</if> UNION ALL SELECT b.id, CONCAT('brand-', b.id), 'BRAND', CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END, b.user_id, b.device_id, b.created_at, CASE WHEN b.status IN ('cancelled','failed','success') THEN b.updated_at END, b.updated_at, b.progress_total, b.progress_current, 0, 1 FROM brand_crawl_tasks b WHERE 1 = 1<if test='userIds != null'> AND b.user_id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></if><if test='moduleType != null'> AND 'BRAND' = #{moduleType}</if><if test='statuses != null'> AND CASE WHEN UPPER(b.status) = 'CANCELED' THEN 'CANCELLED' ELSE UPPER(b.status) END IN <foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach></if><if test='startTime != null'> AND b.created_at >= #{startTime}</if><if test='endTime != null'> AND b.created_at <= #{endTime}</if><if test='shop != null'> AND 1 = 0</if>) m ORDER BY m.createdAt DESC, m.id DESC LIMIT #{limit} OFFSET #{offset}</script>
|
||||
TaskCenterQueryMapper selectUserIdsByUsername Select PURE SELECT id FROM users WHERE username LIKE CONCAT('%', #{keyword}, '%') LIMIT 500
|
||||
TaskCenterQueryMapper selectUsernames Select PURE <script>SELECT id AS userId, username FROM users WHERE id IN <foreach collection='userIds' item='uid' open='(' separator=',' close=')'>#{uid}</foreach></script>
|
||||
TaskResultItemMapper upsertBatch Insert PURE <script>\nINSERT INTO biz_task_result_item\n (task_id, module_type, result_id, scope_key, scope_hash, item_key, asin, status,\n payload_json, payload_hash, created_at, updated_at)\nVALUES\n<foreach collection="rows" item="row" separator=",">\n (#{row.taskId}, #{row.moduleType}, #{row.resultId}, #{row.scopeKey}, #{row.scopeHash},\n #{row.itemKey}, #{row.asin}, #{row.status}, #{row.payloadJson}, #{row.payloadHash},\n #{row.createdAt}, #{row.updatedAt})\n</foreach>\nON DUPLICATE KEY UPDATE\n result_id = VALUES(result_id),\n scope_key = VALUES(scope_key),\n asin = VALUES(asin),\n status = VALUES(status),\n payload_json = VALUES(payload_json),\n payload_hash = VALUES(payload_hash),\n updated_at = VALUES(updated_at)\n</script>
|
||||
TaskScopeStateMapper selectLastChunkAtByTaskIds Select PURE <script>\nSELECT task_id AS taskId, MAX(last_chunk_at) AS lastChunkAt\nFROM biz_task_scope_state\nWHERE task_id IN\n<foreach item="taskId" collection="taskIds" open="(" separator="," close=")">#{taskId}</foreach>\nGROUP BY task_id\nHAVING MAX(last_chunk_at) IS NOT NULL\n</script>
|
||||
UserColumnPermissionMapper countByUserIdAndColumnId Select PURE SELECT COUNT(*) FROM user_column_permission WHERE user_id = #{userId} AND column_id = #{columnId}
|
||||
UserColumnPermissionMapper deleteByColumnId Delete PURE DELETE FROM user_column_permission WHERE column_id = #{columnId}
|
||||
UserColumnPermissionMapper deleteByUserId Delete PURE DELETE FROM user_column_permission WHERE user_id = #{userId}
|
||||
UserColumnPermissionMapper deleteByUserIdAndColumnIds Delete PURE <script>\nDELETE FROM user_column_permission\nWHERE user_id = #{userId}\n AND column_id IN\n <foreach collection="columnIds" item="columnId" open="(" separator="," close=")">\n #{columnId}\n </foreach>\n</script>
|
||||
UserColumnPermissionMapper insert Insert PURE INSERT INTO user_column_permission (user_id, column_id) VALUES (#{userId}, #{columnId})
|
||||
UserColumnPermissionMapper selectByColumnId Select PURE SELECT user_id, column_id FROM user_column_permission WHERE column_id = #{columnId}
|
||||
UserColumnPermissionMapper selectByUserId Select PURE SELECT user_id, column_id FROM user_column_permission WHERE user_id = #{userId}
|
||||
UserNotificationMapper deleteReadBeforeBatch Delete PURE DELETE FROM biz_user_notification\nWHERE read_at IS NOT NULL AND created_at < #{cutoff}\nLIMIT #{batchSize}
|
||||
UserNotificationMapper deleteUnreadBeforeBatch Delete PURE DELETE FROM biz_user_notification\nWHERE read_at IS NULL AND created_at < #{cutoff}\nLIMIT #{batchSize}
|
||||
UserSecretUsageMapper deleteBefore Delete PURE DELETE FROM biz_user_secret_usage_daily\nWHERE business_date < #{cutoff}\nLIMIT #{batchSize}
|
||||
UserSecretUsageMapper increment Insert PURE INSERT INTO biz_user_secret_usage_daily (user_id, module_key, business_date, call_count, created_at, updated_at)\nVALUES (#{userId}, #{moduleKey}, #{businessDate}, #{count}, NOW(), NOW())\nON DUPLICATE KEY UPDATE call_count = call_count + #{count}, updated_at = NOW()
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 222.
|
Reference in New Issue
Block a user