<?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.jx.mapper.DriveSchoolCourseMapper">

    <resultMap type="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse" id="DriveSchoolCourseResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="type"    column="type"    />
        <result property="name"    column="name"    />
        <result property="dayStart"    column="day_start"    />
        <result property="dayEnd"    column="day_end"    />
        <result property="price"    column="price"    />
        <result property="automatic"    column="automatic"    />
        <result property="license"    column="license"    />
        <result property="reserveMoney"    column="reserve_money"    />
        <result property="photo"    column="photo"    />
        <result property="describ"    column="describ"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updater"    column="updater"    />
        <result property="favour"    column="favour"    />
    </resultMap>

    <sql id="selectDriveSchoolCourseVo">
        select id, dept_id, favour,type, name, automatic, license, day_start, day_end, price,reserve_money, photo, describ, create_time, creator, update_time, updater from drive_school_course
    </sql>

    <select id="selectDriveSchoolCourseList" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse" resultMap="DriveSchoolCourseResult">
        <include refid="selectDriveSchoolCourseVo"/>
        <where>
            deleted = 0
            <if test="entity.id != null "> and id = #{entity.id}</if>
            <if test="entity.automatic != null "> and automatic = #{entity.automatic}</if>
            <if test="entity.license != null "> and license = #{entity.license}</if>
            <if test="entity.deptId != null "> and dept_id = #{entity.deptId}</if>
            <if test="entity.type != null  and entity.type != ''"> and type = #{entity.type}</if>
            <if test="entity.name != null  and entity.name != ''"> and name like concat('%', #{entity.name}, '%')</if>
            <if test="entity.dayStart != null  and entity.dayStart != ''"> and day_start = #{entity.dayStart}</if>
            <if test="entity.dayEnd != null  and entity.dayEnd != ''"> and day_end = #{entity.dayEnd}</if>
            <if test="entity.price != null "> and price = #{entity.price}</if>
            <if test="entity.reserveMoney != null "> and reserve_money = #{entity.reserveMoney}</if>
            <if test="entity.photo != null  and entity.photo != ''"> and photo = #{entity.photo}</if>
            <if test="entity.describ != null  and entity.describ != ''"> and describ = #{entity.describ}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectDriveSchoolCourseAppletList" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse" resultMap="DriveSchoolCourseResult">
        <include refid="selectDriveSchoolCourseVo"/>
        <where>
            deleted = 0
            <if test="entity.id != null "> and id = #{entity.id}</if>
            <if test="entity.deptId != null "> and dept_id = #{entity.deptId}</if>
            <if test="entity.type != null  and entity.type != ''"> and type = #{entity.type}</if>
            <if test="entity.name != null  and entity.name != ''"> and name like concat('%', #{entity.name}, '%')</if>
            <if test="entity.dayStart != null  and entity.dayStart != ''"> and day_start = #{entity.dayStart}</if>
            <if test="entity.dayEnd != null  and entity.dayEnd != ''"> and day_end = #{entity.dayEnd}</if>
            <if test="entity.price != null "> and price = #{price}</if>
            <if test="entity.photo != null  and entity.photo != ''"> and photo = #{entity.photo}</if>
            <if test="entity.describ != null  and entity.describ != ''"> and describ = #{entity.describ}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectDriveSchoolCourseAppletListAll" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse" resultMap="DriveSchoolCourseResult">
        <include refid="selectDriveSchoolCourseVo"/>
        <where>
            deleted = 0
            <if test="entity.id != null "> and id = #{entity.id}</if>
            <if test="entity.deptId != null "> and dept_id = #{entity.deptId}</if>
            <if test="entity.type != null  and entity.type != ''"> and type = #{entity.type}</if>
            <if test="entity.name != null  and entity.name != ''"> and name like concat('%', #{entity.name}, '%')</if>
            <if test="entity.dayStart != null  and entity.dayStart != ''"> and day_start = #{entity.dayStart}</if>
            <if test="entity.dayEnd != null  and entity.dayEnd != ''"> and day_end = #{entity.dayEnd}</if>
            <if test="entity.price != null "> and price = #{price}</if>
            <if test="entity.photo != null  and entity.photo != ''"> and photo = #{entity.photo}</if>
            <if test="entity.describ != null  and entity.describ != ''"> and describ = #{entity.describ}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectDriveSchoolCourseAppletFavorableListList" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse" resultMap="DriveSchoolCourseResult">
        <include refid="selectDriveSchoolCourseVo"/>
        <where>
            deleted = 0
            <if test="id != null "> and id = #{id}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="dayStart != null  and dayStart != ''"> and day_start = #{dayStart}</if>
            <if test="dayEnd != null  and dayEnd != ''"> and day_end = #{dayEnd}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="photo != null  and photo != ''"> and photo = #{photo}</if>
            <if test="describ != null  and describ != ''"> and describ = #{describ}</if>
        </where>
        group by dept_id
        order by create_time desc
    </select>

    <select id="selectDriveSchoolCourseById" parameterType="Long" resultMap="DriveSchoolCourseResult">
        <include refid="selectDriveSchoolCourseVo"/>
        where id = #{id}
    </select>
    <select id="findSchoolCourseByOrderNumber"
            resultType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse">
        select dsc.* from drive_school_pay dsp join
            drive_school_course dsc on dsp.courseId = dsc.id where dsp.deleted = 0 and dsp.orderNumber like concat('%', #{concat}, '%')
    </select>


    <insert id="insertDriveSchoolCourse" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse" useGeneratedKeys="true" keyProperty="id">
        insert into drive_school_course
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="type != null">type,</if>
            <if test="automatic != null">automatic,</if>
            <if test="license != null">license,</if>
            <if test="name != null">name,</if>
            <if test="dayStart != null">day_start,</if>
            <if test="dayEnd != null">day_end,</if>
            <if test="price != null">price,</if>
            <if test="reserveMoney != null">reserve_money,</if>
            <if test="photo != null">photo,</if>
            <if test="describ != null">describ,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updater != null">updater,</if>
            <if test="favour != null">favour,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="type != null">#{type},</if>
            <if test="automatic != null">#{automatic},</if>
            <if test="license != null">#{license},</if>
            <if test="name != null">#{name},</if>
            <if test="dayStart != null">#{dayStart},</if>
            <if test="dayEnd != null">#{dayEnd},</if>
            <if test="price != null">#{price},</if>
            <if test="reserveMoney != null">#{reserveMoney},</if>
            <if test="photo != null">#{photo},</if>
            <if test="describ != null">#{describ},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updater != null">#{updater},</if>
            <if test="favour != null">#{favour},</if>
         </trim>
    </insert>

    <update id="updateDriveSchoolCourse" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse">
        update drive_school_course
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="license != null">license = #{license},</if>
            <if test="automatic != null">automatic = #{automatic},</if>
            <if test="name != null">name = #{name},</if>
            <if test="dayStart != null">day_start = #{dayStart},</if>
            <if test="dayEnd != null">day_end = #{dayEnd},</if>
            <if test="price != null">price = #{price},</if>
            <if test="reserveMoney != null">reserve_money = #{reserveMoney},</if>
            <if test="photo != null">photo = #{photo},</if>
            <if test="describ != null">describ = #{describ},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updater != null">updater = #{updater},</if>
            <if test="favour != null">favour = #{favour},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDriveSchoolCourseById" parameterType="Long">
        delete from drive_school_course where id = #{id}
    </delete>

    <delete id="deleteDriveSchoolCourseByIds" parameterType="String">
        delete from drive_school_course where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="getOne"  resultMap="DriveSchoolCourseResult">
        <include refid="selectDriveSchoolCourseVo"/>
        order by create_time desc
        limit 1
    </select>

</mapper>
