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


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCoach;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolExamPass;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolCoachMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolExamPassService;
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;

/**
 * 考试通过Controller
 *
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/drivingSchool/system/pass")
public class DriveSchoolExamPassController extends BaseController
{
    @Autowired
    private IDriveSchoolExamPassService driveSchoolExamPassService;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询考试通过列表
     */
    @GetMapping("/list")
    public CommonResult<IPage<?>> list(DriveSchoolExamPass driveSchoolExamPass)
    {
        Page<DriveSchoolExamPass> page = new Page<>(driveSchoolExamPass.getPageNum(), driveSchoolExamPass.getPageSize());
        IPage<DriveSchoolExamPass> driveSchoolExamPassIPage = driveSchoolExamPassService.selectDriveSchoolExamPassList(driveSchoolExamPass, page);
        return CommonResult.success(driveSchoolExamPassIPage);
        //return getDataTable(list);
    }

    /**
     * 查询教练工资
     */
    @GetMapping("/getBalanceList")
    public CommonResult<IPage<?>> getBalanceList(DriveSchoolExamPass driveSchoolExamPass)
    {
        Page<DriveSchoolExamPass> page = new Page<>(driveSchoolExamPass.getPageNum(), driveSchoolExamPass.getPageSize());
        IPage<DriveSchoolExamPass> balanceList = driveSchoolExamPassService.getBalanceList(driveSchoolExamPass, page);
        return CommonResult.success(balanceList);
        //return getDataTable(list);
    }

    /**
     * 查询教练工资app
     */
    @GetMapping("/getBalanceByCoachId")
    public CommonResult getBalanceByCoachId(DriveSchoolExamPass driveSchoolExamPass)
    {
        DriveSchoolExamPass driveSchoolExamPasses = driveSchoolExamPassService.getBalanceByCoachId(driveSchoolExamPass);
        return CommonResult.success(driveSchoolExamPasses);
    }

    /**
     * 查询教练工资App
     */
    @GetMapping("/getBalanceApp")
    public CommonResult getBalanceApp(DriveSchoolExamPass driveSchoolExamPass)
    {
        DriveSchoolExamPass driveSchoolExamPass1 = driveSchoolExamPassService.getBalanceApp(driveSchoolExamPass);
        return CommonResult.success(driveSchoolExamPass1);
    }

    /**
     * 查询教练工资
     */
    @GetMapping("/getTime")
    public CommonResult getTime(DriveSchoolExamPass driveSchoolExamPass)
    {
        DriveSchoolExamPass driveSchoolExamPass1 = driveSchoolExamPassService.getTime(driveSchoolExamPass);
        return CommonResult.success(driveSchoolExamPass1);
    }

    /**
     * 结算教练工资
     */
    //@Log(title = "考试通过", businessType = BusinessType.UPDATE)
    @PutMapping("pay")
    public CommonResult pay(@RequestBody DriveSchoolExamPass driveSchoolExamPass)
    {
        return toAjax(driveSchoolExamPassService.pay(driveSchoolExamPass));
    }

//    @Resource
//    private SysUserMapper sysUserMapper;

    @Resource
    private DriveSchoolCoachMapper driveSchoolCoachMapper;

    /**
     * 账单管理
     */
    @GetMapping("/checkList")
    public CommonResult<IPage<?>> checkList(DriveSchoolExamPass driveSchoolExamPass)
    {
        //获取教练id
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO sysUser = userApi.getUser(userId);
//        Long userId = SecurityFrameworkUtils.getLoginUserId();
//        SysUser sysUser = sysUserMapper.selectUserById(userId);
        String phonenumber = sysUser.getMobile();
        DriveSchoolCoach driveSchoolCoach = driveSchoolCoachMapper.selectByPhonenumber(phonenumber);
        Long jlId=0L;
        if (ObjectUtils.isNotEmpty(driveSchoolCoach)){
            jlId = driveSchoolCoach.getId();
        }
        driveSchoolExamPass.setJlId(jlId);

        Page<DriveSchoolExamPass> page = new Page<>(driveSchoolExamPass.getPageNum(), driveSchoolExamPass.getPageSize());
        IPage<DriveSchoolExamPass> driveSchoolExamPassIPage = driveSchoolExamPassService.checkList(driveSchoolExamPass, page);
        return CommonResult.success(driveSchoolExamPassIPage);
        //return getDataTable(list);
    }

    /**
     * 导出考试通过列表
     */
    //@Log(title = "考试通过", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, DriveSchoolExamPass driveSchoolExamPass)
//    {
//        List<DriveSchoolExamPass> list = driveSchoolExamPassService.selectDriveSchoolExamPassList(driveSchoolExamPass);
//        ExcelUtil<DriveSchoolExamPass> util = new ExcelUtil<DriveSchoolExamPass>(DriveSchoolExamPass.class);
//        util.exportExcel(response, list, "考试通过数据");
//    }

    /**
     * 获取考试通过详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(driveSchoolExamPassService.selectDriveSchoolExamPassById(id));
    }

    /**
     * 新增考试通过
     */
    //@Log(title = "考试通过", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody DriveSchoolExamPass driveSchoolExamPass)
    {
        return toAjax(driveSchoolExamPassService.insertDriveSchoolExamPass(driveSchoolExamPass));
    }

    /**
     * 修改考试通过
     */
    //@Log(title = "考试通过", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody DriveSchoolExamPass driveSchoolExamPass)
    {
        return toAjax(driveSchoolExamPassService.updateDriveSchoolExamPass(driveSchoolExamPass));
    }

    /**
     * 删除考试通过
     */
    //@Log(title = "考试通过", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driveSchoolExamPassService.deleteDriveSchoolExamPassByIds(ids));
    }
}
