Commit 5596eda7 authored by 刘林's avatar 刘林

fix:(jg) :获取数据库与ES数据差异:找出ES比数据库多的记录ID

parent cfa77872
......@@ -2,7 +2,6 @@ package com.yeejoin.amos.boot.module.common.api.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
......@@ -13,18 +12,15 @@ public enum StatisticalAnalysisEnum {
/**
* 综合统计分析列表查询设备、企业、人员ES索引
*/
company("企业", "company", "idx_biz_enterprise_info"),
inspectionCompany("检验检测机构", "inspectionCompany", "idx_biz_enterprise_info"),
person("人员", "person", "idx_biz_user_info"),
inspectionPerson("检验检测人员", "inspectionPerson", "idx_biz_user_info"),
equip("设备", "equip", "idx_biz_equipment_info");
private String name;
private String code;
private String key;
private final String name;
private final String code;
private final String key;
private static final Map<String, StatisticalAnalysisEnum> CODE_MAP = new HashMap<>();
......
......@@ -521,7 +521,13 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController {
return ResponseHelper.buildResponse(statisticalAnalysisService.getDataDifference(code));
}
/**
* 获取es和数据库中设备数据差异V2
* @return Object
*/
@GetMapping(value = "/getDataDifferenceV2")
@ApiOperation(httpMethod = "GET", value = "获取es和数据库数据差异V2", notes = "获取es和数据库数据差异V2")
public ResponseModel<Object> getDataDifferenceV2() {
return ResponseHelper.buildResponse(statisticalAnalysisService.getDataDifferenceV2());
}
}
......@@ -18,10 +18,12 @@ import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RequestContextWrapper;
import com.yeejoin.amos.boot.module.common.api.dao.EsEquipmentDao;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.api.dto.TechParamItem;
import com.yeejoin.amos.boot.module.common.api.entity.ESEquipmentInfo;
import com.yeejoin.amos.boot.module.common.api.enums.StatisticalAnalysisEnum;
import com.yeejoin.amos.boot.module.common.api.enums.UnitTypeNewEnum;
import com.yeejoin.amos.boot.module.common.biz.service.impl.EsSearchServiceImpl;
import com.yeejoin.amos.boot.module.common.biz.service.impl.TZSCommonServiceImpl;
import com.yeejoin.amos.boot.module.common.biz.utils.TechParamUtil;
import com.yeejoin.amos.boot.module.statistcs.biz.utils.JsonUtils;
......@@ -144,7 +146,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private final TzsUserInfoMapper tzsUserInfoMapper;
private final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
private final EsSearchServiceImpl esSearchService;
@Autowired
EquipmentCategoryMapper equipmentCategoryMapper;
......@@ -4551,4 +4553,59 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
.filter(element -> !bSet.contains(element))
.collect(Collectors.toList());
}
/**
* 获取数据库与ES数据差异:找出ES比数据库多的记录ID
*/
public Object getDataDifferenceV2() {
Map<String, Object> result = new HashMap<>();
List<String> extraInEs;
// 获取索引
String index = "idx_biz_view_jg_all";
// 1. 查询数据库中所有设备 record
List<String> dbRecords = idxBizJgUseInfoMapper.selectEquipsClaimStatus();
log.info("数据库设备记录数: {}", dbRecords.size());
// 2. 从ES中查询对应记录
List<String> esRecords = getEsDataV2(index);
log.info("ES设备记录数: {}", esRecords.size());
// 3. 对比差异(ES比DB多的记录)
extraInEs = findElementsInANotInB(esRecords, dbRecords);
log.info("ES比数据库多的记录数: {}", extraInEs.size());
result.put("extraInEs", extraInEs);
return result;
}
/**
* 从 ES 中拉取索引中所有的 SEQUENCE_NBR(match_all)
*/
private List<String> getEsDataV2(String index) {
// 使用 match_all 查询,拉取所有文档(通过 scroll 分批)
log.info("ES 全量查询开始, index={}, 时间={}", index, System.currentTimeMillis());
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(QueryBuilders.termsQuery("STATUS", Collections.singletonList("已认领")));
// 线程安全的结果容器
List<String> esIds = Collections.synchronizedList(new ArrayList<>());
try {
esSearchService.searchResponseInBatch(index, boolQuery, 2000, searchHits -> {
// 每个批次只解析需要的字段
List<String> batchIds = searchHits.stream()
.map(hit -> {
ESEquipmentCategoryDto dto = JSONObject.parseObject(hit.getSourceAsString(), ESEquipmentCategoryDto.class);
return dto == null ? null : dto.getSEQUENCE_NBR();
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
esIds.addAll(batchIds);
});
} catch (Exception ex) {
log.error("ES 全量查询异常, index={}, 错误={}", index, ex.getMessage(), ex);
throw new RuntimeException("ES 查询失败: " + ex.getMessage(), ex);
}
// 去重并返回
return esIds.stream().distinct().collect(Collectors.toList());
}
}
\ No newline at end of file
......@@ -45,4 +45,6 @@ public interface IdxBizJgUseInfoMapper extends CustomBaseMapper<IdxBizJgUseInfo>
Page<String> selectPiPeRecords(Page<String> page);
JSONObject getUsePlaceAndCodeByRecord(@Param("record") String record);
List<String> selectEquipsClaimStatus();
}
......@@ -191,4 +191,10 @@
order by ibjui."RECORD" desc
</select>
<select id="selectEquipsClaimStatus" resultType="java.lang.String">
SELECT ibjui."RECORD"
FROM idx_biz_jg_use_info ibjui
JOIN idx_biz_jg_other_info joi ON ibjui."RECORD" = joi."RECORD"
WHERE joi.claim_status = '已认领'
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment