package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSLivingSecurityService;
import com.lightinit.hsdatashow.service.ms.IMSTrafficSecurityService;
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/4 10:46
 * @Description:
 **/
@Controller
@RequestMapping(value = "/ms/livingSecurity")
public class MSLivingSecurityController {

    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("万人火灾事故死亡率","AreaFireDeathRate");
        map.put("区域火灾事故占比","AreaFireProportion");
        map.put("万人火灾事故死亡率趋势","AreaFireTendency");
        map.put("火灾事故死亡率排名","AreaFireRanking");
        map.put("火灾事故分布","AreaFireDistribution");
        return map;
    }
    @Autowired
    private IMSLivingSecurityService msLivingSecurityService;
    @RequestMapping(value = "index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/livingSecurity/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }


    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/livingSecurity/"+tableType+"_list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List list=msLivingSecurityService.list(tableType,pager);
        long total=msLivingSecurityService.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/livingSecurity/"+tableType+"_add");
        Object obj=null;
        if(id !=null){
            obj=msLivingSecurityService.findById(tableType,id);
        }
        modelAndView.addObject("outputModel",obj);
        return modelAndView;
    }

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

    @RequestMapping(value="addAreaFireDeathRate.action")
    @ResponseBody
    public ResultState addAreaFireDeathRate(AreaFireDeathRate areaFireDeathRate){
        boolean isEdit=areaFireDeathRate.getId()==null?false:true;
        ResultState resultState=msLivingSecurityService.add(areaFireDeathRate,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAreaFireProportion.action")
    @ResponseBody
    public ResultState addAreaFireProportion(AreaFireProportion areaFireProportion){
        boolean isEdit=areaFireProportion.getId()==null?false:true;
        ResultState resultState=msLivingSecurityService.add(areaFireProportion,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAreaFireTendency.action")
    @ResponseBody
    public ResultState addAreaFireTendency(AreaFireTendency areaFireTendency){
        boolean isEdit=areaFireTendency.getId()==null?false:true;
        ResultState resultState=msLivingSecurityService.add(areaFireTendency,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAreaFireRanking.action")
    @ResponseBody
    public ResultState addAreaFireRanking(AreaFireRanking areaFireRanking){
        boolean isEdit=areaFireRanking.getId()==null?false:true;
        ResultState resultState=msLivingSecurityService.add(areaFireRanking,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAreaFireDistribution.action")
    @ResponseBody
    public ResultState addAreaFireDistribution(AreaFireDistribution areaFireDistribution){
        boolean isEdit=areaFireDistribution.getId()==null?false:true;
        ResultState resultState=msLivingSecurityService.add(areaFireDistribution,isEdit);
        return resultState;
    }

}
