Commit af252cde authored by suhuiguang's avatar suhuiguang

fix(jg) :安全追溯

1.安全追溯更新es优化按照单字段更新
parent 16efe4f3
package com.yeejoin.amos.boot.module.jg.biz.service.impl; package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -16,6 +17,7 @@ import com.google.common.collect.Maps; ...@@ -16,6 +17,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary; import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl; import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory; 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.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.jg.api.dto.SafetyProblemTracingDto; import com.yeejoin.amos.boot.module.jg.api.dto.SafetyProblemTracingDto;
...@@ -27,6 +29,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper; ...@@ -27,6 +29,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.SafetyProblemTracingMapper; import com.yeejoin.amos.boot.module.jg.api.mapper.SafetyProblemTracingMapper;
import com.yeejoin.amos.boot.module.jg.api.service.ISafetyProblemTracingService; import com.yeejoin.amos.boot.module.jg.api.service.ISafetyProblemTracingService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgRegisterInfoService; import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgRegisterInfoService;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipWaitRefreshDataQualityScore;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgInspectionDetectionInfo; import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgInspectionDetectionInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgMaintenanceRecordInfo; import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgMaintenanceRecordInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgOtherInfo; import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgOtherInfo;
...@@ -71,6 +74,9 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr ...@@ -71,6 +74,9 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
@Autowired @Autowired
CommonMapper commonMapper; CommonMapper commonMapper;
@Autowired
private EsBulkService esBulkService;
/** /**
* 分页查询 * 分页查询
*/ */
...@@ -332,16 +338,21 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr ...@@ -332,16 +338,21 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
} catch (Exception e) { } catch (Exception e) {
log.error("Other表更新失败,设备record:{},错误原因:{}", records, e.getMessage(), e); log.error("Other表更新失败,设备record:{},错误原因:{}", records, e.getMessage(), e);
} }
// 分批更新
// 更新ES状态(添加异常处理) Lists.partition(new ArrayList<>(records), 100).forEach(partition -> {
try { try {
Iterable<ESEquipmentCategoryDto> esEquipmentIter = esEquipmentCategory.findAllById(records); // es更新
esEquipmentIter.forEach(dto -> esBulkService.bulkUpdateFieldsByIds(this.buildUpdateFields(partition), TZSCommonConstant.ES_INDEX_NAME_JG_ALL);
dto.setProblemStatus(SafetyProblemStatusEnum.HANDLED.getCode()));
esEquipmentCategory.saveAll(esEquipmentIter);
log.info("ES状态更新成功,记录数:{}", records.size());
} catch (Exception e) { } catch (Exception e) {
log.error("ES状态更新失败,设备record:{},错误原因:{}", records, e.getMessage(), e); log.error("安全追溯实时更新ES状态更新失败,数据为:「{}」", partition, e);
} }
});
log.info("ES状态更新成功,记录数:{}", records.size());
}
protected Map<String, Map<String, Object>> buildUpdateFields(List<String> records) {
Map<String, Map<String, Object>> fieldMap = new HashMap<>();
records.forEach(record -> fieldMap.put(record, MapUtil.of("problemStatus", SafetyProblemStatusEnum.HANDLED.getCode())));
return fieldMap;
} }
} }
\ No newline at end of file
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