|
|
@@ -4,10 +4,12 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.spring.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import com.zsjz.ai.common.cache.CaseDataCache;
|
|
|
+import com.zsjz.ai.common.constants.StrConsts;
|
|
|
import com.zsjz.ai.common.exception.ServerException;
|
|
|
import com.zsjz.ai.common.model.person.dto.PersonBasicInfoDTO;
|
|
|
import com.zsjz.ai.common.model.person.entity.PersonBasicInfo;
|
|
|
@@ -21,6 +23,7 @@ import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
@@ -156,10 +159,13 @@ public class PersonBasicInfoService extends ServiceImpl<PersonBasicInfoMapper, P
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 调整人员排序
|
|
|
+ * 调整人员排序(案件 DuckDB 库)。
|
|
|
*
|
|
|
- * @param list 人员基本信息列表
|
|
|
+ * <p>{@code updateBatchById} 内部走 SqlSession 批量执行,不经过 mapper 代理,
|
|
|
+ * 必须在外层先把数据源切到 slave 并开启事务,否则会落到主库 PostgreSQL。
|
|
|
*/
|
|
|
+ @DS(StrConsts.DS_KEY_SLAVE)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void personOrder(List<PersonBasicInfo> list) {
|
|
|
updateBatchById(list);
|
|
|
}
|
|
|
@@ -171,11 +177,15 @@ public class PersonBasicInfoService extends ServiceImpl<PersonBasicInfoMapper, P
|
|
|
* 多人同时清洗时会互相清掉对方缓冲、把其他案件的人员冲进当前案件库。
|
|
|
* 现在由调用方 {@code CleanCache.drain()} 按 caseId 原子取走快照后传入。
|
|
|
*/
|
|
|
+ @DS(StrConsts.DS_KEY_SLAVE)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void flushPerson(Set<PersonBasicInfo> persons) {
|
|
|
if (CollUtil.isEmpty(persons)) {
|
|
|
return;
|
|
|
}
|
|
|
try {
|
|
|
+ // saveOrUpdateBatch 是 self-invocation,父类的 @Transactional 不会生效;
|
|
|
+ // 由本方法的事务 + 外层 @DS 保证整批写入案件库
|
|
|
saveOrUpdateBatch(persons);
|
|
|
} catch (Exception e) {
|
|
|
log.error("flushPerson error", e);
|