package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSProduceSecurityService;
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 10:25
 * @Description:
 **/
@Controller
@RequestMapping(value = "/ms/produceSecurity")
public class MSProduceSecurityController {

    @Autowired
    private IMSProduceSecurityService msProduceSecurityService;
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("万人工伤事故死亡率","IndustrialAccidentDeath");
        map.put("区域工伤事故占比","IndustrialAccidentProportion");
        map.put("工伤事故类别排名","IndustrialAccidentRanking");
        map.put("工伤事故发展趋势","IndustrialAccidentTendency");
        map.put("工伤事故分布","IndustrialAccidentDistribution");
        return map;
    }
    @RequestMapping(value = "index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/produceSecurity/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }
    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/produceSecurity/"+tableType+"_list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List list=msProduceSecurityService.list(tableType,pager);
        long total=msProduceSecurityService.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/produceSecurity/"+tableType+"_add");
        Object obj=null;
        if(id !=null){
            obj=msProduceSecurityService.findById(tableType,id);
        }
        modelAndView.addObject("outputModel",obj);
        return modelAndView;
    }

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

    @RequestMapping(value="addIndustrialAccidentDeath.action")
    @ResponseBody
    public ResultState addIndustrialAccidentDeath(IndustrialAccidentDeath industrialAccidentDeath){
        boolean isEdit=industrialAccidentDeath.getId()==null?false:true;
        ResultState resultState=msProduceSecurityService.add(industrialAccidentDeath,isEdit);
        return resultState;
    }

    @RequestMapping(value="addIndustrialAccidentProportion.action")
    @ResponseBody
    public ResultState addIndustrialAccidentProportion(IndustrialAccidentProportion industrialAccidentProportion){
        boolean isEdit=industrialAccidentProportion.getId()==null?false:true;
        ResultState resultState=msProduceSecurityService.add(industrialAccidentProportion,isEdit);
        return resultState;
    }

    @RequestMapping(value="addIndustrialAccidentRanking.action")
    @ResponseBody
    public ResultState addIndustrialAccidentRanking(IndustrialAccidentRanking industrialAccidentRanking){
        boolean isEdit=industrialAccidentRanking.getId()==null?false:true;
        ResultState resultState=msProduceSecurityService.add(industrialAccidentRanking,isEdit);
        return resultState;
    }

    @RequestMapping(value="addIndustrialAccidentTendency.action")
    @ResponseBody
    public ResultState addIndustrialAccidentTendency(IndustrialAccidentTendency industrialAccidentTendency){
        boolean isEdit=industrialAccidentTendency.getId()==null?false:true;
        ResultState resultState=msProduceSecurityService.add(industrialAccidentTendency,isEdit);
        return resultState;
    }

    @RequestMapping(value="addIndustrialAccidentDistribution.action")
    @ResponseBody
    public ResultState addIndustrialAccidentDistribution(IndustrialAccidentDistribution industrialAccidentDistribution ){
        boolean isEdit=industrialAccidentDistribution.getId()==null?false:true;
        ResultState resultState=msProduceSecurityService.add(industrialAccidentDistribution,isEdit);
        return resultState;
    }
}
