package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSSocietySecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @Author: sunxiang
 * @Date: 2018/9/3 11:57
 * @Description:
 **/
@Controller
@RequestMapping(value = "/ms/societySecurity")
public class MSSocietySecurityController {

    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("万人刑事犯罪率","CriminalRate");
        map.put("区域立案数占比","RegisterLegalProportion");
        map.put("万人犯罪率趋势","RegisterLegalTendency");
        map.put("重点部位安全监控覆盖率","VideoMonitor");
        map.put("刑事案件立案率","CriminalRegisterProportion");
        return map;
    }
    @Autowired
    private IMSSocietySecurityService msSocietySecurityService;

    @RequestMapping(value = "index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/societySecurity/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/societySecurity/"+tableType+"_list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List list=msSocietySecurityService.list(tableType,pager);
        long total=msSocietySecurityService.queryCount(tableType);
        pager.setTotal(total);
        modelAndView.addObject("list",list);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }

    @RequestMapping(value="add.htm")
    public ModelAndView add(String tableType,Long id){
        ModelAndView modelAndView=new ModelAndView("ms/societySecurity/"+tableType+"_add");
        Object obj=null;
        if(id !=null){
            obj=msSocietySecurityService.findById(tableType,id);
        }
        modelAndView.addObject("outputModel",obj);
        return modelAndView;
    }

    @RequestMapping(value="delete.action")
    @ResponseBody
    public ResultState delete(String tableType, Long id) {
        ResultState resultState =msSocietySecurityService.delete(tableType,id);
        return resultState;
    }

    @RequestMapping(value="addCriminalRate.action")
    @ResponseBody
    public ResultState addCriminalRate(CriminalRate criminalRate){
        boolean isEdit=criminalRate.getId()==null?false:true;
        ResultState resultState=msSocietySecurityService.add(criminalRate,isEdit);
        return resultState;
    }

    @RequestMapping(value="addRegisterLegalProportion.action")
    @ResponseBody
    public ResultState addRegisterLegalProportion(RegisterLegalProportion registerLegalProportion){
        boolean isEdit=registerLegalProportion.getId()==null?false:true;
        ResultState resultState=msSocietySecurityService.add(registerLegalProportion,isEdit);
        return resultState;
    }

    @RequestMapping(value="addRegisterLegalTendency.action")
    @ResponseBody
    public ResultState addRegisterLegalTendency(RegisterLegalTendency registerLegalTendency){
        boolean isEdit=registerLegalTendency.getId()==null?false:true;
        ResultState resultState=msSocietySecurityService.add(registerLegalTendency,isEdit);
        return resultState;
    }

    @RequestMapping(value="addVideoMonitor.action")
    @ResponseBody
    public ResultState addVideoMonitor(VideoMonitor videoMonitor ){
        boolean isEdit=videoMonitor.getId()==null?false:true;
        ResultState resultState=msSocietySecurityService.add(videoMonitor,isEdit);
        return resultState;
    }

    @RequestMapping(value="addCriminalRegisterProportion.action")
    @ResponseBody
    public ResultState addCriminalRegisterProportion(CriminalRegisterProportion  criminalRegisterProportion){
        boolean isEdit=criminalRegisterProportion.getId()==null?false:true;
        ResultState resultState=msSocietySecurityService.add(criminalRegisterProportion,isEdit);
        return resultState;
    }
}
