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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolTeachingJournal;
import cn.iocoder.yudao.module.jx.payment.entity.DriveSchoolBooking;
import cn.iocoder.yudao.module.jx.service.DriveSchoolBookingService;
import cn.iocoder.yudao.module.jx.utils.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预约Controller
 *
 * @author ruoyi
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/system/booking")
public class DriveSchoolBookingController extends BaseController
{
    @Autowired
    private DriveSchoolBookingService driveSchoolBookingService;

    /**
     * 查询预约列表
     */
    @GetMapping("/list")
    public CommonResult<IPage<?>> list(DriveSchoolBooking driveSchoolBooking)
    {
        Page<DriveSchoolBooking> page = new Page<>(driveSchoolBooking.getPageNum(), driveSchoolBooking.getPageSize());
        IPage<DriveSchoolBooking> driveSchoolBookingIPage = driveSchoolBookingService.selectDriveSchoolBookingList(driveSchoolBooking, page);
        return success(driveSchoolBookingIPage);
        //return getDataTable(list);
    }
    /**
     * 查询预约列表
     */
    @GetMapping("/listByUser")
    public CommonResult listByUser(DriveSchoolBooking driveSchoolBooking)
    {

        List<DriveSchoolBooking> list = driveSchoolBookingService.listByUser(driveSchoolBooking);
        return CommonResult.success(list);
    }
    /**
     * 导出预约列表
     */
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, DriveSchoolBooking driveSchoolBooking)
//    {
//        List<DriveSchoolBooking> list = driveSchoolBookingService.selectDriveSchoolBookingList(driveSchoolBooking);
//        ExcelUtil<DriveSchoolBooking> util = new ExcelUtil<DriveSchoolBooking>(DriveSchoolBooking.class);
//        util.exportExcel(response, list, "预约数据");
//    }

    /**
     * 获取预约详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(driveSchoolBookingService.selectDriveSchoolBookingById(id));
    }

    /**
     * 新增预约
     */
    @PostMapping
    public CommonResult add(@RequestBody DriveSchoolBooking driveSchoolBooking)
    {
        return toAjax(driveSchoolBookingService.insertDriveSchoolBooking(driveSchoolBooking));
    }

    /**
     * 修改预约
     */
    @PutMapping
    public CommonResult edit(@RequestBody DriveSchoolBooking driveSchoolBooking)
    {
        return toAjax(driveSchoolBookingService.updateDriveSchoolBooking(driveSchoolBooking));
    }

    /**
     * 删除预约
     */
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driveSchoolBookingService.deleteDriveSchoolBookingByIds(ids));
    }
}
