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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCoach;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolReservationCourse;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolCoachMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolInfoService;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolReservationCourseService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 预约练车Controller - 小程序
 *
 * @author ruoyi
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/drivingSchool/system/reservationCourse")
public class AppDriveSchoolReservationCourseController extends BaseController
{
    @Resource
    private IDriveSchoolReservationCourseService driveSchoolReservationCourseService;


    /**
     * 查询预约练车列表
     */
    @GetMapping("/list")
    @TenantIgnore
    public CommonResult<IPage<?>> list(DriveSchoolReservationCourse driveSchoolReservationCourse)
    {
        Page<DriveSchoolReservationCourse> page = new Page<>(driveSchoolReservationCourse.getPageNum(), driveSchoolReservationCourse.getPageSize());
        //获取当前登陆人
        driveSchoolReservationCourse.setUserId(SecurityFrameworkUtils.getLoginUserId());
        IPage<DriveSchoolReservationCourse> driveSchoolReservationCourseIPage = driveSchoolReservationCourseService.queryUserRecord(driveSchoolReservationCourse, page);
        return CommonResult.success(driveSchoolReservationCourseIPage);
    }

    @GetMapping("/listUser")
    public CommonResult listUser(DriveSchoolReservationCourse driveSchoolReservationCourse)
    {
        Page<DriveSchoolReservationCourse> page = new Page<>(driveSchoolReservationCourse.getPageNum(), 9999);
        driveSchoolReservationCourse.setUserId(SecurityFrameworkUtils.getLoginUserId());
        IPage<DriveSchoolReservationCourse> driveSchoolReservationCourseIPage = driveSchoolReservationCourseService.selectDriveSchoolReservationCourseList(driveSchoolReservationCourse, page);
        List<DriveSchoolReservationCourse> records = driveSchoolReservationCourseIPage.getRecords();
        return CommonResult.success(records);
    }

    @GetMapping("/getListUser")
    public CommonResult getListUser(DriveSchoolReservationCourse driveSchoolReservationCourse)
    {
        List<DriveSchoolReservationCourse> list = driveSchoolReservationCourseService.selectDriveSchoolReservationGetListUser(driveSchoolReservationCourse);

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

    /**
     * 新增预约练车
     */
    @PostMapping
    @TenantIgnore
    public CommonResult add(@RequestBody DriveSchoolReservationCourse driveSchoolReservationCourse) throws Exception {
        driveSchoolReservationCourse.setUserId(SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(driveSchoolReservationCourseService.insertAppReservationCourse(driveSchoolReservationCourse));
    }

    /**
     * 修改预约练车
     */
    //@Log(title = "预约练车", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody DriveSchoolReservationCourse driveSchoolReservationCourse)
    {
        return toAjax(driveSchoolReservationCourseService.updateDriveSchoolReservationCourse(driveSchoolReservationCourse));
    }
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driveSchoolReservationCourseService.deleteDriveSchoolReservationCourseByIds(ids));
    }
}
