package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.controller.admin.BaseController;
import com.lightinit.hsdatashow.entity.BaseExample;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.model.admin.AverageLifetimeModel;
import com.lightinit.hsdatashow.model.admin.PopulationRegionResultModel;
import com.lightinit.hsdatashow.service.ms.IMSAverageLifetimeService;
import com.lightinit.hsdatashow.service.ms.IMSPopulationRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "/ms/PopulationRegion")
public class MSPopulationRegionController extends BaseController {
    @Autowired
    private IMSPopulationRegionService imsPopulationRegionService;
    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("index.htm")
    public ModelAndView index () {
        ModelAndView modelAndView = new ModelAndView("ms/peopleGrowth/populationRegion/index");
        return modelAndView;
    }

    /**
     * 查询列表
     * @param pageNo
     * @return
     */
    @RequestMapping("list.action")
    public ModelAndView list( @RequestParam(defaultValue = "1") int pageNo) {
        ModelAndView modelAndView = new ModelAndView("ms/peopleGrowth/populationRegion/list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List<PopulationRegionResultModel> outputModel = imsPopulationRegionService.queryList(pager);
        pager.setTotal(imsPopulationRegionService.queryCount(pager));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager", pager);
        return modelAndView;
    }

    /**
     * 删除方法
     * @param id
     * @return
     */
    @RequestMapping(value = "del.action/{id}")
    @ResponseBody
    public ResultState delete(@PathVariable long id){
        ResultState<Long> resultState = imsPopulationRegionService.delete(id);
        return resultState;
    }

    /**
     * 添加方法
     * @param inputModel
     * @return
     */
    @RequestMapping(value = "add.action")
    @ResponseBody
    public ResultState doAdd(PopulationRegionResultModel inputModel){
        ResultState resultState = imsPopulationRegionService.add(inputModel);
        return resultState;
    }

    /**
     * 跳转添加页面
     * @return
     */
    @RequestMapping(value = "add.htm")
    public ModelAndView add(){
        ModelAndView modelAndView = new ModelAndView("ms/peopleGrowth/populationRegion/add");
        return modelAndView;
    }
    /**
     * 跳转修改页面
     * @return
     */
    @RequestMapping(value = "edit.htm/{id}")
    public ModelAndView edit(@PathVariable long id){
        ModelAndView modelAndView = new ModelAndView("ms/peopleGrowth/populationRegion/edit");
        PopulationRegionResultModel model = imsPopulationRegionService.edit(id);
        modelAndView.addObject("model",model);
        return modelAndView;
    }

    /**
     * 编辑方法
     * @param inputModel
     * @return
     */
    @RequestMapping(value = "doEdit.action")
    @ResponseBody
    public ResultState doEdit(PopulationRegionResultModel inputModel){
        ResultState resultState = imsPopulationRegionService.doEdit(inputModel);
        return resultState;
    }

}
