package com.hc.web.controller.browser.back;

import com.hc.business.model.ZccmOrders;
import com.hc.business.service.ZccmOrdersService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 订单表(ZccmOrders)表控制层
 *
 * @author java
 * @since 2020-11-26 16:46:48
 */

@RestController
@RequestMapping("/new/api/back/orders")
public class BackOrdersController {

    /**
     * 服务对象
     */
    private final ZccmOrdersService ordersService;

    public BackOrdersController(ZccmOrdersService ordersService) {
        this.ordersService = ordersService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 ZccmOrders", response = Result.class)
    public Result selectBackDetail(@PathVariable("id") Integer id) {
        return Result.success(this.ordersService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmOrders", response = Result.class)
    public Result addBackOrders(@Valid @RequestBody ZccmOrders orders) {
        return Result.success(ordersService.insert(orders));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmOrders", response = Result.class)
    public Result updateBackOrders(@RequestBody ZccmOrders orders) {
        return Result.success(ordersService.update(orders));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 ZccmOrders", response = Result.class)
    public Result deleteBackOrders(@PathVariable("id") Integer id) {
        return Result.success(ordersService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 ZccmOrders列表(分页)", response = Result.class)
    public Result listBackOrders(@RequestParam(defaultValue = "0") Integer page,
                                 @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(ordersService.queryAllByLimit(page, size));
    }

    @GetMapping("/class/list")
    @ApiOperation(value = "依据班次id 获取 ZccmOrders列表(分页)", response = Result.class)
    public Result listBackOrdersByClassId(@ApiParam(value = "班次id") @RequestParam Integer classId,
                                          @RequestParam(defaultValue = "0") Integer page,
                                          @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(ordersService.queryAllByClassId(page, size, classId));
    }

    @GetMapping("/className")
    @ApiOperation(value = "依据班次名称 获取 ZccmOrders列表(分页)", response = Result.class)
    public Result listBackOrdersByClassName(@ApiParam(value = "班次名称") @RequestParam String className,
                                            @RequestParam(defaultValue = "0") Integer page,
                                            @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(ordersService.queryAllByClassName(page, size, className));
    }

    @GetMapping("/status/list")
    @ApiOperation(value = "依据状态 获取 ZccmOrders列表(分页)", response = Result.class)
    public Result listBackOrdersByStatus(@ApiParam(value = "状态") @RequestParam Integer status,
                                         @RequestParam(defaultValue = "0") Integer page,
                                         @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(ordersService.queryAllByStatus(page, size, status));
    }

    @GetMapping("/list/userInvoices")
    @ApiOperation(value = "获取 发票 ZccmOrders列表(分页)", response = Result.class)
    public Result listBackOrdersByUserInvoicesId(@ApiParam(value = "发票id") @RequestParam Integer userInvoicesId) {
        return Result.success(ordersService.queryByUserInvoicesId(userInvoicesId));
    }

    @GetMapping("/create/no")
    @ApiOperation(value = "创建一条订单编号", response = Result.class)
    public Result createZccmOrderNo() {
        return Result.success(ordersService.createOrderNo());
    }

    @GetMapping("/count")
    @ApiOperation(value = "获取 订单金额统计数据", response = Result.class)
    public Result queryZccmOrderCount() {
        return Result.success(ordersService.queryUserCount());
    }

    @GetMapping("/count/no")
    @ApiOperation(value = "获取 订单数量统计数据", response = Result.class)
    public Result queryZccmOrderCountNo() {
        return Result.success(ordersService.countOrderTotal());
    }

    @GetMapping("/no")
    @ApiOperation(value = "依据订单编号获取 ZccmOrders", response = Result.class)
    public Result selectBackOrders(@ApiParam(value = "订单编号") @RequestParam String orderNo) {
        return Result.success(this.ordersService.queryByOrderNo(orderNo.trim()));
    }

}