package com.lightinit.hsdatashow.impl.topic.water;

import com.lightinit.hsdatashow.mapper.StWaterRuralCentralSupplyPopulationMapper;
import com.lightinit.hsdatashow.mapper.StWaterRuralInvestmentMapper;
import com.lightinit.hsdatashow.mapper.StWaterRuralPopulationMapper;
import com.lightinit.hsdatashow.mapper.StWaterrRuralProjectMapper;
import com.lightinit.hsdatashow.model.topic.water.ListNameAndListValueModel;
import com.lightinit.hsdatashow.model.topic.water.NameAndValue;
import com.lightinit.hsdatashow.model.topic.water.ShouyiRenkouFenleiReturnModel;
import com.lightinit.hsdatashow.model.topic.water.StWaterRuralPopulationReturnModel;
import com.lightinit.hsdatashow.service.topic.water.IWaterWorksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class WaterWorksServiceImpl implements IWaterWorksService {

    @Autowired
    private StWaterRuralPopulationMapper stWaterRuralPopulationMapper ;
    @Autowired
    private StWaterrRuralProjectMapper stWaterrRuralProjectMapper ;
    @Autowired
    private StWaterRuralCentralSupplyPopulationMapper stWaterRuralCentralSupplyPopulationMapper ;
    @Autowired
    private StWaterRuralInvestmentMapper stWaterRuralInvestmentMapper ;

    @Override
    public BigDecimal getGongshuiRenkou() {
        return stWaterRuralPopulationMapper.getGongshuiRenkou();
    }

    @Override
    public Integer getGongchengZongliang() {
        return stWaterrRuralProjectMapper.getGongchengZongliang();
    }

    @Override
    public BigDecimal getShouyiRenkou() {
        return stWaterRuralCentralSupplyPopulationMapper.getGongchengZongliang();
    }

    @Override
    public BigDecimal getTouziZongshu() {
        return stWaterRuralInvestmentMapper.getTouziZongshu();
    }

    @Override
    public ListNameAndListValueModel getGequxianRenkou(String type) {
        ListNameAndListValueModel listNameAndListValueModel = new ListNameAndListValueModel() ;
        List<StWaterRuralPopulationReturnModel> stWaterRuralPopulations = stWaterRuralPopulationMapper.selectByType(type) ;
        if (stWaterRuralPopulations.size()>0){
            List<String> names = new ArrayList<>() ;
            List<BigDecimal> values = new ArrayList<>() ;
            for (StWaterRuralPopulationReturnModel stWaterRuralPopulation : stWaterRuralPopulations) {
                names.add(stWaterRuralPopulation.getRegionName()) ;
                values.add(stWaterRuralPopulation.getPopulationSize()) ;
            }
            listNameAndListValueModel.setNames(names);
            listNameAndListValueModel.setValues(values);
        }
        return listNameAndListValueModel;
    }

    @Override
    public List<NameAndValue> getGongchengFenbu() {
        List<NameAndValue> names = stWaterrRuralProjectMapper.getGongchengFenbu() ;
        return names;
    }

    @Override
    public List<NameAndValue> getGongchengGexian(String type) {
        return stWaterrRuralProjectMapper.getGongchengGexian(type);
    }

    @Override
    public List<NameAndValue> getTouziGoucheng() {
        return stWaterRuralInvestmentMapper.getTouziGoucheng();
    }

    @Override
    public List<NameAndValue> getTouziQuxian(String type) {
        return stWaterRuralInvestmentMapper.getTouziQuxian(type);
    }

    @Override
    public ShouyiRenkouFenleiReturnModel getShouyiRenkouFenlei() {
        return stWaterRuralCentralSupplyPopulationMapper.getShouyiRenkouFenlei() ;
    }

    @Override
    public List<NameAndValue> getShouyiRenkouFenbu(String type) {
        if (type.equals("总人数")){
            return stWaterRuralCentralSupplyPopulationMapper.getShouyiRenkouFenbu(null);
        }else {
            return stWaterRuralCentralSupplyPopulationMapper.getShouyiRenkouFenbu(type);
        }
    }
}
