package cn.iocoder.yudao.module.mes.service.energy;
|
|
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
import jakarta.annotation.Resource;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.event.*;
|
|
@Component @Slf4j
|
public class EnergyAlertListener {
|
@Resource private EnergyAlertService energyAlertService;
|
|
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
|
public void onRecordChanged(EnergyRecordChangedEvent event) {
|
TenantUtils.execute(event.tenantId(), () -> {
|
for (var date : event.dates()) {
|
try { energyAlertService.check(date); }
|
catch (Exception e) { log.error("能耗预警检查失败 tenant={} date={}", event.tenantId(), date, e); }
|
}
|
});
|
}
|
}
|