Commit f3eb5eb0 authored by suhuiguang's avatar suhuiguang

Merge branch 'develop_tzs_register' into develop_tzs_main

parents af7b57bd 1f8a90fd
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.common.biz.service.impl; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.common.biz.service.impl;
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 lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
...@@ -11,9 +12,6 @@ import org.elasticsearch.index.query.QueryBuilders; ...@@ -11,9 +12,6 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
...@@ -25,6 +23,7 @@ import static com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant ...@@ -25,6 +23,7 @@ import static com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class EquipmentCategoryService { public class EquipmentCategoryService {
private final ESEquipmentCategory equipmentCategoryDao; private final ESEquipmentCategory equipmentCategoryDao;
...@@ -55,4 +54,5 @@ public class EquipmentCategoryService { ...@@ -55,4 +54,5 @@ public class EquipmentCategoryService {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
} }
\ No newline at end of file
...@@ -11,18 +11,32 @@ import com.baomidou.mybatisplus.core.toolkit.Assert; ...@@ -11,18 +11,32 @@ import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.yeejoin.amos.boot.biz.common.entity.TzsBaseEntity; import com.yeejoin.amos.boot.biz.common.entity.TzsBaseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.Supplier;
import static com.yeejoin.amos.boot.module.jg.biz.edit.utils.ReflectiveFieldAccessor.getAllFields; import static com.yeejoin.amos.boot.module.jg.biz.edit.utils.ReflectiveFieldAccessor.getAllFields;
public class BaseService<M extends BaseMapper<T>, T extends TzsBaseEntity> extends ServiceImpl<M, T> { public class BaseService<M extends BaseMapper<T>, T extends TzsBaseEntity> extends ServiceImpl<M, T> {
private static final String COLUMN_NAME_REC_DATE = "\"REC_DATE\"";
private static final String COLUMN_NAME_REC_USER_ID = "\"REC_USER_ID\"";
private static final ImmutableSet<String> AUTO_FILL_FIELDS = ImmutableSet.of(COLUMN_NAME_REC_DATE, COLUMN_NAME_REC_USER_ID);
private static final ImmutableMap<String, Supplier<Object>> FIELD_PROCESSORS = ImmutableMap.<String, Supplier<Object>>builder().
put(COLUMN_NAME_REC_DATE, Date::new).
put(COLUMN_NAME_REC_USER_ID, RequestContext::getExeUserId).build();
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean saveOrUpdateWithNull(T entity) { public boolean saveOrUpdateWithNull(T entity) {
...@@ -48,7 +62,7 @@ public class BaseService<M extends BaseMapper<T>, T extends TzsBaseEntity> exten ...@@ -48,7 +62,7 @@ public class BaseService<M extends BaseMapper<T>, T extends TzsBaseEntity> exten
// 动态设置非空字段到 SET 语句 // 动态设置非空字段到 SET 语句
allFields.stream().filter(field -> field.getAnnotation(TableField.class) != null && field.getAnnotation(TableField.class).exist()).forEach(field -> { allFields.stream().filter(field -> field.getAnnotation(TableField.class) != null && field.getAnnotation(TableField.class).exist()).forEach(field -> {
String columnName = getColumnName(field); // 获取字段名(处理 @TableField 注解) String columnName = getColumnName(field); // 获取字段名(处理 @TableField 注解)
wrapper.set(columnName, getFieldValue(field, entity)); wrapper.set(columnName, getFieldValue(columnName, field, entity));
}); });
// 设置主键条件(确保主键在父类也能获取) // 设置主键条件(确保主键在父类也能获取)
String idColumn = getColumnName(getIdField(entity.getClass())); // 获取主键字段名 String idColumn = getColumnName(getIdField(entity.getClass())); // 获取主键字段名
...@@ -82,12 +96,21 @@ public class BaseService<M extends BaseMapper<T>, T extends TzsBaseEntity> exten ...@@ -82,12 +96,21 @@ public class BaseService<M extends BaseMapper<T>, T extends TzsBaseEntity> exten
} }
// 安全获取字段值 // 安全获取字段值
private Object getFieldValue(Field field, Object obj) { private Object getFieldValue(String columnName, Field field, Object obj) {
try { try {
field.setAccessible(true); field.setAccessible(true);
return field.get(obj); Object value = field.get(obj);
// 特殊字段自动填充处理
String upperColumnName = columnName.toUpperCase();
if (value == null && AUTO_FILL_FIELDS.contains(upperColumnName)) {
Supplier<Object> processor = FIELD_PROCESSORS.get(upperColumnName);
if (processor != null) {
value = processor.get();
}
}
return value;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException("获取字段值失败", e); throw new RuntimeException(String.format("获取字段[%s]值失败", field.getName()), e);
} }
} }
......
package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service; package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service;
import cn.hutool.core.map.MapUtil;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipWaitRefreshDataQualityScore;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
public abstract class DefaultQualityScoreUpdateService implements IQualityScoreUpdate { public abstract class DefaultQualityScoreUpdateService implements IQualityScoreUpdate {
...@@ -7,12 +13,16 @@ public abstract class DefaultQualityScoreUpdateService implements IQualityScoreU ...@@ -7,12 +13,16 @@ public abstract class DefaultQualityScoreUpdateService implements IQualityScoreU
/** /**
* 前置处理-定义目前支持的业务类型,由于目前仅实现使用登记、新增设备、新增装置、大编辑设备、大编辑装置、安装告知准则, * 前置处理-定义目前支持的业务类型,由于目前仅实现使用登记、新增设备、新增装置、大编辑设备、大编辑装置、安装告知准则,
* 所有都实现后返回true即可 * 所有都实现后返回true即可
*
* @param bizType 业务类型 * @param bizType 业务类型
* @return 是否通过前置检验 * @return 是否通过前置检验
*/ */
protected abstract Boolean shouldProcess(String bizType); protected abstract Boolean shouldProcess(String bizType);
public void doUpdate(String bizType, Set<String> recordOrPIds) { public void doUpdate(String bizType, Set<String> recordOrPIds) {
if (recordOrPIds.isEmpty()) {
return;
}
if (shouldProcess(bizType)) { if (shouldProcess(bizType)) {
doHandle(bizType, recordOrPIds); doHandle(bizType, recordOrPIds);
} }
...@@ -21,6 +31,7 @@ public abstract class DefaultQualityScoreUpdateService implements IQualityScoreU ...@@ -21,6 +31,7 @@ public abstract class DefaultQualityScoreUpdateService implements IQualityScoreU
/** /**
* 执行 * 执行
*
* @param bizType 业务类型 * @param bizType 业务类型
* @param recordOrPIds 装置或者设备id集合 * @param recordOrPIds 装置或者设备id集合
*/ */
...@@ -28,7 +39,17 @@ public abstract class DefaultQualityScoreUpdateService implements IQualityScoreU ...@@ -28,7 +39,17 @@ public abstract class DefaultQualityScoreUpdateService implements IQualityScoreU
/** /**
* 事后处理 * 事后处理
*
* @param recordOrPIds 装置或者设备id集合 * @param recordOrPIds 装置或者设备id集合
*/ */
protected abstract void afterHandle(Set<String> recordOrPIds); protected abstract void afterHandle(Set<String> recordOrPIds);
protected Map<String, Map<String, Object>> buildUpdateFields(List<EquipWaitRefreshDataQualityScore> dataQualityScores) {
Map<String, Map<String, Object>> fieldMap = new HashMap<>();
dataQualityScores.forEach(dataQualityScore -> {
fieldMap.put(dataQualityScore.getRecord(), MapUtil.of("DATA_QUALITY_SCORE", dataQualityScore.getDataQualityScore()));
});
return fieldMap;
}
} }
package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.impl; package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.impl;
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.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.entity.TzsBaseEntity; import com.yeejoin.amos.boot.biz.common.entity.TzsBaseEntity;
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.common.biz.service.impl.EquipmentCategoryService;
import com.yeejoin.amos.boot.module.jg.api.dto.ReminderItemDto; import com.yeejoin.amos.boot.module.jg.api.dto.ReminderItemDto;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum; import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher; import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
...@@ -16,25 +14,32 @@ import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEdit ...@@ -16,25 +14,32 @@ import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEdit
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.DefaultQualityScoreUpdateService; import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.DefaultQualityScoreUpdateService;
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.impl.EsBulkService;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgRegisterInfoServiceImpl; import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgRegisterInfoServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgUseInfoServiceImpl; import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgUseInfoServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipWaitRefreshDataQualityScore;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgRegisterInfo; import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgRegisterInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo; import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum; import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateService { public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateService {
private final ESEquipmentCategory equipmentCategoryDao;
private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService; private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService;
private final IdxBizJgRegisterInfoServiceImpl idxBizJgRegisterInfoService; private final IdxBizJgRegisterInfoServiceImpl idxBizJgRegisterInfoService;
...@@ -46,7 +51,7 @@ public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateSer ...@@ -46,7 +51,7 @@ public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateSer
private final GradeStrategyFactory gradeStrategyFactory; private final GradeStrategyFactory gradeStrategyFactory;
private final EquipmentCategoryService equipmentCategoryService; private final EsBulkService esBulkService;
private final EventPublisher eventPublisher; private final EventPublisher eventPublisher;
...@@ -113,28 +118,45 @@ public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateSer ...@@ -113,28 +118,45 @@ public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateSer
@Override @Override
protected void doHandle(String bizType, Set<String> recordOrPIds) { protected void doHandle(String bizType, Set<String> recordOrPIds) {
recordOrPIds.forEach(record -> { if (recordOrPIds.isEmpty()) {
Optional<ESEquipmentCategoryDto> op = equipmentCategoryDao.findById(record);
// 压力管道不进行管道登记的计算
if (op.isPresent() && op.get().getEQU_LIST_CODE().equals(EquipmentClassifityEnum.YLGD.getCode())) {
return; return;
} }
Integer level = this.getReminderLevel(bizType, record); StopWatch watch = new StopWatch();
op.ifPresent(equipmentCategory -> { watch.start();
equipmentCategory.setDataQualityScore(level); List<IdxBizJgRegisterInfo> idxBizJgRegisterInfos = idxBizJgRegisterInfoService.list(new LambdaQueryWrapper<IdxBizJgRegisterInfo>().in(IdxBizJgRegisterInfo::getRecord, recordOrPIds).select(IdxBizJgRegisterInfo::getRecord, IdxBizJgRegisterInfo::getEquList));
equipmentCategoryService.saveWithImmediateRefresh(equipmentCategory); List<EquipWaitRefreshDataQualityScore> dataQualityScores = idxBizJgRegisterInfos.parallelStream().filter(r -> !EquipmentClassifityEnum.YLGD.getCode().equals(r.getEquList())).map(registerInfo -> {
}); EquipWaitRefreshDataQualityScore dataQualityScore = new EquipWaitRefreshDataQualityScore();
LambdaUpdateWrapper<IdxBizJgUseInfo> updateWrapper = new LambdaUpdateWrapper<>(); dataQualityScore.setRecord(registerInfo.getRecord());
updateWrapper.eq(IdxBizJgUseInfo::getRecord, record); try {
updateWrapper.set(IdxBizJgUseInfo::getDataQualityScore, level); Integer level = this.getReminderLevel(bizType, registerInfo.getRecord());
updateWrapper.set(TzsBaseEntity::getRecDate, new Date()); dataQualityScore.setDataQualityScore(level);
idxBizJgUseInfoService.update(updateWrapper); } catch (Exception e) {
log.error("设备:「{}」,计算数据质量登记失败。", registerInfo.getRecord(), e);
dataQualityScore.setDataQualityScore(null);
}
return dataQualityScore;
}).collect(Collectors.toList());
if (!dataQualityScores.isEmpty()) {
// 分批数据库更新
Lists.partition(dataQualityScores, 200).forEach(partitionData -> {
try {
idxBizJgUseInfoService.getBaseMapper().updateDataQualityScoreBatch(partitionData, null);
// es更新
esBulkService.bulkUpdateFieldsByIds(this.buildUpdateFields(partitionData), TZSCommonConstant.ES_INDEX_NAME_JG_ALL);
} catch (Exception e) {
log.error("更新数据质量等级失败,数据为:「{}」", partitionData, e);
}
}); });
} }
watch.stop();
log.info("计算数据质量等级数量:「{}」,耗时:「{}」", dataQualityScores.size(), watch.getTotalTimeSeconds());
}
@Override @Override
protected void afterHandle(Set<String> recordOrPIds) { protected void afterHandle(Set<String> recordOrPIds) {
// 事务提交后发送数据变更消息 // 事务提交后发送数据变更消息
this.sendDataRefreshMsgEquip(new ArrayList<>(recordOrPIds)); this.sendDataRefreshMsgEquip(new ArrayList<>(recordOrPIds));
} }
} }
...@@ -21,6 +21,7 @@ import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgProjectContrapti ...@@ -21,6 +21,7 @@ import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgProjectContrapti
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;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -34,6 +35,7 @@ import java.util.stream.Collectors; ...@@ -34,6 +35,7 @@ import java.util.stream.Collectors;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateService { public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateService {
...@@ -101,6 +103,7 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS ...@@ -101,6 +103,7 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS
@Override @Override
protected void doHandle(String bizType, Set<String> projectContraptionIds) { protected void doHandle(String bizType, Set<String> projectContraptionIds) {
projectContraptionIds.forEach(projectContraptionId -> { projectContraptionIds.forEach(projectContraptionId -> {
try {
Integer level = this.getReminderLevel(bizType, projectContraptionId); Integer level = this.getReminderLevel(bizType, projectContraptionId);
LambdaUpdateWrapper<IdxBizJgProjectContraption> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<IdxBizJgProjectContraption> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgProjectContraption::getSequenceNbr, projectContraptionId); updateWrapper.eq(IdxBizJgProjectContraption::getSequenceNbr, projectContraptionId);
...@@ -120,6 +123,9 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS ...@@ -120,6 +123,9 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS
} }
equipmentCategoryDao.saveAll(projectEquips); equipmentCategoryDao.saveAll(projectEquips);
} }
} catch (Exception e) {
log.error("装置更新数据质量等级失败,装置 id为:「{}」", projectContraptionId, e);
}
}); });
} }
......
...@@ -3,13 +3,18 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl; ...@@ -3,13 +3,18 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.common.api.entity.EsEntity; import com.yeejoin.amos.boot.module.common.api.entity.EsEntity;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -39,4 +44,34 @@ public class EsBulkService { ...@@ -39,4 +44,34 @@ public class EsBulkService {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
/**
* 批量更新指定索引中的文档字段
*
* @param documentIdFieldsMap key: 要更新的文档ID列表 ,value: 需要更新的字段映射(字段名 → 新值)
* @param targetIndex 目标索引名称
* @throws RuntimeException 当ES操作失败时抛出
*/
public void bulkUpdateFieldsByIds(Map<String, Map<String, Object>> documentIdFieldsMap, String targetIndex) {
try {
BulkRequest bulkRequest = new BulkRequest();
documentIdFieldsMap.forEach((documentId, fieldsToUpdate) -> {
// 构建批量请求
UpdateRequest updateRequest = new UpdateRequest(targetIndex, documentId).doc(fieldsToUpdate, XContentType.JSON);
bulkRequest.add(updateRequest);
});
BulkResponse response = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
// 更详细的错误日志记录
if (response.hasFailures()) {
Arrays.stream(response.getItems())
.filter(BulkItemResponse::isFailed)
.forEach(item -> log.error("Failed to update {}: {}",
item.getId(),
item.getFailureMessage()));
}
} catch (IOException e) {
log.error("批量更新指定索引中的文档字段: batchSize={}, index={}", documentIdFieldsMap.size(), targetIndex, e);
}
}
} }
...@@ -3769,7 +3769,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -3769,7 +3769,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
// 使用信息 // 使用信息
useInfo.setRecord(record); useInfo.setRecord(record);
useInfo.setRecDate(date);
useInfo.setDataSource(dataSource); useInfo.setDataSource(dataSource);
useInfo.setIsIntoManagement(Boolean.FALSE); useInfo.setIsIntoManagement(Boolean.FALSE);
useInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("USEINFO_SEQ"))); useInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("USEINFO_SEQ")));
......
...@@ -70,6 +70,7 @@ public class PersonIdentifyTzsAspect { ...@@ -70,6 +70,7 @@ public class PersonIdentifyTzsAspect {
//电力默认走公司权限 //电力默认走公司权限
// if (!logic) { // if (!logic) {
personIdentity.setBizOrgCode(StringUtils.isEmpty(reginParam.getCompany().getOrgCode()) ? "-1" : reginParam.getCompany().getOrgCode()); personIdentity.setBizOrgCode(StringUtils.isEmpty(reginParam.getCompany().getOrgCode()) ? "-1" : reginParam.getCompany().getOrgCode());
personIdentity.setCompanyBizOrgCode(StringUtils.isEmpty(reginParam.getCompany().getOrgCode()) ? "-1" : reginParam.getCompany().getOrgCode());
// } // }
reginParam.setPersonIdentity(personIdentity); reginParam.setPersonIdentity(personIdentity);
......
...@@ -2,9 +2,11 @@ package com.yeejoin.amos.boot.module.ymt.api.dto; ...@@ -2,9 +2,11 @@ package com.yeejoin.amos.boot.module.ymt.api.dto;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor
public class EquipWaitRefreshDataQualityScore { public class EquipWaitRefreshDataQualityScore {
private String record; private String record;
......
...@@ -31,7 +31,7 @@ public interface IdxBizJgUseInfoMapper extends CustomBaseMapper<IdxBizJgUseInfo> ...@@ -31,7 +31,7 @@ public interface IdxBizJgUseInfoMapper extends CustomBaseMapper<IdxBizJgUseInfo>
Integer selectMaxVersionWithParams(@Param("params") Map<String, Object> params); Integer selectMaxVersionWithParams(@Param("params") Map<String, Object> params);
void updateDataQualityScoreBatch(@Param("equips") List<EquipWaitRefreshDataQualityScore> refreshDataQualityScores, @Param("version") int version); void updateDataQualityScoreBatch(@Param("equips") List<EquipWaitRefreshDataQualityScore> refreshDataQualityScores, @Param("version") Integer version);
void updateVersionBatch(@Param("records") List<String> records, @Param("version") int version); void updateVersionBatch(@Param("records") List<String> records, @Param("version") int version);
......
...@@ -9,10 +9,21 @@ ...@@ -9,10 +9,21 @@
</foreach> </foreach>
</update> </update>
<update id="updateDataQualityScoreBatch"> <update id="updateDataQualityScoreBatch">
<foreach collection="equips" separator=";" item="equip" open="" close=""> UPDATE idx_biz_jg_use_info SET
UPDATE idx_biz_jg_use_info SET "DATA_QUALITY_SCORE" = #{equip.dataQualityScore} , "VERSION"=#{version} WHERE record = #{equip.record} "DATA_QUALITY_SCORE" = tmp."DATA_QUALITY_SCORE"
<if test="version != null and version !=''">
, "VERSION"=#{version}
</if>
FROM (
<foreach collection="equips" item="equip" separator="UNION ALL">
SELECT
#{equip.record} AS record,
#{equip.dataQualityScore} AS "DATA_QUALITY_SCORE"
</foreach> </foreach>
) AS tmp
WHERE idx_biz_jg_use_info.record = tmp.record
</update> </update>
<select id="selectXAList" resultType="com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo"> <select id="selectXAList" resultType="com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo">
select select
u."SEQUENCE_NBR", u."SEQUENCE_NBR",
......
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