package com.fdkankan.platform.order.controller.manager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.platform.order.service.IOrderService;
import com.fdkankan.platform.user.request.RequestOrder;
import com.fdkankan.platform.user.service.IManagerService;
import com.fdkankan.platform.user.vo.ResponseOrder;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台管理-订单管理
 */
@Log4j2
@RestController
@RequestMapping("/service/platform/manager/order")
public class ManagerOrderController extends BaseController {

    @Autowired
    private IManagerService managerService;
    @Autowired
    private IOrderService orderService;

    /**
     * 获取订单列表
     * type             类型
     * orderSn          订单编号
     * phoneNum         手机号码
     * expressNum       快递码
     * startDate        开始时间
     * endDate          结束时间
     * pageNum          分页
     * pageSize         每页大小
     */
    @RequestMapping(value = {"/list"}, method = RequestMethod.POST)
    public Page<ResponseOrder> list(@RequestBody RequestOrder param) throws Exception {
        return orderService.getPageVoByParam(param);
    }

    /**
     * 获取订单详情
     * orderId          订单id
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    public ResponseOrder detail(@RequestBody RequestOrder param) throws Exception {
        return orderService.getOrderDetail(param.getOrderId());
    }

    /**
     * 订单发货确认
     * orderId          订单id
     * orderItemIds     订单详情id，多个用“,”分开
     * expressName      快递公司
     * expressNum       快递码
     */
    @RequestMapping(value = "/confirmDelivery", method = RequestMethod.POST)
    public String confirmDelivery(@RequestBody RequestOrder param) throws Exception {
        return orderService.confirmOrderDelivery(param);
    }

    /**
     * 订单发货确认
     * type         类型
     * orderSn      订单编号
     * phoneNum     手机号码
     * expressNum   快递码
     * startDate    开始时间
     * endDate      结束时间
     */
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void export(String type, String orderSn, String phoneNum, String expressNum, String startDate, String endDate) throws Exception {
        RequestOrder param = new RequestOrder();
        param.setType(type);
        param.setOrderSn(orderSn);
        param.setPhoneNum(phoneNum);
        param.setExpressNum(expressNum);
        param.setStartDate(startDate);
        param.setEndDate(endDate);
        managerService.export(param, request, response);
    }


}
