package org.linlinjava.jz.admin.web;

import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.linlinjava.jz.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.jz.admin.service.AdminBookOrderService;
import org.linlinjava.jz.core.util.ResponseUtil;
import org.linlinjava.jz.db.domain.CustomerClient;
import org.linlinjava.jz.db.domain.JzBookOrder;
import org.linlinjava.jz.db.service.CustomerClientService;
import org.linlinjava.jz.db.service.JzBookOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author fuxubing
 */
@Api(value = "Admin-bookOrderList-Controller", description = "盒马订单")
@RestController
@RequestMapping("/admin/bookOrder")
@Validated
public class AdminBookOrderController {
    @Resource
    private AdminBookOrderService adminBookOrderService;
    @Resource
    private JzBookOrderService jzBookOrderService;

    @GetMapping("/selectByPhone")
    public Object selectByPhone(@NotBlank @RequestParam String mobile) {

        List<JzBookOrder> jzBookOrders = adminBookOrderService.queryByPhone(mobile);
        return ResponseUtil.ok(jzBookOrders);
    }

    @RequiresPermissionsDesc(menu = {"订单中心", "订单管理"}, button = "查询")
    @GetMapping("/list")
    public Object list(@RequestParam(required = false) String mobile, @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit) {

        List<JzBookOrder> jzBookOrders = adminBookOrderService.querySelective(mobile, page, limit);
        return ResponseUtil.okList(jzBookOrders);
    }


    @GetMapping("/selectByBookOrderNo")
    public Object selectByBookOrderNo(@NotNull @RequestParam Integer bookOrderNo) {
        List<JzBookOrder> jzBookOrders = jzBookOrderService.selectByBookOrderNo(bookOrderNo);
        return ResponseUtil.ok(jzBookOrders);
    }

    @GetMapping("/selectByCustomerId")
    public Object selectByCustomerId(@NotNull @RequestParam Integer customerId) {
        List<JzBookOrder> jzBookOrders = jzBookOrderService.selectByCustomerId(customerId);
        return ResponseUtil.ok(jzBookOrders);
    }

    @GetMapping("/selectByPaymentNo")
    public Object selectByPaymentNo(@NotBlank @RequestParam String paymentNo) {
        List<JzBookOrder> jzBookOrders = jzBookOrderService.selectByPaymentNo(paymentNo);
        return ResponseUtil.ok(jzBookOrders);
    }
}
