<?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.KwtWaybillOrderTicketMapper">
    <resultMap id="BaseResultMap" type="com.sckw.transport.model.KwtWaybillOrderTicket">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="w_order_id" jdbcType="BIGINT" property="wOrderId" />
        <result column="type" jdbcType="INTEGER" property="type" />
        <result column="unit" jdbcType="VARCHAR" property="unit" />
        <result column="amount" jdbcType="DECIMAL" property="amount" />
        <result column="gross_amount" jdbcType="DECIMAL" property="grossAmount" />
        <result column="tare_amount" jdbcType="DECIMAL" property="tareAmount" />
        <result column="urls" jdbcType="VARCHAR" property="urls" />
        <result column="operate_time" jdbcType="TIMESTAMP" property="operateTime" />
        <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, `type`, unit, amount, gross_amount, tare_amount, urls, operate_time, remark, `status`,
        create_by, create_time, update_by, update_time, del_flag
    </sql>

    <select id="findWaybillOrderTicket" resultType="com.sckw.transport.model.KwtWaybillOrderTicket" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, `type`, unit, amount,
        gross_amount grossAmount, tare_amount tareAmount, urls, operate_time, remark, `status`, create_by createBy,
        create_time createTime, update_by updateBy, update_time updateTime
        from kwt_waybill_order_ticket
        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="type != null and type != ''">
            and type = #{type, jdbcType=INTEGER}
        </if>
    </select>

    <select id="findWaybillOrderTicketV1" resultType="com.sckw.transport.model.KwtWaybillOrderTicket" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, `type`, unit, amount,
        gross_amount grossAmount, tare_amount tareAmount, urls, operate_time, remark, `status`, create_by createBy,
        create_time createTime, update_by updateBy, update_time updateTime
        from kwt_waybill_order_ticket
        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="type != null and type != ''">
            and type = #{type, jdbcType=INTEGER}
        </if>
        <if test="unit != null and unit != ''">
            and unit = #{unit, jdbcType=VARCHAR}
        </if>
    </select>

    <select id="findWaybillOrderTicketV2" resultType="com.sckw.transport.model.KwtWaybillOrderTicket" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, `type`, unit, amount,
        gross_amount grossAmount, tare_amount tareAmount, urls, operate_time, remark, `status`, create_by createBy,
        create_time createTime, update_by updateBy, update_time updateTime
        from kwt_waybill_order_ticket
        where del_flag = 0
        <if test="wAddressId != null and wAddressId != ''">
            and w_address_id = #{wAddressId, jdbcType=BIGINT}
        </if>
        <if test="unit != null and unit != ''">
            and unit = #{unit, jdbcType=VARCHAR}
        </if>
        order by update_time limit 1
    </select>

    <select id="findWaybillOrderTicketV3" resultType="com.sckw.transport.model.KwtWaybillOrderTicket" >
        select
        id, w_order_id wOrderId, w_subtask_id wSubtaskId, w_address_id wAddressId, `type`, unit, amount,
        gross_amount grossAmount, tare_amount tareAmount, urls, operate_time, remark, `status`, create_by createBy,
        create_time createTime, update_by updateBy, update_time updateTime
        from kwt_waybill_order_ticket
        where del_flag = 0
        <if test="wAddressId != null and wAddressId != ''">
            and w_address_id = #{wAddressId, jdbcType=BIGINT}
        </if>
        <if test="unit != null and unit != ''">
            and unit = #{unit, jdbcType=VARCHAR}
        </if>
    </select>

    <update id="deleteTicket">
        UPDATE kwt_waybill_order_ticket set del_flag = 1
        WHERE del_flag = 0
        and w_order_id = #{wOrderId, jdbcType=BIGINT}
        and type = #{type, jdbcType=INTEGER}
    </update>

</mapper>