Commit e6601a53 authored by tianbo's avatar tianbo

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

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