package com.gyee.alarm.service.realtimelibrary;/*
@author   谢生杰
@date   2022/11/6-12:07
*/

import com.gyee.alarm.init.CacheContext;
import com.gyee.alarm.model.auto.ProEconWtPowerCurveFitting;
import com.gyee.alarm.service.auto.IProEconWtPowerCurveFittingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TheoreticalPowerService {


    @Resource
    private IProEconWtPowerCurveFittingService proEconWtPowerCurveFittingService;

    /**
     * 缓存自算功率，最优功率
     * 1个月
     */
    public void updateCachePower(){
        Map<String, Map<Double,ProEconWtPowerCurveFitting>> resultMap = new HashMap<>();

        List<ProEconWtPowerCurveFitting> econWtPowerCurveFittings = proEconWtPowerCurveFittingService.list();
        econWtPowerCurveFittings.stream().forEach(curveFitting->{
            if (resultMap.containsKey(curveFitting.getWindturbineId())){
                resultMap.get(curveFitting.getWindturbineId()).put(curveFitting.getSpeed(),curveFitting);
            }else {
                Map<Double,ProEconWtPowerCurveFitting> powerMap = new HashMap<>();
                powerMap.put(curveFitting.getSpeed(),curveFitting);
                resultMap.put(curveFitting.getWindturbineId(),powerMap);
            }
        });
        CacheContext.curveFittingPowerMap = resultMap;
    }


}
