package cn.cecep.talroad.service.strategy.support.gt;

import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.domain.MonDevReal;
import cn.cecep.talroad.enums.GtDeviceTypeEnum;
import cn.cecep.talroad.service.IMonDevRealService;
import cn.cecep.talroad.service.strategy.StatusStrategyAdapter;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Auther: cjh
 * @Date: 2023-04-27 15:34
 * @Class: GtStatusStrategyAdapter
 * @Deseription:
 * @Version V1.0
 */
@Slf4j
public abstract class GtStatusStrategyAdapter extends StatusStrategyAdapter {

    @Autowired
    private IMonDevRealService monDevRealService;

    @Override
    protected void doProcessStatus(String industry, String deviceType,Date curr) {
        //查询该行业所有设备
        log.info(industry+"设备类型"+deviceType+"时间:"+DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00",curr));
        Date lastHour = DateUtils.addMinutes(curr,-15);
        List<MonDevReal> list = null;
        // 转炉煤气不读取参数配置，取代码中固定值进行判断
        if(GtDeviceTypeEnum.ZLMQ.getCode().equals(deviceType)){
            lastHour = DateUtils.addMinutes(curr,-10);
            this.doProcessGTStatus(industry, deviceType, null,lastHour,curr);
        }else{
            if(GtDeviceTypeEnum.GLMQ.getCode().equals(deviceType)
                ||GtDeviceTypeEnum.GLMQG.getCode().equals(deviceType)){
                lastHour = DateUtils.addMinutes(curr,-10);
                list = monDevRealService.selectLatestByParam(industry, deviceType, lastHour,curr);
            }else if(GtDeviceTypeEnum.MQGW.getCode().equals(deviceType)){
                lastHour = DateUtils.addMinutes(curr,-10);
                list = monDevRealService.selectLatestMqgwByParam(industry, deviceType, lastHour,curr);
            }else {
                list = monDevRealService.selectLatestByCondition(industry, deviceType, lastHour,curr);
            }
            this.doProcessGTStatus(industry, deviceType, list,lastHour,curr);
        }
    }

    /**
     * 处理设备停限产状态、放散状态、产量计算
     * @param list
     * @return
     */
    protected abstract void doProcessGTStatus(String industry, String deviceType,List<MonDevReal> list,Date lastDate,Date curr);
}
