package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.entity.ProjectType;
import com.lightinit.hsdatashow.mapper.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.model.admin.ChartModel;
import com.lightinit.hsdatashow.model.admin.ChartModel2;
import com.lightinit.hsdatashow.model.admin.MapModel;
import com.lightinit.hsdatashow.service.admin.IBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Author: sunxiang
 * @Date: 2018/12/8 17:18
 * @Description:
 **/
@Service
public class IBuildingServiceImpl implements IBuildingService {

    @Autowired
    private ProjectMapper projectMapper;
    @Autowired
    private ProjectAccidentAnalyseMapper projectAccidentAnalyseMapper;
    @Autowired
    private ProjectAnalyseMapper projectAnalyseMapper;
    @Autowired
    private ProjectStatisticsMapper projectStatisticsMapper;
    @Autowired
    private ProjectTypeMapper projectTypeMapper;

    @Override
    public ResultState getProjec() {
        //projectMapper.getProjecIsMap();地图展示未作
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> names = new ArrayList<>();
        ArrayList<BigDecimal> values= new ArrayList<>();
        List<ChartModel> list=projectMapper.getProjecIsModel();
        if(list !=null && list.size()>0) {
            for (ChartModel chartModel : list) {
                names.add(chartModel.getName());
                values.add((BigDecimal) chartModel.getValue());
            }
        }
        Collections.reverse(names);
        Collections.reverse(values);
        map.put("names",names);
        map.put("values",values);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getProjectAnalysis() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        List<String> name = new ArrayList<>();
        List<BigDecimal> value = new ArrayList<>();
        List<ChartModel> list=projectAnalyseMapper.getProjectAnalysis();
        if(list !=null && list.size()>0) {
            for (ChartModel chartModel : list) {
                name.add(chartModel.getName());
            }
        }
        map.put("name",name);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getProjectType() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        Set<String> names = new HashSet<>();
        Set<String> years = new HashSet<>();
        ArrayList<Integer> ny = new ArrayList<>();
        ArrayList<Integer> zg = new ArrayList<>();
        ArrayList<Integer> jt = new ArrayList<>();
        List<ChartModel> list=projectTypeMapper.getProjectType();
        if(list !=null && list.size()>0) {
            for (ChartModel chartModel : list) {
                names.add(chartModel.getName());
                years.add(chartModel.getTemp()+"年");
                if("农业".equals(chartModel.getName())){
                    ny.add(Integer.parseInt(chartModel.getValue().toString()));
                }else if("重工".equals(chartModel.getName())){
                    zg.add(Integer.parseInt(chartModel.getValue().toString()));
                }else if("交通".equals(chartModel.getName())){
                    jt.add(Integer.parseInt(chartModel.getValue().toString()));
                }
            }
        }
        map.put("names",names);
        map.put("years",years);
        map.put("ny",ny);
        map.put("zg",zg);
        map.put("jt",jt);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getProjectStatistics() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        Integer total=null;
        BigDecimal newGrowth=null;
        BigDecimal newRing=null;
        List<BigDecimal> growths = new ArrayList<>();
        List<BigDecimal> rings = new ArrayList<>();
        List<String> years = new ArrayList<>();
        ArrayList<Integer> value = new ArrayList<>();
        List<ChartModel2> list=projectStatisticsMapper.getProjectAnalysis();
        if(list !=null && list.size()>0) {
            for (ChartModel2 chartModel : list) {
                years.add(chartModel.getName()+"年");
                value.add(Integer.parseInt(chartModel.getValue().toString()));
                growths.add((BigDecimal)chartModel.getTemp1());
                rings.add((BigDecimal)chartModel.getTemp2());
                total=Integer.parseInt(chartModel.getValue().toString());
                newGrowth=(BigDecimal)chartModel.getTemp1();
                newRing=(BigDecimal)chartModel.getTemp2();
            }
        }
        map.put("total",total);
        map.put("value",value);
        map.put("years",years);
        map.put("growths",growths);
        map.put("rings",rings);
        map.put("newGrowth",newGrowth);
        map.put("newRing",newRing);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getProjectAccidentAnalyser() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        Integer total=null;
        BigDecimal newGrowth=null;
        BigDecimal newRing=null;
        Set<String> years = new HashSet<>();
        List<Integer> tbzd = new ArrayList<>();
        List<Integer> zd = new ArrayList<>();
        List<Integer> jd = new ArrayList<>();
        List<Integer> yb = new ArrayList<>();
        ArrayList<Integer> value = new ArrayList<>();
        List<ChartModel> list=projectAccidentAnalyseMapper.getProjectAccidentAnalyser();
        if(list !=null && list.size()>0) {
            for (ChartModel chartModel : list) {
                years.add(chartModel.getName()+"年");
                if("特别重大".equals(chartModel.getTemp().toString())){
                    tbzd.add(Integer.parseInt(chartModel.getValue().toString()));
                }else if("重大".equals(chartModel.getTemp().toString())){
                    zd.add(Integer.parseInt(chartModel.getValue().toString()));
                }else if("较大".equals(chartModel.getTemp().toString())){
                    jd.add(Integer.parseInt(chartModel.getValue().toString()));
                }else if("一般".equals(chartModel.getTemp().toString())){
                    yb.add(Integer.parseInt(chartModel.getValue().toString()));
                }
            }
        }
        map.put("years",years);
        map.put("tbzd",tbzd);
        map.put("zd",zd);
        map.put("jd",jd);
        map.put("yb",yb);
        resultState.setData(map);
        return resultState;
    }
}
