<?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.DriveSchoolCarMapper">

    <resultMap type="cn.iocoder.yudao.module.jx.domain.DriveSchoolCar" id="DriveSchoolCarResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="brand"    column="brand"    />
        <result property="carModel"    column="car_model"    />
        <result property="carNo"    column="car_no"    />
        <result property="carPhoto"    column="car_photo"    />
        <result property="carRegisterDate"    column="car_register_date"    />
        <result property="inspectionDate"    column="inspection_date"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="userId"    column="user_id"    />
        <result property="coachId"    column="coach_id"    />
        <result property="carBlong"    column="car_blong"    />
        <result property="drivingLicence"    column="driving_licence"    />
        <result property="operationCertificate"    column="operation_certificate"    />
        <result property="outlineDate"    column="outline_date"    />
        <result property="repairDate"    column="repair_date"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updater"    column="updater"    />
        <result property="baoxianSttime"    column="baoxian_sttime"    />
        <result property="baoxianEntime"    column="baoxian_entime"    />
        <result property="company"    column="company"    />
        <result property="content"    column="content"    />
    </resultMap>

    <sql id="selectDriveSchoolCarVo">
        select * from drive_school_car
    </sql>

    <select id="selectDriveSchoolCarList" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCar" resultMap="DriveSchoolCarResult">
        <include refid="selectDriveSchoolCarVo"/>
        <where>
            deleted = 0
            <if test="entity.brand != null  and entity.brand != ''"> and brand = #{entity.brand}</if>
            <if test="entity.carModel != null  and entity.carModel != ''"> and car_model = #{entity.carModel}</if>
<!--            <if test="entity.carNo != null  and entity.carNo != ''"> and car_no = #{entity.carNo}</if>-->
            <if test="entity.carNo != null  and entity.carNo != ''"> and car_no like concat('%', #{entity.carNo}, '%')</if>
            <if test="entity.courseType != null  and entity.courseType != ''"> and course_type = #{entity.courseType}</if>
            <if test="entity.carPhoto != null  and carPhoto != ''"> and car_photo = #{entity.carPhoto}</if>
            <if test="entity.carRegisterDate != null "> and car_register_date = #{entity.carRegisterDate}</if>
            <if test="entity.inspectionDate != null "> and inspection_date = #{entity.inspectionDate}</if>
            <if test="entity.userName != null  and entity.userName != ''"> and user_name like concat('%', #{entity.userName}, '%')</if>
            <if test="entity.userPhone != null  and entity.userPhone != ''"> and user_phone = #{entity.userPhone}</if>
            <if test="entity.carBlong != null  and entity.carBlong != ''"> and car_blong = #{entity.carBlong}</if>
            <if test="entity.drivingLicence != null  and entity.drivingLicence != ''"> and driving_licence = #{entity.drivingLicence}</if>
            <if test="entity.operationCertificate != null  and entity.operationCertificate != ''"> and operation_certificate = #{entity.operationCertificate}</if>
            <if test="entity.outlineDate != null "> and outline_date = #{entity.outlineDate}</if>
            <if test="entity.repairDate != null "> and repair_date = #{entity.repairDate}</if>
        </where>
--         order by create_time desc
        ORDER BY create_time DESC, id DESC
    </select>

    <select id="selectDriveSchoolCarListAll" parameterType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCar" resultMap="DriveSchoolCarResult">
        <include refid="selectDriveSchoolCarVo"/>
        <where>
            deleted = 0
            <if test="entity.brand != null  and entity.brand != ''"> and brand = #{entity.brand}</if>
            <if test="entity.carModel != null  and entity.carModel != ''"> and car_model = #{entity.carModel}</if>
            <if test="entity.carNo != null  and entity.carNo != ''"> and car_no = #{entity.carNo}</if>
            <if test="entity.carPhoto != null  and vcarPhoto != ''"> and car_photo = #{entity.carPhoto}</if>
            <if test="entity.carRegisterDate != null "> and car_register_date = #{entity.carRegisterDate}</if>
            <if test="entity.inspectionDate != null "> and inspection_date = #{entity.inspectionDate}</if>
            <if test="entity.userName != null  and entity.userName != ''"> and user_name like concat('%', #{entity.userName}, '%')</if>
            <if test="entity.userPhone != null  and entity.userPhone != ''"> and user_phone = #{entity.userPhone}</if>
            <if test="entity.carBlong != null  and entity.carBlong != ''"> and car_blong = #{entity.carBlong}</if>
            <if test="entity.drivingLicence != null  and entity.drivingLicence != ''"> and driving_licence = #{entity.drivingLicence}</if>
            <if test="entity.operationCertificate != null  and entity.operationCertificate != ''"> and operation_certificate = #{entity.operationCertificate}</if>
            <if test="entity.outlineDate != null "> and outline_date = #{entity.outlineDate}</if>
            <if test="entity.repairDate != null "> and repair_date = #{entity.repairDate}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectDriveSchoolCarById" parameterType="Long" resultMap="DriveSchoolCarResult">
        <include refid="selectDriveSchoolCarVo"/>
        where id = #{id}
    </select>




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

    <select id="selectByCarNo" parameterType="String" resultMap="DriveSchoolCarResult">
        <include refid="selectDriveSchoolCarVo"/>
        where deleted = 0 and car_no = #{carNo}
    </select>
    <select id="selectTrainCar" resultType="cn.iocoder.yudao.module.jx.domain.DriveSchoolCar">
        SELECT
        dsc.*
        FROM
        drive_school_car dsc
        LEFT JOIN drive_school_train dst ON dsc.user_id = dst.coach_id
        AND dst.deleted = 0
        WHERE
        dst.id IS NOT NULL
        AND dsc.deleted = 0
        <if test="coachId != null and coachId != ''">
            AND dst.coach_id = #{coachId}
        </if>
        <if test="searchValue != null and searchValue != ''">
            AND dsc.car_no LIKE CONCAT('%',#{searchValue},'%')
        </if>
        <if test="courseType != null and courseType != ''">
            AND dsc.course_type =#{courseType}
        </if>
        <if test="startTime!=null and startTime!=''">
            AND dst.create_time &gt;= #{startTime}
        </if>
        <if test="endTime!=null and endTime!=''">
            AND dst.create_time &lt;= #{endTime}
        </if>
        GROUP BY
        dsc.id
    </select>


</mapper>
