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

import com.lightinit.hsdatashow.entity.StWaterLake;
import com.lightinit.hsdatashow.mapper.StWaterLakeMapper;
import com.lightinit.hsdatashow.mapper.StWaterRiverMapper;
import com.lightinit.hsdatashow.model.topic.water.*;
import com.lightinit.hsdatashow.service.topic.water.IRiverChiefServer;
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 RiverChiefServerImpl implements IRiverChiefServer {

    @Autowired
    private StWaterRiverMapper stWaterRiverMapper ;

    @Autowired
    private StWaterLakeMapper stWaterLakeMapper ;

    @Override
    public int getRiverCount() {
        return stWaterRiverMapper.getRiverCount() ;
    }

    @Override
    public BigDecimal getRiverLength() {
        return stWaterRiverMapper.getRiverLength();
    }

    @Override
    public StWaterLake getHengshuiHu() {
        return stWaterLakeMapper.getHengshuiHu();
    }

    @Override
    public BigDecimal getHlXs() {
        return stWaterRiverMapper.getHlXs();
    }

    @Override
    public HeliuGaikuangReturnModel getHeliuGaikuang() {
        HeliuGaikuangReturnModel heliuGaikuangReturnModel = new HeliuGaikuangReturnModel() ;
        List<WaterAllListReturnModel> stWaterRivers = stWaterRiverMapper.selectAllList() ;
        if (stWaterRivers.size()>0){
            int falg = 0 ;
            List<String> array1 = new ArrayList<>() ;
            List<Integer> array2 = new ArrayList<>() ;
            List<BigDecimal> riverLengths = new ArrayList<>() ;
            List<String> startSopPoint = new ArrayList<>() ;
            List<BigDecimal> riverImpoundages = new ArrayList<>() ;
            List<String> riverChiefs = new ArrayList<>() ;
            List<BigDecimal> normals = new ArrayList<>() ;
            List<BigDecimal> warnings = new ArrayList<>() ;
            List<String> flowThroughs = new ArrayList<>() ;
            List<BigDecimal> waterLevel = new ArrayList<>() ;
            for (WaterAllListReturnModel stWaterRiver : stWaterRivers) {
                array1.add(stWaterRiver.getRiverName()) ;
                array2.add(falg) ;
                riverLengths.add(stWaterRiver.getRiverLength()) ;
                startSopPoint.add(stWaterRiver.getStartStopPoint()) ;
                riverImpoundages.add(stWaterRiver.getRiverImpoundage()) ;
                riverChiefs.add(stWaterRiver.getRiverChief()) ;
                normals.add(stWaterRiver.getWaterLevelNormal()) ;
                warnings.add(stWaterRiver.getWaterLevelWarning()) ;
                flowThroughs.add(stWaterRiver.getFlowThrough()) ;
                waterLevel.add(stWaterRiver.getWaterLevel()) ;
                falg = falg+1 ;
            }
            heliuGaikuangReturnModel.setArray1(array1);
            heliuGaikuangReturnModel.setArray2(array2);
            heliuGaikuangReturnModel.setRiverLengths(riverLengths);
            heliuGaikuangReturnModel.setStartSopPoint(startSopPoint);
            heliuGaikuangReturnModel.setRiverImpoundages(riverImpoundages);
            heliuGaikuangReturnModel.setRiverChiefs(riverChiefs);
            heliuGaikuangReturnModel.setNormals(normals);
            heliuGaikuangReturnModel.setWarnings(warnings);
            heliuGaikuangReturnModel.setFlowThroughs(flowThroughs);
            heliuGaikuangReturnModel.setWaterLevels(waterLevel);
        }
        return heliuGaikuangReturnModel;
    }

    @Override
    public ModelNameAndNameOrValue getHeliuXushui() {
        ModelNameAndNameOrValue modelNameAndNameOrValue = new ModelNameAndNameOrValue() ;
        List<WaterAllListReturnModel> stWaterRivers = stWaterRiverMapper.selectAllList() ;
        if (stWaterRivers.size()>0){
            List<String> names = new ArrayList<>() ;
            List<NameAndValue> list = new ArrayList<>() ;
            for (WaterAllListReturnModel stWaterRiver : stWaterRivers) {
                names.add(stWaterRiver.getRiverName()) ;
                list.add(new NameAndValue(stWaterRiver.getRiverName(),stWaterRiver.getRiverImpoundage())) ;
            }
            modelNameAndNameOrValue.setNames(names);
            modelNameAndNameOrValue.setList(list);
        }
        return modelNameAndNameOrValue ;
    }

    @Override
    public HeLiuShuiWeiReturnModel getHeliuShuiwei() {
        HeLiuShuiWeiReturnModel heLiuShuiWeiReturnModel = new HeLiuShuiWeiReturnModel() ;
        List<WaterAllListReturnModel> stWaterRivers = stWaterRiverMapper.selectAllList() ;
        if (stWaterRivers.size()>0){
            List<String> names = new ArrayList<>() ;
            List<BigDecimal> nowshiweis = new ArrayList<>() ;
            List<BigDecimal> zcshuiweis = new ArrayList<>() ;
            List<BigDecimal> jingjieshuiwei = new ArrayList<>() ;
            for (WaterAllListReturnModel stWaterRiver : stWaterRivers) {
                names.add(stWaterRiver.getRiverName()) ;
                nowshiweis.add(stWaterRiver.getWaterLevel()) ;
                zcshuiweis.add(stWaterRiver.getWaterLevelNormal()) ;
                jingjieshuiwei.add(stWaterRiver.getWaterLevelWarning()) ;
            }
            heLiuShuiWeiReturnModel.setNames(names);
            heLiuShuiWeiReturnModel.setNowshiweis(nowshiweis);
            heLiuShuiWeiReturnModel.setZcshuiweis(zcshuiweis);
            heLiuShuiWeiReturnModel.setJingjieshuiwei(jingjieshuiwei);
        }
        return heLiuShuiWeiReturnModel;
    }

    @Override
    public NameAndListModel getHshxushui() {
        NameAndListModel nameAndListModel = new NameAndListModel() ;
        StWaterLake stWaterLake = stWaterLakeMapper.getHengshuiHu();
        List<BigDecimal> value  = new ArrayList<>() ;
        value.add(stWaterLake.getLakeImpoundage()) ;
        value.add(stWaterLake.getWaterLevelDead()) ;
        nameAndListModel.setValue(value);
        return nameAndListModel;
    }

    @Override
    public HshxushuiReturnModel getHshshuiwei() {
        return stWaterLakeMapper.getHengshuiHuShuiwei();
    }
}
