package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.entity.CountrysideGarbage;
import com.lightinit.hsdatashow.entity.CountrysideSewage;
import com.lightinit.hsdatashow.entity.CountrysideWater;
import com.lightinit.hsdatashow.entity.CountrysideWc;
import com.lightinit.hsdatashow.mapper.*;
import com.lightinit.hsdatashow.model.admin.CountrysideGarbageModel;
import com.lightinit.hsdatashow.model.admin.CountrysideGarbageRankingModel;
import com.lightinit.hsdatashow.model.admin.CountrysideNameAndValue;
import com.lightinit.hsdatashow.service.admin.ICountrysideService;
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 CountrysideServiceImpl implements ICountrysideService{

    @Autowired
    private CountrysideWaterMapper countrysideWaterMapper ;

    @Autowired
    private CountrysideWcMapper countrysideWcMapper ;

    @Autowired
    private CountrysideSewageMapper countrysideSewageMapper ;

    @Autowired
    private CountrysideGarbageMapper countrysideGarbageMapper ;

    @Autowired
    private CountrysideSewageRankingMapper countrysideSewageRankingMapper ;

    @Autowired
    private CountrysideGarbageRankingMapper countrysideGarbageRankingMapper ;

    @Override
    public CountrysideNameAndValue getCountrysideWater() {
        CountrysideNameAndValue countrysideNameAndValue = new CountrysideNameAndValue() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR)-5 ;
        List<CountrysideWater> countrysideWaters = countrysideWaterMapper.getCountrysideWater(year) ;
        if (countrysideWaters.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (CountrysideWater countrysideWater : countrysideWaters) {
                names.add(countrysideWater.getDataYear()+"年") ;
                quantity.add(countrysideWater.getQuantity()) ;
            }
            countrysideNameAndValue.setNames(names);
            countrysideNameAndValue.setQuantity(quantity);
        }
        return countrysideNameAndValue;
    }

    @Override
    public CountrysideNameAndValue getCountrysideWc() {
        CountrysideNameAndValue countrysideNameAndValue = new CountrysideNameAndValue() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR)-5 ;
        List<CountrysideWc> countrysideWcs = countrysideWcMapper.getCountrysideWc(year) ;
        if (countrysideWcs.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (CountrysideWc countrysideWc : countrysideWcs) {
                names.add(countrysideWc.getDataYear()+"年") ;
                quantity.add(countrysideWc.getQuantity()) ;
            }
            countrysideNameAndValue.setNames(names);
            countrysideNameAndValue.setQuantity(quantity);
        }
        return countrysideNameAndValue;
    }

    @Override
    public CountrysideNameAndValue getCountrysideSewage() {
        CountrysideNameAndValue countrysideNameAndValue = new CountrysideNameAndValue() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR)-5 ;
        List<CountrysideSewage> countrysideSewages = countrysideSewageMapper.getCountrysideSewage(year) ;
        if (countrysideSewages.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (CountrysideSewage countrysideSewage : countrysideSewages) {
                names.add(countrysideSewage.getDataYear()+"年") ;
                quantity.add(countrysideSewage.getQuantity()) ;
            }
            countrysideNameAndValue.setNames(names);
            countrysideNameAndValue.setQuantity(quantity);
        }
        return countrysideNameAndValue;
    }

    @Override
    public CountrysideNameAndValue getCountrysideGarbage() {
        CountrysideNameAndValue countrysideNameAndValue = new CountrysideNameAndValue() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR)-5 ;
        List<CountrysideGarbage> countrysideGarbages = countrysideGarbageMapper.getCountrysideGarbage(year) ;
        if (countrysideGarbages.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (CountrysideGarbage countrysideGarbage : countrysideGarbages) {
                names.add(countrysideGarbage.getDataYear()+"年") ;
                quantity.add(countrysideGarbage.getQuantity()) ;
            }
            countrysideNameAndValue.setNames(names);
            countrysideNameAndValue.setQuantity(quantity);
        }
        return countrysideNameAndValue;
    }

    @Override
    public CountrysideNameAndValue getCountrysideSewageRanking() {
        CountrysideNameAndValue countrysideNameAndValue = new CountrysideNameAndValue() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR) ;
        List<CountrysideGarbageModel> countrysideGarbageModels = countrysideSewageRankingMapper.getCountrysideSewageRanking(year) ;
        if (countrysideGarbageModels.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (CountrysideGarbageModel countrysideGarbageModel : countrysideGarbageModels) {
                names.add(countrysideGarbageModel.getRegionName()) ;
                quantity.add(countrysideGarbageModel.getQuantity()) ;
            }
            countrysideNameAndValue.setNames(names);
            countrysideNameAndValue.setQuantity(quantity);
        }
        return countrysideNameAndValue;
    }

    @Override
    public CountrysideNameAndValue getCountrysideGarbageRanking() {
        CountrysideNameAndValue countrysideNameAndValue = new CountrysideNameAndValue() ;
        Calendar calendar = Calendar.getInstance() ;
        int year = calendar.get(Calendar.YEAR) ;
        List<CountrysideGarbageRankingModel> countrysideGarbageModels = countrysideGarbageRankingMapper.getCountrysideGarbageRanking(year) ;
        if (countrysideGarbageModels.size()>0){
            List<String> names = new ArrayList<>();
            List<BigDecimal> quantity = new ArrayList<>() ;
            for (CountrysideGarbageRankingModel countrysideGarbageRankingModel : countrysideGarbageModels) {
                names.add(countrysideGarbageRankingModel.getRegionName()) ;
                quantity.add(countrysideGarbageRankingModel.getQuantity()) ;
            }
            countrysideNameAndValue.setNames(names);
            countrysideNameAndValue.setQuantity(quantity);
        }
        return countrysideNameAndValue;
    }
}
