package cn.iocoder.yudao.module.booking.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.booking.entity.DlRepairBooking;
import cn.iocoder.yudao.module.booking.service.DlRepairBookingService;
import cn.iocoder.yudao.module.booking.vo.DlRepairBookingReqVO;
import cn.iocoder.yudao.module.booking.vo.DlRepairBookingRespVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 维修预约表(DlRepairBooking)表控制层
 *
 * @author 小李
 * @date 10:19 2024/9/23
 **/
@RestController
@RequestMapping("/repair/booking")
public class DlRepairBookingController {
    /**
     * 服务对象
     */
    @Resource
    private DlRepairBookingService dlRepairBookingService;

    /**
     * 维修预约表 新增、修改
     *
     * @author 小李
     * @date 10:21 2024/9/23
     * @param repairBookingRespVO 预约对象
     **/
    @PostMapping("/update")
    @Operation(summary = "维修预约表 新增、修改")
    public CommonResult<?> updateBooking(@RequestBody DlRepairBookingRespVO repairBookingRespVO) {
        dlRepairBookingService.updateBooking(repairBookingRespVO);
        return CommonResult.ok();
    }

    /**
     * 维修预约表 删除
     *
     * @author 小李
     * @date 10:26 2024/9/23
     * @param id 预约记录id
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "维修预约表 删除")
    public CommonResult<?> deleteBooking(@RequestParam("id") String id) {
        dlRepairBookingService.deleteBooking(id);
        return CommonResult.ok();
    }


    /**
     * 维修预约表 分页
     *
     * @author 小李
     * @date 10:31 2024/9/23
     * @param repairBookingReqVO 请求对象
     * @param pageNo 页码
     * @param pageSize 条数
     **/
    @GetMapping("/page")
    @Operation(summary = "维修预约表 分页")
    public CommonResult<?> getBookingPage(DlRepairBookingReqVO repairBookingReqVO,
                                          @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        Page<DlRepairBooking> page = new Page<>(pageNo, pageSize);
        return success(dlRepairBookingService.getBookingPage(repairBookingReqVO, page));
    }

    /**
     * 维修预约表 查询单个
     *
     * @author 小李
     * @date 10:38 2024/9/23
     * @param id 预约记录id
     **/
    @GetMapping("/get")
    @Operation(summary = "维修预约表 查询单个")
    public CommonResult<?> getBookingById(@RequestParam("id") String id){
        return success(dlRepairBookingService.getBookingById(id));
    }

    @GetMapping("/list")
    @Operation(summary = "维修预约表 不分页")
    public CommonResult<?> getBookingList(@RequestParam("userId")Integer userId){
        return success(dlRepairBookingService.list(new LambdaQueryWrapper<DlRepairBooking>()
                .eq(DlRepairBooking::getUserId,userId)
                .orderByDesc(DlRepairBooking::getBookingTime)));
    }
}

