<?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.warehouseBusiness.mapper.TWarehouseBillsMapper">

    <resultMap type="TWarehousebills" id="TWarehousebillsResult">
        <result property="fId"    column="f_id"    />
        <result property="fBillno"    column="f_billno"    />
        <result property="fCustomsdeclartion"    column="f_customsdeclartion"    />
        <result property="fOriginalbillno"    column="f_originalbillno"    />
        <result property="fDeptid"    column="f_deptid"    />
        <result property="fBsdeptid"    column="f_bsdeptid"    />
        <result property="fContacts"    column="f_contacts"    />
        <result property="fTel"    column="f_tel"    />
        <result property="fCorpid"    column="f_corpid"    />
        <result property="fTocorpid"    column="f_tocorpid"    />
        <result property="fStltypeid"    column="f_stltypeid"    />
        <result property="fBscorpno"    column="f_bscorpno"    />
        <result property="fWarehouseid"    column="f_warehouseid"    />
        <result property="fStorekeeper"    column="f_storekeeper"    />
        <result property="fChargedate"    column="f_chargedate"    />
        <result property="fBsdate"    column="f_bsdate"    />
        <result property="fPlanqty"    column="f_planqty"    />
        <result property="fPlangrossweight"    column="f_plangrossweight"    />
        <result property="fPlannetweight"    column="f_plannetweight"    />
        <result property="fPlanvolumn"    column="f_planvolumn"    />
        <result property="fQty"    column="f_qty"    />
        <result property="fGrossweight"    column="f_grossweight"    />
        <result property="fNetweight"    column="f_netweight"    />
        <result property="fVolumn"    column="f_volumn"    />
        <result property="fTrademodeid"    column="f_trademodeid"    />
        <result property="fBillingway"    column="f_billingway"    />
        <result property="fSbu"    column="f_sbu"    />
        <result property="fFeetunit"    column="f_feetunit"    />
        <result property="fMblno"    column="f_mblno"    />
        <result property="fVslvoy"    column="f_vslvoy"    />
        <result property="fMarks"    column="f_marks"    />
        <result property="fEta"    column="f_eta"    />
        <result property="fCustomno"    column="f_customno"    />
        <result property="fIfweigh"    column="f_ifweigh"    />
        <result property="fIfpledge"    column="f_ifpledge"    />
        <result property="fIfdamage"    column="f_ifdamage"    />
        <result property="fBankcorpid"    column="f_bankcorpid"    />
        <result property="fBilltype"    column="f_billtype"    />
        <result property="fBillstatus"    column="f_billstatus"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="fItemsStatus"    column="f_items_status"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="fBillingDeadline"    column="f_billing_deadline"    />
        <result property="fProductName"    column="f_product_name"    />
        <result property="fReviewDate"    column="f_review_date"    />
        <result property="fTruckno"    column="f_truckno"    />
        <result property="fDriverName"    column="f_driver_name"    />
        <result property="fDriverTel"    column="f_driver_tel"    />
        <result property="fDriverIdCar"    column="f_driver_id_car"    />
        <result property="fBusinessType"    column="f_business_type"    />
        <result property="fLabour"    column="f_labour"    />
        <result property="fFleet"    column="f_fleet"    />
        <result property="fInwarehouseid"    column="f_inwarehouseid"    />
        <result property="fBstime"    column="f_bstime"    />
        <result property="fCartype"    column="f_cartype"    />
        <result property="fGoodsid"    column="f_goodsid"    />
        <result property="fNewTrademodeid"    column="f_new_trademodeid"    />
    </resultMap>

    <sql id="selectTWarehousebillsVo">
        select f_id, f_billno, f_customsdeclartion, f_originalbillno, f_deptid, f_bsdeptid,
               f_contacts, f_tel, f_corpid, f_tocorpid, f_stltypeid, f_bscorpno, f_warehouseid,
               f_storekeeper, f_chargedate, f_bsdate, f_planqty, f_plangrossweight, f_plannetweight,
               f_planvolumn, f_qty, f_grossweight, f_netweight, f_volumn, f_trademodeid, f_billingway,
               f_sbu, f_feetunit, f_mblno, f_vslvoy, f_inwarehouseid, f_marks, f_eta, f_customno, f_ifweigh, f_ifpledge,
               f_ifdamage, f_bankcorpid, f_billtype, f_billstatus, del_flag, create_by, create_time,
               f_items_status, update_by, update_time, remark, f_billing_deadline, f_product_name,
               f_review_date, f_truckno, f_driver_name, f_driver_tel, f_driver_id_car, f_business_type,f_labour,f_fleet,
               f_bstime,f_cartype ,f_goodsid ,f_new_trademodeid  from t_warehousebills
    </sql>

    <select id="selectTWarehousebillsList" parameterType="TWarehousebills" resultMap="TWarehousebillsResult">
        select
            ware.*
        from
            t_warehousebills ware
            left join sys_user u on ware.create_by = u.user_name
            left join sys_dept d on ware.f_bsdeptid = d.dept_id
        <where>
            <if test="fBillno != null  and fBillno != ''">and f_billno = #{fBillno}</if>
            <if test="fCustomsdeclartion != null  and fCustomsdeclartion != ''">and f_customsdeclartion =
                #{fCustomsdeclartion}
            </if>
            <if test="fOriginalbillno != null  and fOriginalbillno != ''">and f_originalbillno = #{fOriginalbillno}</if>
            <if test="fDeptid != null ">and f_deptid = #{fDeptid}</if>
            <if test="fBsdeptid != null ">and f_bsdeptid = #{fBsdeptid}</if>
            <if test="fInwarehouseid != null ">and f_inwarehouseid = #{fInwarehouseid}</if>
            <if test="fContacts != null  and fContacts != ''">and f_contacts = #{fContacts}</if>
            <if test="fTel != null  and fTel != ''">and f_tel = #{fTel}</if>
            <if test="fCorpid != null ">and f_corpid = #{fCorpid}</if>
            <if test="fTocorpid != null ">and f_tocorpid = #{fTocorpid}</if>
            <if test="fChargedate != null ">and f_chargedate = #{fChargedate}</if>
            <if test='timeInterval != null and timeInterval[0] != null and timeInterval[0]!= ""'>
                and f_bsdate &gt;= #{timeInterval[0]}
            </if>
            <if test='timeInterval != null and timeInterval[1] != null and timeInterval[1]!= ""'>
                and f_bsdate &lt;= #{timeInterval[1]}
            </if>
            <if test="fStltypeid != null ">and f_stltypeid = #{fStltypeid}</if>
            <if test="fBscorpno != null  and fBscorpno != ''">and f_bscorpno = #{fBscorpno}</if>
            <if test="fWarehouseid != null ">and f_warehouseid = #{fWarehouseid}</if>
            <if test="fStorekeeper != null  and fStorekeeper != ''">and f_storekeeper = #{fStorekeeper}</if>
            <if test="fBsdate != null ">and f_bsdate = #{fBsdate}</if>
            <if test="fPlanqty != null ">and f_planqty = #{fPlanqty}</if>
            <if test="fProductName != null  and fProductName != ''"> and f_product_name like concat('%', #{fProductName}, '%')</if>
            <if test="fPlangrossweight != null ">and f_plangrossweight = #{fPlangrossweight}</if>
            <if test="fPlannetweight != null ">and f_plannetweight = #{fPlannetweight}</if>
            <if test="fPlanvolumn != null ">and f_planvolumn = #{fPlanvolumn}</if>
            <if test="fQty != null ">and f_qty = #{fQty}</if>
            <if test="fMarks != null  and fMarks != ''">and f_marks = #{fMarks}</if>
            <if test="fGrossweight != null ">and f_grossweight = #{fGrossweight}</if>
            <if test="fNetweight != null ">and f_netweight = #{fNetweight}</if>
            <if test="fVolumn != null ">and f_volumn = #{fVolumn}</if>
            <if test="fTrademodeid != null ">and f_trademodeid = #{fTrademodeid}</if>
            <if test="fBillingway != null ">and f_billingway = #{fBillingway}</if>
            <if test="fSbu != null ">and f_sbu = #{fSbu}</if>
            <if test="fFeetunit != null  and fFeetunit != ''">and f_feetunit = #{fFeetunit}</if>
            <if test="fMblno != null  and fMblno != ''">and f_mblno = #{fMblno}</if>
            <if test="fVslvoy != null  and fVslvoy != ''">and f_vslvoy = #{fVslvoy}</if>
            <if test="fEta != null ">and f_eta = #{fEta}</if>
            <if test="fCustomno != null  and fCustomno != ''">and f_customno = #{fCustomno}</if>
            <if test="fIfweigh != null  and fIfweigh != ''">and f_ifweigh = #{fIfweigh}</if>
            <if test="fIfpledge != null  and fIfpledge != ''">and f_ifpledge = #{fIfpledge}</if>
            <if test="fIfdamage != null  and fIfdamage != ''">and f_ifdamage = #{fIfdamage}</if>
            <if test="fBankcorpid != null ">and f_bankcorpid = #{fBankcorpid}</if>
            <if test="fBillingDeadline != null "> and f_billing_deadline = #{fBillingDeadline}</if>
            <if test="fBilltype != null  and fBilltype != ''">and f_billtype = #{fBilltype}</if>
            <if test="fBillstatus != null  and fBillstatus != ''">and f_billstatus = #{fBillstatus}</if>
            <if test="fNewTrademodeid != null ">and f_new_trademodeid = #{fNewTrademodeid}</if>
        </where>
        ${params.dataScope}
    </select>

    <select id="selectWarehouseBusinessList" parameterType="TWarehousebills" resultType="Map">
        SELECT
            DISTINCT
            bill.f_id AS fId,
            corp.f_name AS fCorpid,
            corpTo.f_name AS fTocorpid,
            bill.f_mblno AS fMblno,
            corpSub.f_name AS fSbu,
            bill.f_marks AS fMarks,
            bill.remark AS remark,
            bill.f_planqty AS fPlanqty,
            bill.f_plangrossweight AS fPlangrossweight,
            bill.f_plannetweight AS fPlannetweight,
            bill.f_planvolumn AS fPlanvolumn,
            bill.f_bsdate AS fBsdate,
            bill.f_trademodeid AS fTrademodeid,
            bill.f_truckno AS fTruckno,
            bill.f_driver_name AS fDriverName,
            bill.f_driver_tel AS fDriverTel,
            bill.f_driver_id_car AS fDriverIdCar,
            dictIn.dict_label AS fBusinessType,
            ware.f_name AS fWarehouseid,
            bill.f_qty AS fQty,
            bill.f_netweight AS fNetweight,
            bill.create_time AS createTime,
            ware1.f_name AS fInwarehouseid,
            bill.create_by AS createBy,
            bill.f_grossweight AS fGrossweight,
            bill.f_product_name AS fProductName,
            bill.f_billing_deadline AS fBillingDeadline,
            CASE WHEN  bill.f_billstatus = '1' THEN '录入'
                WHEN  bill.f_billstatus = '2' THEN '暂存'
                WHEN  bill.f_billstatus = '3' THEN '驳回'
                WHEN  bill.f_billstatus = '4' THEN '请核'
                WHEN  bill.f_billstatus = '5' THEN '审核中'
                WHEN  bill.f_billstatus = '6' THEN '全部入账'
            END
                 AS fBillstatus,
        CASE
        WHEN bill.f_billtype = 'SJRK'
        AND bill.f_items_status = '1' THEN
        '计划'
        WHEN bill.f_billtype = 'SJRK'
        AND bill.f_items_status = '2' THEN
        '待入库'
        WHEN bill.f_billtype = 'SJRK'
        AND bill.f_items_status = '3' THEN
        '入库中'
        WHEN bill.f_billtype = 'SJRK'
        AND bill.f_items_status = '4' THEN
        '已入库'
        WHEN bill.f_billtype = 'SJCK'
        AND bill.f_items_status = '1' THEN
        '计划'
        WHEN bill.f_billtype = 'SJCK'
        AND bill.f_items_status = '2' THEN
        '待出库'
        WHEN bill.f_billtype = 'SJCK'
        AND bill.f_items_status = '3' THEN
        '出库中'
        WHEN bill.f_billtype = 'SJCK'
        AND bill.f_items_status = '4' THEN
        '已出库'
        WHEN bill.f_billtype = 'CKDB'
        AND bill.f_items_status = '1' THEN
        '计划'
        WHEN bill.f_billtype = 'CKDB'
        AND bill.f_items_status = '2' THEN
        '待调拨'
        WHEN bill.f_billtype = 'CKDB'
        AND bill.f_items_status = '3' THEN
        '调拨中'
        WHEN bill.f_billtype = 'CKDB'
        AND bill.f_items_status = '4' THEN
        '已调拨'
        WHEN bill.f_billtype = 'HWTG'
        AND bill.f_items_status = '1' THEN
        '计划'
        WHEN bill.f_billtype = 'HWTG'
        AND bill.f_items_status = '2' THEN
        '待调拨'
        WHEN bill.f_billtype = 'HWTG'
        AND bill.f_items_status = '3' THEN
        '调拨中'
        WHEN bill.f_billtype = 'HWTG'
        AND bill.f_items_status = '4' THEN
        '已调拨'
        END AS fItemsStatus,
            bill.f_billno AS fBillno,
            g.f_name AS fGoodsid,
            bill.f_storekeeper AS fStorekeeper
        FROM
            t_warehousebills bill
            LEFT JOIN t_goods g ON g.f_id = bill.f_goodsid
            left join sys_user u on bill.create_by = u.user_name
            left join sys_dept d on bill.f_bsdeptid = d.dept_id
            LEFT JOIN t_corps corp ON corp.f_id = bill.f_corpid
            LEFT JOIN t_corps corpTo ON corpTo.f_id = bill.f_tocorpid
            LEFT JOIN t_corps corpSub ON corpSub.f_id = bill.f_sbu
            LEFT JOIN t_warehouse ware ON ware.f_id = bill.f_warehouseid
            LEFT JOIN t_warehouse ware1 ON ware1.f_id = bill.f_inwarehouseid
            LEFT JOIN t_warehousebillsitems item ON item.f_pid = bill.f_id
            LEFT JOIN t_goods goods ON goods.f_id = item.f_goodsid
            LEFT JOIN sys_dict_data dictIn ON dictIn.dict_value = bill.f_business_type
        <where>
            <if test="fBillno != null  and fBillno != ''">and bill.f_billno like concat('%', #{fBillno}, '%')</if>
            <if test="fCustomsdeclartion != null  and fCustomsdeclartion != ''">and bill.f_customsdeclartion =
                #{fCustomsdeclartion}
            </if>
            <if test="fOriginalbillno != null  and fOriginalbillno != ''">and bill.f_originalbillno =
                #{fOriginalbillno}
            </if>
            <if test="fDeptid != null ">and bill.f_deptid = #{fDeptid}</if>
            <if test="fInwarehouseid != null ">and bill.f_inwarehouseid = #{fInwarehouseid}</if>
            <if test="fBsdeptid != null ">and bill.f_bsdeptid = #{fBsdeptid}</if>
            <if test="fChargedate != null ">and bill.f_chargedate = #{fChargedate}</if>
            <if test='timeInterval != null and timeInterval[0] != null and timeInterval[0]!= ""'>
                and bill.f_bsdate &gt;= #{timeInterval[0]}
            </if>
            <if test='timeInterval != null and timeInterval[1] != null and timeInterval[1]!= ""'>
                and bill.f_bsdate &lt;= #{timeInterval[1]}
            </if>
            <if test="fGoodsid != null  and fGoodsid != ''">and item.f_goodsid = #{fGoodsid}</if>
            <if test="fContacts != null  and fContacts != ''">and bill.f_contacts = #{fContacts}</if>
            <if test="fTel != null  and fTel != ''">and bill.f_tel = #{fTel}</if>
            <if test="fCorpid != null ">and bill.f_corpid = #{fCorpid}</if>
            <if test="fBillingDeadline != null ">and bill.f_billing_deadline = #{fBillingDeadline}</if>
            <if test="fTocorpid != null ">and bill.f_tocorpid = #{fTocorpid}</if>
            <if test="fMarks != null  and fMarks != ''">and bill.f_marks like concat('%', #{fMarks}, '%')</if>
            <if test="fStltypeid != null ">and bill.f_stltypeid = #{fStltypeid}</if>
            <if test="fReviewDate != null "> and f_review_date = #{fReviewDate}</if>
            <if test="fBscorpno != null  and fBscorpno != ''">and bill.f_bscorpno = #{fBscorpno}</if>
            <if test="fWarehouseid != null ">and bill.f_warehouseid = #{fWarehouseid}</if>
            <if test="fStorekeeper != null  and fStorekeeper != ''">and bill.f_storekeeper = #{fStorekeeper}</if>
            <if test="fBsdate != null ">and bill.f_bsdate = #{fBsdate}</if>
            <if test="fPlanqty != null ">and bill.f_planqty = #{fPlanqty}</if>
            <if test="fPlangrossweight != null ">and bill.f_plangrossweight = #{fPlangrossweight}</if>
            <if test="fPlannetweight != null ">and bill.f_plannetweight = #{fPlannetweight}</if>
            <if test="fPlanvolumn != null ">and bill.f_planvolumn = #{fPlanvolumn}</if>
            <if test="fQty != null ">and bill.f_qty = #{fQty}</if>
            <if test="fGrossweight != null ">and bill.f_grossweight = #{fGrossweight}</if>
            <if test="fNetweight != null ">and bill.f_netweight = #{fNetweight}</if>
            <if test="fVolumn != null ">and bill.f_volumn = #{fVolumn}</if>
            <if test="fTrademodeid != null ">and bill.f_trademodeid = #{fTrademodeid}</if>
            <if test="fBillingway != null ">and bill.f_billingway = #{fBillingway}</if>
            <if test="fSbu != null ">and bill.f_sbu = #{fSbu}</if>
            <if test="fFeetunit != null  and fFeetunit != ''">and bill.f_feetunit = #{fFeetunit}</if>
            <if test="fMblno != null  and fMblno != ''">and bill.f_mblno like concat('%', #{fMblno}, '%')</if>
            <if test="fVslvoy != null  and fVslvoy != ''">and bill.f_vslvoy = #{fVslvoy}</if>
            <if test="fEta != null ">and bill.f_eta = #{fEta}</if>
            <if test="fCustomno != null  and fCustomno != ''">and bill.f_customno = #{fCustomno}</if>
            <if test="fIfweigh != null  and fIfweigh != ''">and bill.f_ifweigh = #{fIfweigh}</if>
            <if test="fIfpledge != null  and fIfpledge != ''">and bill.f_ifpledge = #{fIfpledge}</if>
            <if test="fIfdamage != null  and fIfdamage != ''">and bill.f_ifdamage = #{fIfdamage}</if>
            <if test="fBankcorpid != null ">and bill.f_bankcorpid = #{fBankcorpid}</if>
            <if test="fBilltype != null  and fBilltype == 'SJRK'">
                and bill.f_billtype = #{fBilltype}
                AND dictIn.dict_type = 'st_in_type'
                AND dictIn.status = '0'
            </if>
            <if test="fBilltype != null  and fBilltype == 'SJCK'">
                and bill.f_billtype = #{fBilltype}
                AND dictIn.dict_type = 'st_out_type'
                AND dictIn.status = '0'
            </if>
            <if test="fBilltype != null  and fBilltype == 'CKDB'">
                and bill.f_billtype = #{fBilltype}
                AND dictIn.dict_type = 'st_trans_type'
                AND dictIn.status = '0'
            </if>
            <if test="fBilltype != null  and fBilltype == 'HWTG'">
                and bill.f_billtype = #{fBilltype}
                AND dictIn.dict_type = 'st_trans_type'
                AND dictIn.status = '0'
            </if>
            <if test="fBillstatus != null  and fBillstatus != ''">and bill.f_billstatus = #{fBillstatus}</if>
            <if test="fItemsStatus != null  and fItemsStatus != ''">and bill.f_items_status = #{fItemsStatus}</if>
            <if test="createBy != null and createBy != ''">and bill.create_by = #{createBy}</if>
            <if test="fNewTrademodeid != null ">and bill.f_new_trademodeid = #{fNewTrademodeid}</if>
        </where>
        ${params.dataScope}
            ORDER BY  bill.f_billstatus , bill.f_bsdate  DESC
    </select>

    <select id="selectWarehouseBusinessList1" parameterType="TWarehousebills" resultType="Map">
        SELECT
        DISTINCT
        bill.f_id AS fId,
        corp.f_name AS fCorpid,
        corpTo.f_name AS fTocorpid,
        bill.f_mblno AS fMblno,
        corpSub.f_name AS fSbu,
        bill.f_marks AS fMarks,
        bill.remark AS remark,
        bill.f_planqty AS fPlanqty,
        bill.f_plangrossweight AS fPlangrossweight,
        bill.f_plannetweight AS fPlannetweight,
        bill.f_planvolumn AS fPlanvolumn,
        bill.f_bsdate AS fBsdate,
        dict.dict_label AS fTrademodeid,
        bill.f_truckno AS fTruckno,
        bill.f_driver_name AS fDriverName,
        bill.f_driver_tel AS fDriverTel,
        bill.f_driver_id_car AS fDriverIdCar,
        ware.f_name AS fWarehouseid,
        bill.f_qty AS fQty,
        bill.f_netweight AS fNetweight,
        bill.create_time AS createTime,
        ware1.f_name AS fInwarehouseid,
        bill.create_by AS createBy,
        bill.f_grossweight AS fGrossweight,
        bill.f_product_name AS fProductName,
        bill.f_billing_deadline AS fBillingDeadline,
        CASE
        WHEN bill.f_billtype = 'HQZY' AND  bill.f_billstatus = '1' THEN '录入'
        WHEN bill.f_billtype = 'HQZY' AND   bill.f_billstatus = '2' THEN '暂存'
        WHEN bill.f_billtype = 'HQZY' AND   bill.f_billstatus = '3' THEN '驳回'
        WHEN bill.f_billtype = 'HQZY' AND   bill.f_billstatus = '4' THEN '请核'
        WHEN bill.f_billtype = 'HQZY' AND   bill.f_billstatus = '5' THEN '审核中'
        WHEN bill.f_billtype = 'HQZY' AND   bill.f_billstatus = '6' THEN '全部入账'
        WHEN bill.f_billtype = 'JSCCF' AND  bill.f_billstatus = '1' THEN '新建'
        WHEN bill.f_billtype = 'JSCCF' AND   bill.f_billstatus = '2' THEN '暂存'
        WHEN bill.f_billtype = 'JSCCF' AND   bill.f_billstatus = '3' THEN '审核驳回'
        WHEN bill.f_billtype = 'JSCCF' AND   bill.f_billstatus = '4' THEN '提交审核'
        WHEN bill.f_billtype = 'JSCCF' AND   bill.f_billstatus = '5' THEN '审核中'
        WHEN bill.f_billtype = 'JSCCF' AND   bill.f_billstatus = '6' THEN '审核通过'
        END
        AS fBillstatus,
        CASE
        WHEN bill.f_billtype = 'HQZY'
        AND bill.f_items_status = '1' THEN
        '计划'
        WHEN bill.f_billtype = 'HQZY'
        AND bill.f_items_status = '2' THEN
        '待货转'
        WHEN bill.f_billtype = 'HQZY'
        AND bill.f_items_status = '3' THEN
        '货转中'
        WHEN bill.f_billtype = 'HQZY'
        AND bill.f_items_status = '4' THEN
        '已货转'
        END
        AS fItemsStatus,
        bill.f_billno AS fBillno,
        g.f_name AS fGoodsid,
        bill.f_storekeeper AS fStorekeeper
        FROM
        t_warehousebills bill
        LEFT JOIN t_goods g ON g.f_id = bill.f_goodsid
        left join sys_user u on bill.create_by = u.user_name
        left join sys_dept d on bill.f_bsdeptid = d.dept_id
        LEFT JOIN t_corps corp ON corp.f_id = bill.f_corpid
        LEFT JOIN t_corps corpTo ON corpTo.f_id = bill.f_tocorpid
        LEFT JOIN t_corps corpSub ON corpSub.f_id = bill.f_sbu
        LEFT JOIN t_warehouse ware ON ware.f_id = bill.f_warehouseid
        LEFT JOIN t_warehouse ware1 ON ware1.f_id = bill.f_inwarehouseid
        LEFT JOIN t_warehousebillsitems item ON item.f_pid = bill.f_id
        LEFT JOIN t_goods goods ON goods.f_id = item.f_goodsid
        LEFT JOIN sys_dict_data dict ON dict.dict_value = bill.f_trademodeid
        <where>
            dict.status = '0'
            AND dict.dict_type = 'data_trademodes'
            <if test="fBillno != null  and fBillno != ''">and bill.f_billno like concat('%', #{fBillno}, '%')</if>
            <if test="fCustomsdeclartion != null  and fCustomsdeclartion != ''">and bill.f_customsdeclartion =
                #{fCustomsdeclartion}
            </if>
            <if test="fOriginalbillno != null  and fOriginalbillno != ''">and bill.f_originalbillno =
                #{fOriginalbillno}
            </if>
            <if test="fDeptid != null ">and bill.f_deptid = #{fDeptid}</if>
            <if test="fInwarehouseid != null ">and bill.f_inwarehouseid = #{fInwarehouseid}</if>
            <if test="fBsdeptid != null ">and bill.f_bsdeptid = #{fBsdeptid}</if>
            <if test="fChargedate != null ">and bill.f_chargedate = #{fChargedate}</if>
            <if test='timeInterval != null and timeInterval[0] != null and timeInterval[0]!= ""'>
                and bill.f_bsdate &gt;= #{timeInterval[0]}
            </if>
            <if test='timeInterval != null and timeInterval[1] != null and timeInterval[1]!= ""'>
                and bill.f_bsdate &lt;= #{timeInterval[1]}
            </if>
            <if test="fGoodsid != null  and fGoodsid != ''">and item.f_goodsid = #{fGoodsid}</if>
            <if test="fContacts != null  and fContacts != ''">and bill.f_contacts = #{fContacts}</if>
            <if test="fTel != null  and fTel != ''">and bill.f_tel = #{fTel}</if>
            <if test="fCorpid != null ">and bill.f_corpid = #{fCorpid}</if>
            <if test="fBillingDeadline != null ">and bill.f_billing_deadline = #{fBillingDeadline}</if>
            <if test="fTocorpid != null ">and bill.f_tocorpid = #{fTocorpid}</if>
            <if test="fMarks != null  and fMarks != ''">and bill.f_marks like concat('%', #{fMarks}, '%')</if>
            <if test="fStltypeid != null ">and bill.f_stltypeid = #{fStltypeid}</if>
            <if test="fReviewDate != null "> and f_review_date = #{fReviewDate}</if>
            <if test="fBscorpno != null  and fBscorpno != ''">and bill.f_bscorpno = #{fBscorpno}</if>
            <if test="fWarehouseid != null ">and bill.f_warehouseid = #{fWarehouseid}</if>
            <if test="fStorekeeper != null  and fStorekeeper != ''">and bill.f_storekeeper = #{fStorekeeper}</if>
            <if test="fBsdate != null ">and bill.f_bsdate = #{fBsdate}</if>
            <if test="fPlanqty != null ">and bill.f_planqty = #{fPlanqty}</if>
            <if test="fPlangrossweight != null ">and bill.f_plangrossweight = #{fPlangrossweight}</if>
            <if test="fPlannetweight != null ">and bill.f_plannetweight = #{fPlannetweight}</if>
            <if test="fPlanvolumn != null ">and bill.f_planvolumn = #{fPlanvolumn}</if>
            <if test="fQty != null ">and bill.f_qty = #{fQty}</if>
            <if test="fGrossweight != null ">and bill.f_grossweight = #{fGrossweight}</if>
            <if test="fNetweight != null ">and bill.f_netweight = #{fNetweight}</if>
            <if test="fVolumn != null ">and bill.f_volumn = #{fVolumn}</if>
            <if test="fTrademodeid != null ">and bill.f_trademodeid = #{fTrademodeid}</if>
            <if test="fBillingway != null ">and bill.f_billingway = #{fBillingway}</if>
            <if test="fSbu != null ">and bill.f_sbu = #{fSbu}</if>
            <if test="fFeetunit != null  and fFeetunit != ''">and bill.f_feetunit = #{fFeetunit}</if>
            <if test="fMblno != null  and fMblno != ''">and bill.f_mblno like concat('%', #{fMblno}, '%')</if>
            <if test="fVslvoy != null  and fVslvoy != ''">and bill.f_vslvoy = #{fVslvoy}</if>
            <if test="fEta != null ">and bill.f_eta = #{fEta}</if>
            <if test="fCustomno != null  and fCustomno != ''">and bill.f_customno = #{fCustomno}</if>
            <if test="fIfweigh != null  and fIfweigh != ''">and bill.f_ifweigh = #{fIfweigh}</if>
            <if test="fIfpledge != null  and fIfpledge != ''">and bill.f_ifpledge = #{fIfpledge}</if>
            <if test="fIfdamage != null  and fIfdamage != ''">and bill.f_ifdamage = #{fIfdamage}</if>
            <if test="fBankcorpid != null ">and bill.f_bankcorpid = #{fBankcorpid}</if>
            <if test="fBilltype != null  and fBilltype != ''">
                and bill.f_billtype = #{fBilltype}
            </if>
            <if test="fBillstatus != null  and fBillstatus != ''">and bill.f_billstatus = #{fBillstatus}</if>
            <if test="fItemsStatus != null  and fItemsStatus != ''">and bill.f_items_status = #{fItemsStatus}</if>
            <if test="createBy != null and createBy != ''">and bill.create_by = #{createBy}</if>
            <if test="fNewTrademodeid != null ">and bill.f_new_trademodeid = #{fNewTrademodeid}</if>
        </where>
        ${params.dataScope}
        ORDER BY  bill.f_billstatus , bill.f_bsdate  DESC
    </select>

    <select id="selectTWarehousebillsById" parameterType="Long" resultMap="TWarehousebillsResult">
        <include refid="selectTWarehousebillsVo"/>
        where f_id = #{fId}
        ORDER BY f_bsdate desc
    </select>

    <select id="selectTWarehousebillsItemsList"
            resultType="com.ruoyi.warehouseBusiness.domain.TWareHouseExcelItems">
        SELECT
            ( @ii := @ii + 1 ) AS fId,
            CASE
                wi.f_billtype
                WHEN  'SJRK' THEN
                    '入库'
                WHEN  'SJCK' THEN
                    '出库'
                WHEN 'KCZZ' THEN
                    '库存总账'
                END AS fBilltype,
            wi.f_mblno AS fMblno,
            wi.f_product_name AS fGoodsid,
            wi.f_marks AS fMarks,
            wi.f_bsdate AS fBsdate,
            dict.dict_label AS fFeeUnitid,
            wi.f_billing_qty AS fBillingQty,
            wi.f_chargedate AS fChargedate,
            wi.f_billing_deadline AS fBillingDeadline,
            wi.f_billing_days AS fBillingDays,
            wi.f_inventory_days AS fInventoryDays,
            wi.f_amt AS fAmt,
            wi.remark AS remark
        FROM
            t_warehousebills w
                LEFT JOIN t_warehousebillsfees wi ON w.f_id = wi.f_pid
                LEFT JOIN sys_dict_data dict ON dict.dict_value = wi.f_feeUnitid
                ,(
                SELECT
                    @ii := 0
            ) AS ii
        WHERE
            w.f_id = #{fId}
            AND dict.status = '0'
            AND dict.dict_type = 'data_unitfees'
    </select>

    <select id="selectInventorySJRKList" parameterType="TWarehousebills"  resultType="java.util.Map">
        SELECT
            co.f_name AS fName,
            it.f_bsdate AS fBsdate,
            leg.f_mblno AS fMblno,
            it.f_business_type AS fBusinessType,
            dict.dict_label AS fBusinessTypes,
            it.f_marks AS fMarks ,
            goo.f_name AS fGoodsName,
            it.f_warehouse_information AS fWarehouseLocationids,
            dicttr.dict_label AS fTrademodeid,
            it.f_qty AS fQty,
            it.f_grossweight AS fGrossweight,
            it.f_netweight AS fNetweight,
            CASE
            it.f_billtype
            WHEN 'SJRK' THEN
            '入库'
            WHEN 'SJCK' THEN
            '出库'
            WHEN 'CKDB' THEN
            '调拨'
            END AS fBilltype
        FROM
            t_warehousebills leg
                left join sys_user u on leg.create_by = u.user_name
                left join sys_dept d on leg.f_bsdeptid = d.dept_id
                LEFT JOIN t_warehousebillsitems it ON leg.f_id = it.f_pid
                LEFT JOIN t_goods goo ON it.f_goodsid = goo.f_id
                LEFT JOIN t_corps co ON leg.f_corpid = co.f_id
                LEFT JOIN sys_dict_data dict ON dict.dict_value = it.f_business_type
                LEFT JOIN t_warehouse ware ON ware.f_id = it.f_warehouselocid
                LEFT JOIN sys_dict_data dicttr ON dicttr.dict_value = leg.f_trademodeid
        <where>
            dict.status = '0'
            AND dict.dict_type = 'storage_type'
            AND dicttr.STATUS = '0'
            AND dicttr.dict_type = 'data_trademodes'
            AND leg.f_billtype in ('SJRK','CKDB')
            <if test="fGoodsid != null ">and it.f_goodsid = #{fGoodsid}</if>
            <if test="fTrademodeid != null ">and leg.f_trademodeid = #{fTrademodeid}</if>
            <if test="fNewTrademodeid != null ">and leg.f_new_trademodeid = #{fNewTrademodeid}</if>
            <if test="fCorpid != null ">and leg.f_corpid = #{fCorpid}</if>
            <if test="fMblno != null ">and leg.f_mblno = #{fMblno}</if>
            <if test="fLocation != null  and fLocation ==1 ">
                and it.f_warehouselocid = #{fWarehouseid}
            </if>
            <if test="fLocation != null  and fLocation ==0 ">
                and ware.ancestors  LIKE  concat('%', #{fWarehouseid}, '%')
            </if>
            <if test='timeInterval != null and timeInterval[0] != null and timeInterval[0]!= ""'>
                and it.f_bsdate &gt;= #{timeInterval[0]}
            </if>
            <if test='timeInterval != null and timeInterval[1] != null and timeInterval[1]!= ""'>
                and it.f_bsdate &lt;= #{timeInterval[1]}
            </if>
        </where>
        ${params.dataScope}
    </select>

    <select id="selectInventorySJCKList" parameterType="TWarehousebills"  resultType="java.util.Map">
        SELECT
            co.f_name AS fName,
            it.f_bsdate AS fBsdate,
            leg.f_mblno AS fMblno,
            it.f_business_type AS fBusinessType,
            dict.dict_label AS fBusinessTypes,
            it.f_marks AS fMarks ,
            goo.f_name AS fGoodsName,
            dicttr.dict_label AS fTrademodeid,
            it.f_qty AS fQty,
            it.f_grossweight AS fGrossweight,
            it.f_netweight AS fNetweight,
            CASE
            it.f_billtype
            WHEN 'SJRK' THEN
            '入库'
            WHEN 'SJCK' THEN
            '出库'
            WHEN 'CKDB' THEN
            '调拨'
            END AS fBilltype ,
            CASE
            it.f_billtype
            WHEN 'SJRK' THEN
            it.f_warehouse_information
            WHEN 'SJCK' THEN
            it.f_warehouse_information
            WHEN 'CKDB' THEN
            it.f_orgwarehouse_information
            END AS fWarehouseLocationids
        FROM
            t_warehousebills leg
            left join sys_user u on leg.create_by = u.user_name
            left join sys_dept d on leg.f_bsdeptid = d.dept_id
            LEFT JOIN t_warehousebillsitems it ON leg.f_id = it.f_pid
            LEFT JOIN t_goods goo ON it.f_goodsid = goo.f_id
            LEFT JOIN t_corps co ON leg.f_corpid = co.f_id
            LEFT JOIN sys_dict_data dict ON dict.dict_value = it.f_business_type
            LEFT JOIN t_warehouse ware ON ware.f_id = it.f_warehouselocid
            LEFT JOIN sys_dict_data dicttr ON dicttr.dict_value = leg.f_trademodeid
        <where>
            dict.status = '0'
            AND dict.dict_type = 'storage_type'
            AND dicttr.STATUS = '0'
            AND dicttr.dict_type = 'data_trademodes'
            AND leg.f_billtype in ('SJCK','CKDB')
            <if test="fGoodsid != null ">and it.f_goodsid = #{fGoodsid}</if>
            <if test="fTrademodeid != null ">and leg.f_trademodeid = #{fTrademodeid}</if>
            <if test="fNewTrademodeid != null ">and leg.f_new_trademodeid = #{fNewTrademodeid}</if>
            <if test="fCorpid != null ">and leg.f_corpid = #{fCorpid}</if>
            <if test="fMblno != null ">and leg.f_mblno = #{fMblno}</if>
            <if test="fLocation != null  and fLocation ==1 ">
                and it.f_warehouselocid = #{fWarehouseid}
            </if>
            <if test="fLocation != null  and fLocation ==0 ">
                and ware.ancestors  LIKE  concat('%', #{fWarehouseid}, '%')
            </if>
            <if test='timeInterval != null and timeInterval[0] != null and timeInterval[0]!= ""'>
                and it.f_bsdate &gt;= #{timeInterval[0]}
            </if>
            <if test='timeInterval != null and timeInterval[1] != null and timeInterval[1]!= ""'>
                and it.f_bsdate &lt;= #{timeInterval[1]}
            </if>
        </where>
        ${params.dataScope}
    </select>

    <select id="selectTWarehousebillsItemList"
            resultType="com.ruoyi.reportManagement.domain.TWareHouseItemsExcel">
        SELECT
            ( @ii := @ii + 1 ) AS fId,
            co.f_name AS fCorpid,
            it.f_bsdate AS fBsdate,
            leg.f_mblno AS fMblno,
            dict.dict_label AS fBusinessType,
            it.f_marks AS fMarks,
            go.f_name AS fGoodsid,
            it.f_warehouse_information AS fWarehouseInformation,
            dicttr.dict_label AS fTrademodeid,
            it.f_qty AS fQty,
            it.f_grossweight AS fGrossweight,
            it.f_netweight AS fNetweight
        FROM
            t_warehousebills leg
                LEFT JOIN t_warehousebillsitems it ON leg.f_id = it.f_pid
                LEFT JOIN t_goods go ON it.f_goodsid = go.f_id
                LEFT JOIN t_corps co ON leg.f_corpid = co.f_id
                LEFT JOIN sys_dict_data dict ON dict.dict_value = it.f_business_type
                LEFT JOIN t_warehouse_area area ON area.f_id = it.f_warehouselocid
                LEFT JOIN sys_dict_data dicttr ON dicttr.dict_value = leg.f_trademodeid,(
                SELECT
                @ii := 0
                ) AS ii
        WHERE
              dict.STATUS = '0'
              AND dict.dict_type = 'storage_type'
              AND dicttr.STATUS = '0'
              AND dicttr.dict_type = 'data_trademodes'
              AND leg.f_billtype IN (
                'SJRk',
                'SJCK'
                )
        <if test="fBilltype != null">AND leg.f_billtype = #{fBilltype}</if>
        <if test="fGoodsid != null ">and it.f_goodsid = #{fGoodsid}</if>
        <if test="fTrademodeid != null ">and leg.f_trademodeid = #{fTrademodeid}</if>
        <if test="fNewTrademodeid != null ">and leg.f_new_trademodeid = #{fNewTrademodeid}</if>
        <if test="fCorpid != null ">and leg.f_corpid = #{fCorpid}</if>
        <if test="fMblno != null ">and leg.f_mblno = #{fMblno}</if>
        <if test="fLocation != null  and fLocation ==1 ">
            and it.f_warehouselocid = #{fWarehouseid}
        </if>
        <if test="fLocation != null  and fLocation ==0 ">
            and ware.ancestors  LIKE  concat('%', #{fWarehouseid}, '%')
        </if>
        <if test='timeInterval != null and timeInterval[0] != null and timeInterval[0]!= ""'>
            and it.f_bsdate &gt;= #{timeInterval[0]}
        </if>
        <if test='timeInterval != null and timeInterval[1] != null and timeInterval[1]!= ""'>
            and it.f_bsdate &lt;= #{timeInterval[1]}
        </if>
    </select>

    <select id="selectContainMblno" parameterType="TWarehousebills" resultType="int">
        SELECT
            count( f_id )
        FROM
            t_warehousebills
        where
            f_mblno = #{mblNo}
            AND f_bsdate = #{currentDay}
            AND f_billtype = #{fBilltype}
    </select>

    <insert id="insertTWarehousebills" parameterType="TWarehousebills" useGeneratedKeys="true" keyProperty="fId">
        insert into t_warehousebills
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fBillno != null">f_billno,</if>
            <if test="fCustomsdeclartion != null">f_customsdeclartion,</if>
            <if test="fOriginalbillno != null">f_originalbillno,</if>
            <if test="fDeptid != null">f_deptid,</if>
            <if test="fBsdeptid != null">f_bsdeptid,</if>
            <if test="fContacts != null">f_contacts,</if>
            <if test="fTel != null">f_tel,</if>
            <if test="fCorpid != null">f_corpid,</if>
            <if test="fTocorpid != null">f_tocorpid,</if>
            <if test="fStltypeid != null">f_stltypeid,</if>
            <if test="fBscorpno != null and fBscorpno != ''">f_bscorpno,</if>
            <if test="fWarehouseid != null">f_warehouseid,</if>
            <if test="fStorekeeper != null">f_storekeeper,</if>
            <if test="fChargedate != null">f_chargedate,</if>
            <if test="fBsdate != null">f_bsdate,</if>
            <if test="fPlanqty != null">f_planqty,</if>
            <if test="fPlangrossweight != null">f_plangrossweight,</if>
            <if test="fPlannetweight != null">f_plannetweight,</if>
            <if test="fPlanvolumn != null">f_planvolumn,</if>
            <if test="fQty != null">f_qty,</if>
            <if test="fGrossweight != null">f_grossweight,</if>
            <if test="fNetweight != null">f_netweight,</if>
            <if test="fVolumn != null">f_volumn,</if>
            <if test="fTrademodeid != null">f_trademodeid,</if>
            <if test="fBillingway != null">f_billingway,</if>
            <if test="fSbu != null">f_sbu,</if>
            <if test="fFeetunit != null">f_feetunit,</if>
            <if test="fMblno != null">f_mblno,</if>
            <if test="fVslvoy != null">f_vslvoy,</if>
            <if test="fMarks != null and fMarks != ''">f_marks,</if>
            <if test="fEta != null">f_eta,</if>
            <if test="fCustomno != null">f_customno,</if>
            <if test="fIfweigh != null">f_ifweigh,</if>
            <if test="fIfpledge != null">f_ifpledge,</if>
            <if test="fIfdamage != null">f_ifdamage,</if>
            <if test="fBankcorpid != null">f_bankcorpid,</if>
            <if test="fBilltype != null">f_billtype,</if>
            <if test="fBillstatus != null">f_billstatus,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="fItemsStatus != null">f_items_status,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="fBillingDeadline != null">f_billing_deadline,</if>
            <if test="fProductName != null">f_product_name,</if>
            <if test="fReviewDate != null">f_review_date,</if>
            <if test="fTruckno != null">f_truckno,</if>
            <if test="fDriverName != null">f_driver_name,</if>
            <if test="fDriverTel != null">f_driver_tel,</if>
            <if test="fDriverIdCar != null">f_driver_id_car,</if>
            <if test="fBusinessType != null">f_business_type,</if>
            <if test="fLabour != null">f_labour,</if>
            <if test="fFleet != null">f_fleet,</if>
            <if test="fInwarehouseid != null">f_inwarehouseid,</if>
            <if test="fBstime != null">f_bstime,</if>
            <if test="fCartype != null">f_cartype,</if>
            <if test="fGoodsid != null">f_goodsid,</if>
            <if test="fNewTrademodeid != null">f_new_trademodeid,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fBillno != null">#{fBillno},</if>
            <if test="fCustomsdeclartion != null">#{fCustomsdeclartion},</if>
            <if test="fOriginalbillno != null">#{fOriginalbillno},</if>
            <if test="fDeptid != null">#{fDeptid},</if>
            <if test="fBsdeptid != null">#{fBsdeptid},</if>
            <if test="fContacts != null">#{fContacts},</if>
            <if test="fTel != null">#{fTel},</if>
            <if test="fCorpid != null">#{fCorpid},</if>
            <if test="fTocorpid != null">#{fTocorpid},</if>
            <if test="fStltypeid != null">#{fStltypeid},</if>
            <if test="fBscorpno != null and fBscorpno != ''">#{fBscorpno},</if>
            <if test="fWarehouseid != null">#{fWarehouseid},</if>
            <if test="fStorekeeper != null">#{fStorekeeper},</if>
            <if test="fChargedate != null">#{fChargedate},</if>
            <if test="fBsdate != null">#{fBsdate},</if>
            <if test="fPlanqty != null">#{fPlanqty},</if>
            <if test="fPlangrossweight != null">#{fPlangrossweight},</if>
            <if test="fPlannetweight != null">#{fPlannetweight},</if>
            <if test="fPlanvolumn != null">#{fPlanvolumn},</if>
            <if test="fQty != null">#{fQty},</if>
            <if test="fGrossweight != null">#{fGrossweight},</if>
            <if test="fNetweight != null">#{fNetweight},</if>
            <if test="fVolumn != null">#{fVolumn},</if>
            <if test="fTrademodeid != null">#{fTrademodeid},</if>
            <if test="fBillingway != null">#{fBillingway},</if>
            <if test="fSbu != null">#{fSbu},</if>
            <if test="fFeetunit != null">#{fFeetunit},</if>
            <if test="fMblno != null">#{fMblno},</if>
            <if test="fVslvoy != null">#{fVslvoy},</if>
            <if test="fMarks != null and fMarks != ''">#{fMarks},</if>
            <if test="fEta != null">#{fEta},</if>
            <if test="fCustomno != null">#{fCustomno},</if>
            <if test="fIfweigh != null">#{fIfweigh},</if>
            <if test="fIfpledge != null">#{fIfpledge},</if>
            <if test="fIfdamage != null">#{fIfdamage},</if>
            <if test="fBankcorpid != null">#{fBankcorpid},</if>
            <if test="fBilltype != null">#{fBilltype},</if>
            <if test="fBillstatus != null">#{fBillstatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="fItemsStatus != null">#{fItemsStatus},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="fBillingDeadline != null">#{fBillingDeadline},</if>
            <if test="fProductName != null">#{fProductName},</if>
            <if test="fReviewDate != null">#{fReviewDate},</if>
            <if test="fTruckno != null">#{fTruckno},</if>
            <if test="fDriverName != null">#{fDriverName},</if>
            <if test="fDriverTel != null">#{fDriverTel},</if>
            <if test="fDriverIdCar != null">#{fDriverIdCar},</if>
            <if test="fBusinessType != null">#{fBusinessType},</if>
            <if test="fLabour != null">#{fLabour},</if>
            <if test="fFleet != null">#{fFleet},</if>
            <if test="fInwarehouseid != null">#{fInwarehouseid},</if>
            <if test="fBstime != null">#{fBstime},</if>
            <if test="fCartype != null">#{fCartype},</if>
            <if test="fGoodsid != null">#{fGoodsid},</if>
            <if test="fNewTrademodeid != null">#{fNewTrademodeid},</if>
        </trim>
    </insert>

    <update id="updateTWarehousebills" parameterType="TWarehousebills">
        update t_warehousebills
        <trim prefix="SET" suffixOverrides=",">
            <if test="fBillno != null">f_billno = #{fBillno},</if>
            <if test="fCustomsdeclartion != null">f_customsdeclartion = #{fCustomsdeclartion},</if>
            <if test="fOriginalbillno != null">f_originalbillno = #{fOriginalbillno},</if>
            <if test="fDeptid != null">f_deptid = #{fDeptid},</if>
            <if test="fBsdeptid != null">f_bsdeptid = #{fBsdeptid},</if>
            <if test="fContacts != null">f_contacts = #{fContacts},</if>
            <if test="fTel != null">f_tel = #{fTel},</if>
            <if test="fCorpid != null">f_corpid = #{fCorpid},</if>
            <if test="fTocorpid != null">f_tocorpid = #{fTocorpid},</if>
            <if test="fStltypeid != null">f_stltypeid = #{fStltypeid},</if>
            <if test="fBscorpno != null and fBscorpno != ''">f_bscorpno = #{fBscorpno},</if>
            <if test="fWarehouseid != null">f_warehouseid = #{fWarehouseid},</if>
            <if test="fStorekeeper != null">f_storekeeper = #{fStorekeeper},</if>
            <if test="fChargedate != null">f_chargedate = #{fChargedate},</if>
            <if test="fBsdate != null">f_bsdate = #{fBsdate},</if>
            <if test="fPlanqty != null">f_planqty = #{fPlanqty},</if>
            <if test="fPlangrossweight != null">f_plangrossweight = #{fPlangrossweight},</if>
            <if test="fPlannetweight != null">f_plannetweight = #{fPlannetweight},</if>
            <if test="fPlanvolumn != null">f_planvolumn = #{fPlanvolumn},</if>
            <if test="fQty != null">f_qty = #{fQty},</if>
            <if test="fGrossweight != null">f_grossweight = #{fGrossweight},</if>
            <if test="fNetweight != null">f_netweight = #{fNetweight},</if>
            <if test="fVolumn != null">f_volumn = #{fVolumn},</if>
            <if test="fTrademodeid != null">f_trademodeid = #{fTrademodeid},</if>
            <if test="fBillingway != null">f_billingway = #{fBillingway},</if>
            <if test="fSbu != null">f_sbu = #{fSbu},</if>
            <if test="fFeetunit != null">f_feetunit = #{fFeetunit},</if>
            <if test="fMblno != null">f_mblno = #{fMblno},</if>
            <if test="fVslvoy != null">f_vslvoy = #{fVslvoy},</if>
            <if test="fMarks != null and fMarks != ''">f_marks = #{fMarks},</if>
            <if test="fEta != null">f_eta = #{fEta},</if>
            <if test="fCustomno != null">f_customno = #{fCustomno},</if>
            <if test="fIfweigh != null">f_ifweigh = #{fIfweigh},</if>
            <if test="fIfpledge != null">f_ifpledge = #{fIfpledge},</if>
            <if test="fIfdamage != null">f_ifdamage = #{fIfdamage},</if>
            <if test="fBankcorpid != null">f_bankcorpid = #{fBankcorpid},</if>
            <if test="fBilltype != null">f_billtype = #{fBilltype},</if>
            <if test="fBillstatus != null">f_billstatus = #{fBillstatus},</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="fItemsStatus != null">f_items_status = #{fItemsStatus},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="fBillingDeadline != null">f_billing_deadline = #{fBillingDeadline},</if>
            <if test="fProductName != null">f_product_name = #{fProductName},</if>
            <if test="fReviewDate != null">f_review_date = #{fReviewDate},</if>
            <if test="fTruckno != null">f_truckno = #{fTruckno},</if>
            <if test="fDriverName != null">f_driver_name = #{fDriverName},</if>
            <if test="fDriverTel != null">f_driver_tel = #{fDriverTel},</if>
            <if test="fDriverIdCar != null">f_driver_id_car = #{fDriverIdCar},</if>
            <if test="fBusinessType != null">f_business_type = #{fBusinessType},</if>
            <if test="fReviewDate == null">f_review_date = null,</if>
            <if test="fLabour  != null">f_labour  = #{fLabour },</if>
            <if test="fFleet != null">f_fleet = #{fFleet},</if>
            <if test="fInwarehouseid != null">f_inwarehouseid = #{fInwarehouseid},</if>
            <if test="fBstime != null">f_bstime = #{fBstime},</if>
            <if test="fCartype != null">f_cartype = #{fCartype},</if>
            <if test="fGoodsid != null">f_goodsid = #{fGoodsid},</if>
            <if test="fNewTrademodeid != null">f_new_trademodeid = #{fNewTrademodeid},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTWarehousebillsById" parameterType="Long">
        delete from t_warehousebills where f_id = #{fId}
    </delete>

    <delete id="deleteTWarehousebillsByIds" parameterType="String">
        delete
            item.*,
            bill.*,
            fess.*,
            enclosure.*
        from
            t_warehousebills bill
            LEFT JOIN t_warehousebillsfees fess ON fess.f_pid = bill.f_id
            LEFT JOIN t_enclosure enclosure ON enclosure.f_pid = bill.f_id
            LEFT JOIN t_warehousebillsitems item ON item.f_pid = bill.f_id
        where
            bill.f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

    <update id="warehouseFollowUpdate">
        update
            t_warehousebills
        <trim prefix="SET" suffixOverrides=",">
            <if test="fettle != null">f_billstatus = #{fettle},</if>
            <if test="auditItem != null and fettle == 6">f_review_date = #{auditItem},</if>
            <if test="auditItem != null and fettle != 6">f_review_date = null,</if>
        </trim>
        where f_id = #{fPid}
    </update>
    <select id="selectDetailedList" resultType="java.util.Map">
        SELECT
            t.f_id AS fId,
            item.f_id AS  fItemsId,
            C.f_name AS fcorpid,
            t.f_mblno AS fMblno,
            g.f_name AS fGoodsid,
            dict.dict_label AS fBusinessType,
            t.f_marks AS fMarks,
            CASE
                WHEN t.f_billtype = 'SJRK' THEN
                    '入库'
                WHEN t.f_billtype = 'SJCK' THEN
                    '出库'
                WHEN t.f_billtype = 'CKDB' THEN
                    '调拨'
                WHEN t.f_billtype = 'HQZY' THEN
                    '货权转移'
                WHEN t.f_billtype = 'HWTG' THEN
                    '货物通关'
                END AS fBilltype,
            item.f_bsdate AS fBsdate,
            item.f_warehouse_information AS fWarehouseInformation,
            dictTra.dict_label AS fTrademodeid,
            CASE
                WHEN t.f_billtype = 'SJRK' THEN
                    item.f_qty
                else '0'
                END AS fQtyRK,
            CASE
                WHEN t.f_billtype = 'SJRK' THEN
                    item.f_grossweight
                else '0'
                END AS fGrossweightRK,
            CASE
                WHEN t.f_billtype = 'SJRK' THEN
                    item.f_netweight
                else '0'
                END AS fNetweightRK,
            CASE
                WHEN t.f_billtype = 'SJCK' THEN
                    item.f_qty
                else '0'
                END AS fQtyCK,
            CASE
                WHEN t.f_billtype = 'SJCK' THEN
                    item.f_grossweight
                else '0'
                END AS fGrossweightCK,
            CASE
                WHEN t.f_billtype = 'SJCK' THEN
                    item.f_netweight
                else '0'
                END AS fNetweightCK,
            CASE
                WHEN t.f_billtype = 'CKDB' THEN
                    item.f_qty
                else '0'
                END AS fQtyDB,
            CASE
                WHEN t.f_billtype = 'CKDB' THEN
                    item.f_grossweight
                else '0'
                END AS fGrossweightDB,
            CASE
                WHEN t.f_billtype = 'CKDB' THEN
                    item.f_netweight
                else '0'
                END AS fNetweightDB,
            CASE
                WHEN t.f_billtype = 'HQZY' THEN
                    item.f_qty
                else '0'
                END AS fQtyHZ,
            CASE
                WHEN t.f_billtype = 'HQZY' THEN
                    item.f_grossweight
                else '0'
                END AS fGrossweightHZ,
            CASE
                WHEN t.f_billtype = 'HQZY' THEN
                    item.f_netweight
                else '0'
                END AS fNetweightHZ,
            CASE
                WHEN t.f_billtype = 'HWTG' THEN
                    item.f_qty
                else '0'
                END AS fQtyTG,
            CASE
                WHEN t.f_billtype = 'HWTG' THEN
                    item.f_grossweight
                else '0'
                END AS fGrossweightTG,
            CASE
                WHEN t.f_billtype = 'HWTG' THEN
                    item.f_netweight
                else '0'
                END AS fNetweightTG
        FROM
            t_warehousebills  t
                LEFT JOIN t_warehousebillsitems item ON item.f_pid = t.f_id
                LEFT JOIN t_goods g ON item.f_goodsid = g.f_id
                LEFT JOIN t_corps C ON t.f_corpid = C.f_id
                LEFT JOIN sys_dict_data dict ON dict.dict_value = item.f_business_type
                LEFT JOIN sys_dict_data dictTra ON dictTra.dict_value = t.f_trademodeid
        WHERE
            dict.STATUS = '0'
          AND dict.dict_type = 'storage_type'
          AND dictTra.STATUS = '0'
          AND dictTra.dict_type = 'data_trademodes'
          AND item.f_billstatus = 40
          AND item.f_mblno = #{fMblno}
          AND  ( item.f_warehouselocid = #{fWarehouseLocationid} or
                 item.f_transfer_warehouselocid = #{fWarehouseLocationid}  )
          AND t.f_trademodeid =  #{fTrademodeids}
          AND item.f_business_type =  #{fBusinessType}
          AND item.f_goodsid =  #{fGoodsid}
          AND item.f_marks =  #{fMarks}
          AND t.f_corpid =  #{fCorpIds}

    </select>
</mapper>