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

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.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


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

@RestController
@RequestMapping("/new/api/front/orders")
public class FrontOrdersController {

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

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

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

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

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

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


    @GetMapping("/list/user")
    @ApiOperation(value = "获取 用户 ZccmOrders列表(分页)", response = Result.class)
    public Result listFrontOrdersByUserId(@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 createZccmOrderNo() {
        return Result.success(ordersService.createOrderNo());
    }


}