package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.controller.admin.BaseController;
import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSAtmosphereService;
import com.lightinit.hsdatashow.service.ms.IMSEcologicalCivilizationService;
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;

@Controller
@RequestMapping(value = "/ms/atmosphere")
public class MSAtmosphereController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("空气质量指数","AtmosphereIndex");
        map.put("机动车尾气排放情况","AtmosphereEmission");
        map.put("全年空气质量状况","AtmosphereYear");
        map.put("城市气化率","AtmosphereGasification");
        map.put("重点污染源工业废气排放","AtmosphereIndustry");
        return map;
    }
    @Autowired
    private IMSAtmosphereService imsEcologicalCivilizationService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/atmosphere/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

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

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

    @RequestMapping(value="addAtmosphereIndex.action")
    @ResponseBody
    public ResultState addAtmosphereIndex(AtmosphereIndex atmosphereIndex){
        boolean isEdit=atmosphereIndex.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(atmosphereIndex,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAtmosphereYear.action")
    @ResponseBody
    public ResultState addAtmosphereYear(AtmosphereYear atmosphereYear){
        boolean isEdit=atmosphereYear.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(atmosphereYear,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAtmosphereIndustry.action")
    @ResponseBody
    public ResultState addAtmosphereIndustry(AtmosphereIndustry atmosphereIndustry){
        boolean isEdit=atmosphereIndustry.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(atmosphereIndustry,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAtmosphereGasification.action")
    @ResponseBody
    public ResultState addAtmosphereGasification(AtmosphereGasification atmosphereGasification){
        boolean isEdit=atmosphereGasification.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(atmosphereGasification,isEdit);
        return resultState;
    }

    @RequestMapping(value="addAtmosphereEmission.action")
    @ResponseBody
    public ResultState addAtmosphereEmission(AtmosphereEmission atmosphereEmission){
        boolean isEdit=atmosphereEmission.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(atmosphereEmission,isEdit);
        return resultState;
    }

}
