package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
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/trafficSecurity")
public class MSTrafficSecurityController {

    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("万人交通事故死亡率","TrafficDeathRate");
        map.put("交通事故类型占比","TrafficAccidentProportion");
        map.put("交通事故趋势","TrafficAccidentTendency");
        map.put("交通事故区域排名","TrafficAccidentRanking");
        map.put("交通事故分布","TrafficAccidentDistribution");
        map.put("交通事故结案情况","TrafficAccidentComplete");
        return map;
    }
    @Autowired
    private IMSTrafficSecurityService msTrafficSecurityService;
    @RequestMapping(value = "index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/trafficSecurity/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }


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

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

    @RequestMapping(value="addTrafficDeathRate.action")
    @ResponseBody
    public ResultState addTrafficDeathRate(TrafficDeathRate trafficDeathRate){
        boolean isEdit=trafficDeathRate.getId()==null?false:true;
        ResultState resultState=msTrafficSecurityService.add(trafficDeathRate,isEdit);
        return resultState;
    }

    @RequestMapping(value="addTrafficAccidentProportion.action")
    @ResponseBody
    public ResultState addTrafficAccidentProportion(TrafficAccidentProportion trafficAccidentProportion){
        boolean isEdit=trafficAccidentProportion.getId()==null?false:true;
        ResultState resultState=msTrafficSecurityService.add(trafficAccidentProportion,isEdit);
        return resultState;
    }

    @RequestMapping(value="addTrafficAccidentTendency.action")
    @ResponseBody
    public ResultState addTrafficAccidentTendency(TrafficAccidentTendency trafficAccidentTendency){
        boolean isEdit=trafficAccidentTendency.getId()==null?false:true;
        ResultState resultState=msTrafficSecurityService.add(trafficAccidentTendency,isEdit);
        return resultState;
    }

    @RequestMapping(value="addTrafficAccidentRanking.action")
    @ResponseBody
    public ResultState addTrafficAccidentRanking(TrafficAccidentRanking trafficAccidentRanking){
        boolean isEdit=trafficAccidentRanking.getId()==null?false:true;
        ResultState resultState=msTrafficSecurityService.add(trafficAccidentRanking,isEdit);
        return resultState;
    }

    @RequestMapping(value="addTrafficAccidentDistribution.action")
    @ResponseBody
    public ResultState addTrafficAccidentDistribution(TrafficAccidentDistribution trafficAccidentDistribution){
        boolean isEdit=trafficAccidentDistribution.getId()==null?false:true;
        ResultState resultState=msTrafficSecurityService.add(trafficAccidentDistribution,isEdit);
        return resultState;
    }

    @RequestMapping(value="addTrafficAccidentComplete.action")
    @ResponseBody
    public ResultState addTrafficAccidentComplete(TrafficAccidentComplete trafficAccidentComplete){
        boolean isEdit=trafficAccidentComplete.getId()==null?false:true;
        ResultState resultState=msTrafficSecurityService.add(trafficAccidentComplete,isEdit);
        return resultState;
    }
}
