package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.controller.admin.BaseController;
import com.lightinit.hsdatashow.entity.BaseExample;
import com.lightinit.hsdatashow.entity.Greening;
import com.lightinit.hsdatashow.entity.TrafficTravel;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSGreeningService;
import com.lightinit.hsdatashow.service.ms.IMSTrafficTravelService;
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/greening")
public class MSGreeningController extends BaseController {
    @Autowired
    private IMSGreeningService imsGreeningService;
    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("index.htm")
    public ModelAndView index () {
        ModelAndView modelAndView = new ModelAndView("ms/publicService/greening/index");
        return modelAndView;
    }

    /**
     * 查询列表
     * @param pageNo
     * @return
     */
    @RequestMapping("list.action")
    public ModelAndView list( @RequestParam(defaultValue = "1") int pageNo) {
        ModelAndView modelAndView = new ModelAndView("ms/publicService/greening/list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List<Greening> outputModel = imsGreeningService.queryList(pager);
        pager.setTotal(imsGreeningService.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 = imsGreeningService.delete(id);
        return resultState;
    }

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

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

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

}
