package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.entity.GreenCity;
import com.lightinit.hsdatashow.entity.GreenForest;
import com.lightinit.hsdatashow.mapper.GreenBuildMapper;
import com.lightinit.hsdatashow.mapper.GreenCityMapper;
import com.lightinit.hsdatashow.mapper.GreenForestMapper;
import com.lightinit.hsdatashow.model.admin.GreenBuildModel;
import com.lightinit.hsdatashow.model.admin.GreenNameAndValueModel;
import com.lightinit.hsdatashow.service.admin.IGreenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@Service
public class GreenServiceImpl implements IGreenService{

    @Autowired
    private GreenCityMapper greenCityMapper ;

    @Autowired
    private GreenForestMapper greenForestMapper ;

    @Autowired
    private GreenBuildMapper greenBuildMapper ;

    @Override
    public GreenNameAndValueModel getGreenCity() {
        GreenNameAndValueModel greenNameAndValueModel = new GreenNameAndValueModel() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR)-5 ;
        List<GreenCity> greenCities = greenCityMapper.getGreenCity(year) ;
        if (greenCities.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            List<BigDecimal> forecastQuantity = new ArrayList<>() ;
            for (GreenCity greenCity : greenCities) {
                names.add(greenCity.getDataYear()+"年") ;
                quantity.add(greenCity.getQuantity()) ;
                forecastQuantity.add(greenCity.getForecastQuantity()) ;
            }
            greenNameAndValueModel.setNames(names);
            greenNameAndValueModel.setQuantity(quantity);
            greenNameAndValueModel.setForecastQuantity(forecastQuantity);
        }
        return greenNameAndValueModel;
    }

    @Override
    public GreenNameAndValueModel getGreenForest() {
        GreenNameAndValueModel greenNameAndValueModel = new GreenNameAndValueModel() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR)-5 ;
        List<GreenForest> greenForests = greenForestMapper.getGreenForest(year) ;
        if (greenForests.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            List<BigDecimal> forecastQuantity = new ArrayList<>() ;
            for (GreenForest greenForest : greenForests) {
                names.add(greenForest.getDataYear()+"年") ;
                quantity.add(greenForest.getQuantity()) ;
                forecastQuantity.add(greenForest.getForecastQuantity()) ;
            }
            greenNameAndValueModel.setNames(names);
            greenNameAndValueModel.setQuantity(quantity);
            greenNameAndValueModel.setForecastQuantity(forecastQuantity);
        }
        return greenNameAndValueModel;
    }

    @Override
    public GreenNameAndValueModel getGreenBuild() {
        GreenNameAndValueModel greenNameAndValueModel = new GreenNameAndValueModel() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR) ;
        List<GreenBuildModel> greenBuildModels = greenBuildMapper.getGreenBuild(year) ;
        if (greenBuildModels.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (GreenBuildModel greenBuildModel : greenBuildModels) {
                names.add(greenBuildModel.getRegionName()) ;
                quantity.add(greenBuildModel.getQuantity()) ;
            }
            greenNameAndValueModel.setNames(names);
            greenNameAndValueModel.setQuantity(quantity);
        }
        return greenNameAndValueModel;
    }
}
