云
2 天以前 657698fd2fb32794932474648dbaee9e284e38c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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); }
            }
        });
    }
}