package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.dictionary.DicFireDisasterDegree;
import com.lightinit.hsdatashow.dictionary.DicIndustrialAccidentDegree;
import com.lightinit.hsdatashow.dictionary.DicNewEnergyCategory;
import com.lightinit.hsdatashow.mapper.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.model.admin.AccidentDistributionModel;
import com.lightinit.hsdatashow.model.admin.ChartModel;
import com.lightinit.hsdatashow.model.admin.ChartModel2;
import com.lightinit.hsdatashow.service.admin.IProduceSecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @Author: sunxiang
 * @Date: 2018/8/8 15:55
 * @Description:
 **/
@Service
public class ProduceSecurityServiceImpl implements IProduceSecurityService {

    @Autowired
    private IndustrialAccidentDeathMapper industrialAccidentDeathMapper;
    @Autowired
    private IndustrialAccidentProportionMapper industrialAccidentProportionMapper;
    @Autowired
    private IndustrialAccidentRankingMapper industrialAccidentRankingMapper;
    @Autowired
    private IndustrialAccidentTendencyMapper industrialAccidentTendencyMapper;
    @Autowired
    private IndustrialAccidentDistributionMapper industrialAccidentDistributionMapper;
    @Override
    public ResultState getAccidentDeath() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<BigDecimal> deathAmount = new ArrayList<>();
        BigDecimal newGrowth=null;
        List<ChartModel> list=industrialAccidentDeathMapper.getAccidentDeath();
        if(list !=null && list.size()>0){
            for (ChartModel chartModel : list) {
                if(!years.contains(chartModel.getName()+"年")){
                    years.add(chartModel.getName()+"年");
                }
                deathAmount.add((BigDecimal) chartModel.getValue());
                newGrowth=(BigDecimal) chartModel.getTemp();
            }
        }
        map.put("years",years);
        map.put("deathAmount",deathAmount);
        map.put("newGrowth",newGrowth);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getAccidentProportion() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        int total=0;
        List<ChartModel> list=industrialAccidentProportionMapper.getAccidentProportion();
        ArrayList<String> names = new ArrayList<>();
        if(list !=null && list.size()>0){
            for (ChartModel chartModel : list) {
                names.add(chartModel.getName());
                total+=(Integer) chartModel.getValue();
            }
        }
        map.put("names",names);
        map.put("total",total);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getIndustrialAccidentRanking() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        List<ChartModel> list=industrialAccidentRankingMapper.getIndustrialAccidentRanking();
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Double> amount = new ArrayList<>();
        if(list !=null && list.size()>0){
            for (ChartModel chartModel : list) {
                names.add(chartModel.getName());
                amount.add((Double) chartModel.getValue());
            }
        }
        map.put("names",names);
        map.put("amount",amount);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getIndustrialAccidentTendency() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<Integer> hurtAmount = new ArrayList<>();  //受伤
        ArrayList<Integer> deathAmount = new ArrayList<>(); //死亡
        ArrayList<Double>  proportionAmount= new ArrayList<>();//死亡率
        List<ChartModel2> list=industrialAccidentTendencyMapper.getIndustrialAccidentTendency();
        if(list !=null && list.size()>0){
            for (ChartModel2 chartModel : list) {
                years.add(chartModel.getName()+"年");
                hurtAmount.add((Integer) chartModel.getValue());
                deathAmount.add((Integer) chartModel.getTemp1());
                proportionAmount.add((Double) chartModel.getTemp2());
            }
        }
        map.put("years",years);
        map.put("hurtAmount",hurtAmount);
        map.put("deathAmount",deathAmount);
        map.put("proportionAmount",proportionAmount);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getIndustrialAccidentDistribution() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        List<AccidentDistributionModel> lightDegree=new ArrayList<>(); //轻伤事故
        List<AccidentDistributionModel> seriouseDegree=new ArrayList<>();   //重伤事故
        List<AccidentDistributionModel> deathDegree=new ArrayList<>();    //死亡事故
        List<AccidentDistributionModel> list =industrialAccidentDistributionMapper.getIndustrialAccidentDistribution();
        for (AccidentDistributionModel accidentDistributionModel : list) {
            if(DicIndustrialAccidentDegree.LIGHTDEGREE.equals(accidentDistributionModel.getDegree())){
                lightDegree.add(accidentDistributionModel);
            }else if(DicIndustrialAccidentDegree.SERIOUSEDEGREE.equals(accidentDistributionModel.getDegree())){
                seriouseDegree.add(accidentDistributionModel);
            }else if(DicIndustrialAccidentDegree.DEATHDEGREE.equals(accidentDistributionModel.getDegree())){
                deathDegree.add(accidentDistributionModel);
            }
        }
        map.put("lightDegree",lightDegree);
        map.put("seriouseDegree",seriouseDegree);
        map.put("deathDegree",deathDegree);
        resultState.setData(map);
        return resultState;
    }
}
