|
|
@@ -10,11 +10,13 @@ import com.zsjz.ai.module.dm.mapper.FileInfoMapper;
|
|
|
import com.zsjz.ai.module.eds.duckdb.EdsImportActivityProbe;
|
|
|
import com.zsjz.ai.module.eds.enums.EdsEntityEnum;
|
|
|
import com.zsjz.ai.module.eds.enums.EdsTreeEnum;
|
|
|
-import com.zsjz.ai.module.eds.mapper.EdsImportMaterialMapper;
|
|
|
+import com.zsjz.ai.module.eds.mapper.EdsMaterialMapper;
|
|
|
import com.zsjz.ai.module.eds.mapper.EdsTreeCountMapper;
|
|
|
import com.zsjz.ai.module.eds.po.EdsEntityFieldInfo;
|
|
|
+import com.zsjz.ai.module.eds.po.EdsMaterial;
|
|
|
import com.zsjz.ai.module.eds.po.EdsTreeCount;
|
|
|
import com.zsjz.ai.module.eds.po.basic.EdsMforensics010100;
|
|
|
+import com.zsjz.ai.module.eds.po.checkmaterial.EdsMforensics160100;
|
|
|
import com.zsjz.ai.module.eds.utils.DataCountInfo;
|
|
|
import com.zsjz.ai.module.eds.utils.Eds;
|
|
|
import com.zsjz.ai.module.eds.utils.EdsConstant;
|
|
|
@@ -27,6 +29,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.sql.DataSource;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -63,7 +66,7 @@ public class EdsExtra {
|
|
|
private final XStream xStream;
|
|
|
|
|
|
private final StringRedisTemplate stringRedisTemplate;
|
|
|
- private final EdsImportMaterialMapper edsImportMaterialMapper;
|
|
|
+ private final EdsMaterialMapper edsMaterialMapper;
|
|
|
|
|
|
private final FileInfoMapper fileInfoMapper;
|
|
|
|
|
|
@@ -149,7 +152,32 @@ public class EdsExtra {
|
|
|
message.setTask(dto);
|
|
|
|
|
|
//解析数据并批量入库
|
|
|
- dataStorage(message);
|
|
|
+ EdsMaterial material = buildMaterial(baseInfo, message, ctId);
|
|
|
+ material.setFileName(dto.getFileName());
|
|
|
+ dataStorage(message, material);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装检材登记信息(数据量在 finish 阶段从 Redis 读取后回填)。
|
|
|
+ *
|
|
|
+ * @param baseInfo 010100 基础信息
|
|
|
+ * @param message 索引文件消息
|
|
|
+ * @param ctId 清洗后的采集编号
|
|
|
+ * @return 检材登记草稿
|
|
|
+ */
|
|
|
+ private EdsMaterial buildMaterial(EdsMforensics010100 baseInfo, DataMessage message, String ctId) {
|
|
|
+ EdsMaterial material = new EdsMaterial();
|
|
|
+ material.setCollectTargetId(ctId);
|
|
|
+ material.setPoliceName(baseInfo.getPrincipalName());
|
|
|
+ material.setPoliceNo(baseInfo.getPoliceNo());
|
|
|
+ material.setInchargeDepartment(baseInfo.getInchargeWaDepartment());
|
|
|
+ material.setCaseType(baseInfo.getCaseType());
|
|
|
+ //检材类型在 160100 中描述,缺失时留空
|
|
|
+ List<EdsMforensics160100> materialRows = message.readRows(EdsMforensics160100.class);
|
|
|
+ if (CollUtil.isNotEmpty(materialRows)) {
|
|
|
+ material.setMaterialType(materialRows.getFirst().getMaterialType());
|
|
|
+ }
|
|
|
+ return material;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -181,9 +209,10 @@ public class EdsExtra {
|
|
|
/**
|
|
|
* 逐表解析并入库。
|
|
|
*
|
|
|
- * @param message 索引文件消息
|
|
|
+ * @param message 索引文件消息
|
|
|
+ * @param material 检材登记草稿
|
|
|
*/
|
|
|
- private void dataStorage(DataMessage message) {
|
|
|
+ private void dataStorage(DataMessage message, EdsMaterial material) {
|
|
|
String collectTargetId = message.getCollectTargetId();
|
|
|
List<DataInfo> dataInfoList = message.tables();
|
|
|
DataCountInfo dataCountInfo = new DataCountInfo(collectTargetId);
|
|
|
@@ -195,7 +224,7 @@ public class EdsExtra {
|
|
|
EdsExtraFile dto = message.getTask();
|
|
|
if (dataInfoList.isEmpty()) {
|
|
|
//没有需要提取的数据集,也要走清理/登记,否则 Redis key 与 file_info 会残留
|
|
|
- finish(dto, dataCountInfo);
|
|
|
+ finish(dto, dataCountInfo, material);
|
|
|
return;
|
|
|
}
|
|
|
for (DataInfo dataInfo : dataInfoList) {
|
|
|
@@ -206,7 +235,7 @@ public class EdsExtra {
|
|
|
//当前数据集处理完成,剩余计数减一
|
|
|
Long remaining = stringRedisTemplate.opsForValue().decrement(remainingKey);
|
|
|
if (remaining != null && remaining <= 0) {
|
|
|
- finish(dto, dataCountInfo);
|
|
|
+ finish(dto, dataCountInfo, material);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -264,7 +293,7 @@ public class EdsExtra {
|
|
|
|
|
|
//确认采集编号未被导入
|
|
|
try {
|
|
|
- int count = edsImportMaterialMapper.countByCid(ctId);
|
|
|
+ int count = edsMaterialMapper.countByCid(ctId);
|
|
|
return count <= 0;
|
|
|
} catch (Exception e) {
|
|
|
log.error("包:{},基本信息采集编号异常或基本信息表不存在, 无法解析", ctId, e);
|
|
|
@@ -275,24 +304,83 @@ public class EdsExtra {
|
|
|
/**
|
|
|
* 提取完成后的清理与登记。
|
|
|
*
|
|
|
- * @param dto 提取任务信息
|
|
|
+ * @param dto 提取任务信息
|
|
|
+ * @param dataCountInfo 目录树统计
|
|
|
+ * @param material 检材登记草稿
|
|
|
*/
|
|
|
- public void finish(EdsExtraFile dto, DataCountInfo dataCountInfo) {
|
|
|
- Eds.delZip(dto.getExtractDir(), dto.getArchivePath());
|
|
|
+ public void finish(EdsExtraFile dto, DataCountInfo dataCountInfo, EdsMaterial material) {
|
|
|
String dataCntKey = EtlRedisKey.dataCountKey(dto.getCollectTargetId());
|
|
|
+ //入库计数必须在删除前读取:BcpTableWriter 每批 flush 成功后累计
|
|
|
+ int importedRows = readDataCount(dataCntKey);
|
|
|
String dataSetKey = EtlRedisKey.dataSetKey(dto.getCollectTargetId());
|
|
|
stringRedisTemplate.delete(List.of(dataCntKey, dataSetKey));
|
|
|
|
|
|
+ Eds.delZip(dto.getExtractDir(), dto.getArchivePath());
|
|
|
+
|
|
|
FileInfo fileInfo = new FileInfo();
|
|
|
fileInfo.setPid(0L);
|
|
|
fileInfo.setFileName(dto.getFileName());
|
|
|
fileInfo.setFileType(FILE_TYPE_DATA_PACKAGE);
|
|
|
fileInfo.setFilePath(dto.getPath().toString());
|
|
|
fileInfoMapper.insert(fileInfo);
|
|
|
+ registerMaterial(material, importedRows);
|
|
|
addDirTreeCount(dataCountInfo);
|
|
|
log.info("数据包[{}]:已提取完成。", dto.getFileName());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 读取 Redis 中累计的入库数据量。
|
|
|
+ */
|
|
|
+ private int readDataCount(String dataCntKey) {
|
|
|
+ try {
|
|
|
+ String value = stringRedisTemplate.opsForValue().get(dataCntKey);
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return (int) Math.min(Long.parseLong(value.trim()), Integer.MAX_VALUE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("读取入库数据量失败: key={}, err={}", dataCntKey, e.getMessage());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登记检材导入记录,供治理树展示(fillEds)。
|
|
|
+ *
|
|
|
+ * <p>旧案件库可能没有 {@code eds_material} 表,登记失败只记日志,不影响提取结果。</p>
|
|
|
+ */
|
|
|
+ private void registerMaterial(EdsMaterial material, int dataCount) {
|
|
|
+ if (material == null || StrUtil.isEmpty(material.getCollectTargetId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ material.setDataCount(dataCount);
|
|
|
+ material.setImportTime(LocalDateTime.now());
|
|
|
+ try {
|
|
|
+ edsMaterialMapper.insert(material);
|
|
|
+ log.info("检材登记完成: cid={}, dataCount={}", material.getCollectTargetId(), dataCount);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("检材登记失败: cid={}, err={}", material.getCollectTargetId(), e.getMessage());
|
|
|
+ retryWithoutFileName(material, dataCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 旧案件库可能还没有 {@code file_name} 列:去掉文件名重试一次,保证检材登记不丢。
|
|
|
+ */
|
|
|
+ private void retryWithoutFileName(EdsMaterial material, int dataCount) {
|
|
|
+ if (StrUtil.isEmpty(material.getFileName())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ material.setFileName(null);
|
|
|
+ try {
|
|
|
+ edsMaterialMapper.insert(material);
|
|
|
+ log.info("检材登记完成(库中无 file_name 列,未记录文件名): cid={}, dataCount={}",
|
|
|
+ material.getCollectTargetId(), dataCount);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("检材登记重试失败: cid={}, err={}", material.getCollectTargetId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 将目录树统计写入 DuckDB(数据量很小,走 MyBatis)。
|
|
|
*
|