task-50: 结果明细批量 upsert 写入器与唯一键幂等
CollectDataResultItemBatchWriter 按唯一键 uk_task_scope_item 批量 upsert biz_task_result_item:一次批量查询现有行(payload_hash 相等即跳过), 分批发 INSERT ... ON DUPLICATE KEY UPDATE,替代逐行 select/insert/update; 旧格式逐行 payload 升级为引用时物理删除(引用计数兜底)。CollectDataService submitResult 接入批量写入,移除逐行 upsertResultItem。
This commit is contained in:
+31
@@ -2,8 +2,39 @@ 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user