<?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.sckw.transport.dao.KwtWaybillOrderTrackMapper">
    <resultMap id="BaseResultMap" type="com.sckw.transport.model.KwtWaybillOrderTrack">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="w_order_id" jdbcType="BIGINT" property="wOrderId" />
        <result column="remark" jdbcType="VARCHAR" property="remark" />
        <result column="status" jdbcType="INTEGER" property="status" />
        <result column="create_by" jdbcType="BIGINT" property="createBy" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="update_by" jdbcType="BIGINT" property="updateBy" />
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
        <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
    </resultMap>
    <sql id="Base_Column_List">
        id, w_order_id, remark, `status`, create_by, create_time, update_by, update_time,
    del_flag
    </sql>

    <select id="findWaybillOrderTrack" resultType="com.sckw.transport.model.KwtWaybillOrderTrack" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, remark,
        `status`, operate_time operateTime, create_by createBy, create_time createTime, update_by updateBy,
        update_time updateTime
        from kwt_waybill_order_track
        where del_flag = 0
        <if test="wOrderId != null and wOrderId != ''">
            and w_order_id = #{wOrderId, jdbcType=BIGINT}
        </if>
        <if test="wSubtaskId != null and wSubtaskId != ''">
            and w_subtask_id = #{wSubtaskId, jdbcType=BIGINT}
        </if>
        <if test="wAddressId != null and wAddressId != ''">
            and w_address_id = #{wAddressId, jdbcType=BIGINT}
        </if>
        <if test="status != null and status != ''">
            and status = #{status, jdbcType=INTEGER}
        </if>
        order by create_time desc limit 1
    </select>

    <select id="findWaybillOrderTrackV1" resultType="com.sckw.transport.model.KwtWaybillOrderTrack" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, remark,
        `status`, operate_time operateTime, create_by createBy, create_time createTime, update_by updateBy,
        update_time updateTime
        from kwt_waybill_order_track
        where del_flag = 0
        <if test="wOrderId != null and wOrderId != ''">
            and w_order_id = #{wOrderId, jdbcType=BIGINT}
        </if>
        <if test="status != null and status != ''">
            and status in (#{status})
        </if>
        order by create_time desc limit 1
    </select>

    <select id="findTrack" resultType="com.sckw.transport.model.KwtWaybillOrderTrack" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, remark,
        `status`, operate_time operateTime, create_by createBy, create_time createTime, update_by updateBy,
        update_time updateTime
        from kwt_waybill_order_track
        where del_flag = 0
        <if test="wOrderId != null and wOrderId != ''">
            and w_order_id = #{wOrderId, jdbcType=BIGINT}
        </if>
        <if test="wSubtaskId != null and wSubtaskId != ''">
            and w_subtask_id = #{wSubtaskId, jdbcType=BIGINT}
        </if>
        <if test="wAddressId != null and wAddressId != ''">
            and w_address_id = #{wAddressId, jdbcType=BIGINT}
        </if>
        <if test="status != null and status != ''">
            and status = #{status, jdbcType=INTEGER}
        </if>
        order by create_time
    </select>
</mapper>