Commit e6601a53 authored by tianbo's avatar tianbo

fix(jg):修复设备事件发布时的空值处理问题

- 在设备记录和装置ID列表中移除null元素,避免发布空事件 - 添加对设备使用信息和注册信息的空值校验,防止空指针异常 - 使用事务同步回调确保设备创建事件在事务提交后发送 - 对项目装置信息增加空值检查,提升系统稳定性
parent c8d91a90
...@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor; ...@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor;
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.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.*; import java.util.*;
...@@ -59,6 +60,9 @@ public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateSer ...@@ -59,6 +60,9 @@ public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateSer
MatchItemDto matchItemDto = MatchItemDto.builder().build(); MatchItemDto matchItemDto = MatchItemDto.builder().build();
IdxBizJgUseInfo useInfo = getIdxBizJgUseInfo(record); IdxBizJgUseInfo useInfo = getIdxBizJgUseInfo(record);
IdxBizJgRegisterInfo registerInfo = getIdxBizJgRegisterInfo(record); IdxBizJgRegisterInfo registerInfo = getIdxBizJgRegisterInfo(record);
if (ValidationUtil.isEmpty(useInfo) || ValidationUtil.isEmpty(registerInfo)) {
return null;
}
matchItemDto.setBizType(bizType); matchItemDto.setBizType(bizType);
matchItemDto.setEquList(registerInfo.getEquList()); matchItemDto.setEquList(registerInfo.getEquList());
matchItemDto.setEquCategory(registerInfo.getEquCategory()); matchItemDto.setEquCategory(registerInfo.getEquCategory());
......
...@@ -57,6 +57,9 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS ...@@ -57,6 +57,9 @@ public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateS
private Integer getReminderLevel(String bizType, String projectContraptionId) { private Integer getReminderLevel(String bizType, String projectContraptionId) {
IdxBizJgProjectContraption projectContraption = idxBizJgProjectContraptionService.getById(projectContraptionId); IdxBizJgProjectContraption projectContraption = idxBizJgProjectContraptionService.getById(projectContraptionId);
if (ValidationUtil.isEmpty(projectContraption)) {
return null;
}
MatchItemDto matchItemDto = MatchItemDto.builder().build(); MatchItemDto matchItemDto = MatchItemDto.builder().build();
matchItemDto.setBizType(bizType); matchItemDto.setBizType(bizType);
matchItemDto.setEquList(projectContraption.getEquList()); matchItemDto.setEquList(projectContraption.getEquList());
......
...@@ -2395,6 +2395,7 @@ public class DataHandlerServiceImpl { ...@@ -2395,6 +2395,7 @@ public class DataHandlerServiceImpl {
esEquipmentCategoryList.size(), projectContraptionIds.size(), equipRecord.size()); esEquipmentCategoryList.size(), projectContraptionIds.size(), equipRecord.size());
if (!ValidationUtil.isEmpty(equipRecord)) { if (!ValidationUtil.isEmpty(equipRecord)) {
equipRecord.remove(null);
log.info("发布设备事件,设备数量: {}", equipRecord.size()); log.info("发布设备事件,设备数量: {}", equipRecord.size());
eventPublisher.publish(new EquipCreateOrEditEvent( eventPublisher.publish(new EquipCreateOrEditEvent(
this, this,
...@@ -2405,6 +2406,7 @@ public class DataHandlerServiceImpl { ...@@ -2405,6 +2406,7 @@ public class DataHandlerServiceImpl {
} }
if (!ValidationUtil.isEmpty(projectContraptionIds)) { if (!ValidationUtil.isEmpty(projectContraptionIds)) {
projectContraptionIds.remove(null);
log.info("发布装置设备事件,设备数量: {}", projectContraptionIds.size()); log.info("发布装置设备事件,设备数量: {}", projectContraptionIds.size());
eventPublisher.publish(new EquipCreateOrEditEvent( eventPublisher.publish(new EquipCreateOrEditEvent(
this, this,
......
...@@ -84,6 +84,8 @@ import org.springframework.http.HttpStatus; ...@@ -84,6 +84,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
...@@ -4712,14 +4714,20 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -4712,14 +4714,20 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
futures.add(CompletableFuture.runAsync(() -> esEquipmentCategory.saveAll(esEquipmentCategoryList), executor)); futures.add(CompletableFuture.runAsync(() -> esEquipmentCategory.saveAll(esEquipmentCategoryList), executor));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
eventPublisher.publish( // 使用事务同步回调确保事件在事务提交后发送
new EquipCreateOrEditEvent( TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
this, @Override
BusinessTypeEnum.JG_NEW_EQUIP.name(), public void afterCommit() {
recordSet, eventPublisher.publish(
EquipCreateOrEditEvent.EquipType.equip new EquipCreateOrEditEvent(
) this,
); BusinessTypeEnum.JG_NEW_EQUIP.name(),
recordSet,
EquipCreateOrEditEvent.EquipType.equip
)
);
}
});
return String.format("导入完成,成功导入: %d 条数据!", useInfoList.size()); return String.format("导入完成,成功导入: %d 条数据!", useInfoList.size());
} }
// 定义线程池,CPU 核数 * 2,避免阻塞主线程 // 定义线程池,CPU 核数 * 2,避免阻塞主线程
......
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