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

import cn.cecep.talroad.domain.MonDevReal;
import cn.cecep.talroad.domain.STaskYieldTrend;
import cn.cecep.talroad.enums.YieldTypeEnum;
import cn.cecep.talroad.vo.FactoryDeviceVo;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * @Auther: cjh
 * @Date: 2023-04-03 11:36
 * @Class: GtGlCountAdapter
 * @Deseription: 任务调度-计算高炉每小时出铁量
 * @Version V1.0
 */
@Service("GTGLGL")
public class GtGlCountAdapter extends GtYieldStrategyAdapter {

    @Override
    protected void doProcessYieldData(FactoryDeviceVo vo, List<MonDevReal> currList, List<MonDevReal> oldList,Date lastHour,boolean flag) {
        if(currList!=null&&currList.size()>0) {
            // 查询一小时内该设备的所有出铁量最大值
            Double currTotal = currList.stream().mapToDouble(m ->Double.valueOf(m.getG929())).max().getAsDouble();
            // 当前小时产量
            BigDecimal currentCount = null;
            // 前一小时数据不为空
            if(oldList!=null&&oldList.size()>0) {
                Double lastCl = oldList.stream().mapToDouble(dt -> Double.valueOf(dt.getG929()))
                    .max().getAsDouble();
                // 本次出铁量大于上次出铁量，则取本次出铁量减去上次出铁量差值，当作本小时产量
                if(currTotal>=lastCl) {
                    currentCount = new BigDecimal(currTotal).subtract(new BigDecimal(lastCl)).setScale(2, RoundingMode.HALF_UP);
                }else{
                    // 本次出铁量
                    currentCount = new BigDecimal(currTotal).setScale(2, RoundingMode.HALF_UP);
                }
            }else{
                // 本次出铁量
                currentCount = new BigDecimal(currTotal).setScale(2, RoundingMode.HALF_UP);
            }

            // 保存出铁量数据记录
            super.doSaveAnalysisFurnaceData(vo, lastHour, currentCount);
            // 保存出铁量趋势
            STaskYieldTrend trend = super.doBuildTrenData(vo.getFactoryId(),vo.getDeviceId(), YieldTypeEnum.GT_004,lastHour,currentCount,flag);
            // 保存产量
            super.doSaveYieldTrendData(trend);
        }
    }

}
