package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.entity.Refund;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.RefundSearchModel;
import com.lightinit.hsdataplatform.service.admin.IOrderService;
import com.lightinit.hsdataplatform.service.admin.IRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
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 javax.validation.Valid;
import java.util.List;

@Controller
@RequestMapping("/admin/refund")
public class RefundController extends BaseController{
    @Autowired
    private IRefundService iRefundService;
    @Autowired
    private IOrderService iOrderService;

    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("index.htm")
    public ModelAndView index () {
        ModelAndView modelAndView = new ModelAndView("admin/refund/index");
        return modelAndView;
    }

    /**
     * 查询列表
     * @param refundSearchModel
     * @param pageNo
     * @return
     */
    @RequestMapping("list.action")
    public ModelAndView list(RefundSearchModel refundSearchModel, @RequestParam(defaultValue = "1") int pageNo) {
        ModelAndView modelAndView = new ModelAndView("admin/refund/list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List<Refund> outputModel = iRefundService.queryList(refundSearchModel, pager);
        pager.setTotal(iRefundService.queryCount(refundSearchModel));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager", pager);
        return modelAndView;
    }

    /**
     * 跳转添加页面
     * @return
     */
    @RequestMapping(value = "add.htm")
    public ModelAndView add(){
        ModelAndView modelAndView = new ModelAndView("admin/refund/add");
        return modelAndView;
    }

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

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

    /**
     * 跳转修改页
     * @param id
     * @return
     */
    @RequestMapping(value = "update.htm/{id}")
    public ModelAndView edit(@PathVariable long id){
        ModelAndView modelAndView = new ModelAndView("admin/refund/edit");
        modelAndView.addObject("busiModel", iRefundService.queryOne(id));
        return modelAndView;
    }

    /**
     * 修改
     * @param inputModel
     * @return
     */
    @RequestMapping(value = "doEdit.action")
    @ResponseBody
    public ResultState doEdit(Refund inputModel){

        ResultState resultState = iRefundService.edit(inputModel);
        return resultState;
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @RequestMapping(value = "toDetail.htm/{id}")
    @ResponseBody
    public ModelAndView toDetail(@PathVariable long id){
        ModelAndView modelAndView = new ModelAndView("admin/refund/detail");
        modelAndView.addObject("busiModel", iRefundService.detail(id));
        return modelAndView;
    }
}
