package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.dictionary.DicCompanyAuthResult;
import com.lightinit.hsdataplatform.dictionary.DicOrderState;
import com.lightinit.hsdataplatform.dictionary.DicOrderType;
import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.model.admin.*;
import com.lightinit.hsdataplatform.service.admin.IOrderService;
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.servlet.ModelAndView;

import java.util.List;

/**
 * @Author: sunxiang
 * @Date: 2018/6/6 13:27
 * @Description:
 **/
@Controller
@RequestMapping("/admin/order_mgr")
public class OrderMgrController {

    @Autowired
    private IOrderService orderServiceImpl;
    @RequestMapping("/index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("/admin/order_mgr/index");
        modelAndView.addObject("dicOrderState", DicOrderState.getInstance().getDicMap().clone());
        modelAndView.addObject("dicOrderType", DicOrderType.getInstance().getDicMap().clone());
        return modelAndView;
    }

    @RequestMapping("list.action")
    public ModelAndView list(OrderSearchModel inputModel, @RequestParam(defaultValue = "1") int  pageNo){
        ModelAndView modelAndView = new ModelAndView("admin/order_mgr/list");
        BaseExample.Page pager = new BaseExample.Page(pageNo,10);
        inputModel.setPage(pager);
        List<OrderListModel> outputModel=orderServiceImpl.queryOrderList(inputModel);
        pager.setTotal(orderServiceImpl.queryOrderCount(inputModel));
        modelAndView.addObject("list",outputModel);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }



    /*
    *@Description 查询订单下的详细购物项
    *@Param
    *@Date 2018/6/6
    *@return
    **/
    @RequestMapping("detail.htm/{id}")
    public ModelAndView detail(@PathVariable Long id){
        ModelAndView modelAndView = new ModelAndView("admin/order_mgr/detail");
        OrderDetailModel orderDetailModel=orderServiceImpl.queryOrderDetail(id);
        modelAndView.addObject("busiModel",orderDetailModel);
        return modelAndView;
    }
}
