<?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.orderPlan.mapper.FtmsorderbillsMapper">

    <resultMap type="ftmsorderbills" id="ftmsorderbillsResult">
        <result property="id"    column="id"    />
        <result property="billNo"    column="bill_no"    />
        <result property="actId"    column="act_id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="planUserId"    column="plan_user_id"    />
        <result property="transUserName"    column="trans_user_name"    />
        <result property="planUserName"    column="plan_user_name"    />
        <result property="billType"    column="bill_type"    />
        <result property="transUserId"    column="trans_user_id"    />
        <result property="transType"    column="trans_type"    />
        <result property="transProp"    column="trans_prop"    />
        <result property="ifContracted"    column="if_contracted"    />
        <result property="contractNo"    column="contract_no"    />
        <result property="refNo"    column="ref_no"    />
        <result property="accstlType"    column="accstl_type"    />
        <result property="accdays"    column="accdays"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="goodsPrice"    column="goods_price"    />
        <result property="goodsLossType"    column="goods_loss_type"    />
        <result property="goodsLossStd"    column="goods_loss_std"    />
        <result property="mblno"    column="mblno"    />
        <result property="ysl"    column="ysl"    />
        <result property="voy"    column="voy"    />
        <result property="polId"    column="pol_id"    />
        <result property="qtyPlan"    column="qty_plan"    />
        <result property="podId"    column="pod_id"    />
        <result property="qtyDisPatch"    column="qty_dis_patch"    />
        <result property="weightPlan"    column="weight_plan"    />
        <result property="cntrDesc"    column="cntr_desc"    />
        <result property="carNoList"    column="car_no_list"    />
        <result property="loadAddr"    column="load_addr"    />
        <result property="loadAttn"    column="load_attn"    />
        <result property="loadAttntel"    column="load_attntel"    />
        <result property="loadDate"    column="load_date"    />
        <result property="mdLoadAddr"    column="md_load_addr"    />
        <result property="mdLoadAttn"    column="md_load_attn"    />
        <result property="mdLoadAttnTel"    column="md_load_attn_tel"    />
        <result property="mdLoadDate"    column="md_load_date"    />
        <result property="unLoadAddr"    column="un_load_addr"    />
        <result property="unLoadAttn"    column="un_load_attn"    />
        <result property="unLoadAttnTel"    column="un_load_attn_tel"    />
        <result property="unLoadDate"    column="un_load_date"    />
        <result property="routeId"    column="route_id"    />
        <result property="routeDesc"    column="route_desc"    />
        <result property="ifWaybill"    column="if_waybill"    />
        <result property="ifNeedinvDr"    column="if_needinv_dr"    />
        <result property="postDate"    column="post_date"    />
        <result property="billStatus"    column="bill_status"    />
        <result property="delFlag"    column="del_flag"    />
        <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="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectftmsorderbillsVo">
        select id, bill_no, act_id, corp_id, trans_user_name, plan_user_id, plan_user_name, bill_type, trans_user_id, trans_type,
        trans_prop, if_contracted, contract_no, ref_no, accstl_type, accdays, goods_id, goods_price, goods_loss_type, goods_loss_std,
        mblno, ysl, voy, pol_id, pod_id, qty_plan, qty_dis_patch, weight_plan, cntr_desc, car_no_list, load_addr, load_attn, load_attntel,
        load_date, md_load_addr, md_load_attn, md_load_attn_tel, md_load_date, un_load_addr, un_load_attn, un_load_attn_tel, un_load_date,
        route_id, route_desc, if_waybill, if_needinv_dr, post_date, bill_status, del_flag, create_by, create_time, update_by, update_time,
        remarks from F_TMSORDERBILLS
    </sql>

    <select id="selectftmsorderbillsList" parameterType="ftmsorderbills" resultMap="ftmsorderbillsResult">
        <include refid="selectftmsorderbillsVo"/>
        <where>
            <if test="billNo != null  and billNo != ''"> and bill_no = #{billNo}</if>
            <if test="actId != null "> and act_id = #{actId}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
            <if test="transUserName != null  and transUserName != ''"> and trans_user_name like concat('%', #{transUserName}, '%')</if>
            <if test="planUserId != null "> and plan_user_id = #{planUserId}</if>
            <if test="planUserName != null  and planUserName != ''"> and plan_user_name like concat('%', #{planUserName}, '%')</if>
            <if test="billType != null "> and bill_type = #{billType}</if>
            <if test="transUserId != null "> and trans_user_id = #{transUserId}</if>
            <if test="transType != null  and transType != ''"> and trans_type = #{transType}</if>
            <if test="transProp != null  and transProp != ''"> and trans_prop = #{transProp}</if>
            <if test="ifContracted != null  and ifContracted != ''"> and if_contracted = #{ifContracted}</if>
            <if test="contractNo != null  and contractNo != ''"> and contract_no = #{contractNo}</if>
            <if test="refNo != null  and refNo != ''"> and ref_no = #{refNo}</if>
            <if test="accstlType != null "> and accstl_type = #{accstlType}</if>
            <if test="accdays != null "> and accdays = #{accdays}</if>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="goodsPrice != null "> and goods_price = #{goodsPrice}</if>
            <if test="goodsLossType != null  and goodsLossType != ''"> and goods_loss_type = #{goodsLossType}</if>
            <if test="goodsLossStd != null "> and goods_loss_std = #{goodsLossStd}</if>
            <if test="mblno != null  and mblno != ''"> and mblno = #{mblno}</if>
            <if test="ysl != null  and ysl != ''"> and ysl = #{ysl}</if>
            <if test="voy != null  and voy != ''"> and voy = #{voy}</if>
            <if test="polId != null "> and pol_id = #{polId}</if>
            <if test="podId != null "> and pod_id = #{podId}</if>
            <if test="qtyPlan != null "> and qty_plan = #{qtyPlan}</if>
            <if test="qtyDisPatch != null "> and qty_dis_patch = #{qtyDisPatch}</if>
            <if test="weightPlan != null "> and weight_plan = #{weightPlan}</if>
            <if test="cntrDesc != null  and cntrDesc != ''"> and cntr_desc = #{cntrDesc}</if>
            <if test="carNoList != null  and carNoList != ''"> and car_no_list = #{carNoList}</if>
            <if test="loadAddr != null  and loadAddr != ''"> and load_addr = #{loadAddr}</if>
            <if test="loadAttn != null  and loadAttn != ''"> and load_attn = #{loadAttn}</if>
            <if test="loadAttntel != null  and loadAttntel != ''"> and load_attntel = #{loadAttntel}</if>
            <if test="loadDate != null "> and load_date = #{loadDate}</if>
            <if test="mdLoadAddr != null  and mdLoadAddr != ''"> and md_load_addr = #{mdLoadAddr}</if>
            <if test="mdLoadAttn != null  and mdLoadAttn != ''"> and md_load_attn = #{mdLoadAttn}</if>
            <if test="mdLoadAttnTel != null  and mdLoadAttnTel != ''"> and md_load_attn_tel = #{mdLoadAttnTel}</if>
            <if test="mdLoadDate != null "> and md_load_date = #{mdLoadDate}</if>
            <if test="unLoadAddr != null  and unLoadAddr != ''"> and un_load_addr = #{unLoadAddr}</if>
            <if test="unLoadAttn != null  and unLoadAttn != ''"> and un_load_attn = #{unLoadAttn}</if>
            <if test="unLoadAttnTel != null  and unLoadAttnTel != ''"> and un_load_attn_tel = #{unLoadAttnTel}</if>
            <if test="unLoadDate != null "> and un_load_date = #{unLoadDate}</if>
            <if test="routeId != null "> and route_id = #{routeId}</if>
            <if test="routeDesc != null  and routeDesc != ''"> and route_desc = #{routeDesc}</if>
            <if test="ifWaybill != null  and ifWaybill != ''"> and if_waybill = #{ifWaybill}</if>
            <if test="ifNeedinvDr != null  and ifNeedinvDr != ''"> and if_needinv_dr = #{ifNeedinvDr}</if>
            <if test="postDate != null "> and post_date = #{postDate}</if>
            <if test="billStatus != null "> and bill_status = #{billStatus}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="selectftmsorderbillsMapList" parameterType="ftmsorderbills" resultType="Map">
        SELECT
            f.id,
            f.bill_no AS billNo,
            f.act_id AS actId,
            c.f_name AS corpId,
            p.nick_name AS planUserId,
            a.nick_name AS transUserId,
            type.dict_label AS billType,
            trans.dict_label AS transType,
            prop.dict_label AS transProp,
            f.if_contracted AS ifContracted,
            f.contract_no AS contractNo,
            f.accstl_type AS accstlType,
            f.accdays,
            f.load_date AS loadDate,
            f.load_addr AS loadAddr,
            f.md_load_addr AS mdLoadAddr,
            f.un_load_addr AS unLoadAddr,
            g.f_name AS goodsId,
            f.goods_price AS goodsPrice,
            f.mblno,
            f.remarks,
            f.qty_plan AS qtyPlan,
            f.qty_dis_patch AS qtyDisPatch,
            f.weight_plan AS weightPlan,
            f.cntr_desc AS cntrDesc,
            f.car_no_list AS carNoList,
            f.bill_status AS billStatus,
            u.nick_name AS createBy,
            f.create_time AS createTime
        FROM
            F_TMSORDERBILLS f
            LEFT JOIN sys_dict_data type ON type.dict_type = 'data_billType'
            AND type.dict_value = f.bill_type
            LEFT JOIN sys_dict_data trans ON trans.dict_type = 'data_transType'
            AND trans.dict_value = f.trans_type
            LEFT JOIN sys_dict_data prop ON prop.dict_type = 'data_transProp'
            AND prop.dict_value = f.trans_prop
            LEFT JOIN t_corps c ON c.f_id = f.corp_id
            LEFT JOIN sys_user p ON p.user_id = f.plan_user_id
            LEFT JOIN sys_user a ON a.user_id = f.trans_user_id
            LEFT JOIN t_goods g ON g.f_id = f.goods_id
            LEFT JOIN sys_user u ON u.user_name = f.create_by
        <where>
            <if test="corpId != null and corpId != ''">
                AND f.corp_id = #{corpId}
            </if>
            <if test="actId != null and actId != 0">
                AND f.act_id = #{actId}
            </if>
            <if test="billType != null and billType != ''">
                AND f.bill_type = #{billType}
            </if>
            <if test="transType != null and transType != ''">
                AND f.trans_type = #{transType}
            </if>
            <if test="transProp != null and transProp != ''">
                AND f.trans_prop = #{transProp}
            </if>
            <if test="goodsId != null and goodsId != 0">
                AND f.goods_id = #{goodsId}
            </if>
            <if test="incompleteStatus != null and incompleteStatus != 2">
                AND f.bill_status &lt; 6
            </if>
            <if test="dispatchStatus != null and dispatchStatus != 2">
                AND f.bill_status &gt;1
            </if>
            <if test="dispatchStatus != null and dispatchStatus == 2">
                AND f.bill_status =1
            </if>
            <if test="mblno != null and mblno != ''">
                AND f.mblno LIKE "%${mblno}%"
            </if>
            <if test="loadAddr != null and loadAddr != ''">
                AND f.load_addr LIKE "%${loadAddr}%"
            </if>
            <if test="mdLoadAddr != null and mdLoadAddr != ''">
                AND f.md_load_addr LIKE "%${mdLoadAddr}%"
            </if>
            <if test="unLoadAddr != null and unLoadAddr != ''">
                AND f.un_load_addr LIKE "%${unLoadAddr}%"
            </if>
            ${params.dataScope}
        </where>
        ORDER BY f.bill_status, f.id asc
    </select>

    <select id="selectftmsorderbillsById" parameterType="Long" resultMap="ftmsorderbillsResult">
        <include refid="selectftmsorderbillsVo"/>
        where id = #{id}
    </select>

    <insert id="insertftmsorderbills" parameterType="ftmsorderbills" useGeneratedKeys="true" keyProperty="id">
        insert into F_TMSORDERBILLS
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="billNo != null">bill_no,</if>
            <if test="actId != null">act_id,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="transUserName != null">trans_user_name,</if>
            <if test="planUserId != null">plan_user_id,</if>
            <if test="planUserName != null">plan_user_name,</if>
            <if test="billType != null">bill_type,</if>
            <if test="transUserId != null">trans_user_id,</if>
            <if test="transType != null">trans_type,</if>
            <if test="transProp != null">trans_prop,</if>
            <if test="ifContracted != null">if_contracted,</if>
            <if test="contractNo != null">contract_no,</if>
            <if test="refNo != null">ref_no,</if>
            <if test="accstlType != null">accstl_type,</if>
            <if test="accdays != null">accdays,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="goodsPrice != null">goods_price,</if>
            <if test="goodsLossType != null">goods_loss_type,</if>
            <if test="goodsLossStd != null">goods_loss_std,</if>
            <if test="mblno != null">mblno,</if>
            <if test="ysl != null">ysl,</if>
            <if test="voy != null">voy,</if>
            <if test="polId != null">pol_id,</if>
            <if test="podId != null">pod_id,</if>
            <if test="qtyPlan != null">qty_plan,</if>
            <if test="qtyDisPatch != null">qty_dis_patch,</if>
            <if test="weightPlan != null">weight_plan,</if>
            <if test="cntrDesc != null">cntr_desc,</if>
            <if test="carNoList != null">car_no_list,</if>
            <if test="loadAddr != null">load_addr,</if>
            <if test="loadAttn != null">load_attn,</if>
            <if test="loadAttntel != null">load_attntel,</if>
            <if test="loadDate != null">load_date,</if>
            <if test="mdLoadAddr != null">md_load_addr,</if>
            <if test="mdLoadAttn != null">md_load_attn,</if>
            <if test="mdLoadAttnTel != null">md_load_attn_tel,</if>
            <if test="mdLoadDate != null">md_load_date,</if>
            <if test="unLoadAddr != null">un_load_addr,</if>
            <if test="unLoadAttn != null">un_load_attn,</if>
            <if test="unLoadAttnTel != null">un_load_attn_tel,</if>
            <if test="unLoadDate != null">un_load_date,</if>
            <if test="routeId != null">route_id,</if>
            <if test="routeDesc != null">route_desc,</if>
            <if test="ifWaybill != null">if_waybill,</if>
            <if test="ifNeedinvDr != null">if_needinv_dr,</if>
            <if test="postDate != null">post_date,</if>
            <if test="billStatus != null">bill_status,</if>
            <if test="delFlag != null">del_flag,</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="remarks != null">remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="billNo != null">#{billNo},</if>
            <if test="actId != null">#{actId},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="transUserName != null">#{transUserName},</if>
            <if test="planUserId != null">#{planUserId},</if>
            <if test="planUserName != null">#{planUserName},</if>
            <if test="billType != null">#{billType},</if>
            <if test="transUserId != null">#{transUserId},</if>
            <if test="transType != null">#{transType},</if>
            <if test="transProp != null">#{transProp},</if>
            <if test="ifContracted != null">#{ifContracted},</if>
            <if test="contractNo != null">#{contractNo},</if>
            <if test="refNo != null">#{refNo},</if>
            <if test="accstlType != null">#{accstlType},</if>
            <if test="accdays != null">#{accdays},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="goodsPrice != null">#{goodsPrice},</if>
            <if test="goodsLossType != null">#{goodsLossType},</if>
            <if test="goodsLossStd != null">#{goodsLossStd},</if>
            <if test="mblno != null">#{mblno},</if>
            <if test="ysl != null">#{ysl},</if>
            <if test="voy != null">#{voy},</if>
            <if test="polId != null">#{polId},</if>
            <if test="podId != null">#{podId},</if>
            <if test="qtyPlan != null">#{qtyPlan},</if>
            <if test="qtyDisPatch != null">#{qtyDisPatch},</if>
            <if test="weightPlan != null">#{weightPlan},</if>
            <if test="cntrDesc != null">#{cntrDesc},</if>
            <if test="carNoList != null">#{carNoList},</if>
            <if test="loadAddr != null">#{loadAddr},</if>
            <if test="loadAttn != null">#{loadAttn},</if>
            <if test="loadAttntel != null">#{loadAttntel},</if>
            <if test="loadDate != null">#{loadDate},</if>
            <if test="mdLoadAddr != null">#{mdLoadAddr},</if>
            <if test="mdLoadAttn != null">#{mdLoadAttn},</if>
            <if test="mdLoadAttnTel != null">#{mdLoadAttnTel},</if>
            <if test="mdLoadDate != null">#{mdLoadDate},</if>
            <if test="unLoadAddr != null">#{unLoadAddr},</if>
            <if test="unLoadAttn != null">#{unLoadAttn},</if>
            <if test="unLoadAttnTel != null">#{unLoadAttnTel},</if>
            <if test="unLoadDate != null">#{unLoadDate},</if>
            <if test="routeId != null">#{routeId},</if>
            <if test="routeDesc != null">#{routeDesc},</if>
            <if test="ifWaybill != null">#{ifWaybill},</if>
            <if test="ifNeedinvDr != null">#{ifNeedinvDr},</if>
            <if test="postDate != null">#{postDate},</if>
            <if test="billStatus != null">#{billStatus},</if>
            <if test="delFlag != null">#{delFlag},</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="remarks != null">#{remarks},</if>
        </trim>
    </insert>

    <update id="updateftmsorderbills" parameterType="ftmsorderbills">
        update F_TMSORDERBILLS
        <trim prefix="SET" suffixOverrides=",">
            <if test="billNo != null">bill_no = #{billNo},</if>
            <if test="actId != null">act_id = #{actId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="transUserName != null">trans_user_name = #{transUserName},</if>
            <if test="planUserId != null">plan_user_id = #{planUserId},</if>
            <if test="planUserName != null">plan_user_name = #{planUserName},</if>
            <if test="billType != null">bill_type = #{billType},</if>
            <if test="transUserId != null">trans_user_id = #{transUserId},</if>
            <if test="transType != null">trans_type = #{transType},</if>
            <if test="transProp != null">trans_prop = #{transProp},</if>
            <if test="ifContracted != null">if_contracted = #{ifContracted},</if>
            <if test="contractNo != null">contract_no = #{contractNo},</if>
            <if test="refNo != null">ref_no = #{refNo},</if>
            <if test="accstlType != null">accstl_type = #{accstlType},</if>
            <if test="accdays != null">accdays = #{accdays},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="goodsPrice != null">goods_price = #{goodsPrice},</if>
            <if test="goodsLossType != null">goods_loss_type = #{goodsLossType},</if>
            <if test="goodsLossStd != null">goods_loss_std = #{goodsLossStd},</if>
            <if test="mblno != null">mblno = #{mblno},</if>
            <if test="ysl != null">ysl = #{ysl},</if>
            <if test="voy != null">voy = #{voy},</if>
            <if test="polId != null">pol_id = #{polId},</if>
            <if test="podId != null">pod_id = #{podId},</if>
            <if test="qtyPlan != null">qty_plan = #{qtyPlan},</if>
            <if test="qtyDisPatch != null">qty_dis_patch = #{qtyDisPatch},</if>
            <if test="weightPlan != null">weight_plan = #{weightPlan},</if>
            <if test="cntrDesc != null">cntr_desc = #{cntrDesc},</if>
            <if test="carNoList != null">car_no_list = #{carNoList},</if>
            <if test="loadAddr != null">load_addr = #{loadAddr},</if>
            <if test="loadAttn != null">load_attn = #{loadAttn},</if>
            <if test="loadAttntel != null">load_attntel = #{loadAttntel},</if>
            <if test="loadDate != null">load_date = #{loadDate},</if>
            <if test="mdLoadAddr != null">md_load_addr = #{mdLoadAddr},</if>
            <if test="mdLoadAttn != null">md_load_attn = #{mdLoadAttn},</if>
            <if test="mdLoadAttnTel != null">md_load_attn_tel = #{mdLoadAttnTel},</if>
            <if test="mdLoadDate != null">md_load_date = #{mdLoadDate},</if>
            <if test="unLoadAddr != null">un_load_addr = #{unLoadAddr},</if>
            <if test="unLoadAttn != null">un_load_attn = #{unLoadAttn},</if>
            <if test="unLoadAttnTel != null">un_load_attn_tel = #{unLoadAttnTel},</if>
            <if test="unLoadDate != null">un_load_date = #{unLoadDate},</if>
            <if test="routeId != null">route_id = #{routeId},</if>
            <if test="routeDesc != null">route_desc = #{routeDesc},</if>
            <if test="ifWaybill != null">if_waybill = #{ifWaybill},</if>
            <if test="ifNeedinvDr != null">if_needinv_dr = #{ifNeedinvDr},</if>
            <if test="postDate != null">post_date = #{postDate},</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="createTime != null">create_time = #{createTime},</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="deleteftmsorderbillsById" parameterType="Long">
        delete from F_TMSORDERBILLS where id = #{id}
    </delete>

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

</mapper>