package com.gyee.runeconomy.service.realtimelibrary;

/*
@author   谢生杰
@date   2022/11/6-12:07

*/

import com.gyee.runeconomy.model.auto.ProEconWtPowerCurveFitting;
import com.gyee.runeconomy.service.auto.IProBasicModelPowerRdService;
import com.gyee.runeconomy.service.auto.IProEconWtPowerCurveFittingService;
import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
import com.gyee.runeconomy.util.redis.RedisService;
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 RedisService redisService;
    @Resource
    private IProBasicModelPowerRdService proBasicModelPowerRdService;
    @Resource
    private IProEconWtPowerCurveFittingService proEconWtPowerCurveFittingService;
    @Resource
    private IEdosUtil edosUtil;

    /**
     * 缓存自算功率，最优功率
     * 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;
    }


}
