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.IMSEcologicalCivilizationService;
import com.lightinit.hsdatashow.service.ms.IMSEconomicDevelopmentService;
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/EcologicalCivilization")
public class MSEcologicalCivilizationController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("水耗、能耗、用地耗、CO2耗","Consume");
        map.put("环境质量指数","EnvironmentalQuality");
        map.put("环境治理投资占GDP比重","EnvironmentalGovernanceGdp");
        map.put("处理达标率","DealWithTheStandard");
        return map;
    }
    @Autowired
    private IMSEcologicalCivilizationService imsEcologicalCivilizationService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/ecologicalCivilization/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/ecologicalCivilization/"+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/ecologicalCivilization/"+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="addConsume.action")
    @ResponseBody
    public ResultState addConsume(Consume consume){
        boolean isEdit=consume.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(consume,isEdit);
        return resultState;
    }

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

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

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

}
