<?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="com.ruoyi.basicData.mapper.FleetDriverMsgMapper">
    
    <resultMap type="FleetDriverMsg" id="FleetDriverMsgResult">
        <result property="id"    column="id"    />
        <result property="fleetCompanyId"    column="fleet_company_id"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="birthday"    column="birthday"    />
        <result property="allowDriverCar"    column="allow_driver_car"    />
        <result property="firstCertificateDate"    column="first_certificate_date"    />
        <result property="idcarNum"    column="idcar_num"    />
        <result property="tel"    column="tel"    />
        <result property="address"    column="address"    />
        <result property="resumePic"    column="resume_pic"    />
        <result property="drivingPic"    column="driving_pic"    />
        <result property="creatTime"    column="creat_time"    />
        <result property="modificationTime"    column="modification_time"    />
        <result property="billStatus"    column="bill_status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectFleetDriverMsgVo">
        select id, fleet_company_id, name, sex, birthday, allow_driver_car, first_certificate_date, idcar_num, tel, address, resume_pic, driving_pic, creat_time, modification_time, bill_status, del_flag, create_by, update_by, update_time, remarks from fleet_driver_msg
    </sql>

    <select id="selectFleetDriverMsgList" parameterType="FleetDriverMsg" resultMap="FleetDriverMsgResult">
        <include refid="selectFleetDriverMsgVo"/>
        <where>  
            <if test="fleetCompanyId != null "> and fleet_company_id = #{fleetCompanyId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="allowDriverCar != null  and allowDriverCar != ''"> and allow_driver_car = #{allowDriverCar}</if>
            <if test="firstCertificateDate != null "> and first_certificate_date = #{firstCertificateDate}</if>
            <if test="idcarNum != null  and idcarNum != ''"> and idcar_num = #{idcarNum}</if>
            <if test="tel != null  and tel != ''"> and tel = #{tel}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="resumePic != null  and resumePic != ''"> and resume_pic = #{resumePic}</if>
            <if test="drivingPic != null  and drivingPic != ''"> and driving_pic = #{drivingPic}</if>
            <if test="creatTime != null "> and creat_time = #{creatTime}</if>
            <if test="modificationTime != null "> and modification_time = #{modificationTime}</if>
            <if test="billStatus != null "> and bill_status = #{billStatus}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="selectFleetDriverMsgIdNameList" resultType="FleetDriverMsg" resultMap="FleetDriverMsgResult">
        select id, fleet_company_id, name, tel from fleet_driver_msg
        <where>
            <if test="fPid != null "> and f_pid = #{fPid}</if>
            <if test="fleetCompanyId != null "> and fleet_company_id = #{fleetCompanyId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="allowDriverCar != null  and allowDriverCar != ''"> and allow_driver_car = #{allowDriverCar}</if>
            <if test="firstCertificateDate != null "> and first_certificate_date = #{firstCertificateDate}</if>
            <if test="idcarNum != null  and idcarNum != ''"> and idcar_num = #{idcarNum}</if>
            <if test="tel != null  and tel != ''"> and tel = #{tel}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="resumePic != null  and resumePic != ''"> and resume_pic = #{resumePic}</if>
            <if test="drivingPic != null  and drivingPic != ''"> and driving_pic = #{drivingPic}</if>
            <if test="creatTime != null "> and creat_time = #{creatTime}</if>
            <if test="modificationTime != null "> and modification_time = #{modificationTime}</if>
            <if test="billStatus != null "> and bill_status = #{billStatus}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="selectFleetDriverMsgById" parameterType="Long" resultMap="FleetDriverMsgResult">
        <include refid="selectFleetDriverMsgVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFleetDriverMsg" parameterType="FleetDriverMsg" useGeneratedKeys="true" keyProperty="id">
        insert into fleet_driver_msg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fleetCompanyId != null">fleet_company_id,</if>
            <if test="name != null">name,</if>
            <if test="sex != null">sex,</if>
            <if test="birthday != null">birthday,</if>
            <if test="allowDriverCar != null">allow_driver_car,</if>
            <if test="firstCertificateDate != null">first_certificate_date,</if>
            <if test="idcarNum != null">idcar_num,</if>
            <if test="tel != null">tel,</if>
            <if test="address != null">address,</if>
            <if test="resumePic != null">resume_pic,</if>
            <if test="drivingPic != null">driving_pic,</if>
            <if test="creatTime != null">creat_time,</if>
            <if test="modificationTime != null">modification_time,</if>
            <if test="billStatus != null">bill_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fleetCompanyId != null">#{fleetCompanyId},</if>
            <if test="name != null">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="allowDriverCar != null">#{allowDriverCar},</if>
            <if test="firstCertificateDate != null">#{firstCertificateDate},</if>
            <if test="idcarNum != null">#{idcarNum},</if>
            <if test="tel != null">#{tel},</if>
            <if test="address != null">#{address},</if>
            <if test="resumePic != null">#{resumePic},</if>
            <if test="drivingPic != null">#{drivingPic},</if>
            <if test="creatTime != null">#{creatTime},</if>
            <if test="modificationTime != null">#{modificationTime},</if>
            <if test="billStatus != null">#{billStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateFleetDriverMsg" parameterType="FleetDriverMsg">
        update fleet_driver_msg
        <trim prefix="SET" suffixOverrides=",">
            <if test="fleetCompanyId != null">fleet_company_id = #{fleetCompanyId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="allowDriverCar != null">allow_driver_car = #{allowDriverCar},</if>
            <if test="firstCertificateDate != null">first_certificate_date = #{firstCertificateDate},</if>
            <if test="idcarNum != null">idcar_num = #{idcarNum},</if>
            <if test="tel != null">tel = #{tel},</if>
            <if test="address != null">address = #{address},</if>
            <if test="resumePic != null">resume_pic = #{resumePic},</if>
            <if test="drivingPic != null">driving_pic = #{drivingPic},</if>
            <if test="creatTime != null">creat_time = #{creatTime},</if>
            <if test="modificationTime != null">modification_time = #{modificationTime},</if>
            <if test="billStatus != null">bill_status = #{billStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFleetDriverMsgById" parameterType="Long">
        delete from fleet_driver_msg where id = #{id}
    </delete>

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

    <select id="selectFleetDriverMsgListMap" parameterType="FleetDriverMsg" resultType="Map">
        SELECT
            dri.id AS id,
            com.company_name AS companyName,
            dri.`name` AS `name`,
            dri.sex AS sex,
            dri.birthday AS birthday,
            dri.allow_driver_car AS allowDriverCar,
            dri.first_certificate_date AS firstCertificateDate,
            dri.idcar_num AS idcarNum,
            dri.tel AS tel,
            dri.address AS address,
            dri.resume_pic AS resumePic,
            dri.driving_pic AS drivingPic,
            dri.creat_time AS creatTime,
            dri.modification_time AS modificationTime,
            dri.bill_status AS billStatus,
            dri.del_flag,
            dri.create_by,
            dri.update_by,
            dri.update_time,
            dri.remarks AS remarks
        FROM
            fleet_driver_msg dri
        LEFT JOIN fleet_company_msg AS com ON dri.fleet_company_id = com.id
        <where>
            <if test="fleetCompanyId != null "> and dri.fleet_company_id = #{fleetCompanyId}</if>
            <if test="name != null  and name != ''"> and dri.name like concat('%', #{name}, '%')</if>
            <if test="sex != null "> and dri.sex = #{sex}</if>
            <if test="birthday != null "> and dri.birthday = #{birthday}</if>
            <if test="allowDriverCar != null  and allowDriverCar != ''"> and dri.allow_driver_car = #{allowDriverCar}</if>
            <if test="firstCertificateDate != null "> and dri.first_certificate_date = #{firstCertificateDate}</if>
            <if test="idcarNum != null  and idcarNum != ''"> and dri.idcar_num = #{idcarNum}</if>
            <if test="tel != null  and tel != ''"> and dri.tel = #{tel}</if>
            <if test="address != null  and address != ''"> and dri.address = #{address}</if>
            <if test="resumePic != null  and resumePic != ''"> and dri.resume_pic = #{resumePic}</if>
            <if test="drivingPic != null  and drivingPic != ''"> and dri.driving_pic = #{drivingPic}</if>
            <if test="creatTime != null "> and dri.creat_time = #{creatTime}</if>
            <if test="modificationTime != null "> and dri.modification_time = #{modificationTime}</if>
            <if test="billStatus != null "> and dri.bill_status = #{billStatus}</if>
            <if test="remarks != null  and remarks != ''"> and dri.remarks = #{remarks}</if>
        </where>
    </select>
</mapper>