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