Commit 520238cc authored by suhuiguang's avatar suhuiguang

feat(jg): 西安数据核对

1.核对数据同步接口初稿
parent 9c929954
......@@ -219,4 +219,10 @@ public class ESEquipmentCategoryDto {
*/
@Field(type = FieldType.Keyword)
private String whetherSphericalTank;
/**
* 版本号
*/
@Field(type = FieldType.Keyword)
private String version;
}
......@@ -421,4 +421,25 @@ public class DataHandlerController extends BaseController {
dataHandlerService.addDbData2EsBatch(paramMap);
return ResponseHelper.buildResponse(true);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/orgBranchCode2Db")
@ApiOperation(httpMethod = "PUT", value = "属地监管部门以es老索引为准刷数据库", notes = "属地监管部门以es为准刷数据库")
public ResponseModel<Long> orgBranchCode2Db(@ApiParam(value = "设备种类code") @RequestParam String equListCode,
@ApiParam(value = "设备类别code") @RequestParam(required = false) String equCategoryCode,
@ApiParam(value = "属地code") @RequestParam String orgBranchCode ,
@ApiParam(value = "序列号,不能重复") @RequestParam Integer seq) {
return ResponseHelper.buildResponse(dataHandlerService.orgBranchCode2Db(equListCode, equCategoryCode, orgBranchCode, seq));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/synEquipFromDb2Es")
@ApiOperation(httpMethod = "PUT", value = "同步设备数据到es新旧索引", notes = "同步设备数据到es新旧索引")
public ResponseModel<Integer> synEquipFromDb2Es(@ApiParam(value = "设备种类code") @RequestParam String equListCode,
@ApiParam(value = "设备类别code") @RequestParam(required = false) String equCategoryCode,
@ApiParam(value = "属地code") @RequestParam String orgBranchCode) {
return ResponseHelper.buildResponse(dataHandlerService.synEquipFromDb2Es(equListCode, equCategoryCode, orgBranchCode));
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.util.StopWatch;
import java.util.List;
import java.util.Map;
@Slf4j
public abstract class BatchDataPatcher implements HistoricalDataPatcher {
......@@ -17,7 +18,7 @@ public abstract class BatchDataPatcher implements HistoricalDataPatcher {
}
@Override
public Integer patchBatchData() {
public Integer patchBatchData(Map<String, Object> params) {
StopWatch watch = new StopWatch();
watch.start();
IdxBizJgUseInfoServiceImpl useInfoService = applicationContext.getBean(IdxBizJgUseInfoServiceImpl.class);
......
package com.yeejoin.amos.boot.module.jg.biz.data.fix.patcher;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgUseInfoServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.util.StopWatch;
import java.util.List;
import java.util.Map;
@Slf4j
public abstract class BatchDataPatcherWithFilter implements HistoricalDataPatcher {
private final ApplicationContext applicationContext;
protected BatchDataPatcherWithFilter(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Override
public Integer patchBatchData(Map<String, Object> params) {
StopWatch watch = new StopWatch();
watch.start();
IdxBizJgUseInfoServiceImpl useInfoService = applicationContext.getBean(IdxBizJgUseInfoServiceImpl.class);
Integer maxVersion = useInfoService.getBaseMapper().selectMaxVersionWithParams(buildFilter(params));
Integer nextVersion = maxVersion + 1;
List<String> refreshRecords = useInfoService.getBaseMapper().selectUseInfoOfOneVersionWithParams(nextVersion,buildFilter(params));
while (!refreshRecords.isEmpty()) {
refreshRecords.parallelStream().forEach(record -> {
try {
beforePatching(record);
patchSingleRecord(record);
afterPatching(record);
} catch (Exception e) {
// 异常数据跳过
log.error("数据修补失败,设备:{}", record, e);
}
});
useInfoService.getBaseMapper().updateVersionBatch(refreshRecords, nextVersion);
refreshRecords = useInfoService.getBaseMapper().selectUseInfoOfOneVersionAll(nextVersion);
}
watch.stop();
log.info("数据修补完成,共处理{}条记录,耗时: {}秒", refreshRecords, watch.getTotalTimeSeconds());
return null;
}
protected abstract Map<String, Object> buildFilter(Map<String, Object> params);
protected abstract void beforePatching(String record);
protected abstract void patchSingleRecord(String record);
protected abstract void afterPatching(String record);
}
package com.yeejoin.amos.boot.module.jg.biz.data.fix.patcher;
import java.util.Map;
public interface HistoricalDataPatcher {
/**
* 执行批量修补
* @return 处理成功的记录数,如果不可计算则返回null
*/
Integer patchBatchData();
Integer patchBatchData(Map<String, Object> params);
}
package com.yeejoin.amos.boot.module.jg.biz.data.fix.service;
import cn.hutool.core.bean.BeanUtil;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.api.entity.TzsDataRefreshMessage;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.jg.biz.data.fix.patcher.BatchDataPatcherWithFilter;
import com.yeejoin.amos.boot.module.jg.biz.refresh.StatisticsDataUpdateService;
import com.yeejoin.amos.boot.module.jg.biz.refresh.handler.EquipmentRefreshHandler;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgUseInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Optional;
@Component
@Slf4j
public class EquipInsert2EsPatcher extends BatchDataPatcherWithFilter {
private final ESEquipmentCategory equipmentCategory;
private final EquipmentRefreshHandler refreshHandler;
private final IdxBizJgUseInfoMapper idxBizJgUseInfoMapper;
protected EquipInsert2EsPatcher(ApplicationContext applicationContext, ESEquipmentCategory equipmentCategory, EquipmentRefreshHandler refreshHandler, IdxBizJgUseInfoMapper idxBizJgUseInfoMapper) {
super(applicationContext);
this.equipmentCategory = equipmentCategory;
this.refreshHandler = refreshHandler;
this.idxBizJgUseInfoMapper = idxBizJgUseInfoMapper;
}
@Override
protected Map<String, Object> buildFilter(Map<String, Object> params) {
return params;
}
@Override
protected void beforePatching(String record) {
}
@Override
protected void patchSingleRecord(String record) {
Optional<ESEquipmentCategoryDto> op = equipmentCategory.findById(record);
// 插入旧索引
if (!op.isPresent()) {
try {
Map<String, Object> detail = idxBizJgUseInfoMapper.queryDetail(record);
ESEquipmentCategoryDto esEquipmentInfo = new ESEquipmentCategoryDto();
StatisticsDataUpdateService.formatUseDate(detail);
BeanUtil.copyProperties(detail, esEquipmentInfo, true);
equipmentCategory.save(esEquipmentInfo);
} catch (Exception e) {
log.error("老设备索引插入处理失败:{}", record, e);
}
}
// 插入或者新索引
try {
refreshHandler.doRefresh(new TzsDataRefreshMessage().setDataId(record).setOperation(DataRefreshEvent.Operation.INSERT.name()));
} catch (Exception e) {
log.error("新设备索引插入处理失败:{}", record, e);
}
}
@Override
protected void afterPatching(String record) {
}
}
......@@ -457,7 +457,11 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
* @return null or 非空的字符串
*/
private String nullIfNullOrEmpty(String str) {
return CompareUtils.isNullOrEmpty(str) ? null : str;
return CompareUtils.isNullOrEmpty(str) ? null : trimNoIllegalChar(str);
}
private String trimNoIllegalChar(String str) {
return "\\".equals(str) || "/".equals(str) ? null : str;
}
private String getTableName(String paramType) {
......
......@@ -29,6 +29,8 @@ public interface IdxBizJgUseInfoMapper extends CustomBaseMapper<IdxBizJgUseInfo>
Integer selectMaxVersion();
Integer selectMaxVersionWithParams(@Param("params") Map<String, Object> params);
void updateDataQualityScoreBatch(@Param("equips") List<EquipWaitRefreshDataQualityScore> refreshDataQualityScores, @Param("version") int version);
void updateVersionBatch(@Param("records") List<String> records, @Param("version") int version);
......@@ -52,4 +54,6 @@ public interface IdxBizJgUseInfoMapper extends CustomBaseMapper<IdxBizJgUseInfo>
List<IdxBizJgOtherInfo> selectOneMockRecord(@Param("equList") String equList, @Param("equCategory") String equCategory, @Param("equDefine") String equDefine, @Param("useUnitCode") String useUnitCode, @Param("size") Integer size);
List<String> selectEquipsClaimStatus();
List<String> selectUseInfoOfOneVersionWithParams(@Param("nextVersion") Integer nextVersion,@Param("params") Map<String, Object> params);
}
......@@ -59,11 +59,53 @@
ui.VERSION <![CDATA[ <> ]]> #{version} or ui.VERSION is null
limit 10000
</select>
<select id="selectUseInfoOfOneVersionWithParams" resultType="java.lang.String">
SELECT
u.record
from
"idx_biz_jg_use_info" u
"idx_biz_jg_supervision_info" s,
idx_biz_jg_register_info r
where
u.VERSION <![CDATA[ <> ]]> #{version} or u.VERSION is null
and u."RECORD" = r."RECORD"
and s."RECORD" = r."RECORD"
<if test="params.equListCode != null and params.equListCode != ''">
and r."EQU_LIST" = '3000'
</if>
<if test="params.equCategoryCode != null and params.equCategoryCode != ''">
and r."EQU_CATEGORY" = #{params.equListCode}
</if>
<if test="params.orgBranchCode != null and params.orgBranchCode != ''">
and s."ORG_BRANCH_CODE" like concat(#{params.orgBranchCode},'%')
</if>
limit 10000
</select>
<select id="selectMaxVersion" resultType="java.lang.Integer">
SELECT
COALESCE(MAX(version),0) as version
FROM "idx_biz_jg_use_info"
</select>
<select id="selectMaxVersionWithParams" resultType="java.lang.Integer">
SELECT
COALESCE(MAX(version),0) as version
FROM
"idx_biz_jg_use_info" u
"idx_biz_jg_supervision_info" s,
idx_biz_jg_register_info r
where
u."RECORD" = r."RECORD"
and s."RECORD" = r."RECORD"
<if test="params.equListCode != null and params.equListCode != ''">
and r."EQU_LIST" = '3000'
</if>
<if test="params.equCategoryCode != null and params.equCategoryCode != ''">
and r."EQU_CATEGORY" = #{params.equListCode}
</if>
<if test="params.orgBranchCode != null and params.orgBranchCode != ''">
and s."ORG_BRANCH_CODE" like concat(#{params.orgBranchCode},'%')
</if>
</select>
<select id="queryDetail" resultType="java.util.Map">
<include refid="equip-detail-es"/>
WHERE
......
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