Commit 08926bca authored by suhuiguang's avatar suhuiguang

fix(jg) :数据质量等级计算

1.装置导入时计算慢问题处理优化
parent f3eb5eb0
......@@ -3,9 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
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.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.biz.constats.Constants;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.jg.api.dto.ReminderItemDto;
......@@ -17,7 +17,9 @@ import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.DefaultQu
import com.yeejoin.amos.boot.module.jg.biz.reminder.dto.MatchItemDto;
import com.yeejoin.amos.boot.module.jg.biz.reminder.service.CommonReminderService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgUseInfoService;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.EsBulkService;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgProjectContraptionServiceImplService;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipWaitRefreshDataQualityScore;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo;
import lombok.RequiredArgsConstructor;
......@@ -50,7 +52,7 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS
@Value("${grade.calculation.strategy:MAX_GRADE}")
private String activeStrategy;
private final ESEquipmentCategory equipmentCategoryDao;
private final EsBulkService esBulkService;
@Override
public Boolean support(EquipCreateOrEditEvent.EquipType equipType) {
......@@ -115,13 +117,18 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS
updateWrapper2.eq(IdxBizJgUseInfo::getProjectContraptionId, projectContraptionId);
updateWrapper2.set(IdxBizJgUseInfo::getDataQualityScore, level);
idxBizJgUseInfoService.update(updateWrapper2);
List<ESEquipmentCategoryDto> projectEquips = equipmentCategoryDao.findAllByProjectContraptionId(projectContraptionId);
if (!ValidationUtil.isEmpty(projectEquips)) {
for (ESEquipmentCategoryDto esEquipmentCategoryDto : projectEquips) {
esEquipmentCategoryDto.setDataQualityScore(level);
List<String> records = idxBizJgUseInfoService.list(new LambdaQueryWrapper<IdxBizJgUseInfo>().eq(IdxBizJgUseInfo::getProjectContraptionId, projectContraptionId).select(IdxBizJgUseInfo::getRecord)).stream().map(IdxBizJgUseInfo::getRecord).collect(Collectors.toList());
if (!ValidationUtil.isEmpty(records)) {
// 分批更新
List<EquipWaitRefreshDataQualityScore> dataQualityScores = this.buildDataQualityScores(records, level);
Lists.partition(dataQualityScores, 200).forEach(partitionData -> {
try {
// es更新
esBulkService.bulkUpdateFieldsByIds(this.buildUpdateFields(partitionData), TZSCommonConstant.ES_INDEX_NAME_JG_ALL);
} catch (Exception e) {
log.error("装置分批更新数据质量等级失败,数据为:「{}」", partitionData, e);
}
equipmentCategoryDao.saveAll(projectEquips);
});
}
} catch (Exception e) {
log.error("装置更新数据质量等级失败,装置 id为:「{}」", projectContraptionId, e);
......@@ -129,6 +136,10 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS
});
}
private List<EquipWaitRefreshDataQualityScore> buildDataQualityScores(List<String> records, Integer level) {
return records.stream().map(record -> new EquipWaitRefreshDataQualityScore(record, level)).collect(Collectors.toList());
}
@Override
protected void afterHandle(Set<String> projectContraptionIds) {
this.sendDataRefreshMsg(projectContraptionIds);
......
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