<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.course.mapper.SchoolCommissionMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="queryPage" resultType="cn.iocoder.yudao.module.course.vo.SchoolCommissionVO">
        SELECT
            main.*,
            dsc.name AS courseName,
            dsc.type AS courseType
        FROM
            drive_school_commission main
                LEFT JOIN drive_school_course dsc ON main.course_id = dsc.id AND dsc.deleted = 0
        <where>
            main.deleted = 0
            <if test="entity.coachName != null and entity.coachName != '' "> and main.coach_name like concat('%', #{entity.coachName}, '%')</if>
            <if test="entity.studentName != null and entity.studentName != '' "> and main.student_name like concat('%', #{entity.studentName}, '%')</if>
            <if test="entity.checkName != null and entity.checkName != '' "> and main.check_name like concat('%', #{entity.checkName}, '%')</if>
            <if test="entity.courseName != null and entity.courseName != '' "> and dsc.name like concat('%', #{entity.courseName}, '%')</if>
        </where>
order by main.create_time desc
    </select>
    <select id="selectByCoachId" resultType="cn.iocoder.yudao.module.course.entity.SchoolCommission">
        SELECT
            dsc.*
        FROM
            drive_school_commission dsc
        WHERE
            dsc.deleted = 0
        <if test="coachId != null and coachId != ''">
            AND dsc.coach_user_id = #{coachId}
        </if>
        <if test="startTime!=null and startTime!=''">
            AND dsc.create_time &gt;= #{startTime}
        </if>
        <if test="endTime!=null and endTime!=''">
            AND dsc.create_time &lt;= #{endTime}
        </if>
        ORDER BY dsc.create_time DESC
    </select>
</mapper>