package com.jiayue.ipp.idp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ipp.common.data.entity.ElectricField;
import com.jiayue.ipp.common.data.entity.ForecastManufactor;
import com.jiayue.ipp.idp.dto.KVPDto;
import com.jiayue.ipp.idp.mapper.ForecastManufactorMapper;
import com.jiayue.ipp.idp.service.ElectricFieldService;
import com.jiayue.ipp.idp.service.ForecastManufactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 气象站数据业务层实现类
 *
 * @author tl
 * @date 2022-05-11 18:07:03
 */
@Service
public class ForecastManufactorServiceImpl extends ServiceImpl<ForecastManufactorMapper, ForecastManufactor> implements ForecastManufactorService {

    @Override
    public List<KVPDto> getForecastManufactorSelect() {
        List<ForecastManufactor> forecastManufactors = baseMapper.selectList(null);
        List<KVPDto> KVPDtoList = new ArrayList<>();

        forecastManufactors.forEach(f->{
            KVPDto KVPDto = new KVPDto();
            KVPDto.setLabel(f.getName());
            KVPDto.setValue(f.getSign());
            KVPDtoList.add(KVPDto);
        });

        return KVPDtoList;
    }

    @Autowired
    ElectricFieldService electricFieldService;

    /**
     * 根据场站取厂家
     *
     * @return
     */
    public List<Map<String, String>> manufactorByStationCode(String stationCode) {
        ElectricField electricField = electricFieldService.findByStationCode(stationCode);
        String[] mans = electricField.getForecastManufactor().split(",");
        List<Map<String, String>> list = new ArrayList<>();
        List<ForecastManufactor> forecastManufactorList = this.list();
        for (int i=0;i<mans.length;i++){
            for (int j=0;j<forecastManufactorList.size();j++){
                ForecastManufactor forecastManufactor = forecastManufactorList.get(j);
                if (forecastManufactor.getSign().equals(mans[i])){
                    Map<String, String> map = new HashMap<>();
                    map.put("name", forecastManufactor.getName());
                    map.put("sign", mans[i]);
                    list.add(map);
                    break;
                }
            }
        }
        return list;
    }
}
