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.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/economicDevelopment")
public class MSEconomicDevelopmentController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("GDP","Gdp");
        map.put("人均GDP","PerCapitaGdp");
        map.put("GDp占比","GdpOccupationRatio");
        map.put("全社会劳动生产率","LaborProduction");
        map.put("城镇化率","Urbanization");
        return map;
    }
    @Autowired
    private IMSEconomicDevelopmentService imsEconomicDevelopmentService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/economicDevelopment/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

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

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

    @RequestMapping(value="addGdp.action")
    @ResponseBody
    public ResultState addGdp(Gdp gdp){
        boolean isEdit=gdp.getId()==null?false:true;
        ResultState resultState=imsEconomicDevelopmentService.add(gdp,isEdit);
        return resultState;
    }

    @RequestMapping(value="addPerCapitaGdp.action")
    @ResponseBody
    public ResultState addPerCapitaGdp(PerCapitaGdp perCapitaGdp){
        boolean isEdit=perCapitaGdp.getId()==null?false:true;
        ResultState resultState=imsEconomicDevelopmentService.add(perCapitaGdp,isEdit);
        return resultState;
    }

    @RequestMapping(value="addGdpOccupationRatio.action")
    @ResponseBody
    public ResultState addGdpOccupationRatio(GdpOccupationRatio gdpOccupationRatio){
        boolean isEdit=gdpOccupationRatio.getId()==null?false:true;
        ResultState resultState=imsEconomicDevelopmentService.add(gdpOccupationRatio,isEdit);
        return resultState;
    }
    @RequestMapping(value="addLaborProduction.action")
    @ResponseBody
    public ResultState addLaborProduction(LaborProduction laborProduction){
        boolean isEdit=laborProduction.getId()==null?false:true;
        ResultState resultState=imsEconomicDevelopmentService.add(laborProduction,isEdit);
        return resultState;
    }

    @RequestMapping(value="addUrbanization.action")
    @ResponseBody
    public ResultState addUrbanization(Urbanization urbanization){
        boolean isEdit=urbanization.getId()==null?false:true;
        ResultState resultState=imsEconomicDevelopmentService.add(urbanization,isEdit);
        return resultState;
    }

}
