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

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;


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

@RestController
@RequestMapping("/new/api/app/orders")
public class AppOrdersController {

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

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

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

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

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

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

    @GetMapping("/list/user")
    @ApiOperation(value = "获取 用户 Orders列表(分页)", response = Result.class)
    public Result listAppOrdersByUserId(@RequestParam(defaultValue = "0") Integer page,
                                        @RequestParam(defaultValue = "0") Integer size,
                                        @ApiParam(value = "用户id") @RequestParam Integer userId) {
        return Result.success(ordersService.queryAllByUserId(page, size, userId));
    }

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

}