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

import com.hc.business.model.ZccmUserInvoices;
import com.hc.business.service.ZccmUserInvoicesService;
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;


/**
 * 用户发票表(ZccmUserInvoices)表控制层
 *
 * @author java
 * @since 2020-12-02 10:50:41
 */

@RestController
@RequestMapping("/new/api/back/userInvoices")
public class BackUserInvoicesController {

    /**
     * 服务对象
     */
    private final ZccmUserInvoicesService userInvoicesService;

    public BackUserInvoicesController(ZccmUserInvoicesService userInvoicesService) {
        this.userInvoicesService = userInvoicesService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmUserInvoices", response = Result.class)
    public Result addBackUserInvoices(@Valid @RequestBody ZccmUserInvoices userInvoices) {
        return Result.success(userInvoicesService.insert(userInvoices));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmUserInvoices", response = Result.class)
    public Result updateBackUserInvoices(@RequestBody ZccmUserInvoices userInvoices) {
        return Result.success(userInvoicesService.update(userInvoices));
    }

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

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

    @GetMapping("/user/{userId}")
    @ApiOperation(value = "获取用户发票信息", response = Result.class)
    public Result queryDetailByZccmUserId(@ApiParam(value = "用户id") @PathVariable("userId") Integer userId) {
        return Result.success(userInvoicesService.queryDetailByUserId(userId));
    }

    @GetMapping("/class/{classId}")
    @ApiOperation(value = "获取班次发票信息", response = Result.class)
    public Result queryDetailByClassId(@ApiParam(value = "班次id") @PathVariable("classId") Integer classId) {
        return Result.success(userInvoicesService.queryByClassId(classId));
    }

    @GetMapping("/status")
    @ApiOperation(value = "获取用户发票信息", response = Result.class)
    public Result queryDetailByStatus(@ApiParam(value = "状态") @RequestParam Integer status) {
        return Result.success(userInvoicesService.queryByStatus(status));
    }


}