/**
 * 
 */
package com.huatek.busi.task.cwg;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import com.huatek.busi.common.CacMonitorTypeCode;
import com.huatek.busi.dto.CwgTemperatureStatisticsDto;
import com.huatek.busi.service.temperature.CwgTemperatureService;
import com.huatek.busi.service.temperature.TemperIncreaseRateCacheService;
import com.huatek.busi.vo.CwgTemperatureStatisticsVo;

/**
 * 温度增长率告警 定时任务
 * 
 * @author anker_cheng
 * @date 2019/10/25
 */
@Component("temperIncreaseRateTask")
public class TemperIncreaseRateTask {
    @Autowired
    private CwgTemperatureService cwgTemperatureService;
    @Autowired
    private TemperIncreaseRateCacheService temperIncreaseRateCacheService;

    /**
     * 定时任务没5分钟调用一次
     */
    public void execute() {
        // 时间参数
        LocalDateTime dTime = LocalDateTime.now();
        LocalDateTime startTime = dTime.minusMinutes(5);
        LocalDateTime endTime = startTime.minusMinutes(5);
        CwgTemperatureStatisticsDto param = new CwgTemperatureStatisticsDto();
        param.setCacMonitorTypeCode(CacMonitorTypeCode.CWG.getCode());
        param.setStartTime(startTime);
        param.setEndTime(endTime);
        // 统计列表
        List<CwgTemperatureStatisticsVo> list = cwgTemperatureService.getListEquInfo(param);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        for (CwgTemperatureStatisticsVo item : list) {
            // 保存增长率
            temperIncreaseRateCacheService.saveTemperIncreaseRateCache(item, dTime);
        }
    }
}
