package com.gyee.wisdom.alarm.sharding.cache;

import com.gyee.wisdom.alarm.sharding.entity.WindPowerStation;
import com.gyee.wisdom.alarm.sharding.service.WindpowerstationService;
import com.gyee.wisdom.alarm.sharding.util.SpringContextUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @description:
 * @auther: Wanghs
 * @date: 2022-04-02
 */
public class StationCache {

    static List<WindPowerStation> stationList = new ArrayList<>();

    public static String getStationName(String stationId) {
        if (stationList.size() <= 0) {

            WindpowerstationService bean = SpringContextUtil.getBean(WindpowerstationService.class);
            List<WindPowerStation> lst = bean.getAllStation("");
            stationList = lst;
        }
        Optional<WindPowerStation> first = stationList.stream().filter(s -> s.getId().equals(stationId)).findFirst();
        if (first.isPresent())
            return first.get().getName();
        else
            return null;
    }
}
