<?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.qaup.system.mapper.SysDriverInfoMapper">
    
    <resultMap type="SysDriverInfo" id="SysDriverInfoResult">
        <result property="userId"    column="user_id"    />
        <result property="licenseType"    column="license_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="userName"    column="user_name"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="avatar"    column="avatar"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectSysDriverInfoVo">
        select d.user_id, d.license_type, d.create_by, d.create_time, d.update_by, d.update_time, d.remark,
               u.user_name, u.phonenumber, u.avatar, u.status
        from sys_driver_info d
        left join sys_user u on d.user_id = u.user_id
    </sql>

    <select id="selectSysDriverInfoList" parameterType="SysDriverInfo" resultMap="SysDriverInfoResult">
        <include refid="selectSysDriverInfoVo"/>
    </select>
    
    <select id="selectSysDriverInfoByUserId" parameterType="Long" resultMap="SysDriverInfoResult">
        <include refid="selectSysDriverInfoVo"/>
        where d.user_id = #{userId}
    </select>

    <insert id="insertSysDriverInfo" parameterType="SysDriverInfo">
        insert into sys_driver_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="licenseType != null and licenseType != ''">license_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="licenseType != null and licenseType != ''">#{licenseType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysDriverInfo" parameterType="SysDriverInfo">
        update sys_driver_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="licenseType != null and licenseType != ''">license_type = #{licenseType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteSysDriverInfoByUserId" parameterType="Long">
        delete from sys_driver_info where user_id = #{userId}
    </delete>

    <delete id="deleteSysDriverInfoByUserIds" parameterType="String">
        delete from sys_driver_info where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
</mapper>