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.core.page.PageDomain;
import cn.iocoder.yudao.module.jx.core.page.TableSupport;
import cn.iocoder.yudao.module.jx.core.text.HttpStatus;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCheck;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCoach;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolCoachService;
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;
import java.util.stream.Collectors;


/**
 * 驾校教练Controller
 *
 * @author ruoyi
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/drivingSchool/system/schoolCoach")
public class DriveSchoolCoachController extends BaseController
{
    @Autowired
    private IDriveSchoolCoachService driveSchoolCoachService;

    @GetMapping("/findSelfJlListByJxId")
    public List<DriveSchoolCoach> findSelfJlListByJxId(Long jxId) {
        return driveSchoolCoachService.findSelfJlListByJxId(jxId);
    }

    /**
     * 查询驾校教练列表
     */
    @GetMapping("/list")
    public CommonResult list(DriveSchoolCoach driveSchoolCoach)
    {
        List<DriveSchoolCoach> list = driveSchoolCoachService.selectDriveSchoolCoachListAll(driveSchoolCoach);
        return CommonResult.success(list);
    }

//    @GetMapping("/list")
//    public CommonResult<IPage<?>> lists(DriveSchoolCoach driveSchoolCoach)
//    {
//        Page<DriveSchoolCoach> page = new Page<>(driveSchoolCoach.getPageNum(), driveSchoolCoach.getPageSize());
//
//        IPage<DriveSchoolCoach> driveSchoolCoachIPage = driveSchoolCoachService.selectDriveSchoolCoachList(driveSchoolCoach, page);
//        return CommonResult.success(driveSchoolCoachIPage);
////        PageDomain pageDomain = TableSupport.buildPageRequest();
////        Integer pageNum = pageDomain.getPageNum();
////        Integer pageSize = 20;
////
////        int num = 100;
////        list = list.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
////        CommonResult<IPage<?>> rspData = new CommonResult<IPage<?>>();
////        rspData.setCode(HttpStatus.SUCCESS);
////        rspData.set(list);
////        rspData.setTotal(num);
////        return rspData;
//    }

    /**
     * 导出驾校教练列表
     */
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, DriveSchoolCoach driveSchoolCoach)
//    {
//        List<DriveSchoolCoach> list = driveSchoolCoachService.selectDriveSchoolCoachList(driveSchoolCoach);
//        ExcelUtil<DriveSchoolCoach> util = new ExcelUtil<DriveSchoolCoach>(DriveSchoolCoach.class);
//        util.exportExcel(response, list, "驾校教练数据");
//    }

    /**
     * 获取驾校教练详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(driveSchoolCoachService.selectDriveSchoolCoachById(id));
    }

    /**
     * 新增驾校教练
     */
    @PostMapping
    public CommonResult add(@RequestBody DriveSchoolCoach driveSchoolCoach)
    {
        driveSchoolCoachService.insertDriveSchoolCoach(driveSchoolCoach);
        return success("新增成功！");
    }

    /**
     * 修改驾校教练
     */
    @PutMapping
    public CommonResult edit(@RequestBody DriveSchoolCoach driveSchoolCoach)
    {
        return success(driveSchoolCoachService.updateDriveSchoolCoach(driveSchoolCoach));
    }

    /**
     * 删除驾校教练
     */
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driveSchoolCoachService.deleteDriveSchoolCoachByIds(ids));
    }
}
