package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.entity.CriminalRate;
import com.lightinit.hsdatashow.entity.CriminalRateExample;
import com.lightinit.hsdatashow.entity.PoliceManning;
import com.lightinit.hsdatashow.entity.PoliceManningExample;
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.ISocietySecurityService;
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.HashMap;
import java.util.List;

/**
 * @Author: sunxiang
 * @Date: 2018/8/9 14:13
 * @Description:
 **/
@Service
public class SocietySecurityServiceImpl implements ISocietySecurityService {

    @Autowired
    private CriminalRateMapper criminalRateMapper;
    @Autowired
    private RegisterLegalProportionMapper registerLegalProportionMapper;
    @Autowired
    private RegisterLegalTendencyMapper registerLegalTendencyMapper;
    @Autowired
    private CriminalRegisterProportionMapper criminalRegisterProportionMapper;
    @Autowired
    private VideoMonitorMapper videoMonitorMapper;
    @Autowired
    private PoliceManningMapper policeManningMapper;

    @Override
    public ResultState getCriminalRate() {
        ResultState resultState = new ResultState();
        Calendar calendar = Calendar.getInstance();
        CriminalRateExample example = new CriminalRateExample();
        CriminalRateExample.Criteria criteria = example.createCriteria();
        criteria.andDataYearEqualTo(calendar.get(Calendar.YEAR)-1);
        List<CriminalRate> criminalRates = criminalRateMapper.selectByExample(example);
        if(criminalRates!=null && criminalRates.size()>0){
            resultState.setData(criminalRates.get(0).getRate());
        }
        return resultState;
    }

    @Override
    public ResultState getRegisterLegalPro() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        int total=0;
        List<ChartModel> list=registerLegalProportionMapper.getRegisterLegalPro();
        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("total",total);
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getRegisterLegalTen() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<Integer> crimeAmount = new ArrayList<>();  //犯罪人数
        ArrayList<BigDecimal>  proportionAmount= new ArrayList<>();//犯罪率
        List<ChartModel> list=registerLegalTendencyMapper.getRegisterLegalTen();
        if(list !=null && list.size()>0){
            for (ChartModel chartModel : list) {
                years.add(chartModel.getName()+"年");
                crimeAmount.add((Integer) chartModel.getValue());
                proportionAmount.add((BigDecimal) chartModel.getTemp());
            }
        }
        map.put("years",years);
        map.put("crimeAmount",crimeAmount);
        map.put("proportionAmount",proportionAmount);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getCriRegPro() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<Integer> criminalAmount = new ArrayList<>();  //发案总数
        ArrayList<Integer> registerAmount = new ArrayList<>(); //立案总数
        ArrayList<Double>  proportionAmount= new ArrayList<>();//立案率
        List<ChartModel2> list=criminalRegisterProportionMapper.getCriRegPro();
        if(list !=null && list.size()>0){
            for (ChartModel2 chartModel : list) {
                years.add(chartModel.getName()+"年");
                criminalAmount.add((Integer) chartModel.getValue());
                registerAmount.add((Integer) chartModel.getTemp1());
                proportionAmount.add((Double) chartModel.getTemp2());
            }
        }
        map.put("years",years);
        map.put("criminalAmount",criminalAmount);
        map.put("registerAmount",registerAmount);
        map.put("proportionAmount",proportionAmount);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getImportantAreaMonitor() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        List<MapModel> array = videoMonitorMapper.getImportantAreaMonitor((byte)1);//查询重点地区的监控
        map.put("array",array);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getPolicepro() {
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        List<ChartModel> policeMannings = policeManningMapper.getPolicepro();
        resultState.setData(policeMannings);
        return resultState;
    }
}
