package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSLivelihoodImproveService;
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/livelihoodImprove")
public class MSLivelihoodImproveController {

    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("城镇失业率","Unemployment");
        map.put("基尼系数及恩格尔系数","Coefficient");
        map.put("城乡居民收入占GDP比重","UrbanRuralGdp");
        map.put("城乡居民收入对比","UrbanRuralContrast");
        map.put("生活质量画像","Quality");
        return map;
    }
    @Autowired
    private IMSLivelihoodImproveService imsLivelihoodImproveService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/livelihoodImprove/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

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

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

    @RequestMapping(value="addUnemployment.action")
    @ResponseBody
    public ResultState addUnemployment(Unemployment unemployment){
        boolean isEdit=unemployment.getId()==null?false:true;
        ResultState resultState=imsLivelihoodImproveService.add(unemployment,isEdit);
        return resultState;
    }

    @RequestMapping(value="addCoefficient.action")
    @ResponseBody
    public ResultState addCoefficient(Coefficient coefficient){
        boolean isEdit=coefficient.getId()==null?false:true;
        ResultState resultState=imsLivelihoodImproveService.add(coefficient,isEdit);
        return resultState;
    }

    @RequestMapping(value="addUrbanRuralGdp.action")
    @ResponseBody
    public ResultState addUrbanRuralGdp(UrbanRuralGdp urbanRuralGdp){
        boolean isEdit=urbanRuralGdp.getId()==null?false:true;
        ResultState resultState=imsLivelihoodImproveService.add(urbanRuralGdp,isEdit);
        return resultState;
    }
     @RequestMapping(value="addUrbanRuralContrast.action")
     @ResponseBody
     public ResultState addUrbanRuralContrast(UrbanRuralContrast urbanRuralContrast){
        boolean isEdit=urbanRuralContrast.getId()==null?false:true;
        ResultState resultState=imsLivelihoodImproveService.add(urbanRuralContrast,isEdit);
        return resultState;
     }

     @RequestMapping(value="addQuality.action")
     @ResponseBody
     public ResultState addQuality(Quality quality){
        boolean isEdit=quality.getId()==null?false:true;
        ResultState resultState=imsLivelihoodImproveService.add(quality,isEdit);
        return resultState;
     }


}
