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 com.lightinit.hsdatashow.service.ms.IMSProgressService;
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/progress")
public class MSProgressController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("人均基本公共服务支出","ServiceExpenditure");
        map.put("平均受教育年限","YearsEducation");
        map.put("社会保障","SocialSecurity");
        map.put("五岁以下儿童死亡率","ChildMortality");
        map.put("社会安全指数","SocialSafety");
        return map;
    }
    @Autowired
    private IMSProgressService imsProgressService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/progress/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

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

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

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

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

    @RequestMapping(value="addSocialSecurity.action")
    @ResponseBody
    public ResultState addGdpOccupationRatio(SocialSecurity socialSecurity){
        boolean isEdit=socialSecurity.getId()==null?false:true;
        ResultState resultState=imsProgressService.add(socialSecurity,isEdit);
        return resultState;
    }
    @RequestMapping(value="addChildMortality.action")
    @ResponseBody
    public ResultState addLaborProduction(ChildMortality childMortality){
        boolean isEdit=childMortality.getId()==null?false:true;
        ResultState resultState=imsProgressService.add(childMortality,isEdit);
        return resultState;
    }

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

}
