package vip.xiaonuo.coldchain.core.alarm.service.threshold;

/**
 * @author jackzhou
 * @version 1.0
 * @project jfcloud-coldchain
 * @description
 * @date 2024/11/25 17:13:50
 */

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vip.xiaonuo.coldchain.core.alarm.bean.SensorThreshold;
import vip.xiaonuo.coldchain.modular.monitortargetregion.entity.MonitorTargetRegion;
import vip.xiaonuo.coldchain.modular.monitortargetregion.service.MonitorTargetRegionService;

/**
 * 从数据库获取传感器阈值的实现类
 */
@Service
@RequiredArgsConstructor
public class SensorThresholdService implements ThresholdService {
    private final MonitorTargetRegionService monitorTargetRegionService;

    @Override
    public SensorThreshold getThresholdBySensorId(String sensorCode, Integer sensorNo) {
        MonitorTargetRegion oneByDeviceCodeAndSensorNo = monitorTargetRegionService.findOneByDeviceCodeAndSensorNo(sensorCode, sensorNo);
        if (oneByDeviceCodeAndSensorNo == null) {
            return null;
        }
        return new SensorThreshold(oneByDeviceCodeAndSensorNo);
    }
}
