<?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.njzscloud.dispose.cst.driver.mapper.DriverMapper">

    <resultMap id="DriverResultMap" type="com.njzscloud.dispose.cst.driver.pojo.result.DriverResult">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="customer_id" property="customerId"/>
        <result column="org_id" property="orgId"/>
        <result column="org_name" property="orgName"/>
        <result column="driving_licence_no" property="drivingLicenceNo"/>
        <result column="driver_name" property="driverName"/>
        <result column="phone" property="phone"/>
        <result column="driving_licence" property="drivingLicence" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
        <result column="licence_start_time" property="licenceStartTime"/>
        <result column="licence_end_time" property="licenceEndTime"/>
        <result column="busy" property="busy"/>
        <result column="creator_id" property="creatorId"/>
        <result column="modifier_id" property="modifierId"/>
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
        <result column="deleted" property="deleted"/>
    </resultMap>

    <sql id="Base_Column_List">
        cd.id, cd.user_id, cd.customer_id, cd.org_id, co.org_name, cd.driving_licence_no, cd.driver_name, cd.phone,
        cd.driving_licence, cd.licence_start_time, cd.licence_end_time, cd.busy,
        cd.creator_id, cd.modifier_id, cd.create_time, cd.modify_time, cd.deleted
    </sql>

    <select id="getById" resultMap="DriverResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM cst_driver cd
        left join cst_org co on cd.org_id = co.id
        WHERE cd.id = #{id}
    </select>

    <select id="getByUserId" resultMap="DriverResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM cst_driver cd
        left join cst_org co on cd.org_id = co.id
        WHERE cd.user_id = #{userId}
    </select>

    <select id="paging" resultMap="DriverResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM cst_driver cd
        left join cst_org co on cd.org_id = co.id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>

</mapper>
