package com.ruoyi.database.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.database.domain.ParkingBillInfo;
import com.ruoyi.database.service.ParkingBillInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/ParkingBillInfo")
@Api(tags = "订单管理")
@RestController
@RequiredArgsConstructor
public class ParkingBillInfoController extends BaseController {

    private final ParkingBillInfoService parkingBillInfoService;

    @GetMapping
    @ApiOperation("查询订单管理")
    public TableDataInfo<ParkingBillInfo> list(ParkingBillInfo ParkingBillInfo) {
        startPage();
        QueryWrapper<ParkingBillInfo> queryWrapper = new QueryWrapper<>(ParkingBillInfo);
        List<ParkingBillInfo> list = parkingBillInfoService.list(queryWrapper);
        long size = parkingBillInfoService.count(queryWrapper);
        return getDataTableEnhance(list,size);
    }

    @PostMapping
    @ApiOperation("新增订单管理")
    @Log(title = "订单管理表", businessType = BusinessType.INSERT)
    public AjaxResult insert(@RequestBody ParkingBillInfo ParkingBillInfo) {
        return toAjax(parkingBillInfoService.save(ParkingBillInfo));
    }

    @PutMapping
    @ApiOperation("修改订单管理")
    @Log(title = "订单管理表", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody ParkingBillInfo ParkingBillInfo) {
        return toAjax(parkingBillInfoService.updateById(ParkingBillInfo));
    }

    @DeleteMapping
    @ApiOperation("删除订单管理")
    @Log(title = "订单管理表", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return toAjax(parkingBillInfoService.removeByIds(idList));
    }
}
