<?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.reportManagement.mapper.TWhgenlegMapper">

    <resultMap type="TWhgenleg" id="TWhgenlegResult">
        <result property="fId" column="f_id"/>
        <result property="fAccyear" column="f_accyear"/>
        <result property="fAccmonth" column="f_accmonth"/>
        <result property="fCorpid" column="f_corpid"/>
        <result property="fMblno" column="f_mblno"/>
        <result property="fOriginalbillno" column="f_originalbillno"/>
        <result property="fWarehouseLocationid" column="f_warehouse_locationid"/>
        <result property="fGoodsid" column="f_goodsid"/>
        <result property="fChargedate" column="f_chargedate"/>
        <result property="fTrademodeid" column="f_trademodeid"/>
        <result property="fPreqty" column="f_preqty"/>
        <result property="fWarehouseid" column="f_warehouseid"/>
        <result property="fPregrossweight" column="f_pregrossweight"/>
        <result property="fPrenetweight" column="f_prenetweight"/>
        <result property="fQtyd" column="f_qtyD"/>
        <result property="fVolumnd" column="f_volumnD"/>
        <result property="fBillingway" column="f_billingway"/>
        <result property="fGrossweightd" column="f_grossweightD"/>
        <result property="fNetweightd" column="f_netweightD"/>
        <result property="fVolumnc" column="f_volumnC"/>
        <result property="fQtyc" column="f_qtyC"/>
        <result property="fGrossweightc" column="f_grossweightC"/>
        <result property="fQtyblc" column="f_qtyblc"/>
        <result property="fGrossweightblc" column="f_grossweightblc"/>
        <result property="fNetweightc" column="f_netweightC"/>
        <result property="fNetweightblc" column="f_netweightblc"/>
        <result property="fCntrno" column="f_cntrno"/>
        <result property="fStatus" column="f_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="fMarks" column="f_marks"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="fBusinessType" column="f_business_type"/>
        <result property="fOriginalbilldate" column="f_originalbilldate"/>
    </resultMap>

    <sql id="selectTWhgenlegVo">
        select f_id, f_accyear, f_accmonth, f_corpid, f_mblno, f_originalbillno, f_warehouse_locationid, f_goodsid, f_trademodeid, f_preqty, f_pregrossweight, f_warehouseid, f_prenetweight, f_chargedate, f_volumnD, f_qtyD, f_billingway, f_grossweightD, f_netweightD, f_volumnC, f_qtyC, f_grossweightC, f_qtyblc, f_grossweightblc, f_netweightC, f_netweightblc, f_cntrno, f_status, del_flag, f_marks, create_by, create_time, update_by, f_volumnblc, update_time, remark, f_business_type, f_originalbilldate from t_whgenleg
    </sql>

    <select id="selectTWhgenlegList" parameterType="TWhgenleg" resultMap="TWhgenlegResult">
        select
            ware.*
        from
            t_whgenleg ware
            left join sys_user u on ware.create_by = u.user_name
            left join sys_dept d on u.dept_id = d.dept_id
        <where>
            <if test="fOriginalbillno != null  and fOriginalbillno != ''">and f_originalbillno = #{fOriginalbillno}</if>
            <if test="fChargedate != null ">and f_chargedate = #{fChargedate}</if>
            <if test="fPreqty != null ">and f_preqty = #{fPreqty}</if>
            <if test="fWarehouseid != null ">and f_warehouseid = #{fWarehouseid}</if>
            <if test="fPregrossweight != null ">and f_pregrossweight = #{fPregrossweight}</if>
            <if test="fPrenetweight != null ">and f_prenetweight = #{fPrenetweight}</if>
            <if test="fQtyd != null ">and f_qtyD = #{fQtyd}</if>
            <if test="fVolumnd != null ">and f_volumnD = #{fVolumnd}</if>
            <if test="fBillingway != null ">and f_billingway = #{fBillingway}</if>
            <if test="fGrossweightd != null ">and f_grossweightD = #{fGrossweightd}</if>
            <if test="fNetweightd != null ">and f_netweightD = #{fNetweightd}</if>
            <if test="fVolumnc != null ">and f_volumnC = #{fVolumnc}</if>
            <if test="fBusinessType != null "> and f_business_type = #{fBusinessType}</if>
            <if test="fQtyc != null ">and f_qtyC = #{fQtyc}</if>
            <if test="fGrossweightc != null ">and f_grossweightC = #{fGrossweightc}</if>
            <if test="fQtyblc != null ">and f_qtyblc = #{fQtyblc}</if>
            <if test="fGrossweightblc != null ">and f_grossweightblc = #{fGrossweightblc}</if>
            <if test="fNetweightc != null ">and f_netweightC = #{fNetweightc}</if>
            <if test="fNetweightblc != null ">and f_netweightblc = #{fNetweightblc}</if>
            <if test="fCntrno != null  and fCntrno != ''">and f_cntrno = #{fCntrno}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
            <if test="fMarks != null  and fMarks != ''">and f_marks = #{fMarks}</if>
            <if test="fOriginalbilldate != null ">and f_originalbilldate = #{fOriginalbilldate}</if>
        </where>
        ${params.dataScope}
    </select>

    <select id="selectInventoryList" parameterType="TWhgenleg" resultType="Map">
        select
        DISTINCT
            leg.f_id AS fId,
            leg.f_corpid AS fCorpIds,
            corp.f_name AS fCorpid,
            ware.f_warehouse_information AS fWarehouseids,
            area.f_name AS fWarehouseLocationids,
            leg.f_originalbillno AS fOriginalbillno,
            leg.f_warehouse_locationid AS fWarehouseLocationid,
            dict1.dict_label AS fTrademodeid,
            goods.f_name AS fGoodsids,
            leg.f_trademodeid AS fTrademodeids,
            goods.f_packagespecs AS fPackagespecs,
            leg.f_goodsid AS fGoodsid,
            leg.f_volumnD AS fVolumnD,
            leg.f_qtyD AS fQtyD,
            leg.f_mblno AS fMblno,
            leg.f_grossweightD AS fGrossweightD,
            leg.f_netweightD AS fNetweightD,
            leg.f_volumnC AS fVolumnC,
            leg.f_volumnblc AS fVolumnblc,
            leg.f_qtyC AS fQtyC,
            leg.f_business_type AS fBusinessType,
            leg.f_grossweightC AS fGrossweightC,
            leg.f_netweightC AS fNetweightC,
            leg.f_qtyblc AS fQtyblc,
            leg.f_billingway AS fBillingway,
            leg.f_chargedate AS fChargedate,
            leg.f_grossweightblc AS fGrossweightblc,
            leg.f_netweightblc AS fNetweightblc,
            dict.dict_label AS fBusinessTypes,
            leg.f_marks AS fMarks,
            DATE_FORMAT( leg.create_time, '%Y-%m-%d' ) AS createTime,
            DATE_FORMAT( leg.f_originalbilldate, '%Y-%m-%d' ) AS fOriginalbilldate,
            leg.f_cntrno AS fCntrno
        FROM
            t_whgenleg leg
            left join sys_user u on leg.create_by = u.user_name
            left join sys_dept d on u.dept_id = d.dept_id
            LEFT JOIN t_corps corp ON corp.f_id = leg.f_corpid
            LEFT JOIN t_goods goods ON goods.f_id = leg.f_goodsid
            LEFT JOIN t_warehouse ware ON ware.f_id = leg.f_warehouse_locationid
            LEFT JOIN sys_dict_data dict ON dict.dict_value = leg.f_business_type
            LEFT JOIN t_warehouse_area area ON area.f_id = leg.f_warehouse_locationid
            LEFT JOIN sys_dict_data dict1 ON dict1.dict_value = leg.f_trademodeid
        <where>
            dict.status = '0'
            AND dict.dict_type = 'storage_type'
            AND dict1.status = '0'
            AND dict1.dict_type = 'data_trademodes'
            <if test="fOriginalbillno != null  and fOriginalbillno != ''">and leg.f_originalbillno = #{fOriginalbillno}</if>
            <if test="fPreqty != null ">and leg.f_preqty = #{fPreqty}</if>
            <if test="fCorpid != null ">and leg.f_corpid = #{fCorpid}</if>
            <if test="fMblno != null ">and leg.f_mblno LIKE  concat('%', #{fMblno}, '%') </if>
            <if test='orgStorageDate != null and orgStorageDate[0] != null and orgStorageDate[0]!= ""'>
                and leg.f_originalbilldate &gt;= #{orgStorageDate[0]}
            </if>
            <if test='orgStorageDate != null and orgStorageDate[1] != null and orgStorageDate[1]!= ""'>
                and leg.f_originalbilldate &lt;= #{orgStorageDate[1]}
            </if>
            <if test="fPregrossweight != null ">and leg.f_pregrossweight = #{fPregrossweight}</if>
            <if test="fPrenetweight != null ">and leg.f_prenetweight = #{fPrenetweight}</if>
            <if test="fQtyd != null ">and leg.f_qtyD = #{fQtyd}</if>
            <if test="fTrademodeid != null ">and leg.f_trademodeid = #{fTrademodeid}</if>
            <if test="fGoodsid != null ">and leg.f_goodsid = #{fGoodsid}</if>
            <if test="fVolumnd != null ">and leg.f_volumnD = #{fVolumnd}</if>
            <if test="fGrossweightd != null ">and leg.f_grossweightD = #{fGrossweightd}</if>
            <if test="fNetweightd != null ">and leg.f_netweightD = #{fNetweightd}</if>
            <if test="fVolumnc != null ">and leg.f_volumnC = #{fVolumnc}</if>
            <if test="fQtyc != null ">and leg.f_qtyC = #{fQtyc}</if>
            <if test="fOriginalbilldate != null ">and leg.f_originalbilldate = #{fOriginalbilldate}</if>
            <if test="fMarks != null  and fMarks != ''">and leg.f_marks = #{fMarks}</if>
            <if test="fQtyblc != null ">and leg.f_qtyblc = #{fQtyblc}</if>
            <if test="fGrossweightc != null ">and leg.f_grossweightC = #{fGrossweightc}</if>
            <if test="fNetweightc != null ">and leg.f_netweightC = #{fNetweightc}</if>
            <if test="fGrossweightblc != null ">and leg.f_grossweightblc = #{fGrossweightblc}</if>
            <if test="fNetweightblc != null ">and leg.f_netweightblc = #{fNetweightblc}</if>
            <if test="fCntrno != null  and fCntrno != ''">and leg.f_cntrno = #{fCntrno}</if>
            <if test="fStatus != null  and fStatus != ''">and leg.f_status = #{fStatus}</if>
            <if test="fWarehouseid != null ">and leg.f_warehouseid = #{fWarehouseid} </if>

            <if test="fLocation != null  and fLocation ==1 ">
                and leg.f_warehouse_locationid = #{fWarehouseLocationid}
            </if>
            <if test="fLocation != null  and fLocation ==0 ">
                and ware.ancestors  LIKE  concat('%', #{fWarehouseLocationid}, '%')
            </if>
        </where>
        ${params.dataScope}
    </select>

    <select id="selectTWhgenleg" parameterType="TWhgenleg" resultMap="TWhgenlegResult">
        <include refid="selectTWhgenlegVo"/>
        <where>
            <if test="fCorpid != null ">and f_corpid = #{fCorpid}</if>
            <if test="fMblno != null ">and f_mblno = #{fMblno}</if>
            <if test="fCntrno != null ">and f_cntrno = #{fCntrno}</if>
            <if test="fWarehouseLocationid != null ">and f_warehouse_locationid = #{fWarehouseLocationid}</if>
            <if test="fGoodsid != null ">and f_goodsid = #{fGoodsid}</if>
            <if test="fTrademodeid != null ">and f_trademodeid = #{fTrademodeid}</if>
        </where>
    </select>

    <select id="selectTWhgenlegById" parameterType="Long" resultMap="TWhgenlegResult">
        <include refid="selectTWhgenlegVo"/>
        where f_id = #{fId}
    </select>

    <insert id="insertTWhgenleg" parameterType="TWhgenleg">
        insert into t_whgenleg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fAccyear != null">f_accyear,</if>
            <if test="fAccmonth != null">f_accmonth,</if>
            <if test="fCorpid != null">f_corpid,</if>
            <if test="fMblno != null">f_mblno,</if>
            <if test="fOriginalbillno != null">f_originalbillno,</if>
            <if test="fWarehouseLocationid != null">f_warehouse_locationid,</if>
            <if test="fGoodsid != null">f_goodsid,</if>
            <if test="fTrademodeid != null">f_trademodeid,</if>
            <if test="fPreqty != null">f_preqty,</if>
            <if test="fPregrossweight != null">f_pregrossweight,</if>
            <if test="fWarehouseid != null">f_warehouseid,</if>
            <if test="fPrenetweight != null">f_prenetweight,</if>
            <if test="fChargedate != null">f_chargedate,</if>
            <if test="fVolumnd != null">f_volumnD,</if>
            <if test="fQtyd != null">f_qtyD,</if>
            <if test="fBillingway != null">f_billingway,</if>
            <if test="fGrossweightd != null">f_grossweightD,</if>
            <if test="fNetweightd != null">f_netweightD,</if>
            <if test="fVolumnc != null">f_volumnC,</if>
            <if test="fQtyc != null">f_qtyC,</if>
            <if test="fGrossweightc != null">f_grossweightC,</if>
            <if test="fQtyblc != null">f_qtyblc,</if>
            <if test="fGrossweightblc != null">f_grossweightblc,</if>
            <if test="fNetweightc != null">f_netweightC,</if>
            <if test="fNetweightblc != null">f_netweightblc,</if>
            <if test="fCntrno != null">f_cntrno,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="fMarks != null and fMarks != ''">f_marks,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="fVolumnblc != null">f_volumnblc,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="fBusinessType != null">f_business_type,</if>
            <if test="fOriginalbilldate != null">f_originalbilldate,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fAccyear != null">#{fAccyear},</if>
            <if test="fAccmonth != null">#{fAccmonth},</if>
            <if test="fCorpid != null">#{fCorpid},</if>
            <if test="fMblno != null">#{fMblno},</if>
            <if test="fOriginalbillno != null">#{fOriginalbillno},</if>
            <if test="fWarehouseLocationid != null">#{fWarehouseLocationid},</if>
            <if test="fGoodsid != null">#{fGoodsid},</if>
            <if test="fTrademodeid != null">#{fTrademodeid},</if>
            <if test="fPreqty != null">#{fPreqty},</if>
            <if test="fPregrossweight != null">#{fPregrossweight},</if>
            <if test="fWarehouseid != null">#{fWarehouseid},</if>
            <if test="fPrenetweight != null">#{fPrenetweight},</if>
            <if test="fChargedate != null">#{fChargedate},</if>
            <if test="fVolumnd != null">#{fVolumnd},</if>
            <if test="fQtyd != null">#{fQtyd},</if>
            <if test="fBillingway != null">#{fBillingway},</if>
            <if test="fGrossweightd != null">#{fGrossweightd},</if>
            <if test="fNetweightd != null">#{fNetweightd},</if>
            <if test="fVolumnc != null">#{fVolumnc},</if>
            <if test="fQtyc != null">#{fQtyc},</if>
            <if test="fGrossweightc != null">#{fGrossweightc},</if>
            <if test="fQtyblc != null">#{fQtyblc},</if>
            <if test="fGrossweightblc != null">#{fGrossweightblc},</if>
            <if test="fNetweightc != null">#{fNetweightc},</if>
            <if test="fNetweightblc != null">#{fNetweightblc},</if>
            <if test="fCntrno != null">#{fCntrno},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="fMarks != null and fMarks != ''">#{fMarks},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="fVolumnblc != null">#{fVolumnblc},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="fBusinessType != null">#{fBusinessType},</if>
            <if test="fOriginalbilldate != null">#{fOriginalbilldate},</if>
        </trim>
    </insert>

    <update id="updateTWhgenleg" parameterType="TWhgenleg">
        update t_whgenleg
        <trim prefix="SET" suffixOverrides=",">
            <if test="fAccyear != null">f_accyear = #{fAccyear},</if>
            <if test="fAccmonth != null">f_accmonth = #{fAccmonth},</if>
            <if test="fCorpid != null">f_corpid = #{fCorpid},</if>
            <if test="fMblno != null">f_mblno = #{fMblno},</if>
            <if test="fOriginalbillno != null">f_originalbillno = #{fOriginalbillno},</if>
            <if test="fWarehouseLocationid != null">f_warehouse_locationid = #{fWarehouseLocationid},</if>
            <if test="fGoodsid != null">f_goodsid = #{fGoodsid},</if>
            <if test="fTrademodeid != null">f_trademodeid = #{fTrademodeid},</if>
            <if test="fPreqty != null">f_preqty = #{fPreqty},</if>
            <if test="fPregrossweight != null">f_pregrossweight = #{fPregrossweight},</if>
            <if test="fWarehouseid != null">f_warehouseid = #{fWarehouseid},</if>
            <if test="fPrenetweight != null">f_prenetweight = #{fPrenetweight},</if>
            <if test="fChargedate != null">f_chargedate = #{fChargedate},</if>
            <if test="fVolumnd != null">f_volumnD = #{fVolumnd},</if>
            <if test="fQtyd != null">f_qtyD = #{fQtyd},</if>
            <if test="fBillingway != null">f_billingway = #{fBillingway},</if>
            <if test="fGrossweightd != null">f_grossweightD = #{fGrossweightd},</if>
            <if test="fNetweightd != null">f_netweightD = #{fNetweightd},</if>
            <if test="fVolumnc != null">f_volumnC = #{fVolumnc},</if>
            <if test="fQtyc != null">f_qtyC = #{fQtyc},</if>
            <if test="fGrossweightc != null">f_grossweightC = #{fGrossweightc},</if>
            <if test="fQtyblc != null">f_qtyblc = #{fQtyblc},</if>
            <if test="fGrossweightblc != null">f_grossweightblc = #{fGrossweightblc},</if>
            <if test="fNetweightc != null">f_netweightC = #{fNetweightc},</if>
            <if test="fNetweightblc != null">f_netweightblc = #{fNetweightblc},</if>
            <if test="fCntrno != null">f_cntrno = #{fCntrno},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="fMarks != null and fMarks != ''">f_marks = #{fMarks},</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="fVolumnblc != null">f_volumnblc = #{fVolumnblc},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="fBusinessType != null">f_business_type = #{fBusinessType},</if>
            <if test="fOriginalbilldate != null">f_originalbilldate = #{fOriginalbilldate},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <update id="updateTWhgenlegData" parameterType="Map">
        update t_whgenleg
        <trim prefix="SET" suffixOverrides=",">
            /*判断是否入库*/
            <if test="map.billType == 'SJRK'">
                f_qtyD = f_qtyD + #{map.warehousebillsitems.fQty},
                f_volumnD = f_volumnD + #{map.warehousebillsitems.fVolumn},
                f_netweightD = f_netweightD + #{map.warehousebillsitems.fNetweight},
                f_grossweightD = f_grossweightD + #{map.warehousebillsitems.fGrossweight},
                f_qtyblc = f_qtyblc + #{map.warehousebillsitems.fQty}
            </if>
            /*判断是否撤销入库*/
            <if test="map.billType == 'SJRKRevoke'">
                f_qtyD = f_qtyD - #{map.warehousebillsitems.fQty},
                f_volumnD = f_volumnD - #{map.warehousebillsitems.fVolumn},
                f_netweightD = f_netweightD - #{map.warehousebillsitems.fNetweight},
                f_grossweightD = f_grossweightD - #{map.warehousebillsitems.fGrossweight},
                f_qtyblc = f_qtyblc - #{map.warehousebillsitems.fQty}
            </if>
            /*判断是否出库*/
            <if test="map.billType == 'SJCK'">
                f_qtyC = f_qtyC + #{map.warehousebillsitems.fQty},
                f_volumnC = f_volumnC + #{map.warehousebillsitems.fVolumn},
                f_netweightC = f_netweightC + #{map.warehousebillsitems.fNetweight},
                f_grossweightC = f_grossweightC + #{map.warehousebillsitems.fGrossweight},
                f_qtyblc = f_qtyblc - #{map.warehousebillsitems.fQty}
            </if>
            /*判断是否撤销出库*/
            <if test="map.billType == 'SJCKRevoke'">
                f_qtyC = f_qtyC - #{map.warehousebillsitems.fQty},
                f_volumnC = f_volumnC - #{map.warehousebillsitems.fVolumn},
                f_netweightC = f_netweightC - #{map.warehousebillsitems.fNetweight},
                f_grossweightC = f_grossweightC - #{map.warehousebillsitems.fGrossweight},
                f_qtyblc = f_qtyblc + #{map.warehousebillsitems.fQty}
            </if>
            -- update_by = NOW()
        </trim>
        where f_id = #{map.whgenlegId}
    </update>

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

    <delete id="deleteTWhgenlegByIds" parameterType="String">
        delete from t_whgenleg where f_id in
        <foreach item="fAccyear" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

    <select id="selectGoodsList"  resultType="Map">
        SELECT
            t.f_goodsid AS fGoodsid,
            g.f_name AS fName
        FROM
            t_goods g
            RIGHT JOIN (
            SELECT
                f_goodsid AS f_goodsid
            FROM
                t_whgenleg
            GROUP BY
                f_goodsid
            ) t ON g.f_id = t.f_goodsid
    </select>

    <select id="selectGoodsListWhouse"  resultType="Map">
        SELECT
            t.f_goodsid AS fGoodsid,
            g.f_name AS fName,
			w.f_name AS fWarehouseName,
			w.f_totalgross AS fTotalgross,
            t.f_grossweightblc  AS fGrossweightD
        FROM
            t_goods g
            RIGHT JOIN (
            SELECT
                f_goodsid AS f_goodsid,
				f_warehouseid AS f_warehouseid,
                sum( f_grossweightblc ) AS f_grossweightblc
            FROM
                t_whgenleg
            GROUP BY
                f_goodsid,
				f_warehouseid
            ORDER BY
                sum( f_grossweightblc ) DESC
            ) t ON g.f_id = t.f_goodsid
			LEFT JOIN  t_warehouse w ON w.f_id = t.f_warehouseid
        <where>
            <if test="fId != null ">and w.f_id = #{fId}</if>
        </where>
    </select>

    <select id="selectWareHouseList" resultType="Map">
        SELECT
            t.f_warehouseid AS fWarehouseid,
            w.f_name AS fName,
            t.f_grossweightblc AS fGrossweightD,
	        w.f_totalgross AS fTotalgross
        FROM
            t_warehouse w
            RIGHT JOIN (
            SELECT
                f_warehouseid AS f_warehouseid,
                sum( f_grossweightblc ) AS f_grossweightblc
            FROM
                t_whgenleg
            GROUP BY
                f_warehouseid
            ORDER BY
                sum( f_grossweightblc ) DESC
            ) t ON w.f_id = t.f_warehouseid
    </select>

    <select id="selectWareHouseListWhouse"  resultType="Map">
        SELECT
            t.f_warehouseid AS fWarehouseid,
            w.f_name AS fName,
            t.f_grossweightblc AS fGrossweightD,
            w.f_totalgross AS fTotalgross
        FROM
            t_warehouse w
        RIGHT JOIN (
        SELECT
            f_warehouseid AS f_warehouseid,
            sum( f_grossweightblc ) AS f_grossweightblc
        FROM
            t_whgenleg
        GROUP BY
            f_warehouseid
        ORDER BY
            sum( f_grossweightblc ) DESC
            ) t ON w.f_id = t.f_warehouseid
        <where>
            <if test="fId != null ">and w.f_id = #{fId}</if>
        </where>
    </select>

    <select id="selectCorpsList" resultType="Map">
        SELECT
            t.f_corpid AS fCorpid,
            c.f_name AS fName
        FROM
            t_corps c
            RIGHT JOIN (
            SELECT
                f_corpid AS f_corpid
            FROM
                t_whgenleg
            GROUP BY
                f_corpid
            ) t ON c.f_id = t.f_corpid
    </select>

    <select id="selectCorpsListWhouse"  resultType="Map">
        SELECT
            t.f_corpid AS fCorpid,
            g.f_name AS fName,
            w.f_name AS fWarehouseName,
            w.f_totalgross AS fTotalgross,
            t.f_grossweightblc  AS fGrossweightD
        FROM
            t_corps g
        RIGHT JOIN (
            SELECT
            f_corpid AS f_corpid,
            f_warehouseid AS f_warehouseid,
            sum( f_grossweightblc ) AS f_grossweightblc
            FROM
            t_whgenleg
            GROUP BY
            f_corpid,
            f_warehouseid
            ORDER BY
            sum( f_grossweightblc ) DESC
            ) t ON g.f_id = t.f_corpid
        LEFT JOIN  t_warehouse w ON w.f_id = t.f_warehouseid
        <where>
            <if test="fId != null ">and w.f_id = #{fId}</if>
        </where>
    </select>

    <select id="selectDateFQtyblcListList"  resultType="Map">
        SELECT
            t.f_originalbilldate AS fOriginalbilldate,
            sum(t.f_qtyblc) AS fQtyblc
        FROM
            t_whgenleg t
        WHERE
            t.f_originalbilldate &gt; #{map.frontday}
            AND t.f_originalbilldate &lt; #{map.nowadays}
        GROUP BY
	        t.f_originalbilldate
        ORDER BY
            t.f_originalbilldate
    </select>

    <select id="selectStorageFeeItemList" parameterType="com.ruoyi.warehouseBusiness.domain.TWarehouseBills" resultType="Map">
        SELECT
            wh.f_id AS fId,
            wh.f_originalbillno AS fBillno,
            wh.f_goodsid AS fGoodsid,
            wh.f_originalbilldate AS fBsdate,
            wh.f_billingway AS fBillingway,
            wh.f_mblno AS fMblno,
            wh.f_chargedate AS fChargedate,
            wh.f_originalbilldate AS fOriginalbilldate,
            wh.f_marks AS fMarks,
            wh.f_volumnblc AS fVolumn,
            wh.f_qtyblc AS fQty,
            wh.f_grossweightblc AS fGrossweight,
            wh.f_netweightblc AS fNetweight,
            "KCZZ" AS fBilltype,
            goods.f_typeid AS fTypeid,
            goods.f_name AS fGoodsids
        FROM
            t_whgenleg wh
            LEFT JOIN t_goods goods ON goods.f_id = wh.f_goodsid
            LEFT JOIN t_warehouse ware ON ware.f_id = wh.f_warehouseid
        <where>
            wh.f_corpid = #{warehouse.fCorpid}
            and ware.f_charg = 1
            and wh.f_chargedate &lt; #{warehouse.fBillingDeadline}
            <if test="warehouse.fGoodsid != null">and wh.f_goodsid = #{warehouse.fGoodsid}</if>
            <if test="warehouse.fMblno != null">and wh.f_mblno = #{warehouse.fMblno}</if>
        </where>
    </select>
    <select id="selectWhgenlegList" resultType="java.util.Map">
        select
            DISTINCT
            leg.f_id AS fId,
            corp.f_name AS fCorpid,
            DATE_FORMAT( leg.f_originalbilldate, '%Y-%m-%d' ) AS fOriginalbilldate,
            ware.f_warehouse_information AS fWarehouseids,
            leg.f_mblno AS fMblno,
            goods.f_name AS fGoodsids,
            dict.dict_label AS fBusinessTypes,
            leg.f_marks AS fMarks,
            leg.f_qtyblc AS fQtyblc,
            leg.f_grossweightblc AS fGrossweightblc,
            leg.f_netweightblc AS fNetweightblc
        FROM
            t_whgenleg leg
            LEFT JOIN t_corps corp ON corp.f_id = leg.f_corpid
            LEFT JOIN t_goods goods ON goods.f_id = leg.f_goodsid
            LEFT JOIN t_warehouse ware ON ware.f_id = leg.f_warehouse_locationid
            LEFT JOIN sys_dict_data dict ON dict.dict_value = leg.f_business_type
            LEFT JOIN t_warehouse_area area ON area.f_id = leg.f_warehouse_locationid
        <where>
            dict.status = '0'
            AND dict.dict_type = 'storage_type'
            <if test="fOriginalbillno != null  and fOriginalbillno != ''">and leg.f_originalbillno = #{fOriginalbillno}</if>
            <if test="fPreqty != null ">and leg.f_preqty = #{fPreqty}</if>
            <if test="fCorpid != null ">and leg.f_corpid = #{fCorpid}</if>
            <if test="fMblno != null ">and leg.f_mblno LIKE  concat('%', #{fMblno}, '%') </if>
            <if test='timeStartBsdate != null and timeStartBsdate!= ""'>
                and leg.f_originalbilldate &gt;= #{timeStartBsdate}
            </if>
            <if test='timeEndBsdate != null  timeEndBsdate!= ""'>
                and leg.f_originalbilldate &lt;= #{timeEndBsdate}
            </if>
            <if test="fPregrossweight != null ">and leg.f_pregrossweight = #{fPregrossweight}</if>
            <if test="fPrenetweight != null ">and leg.f_prenetweight = #{fPrenetweight}</if>
            <if test="fQtyd != null ">and leg.f_qtyD = #{fQtyd}</if>
            <if test="fTrademodeid != null ">and leg.f_trademodeid = #{fTrademodeid}</if>
            <if test="fGoodsid != null ">and leg.f_goodsid = #{fGoodsid}</if>
            <if test="fVolumnd != null ">and leg.f_volumnD = #{fVolumnd}</if>
            <if test="fGrossweightd != null ">and leg.f_grossweightD = #{fGrossweightd}</if>
            <if test="fNetweightd != null ">and leg.f_netweightD = #{fNetweightd}</if>
            <if test="fVolumnc != null ">and leg.f_volumnC = #{fVolumnc}</if>
            <if test="fQtyc != null ">and leg.f_qtyC = #{fQtyc}</if>
            <if test="fOriginalbilldate != null ">and leg.f_originalbilldate = #{fOriginalbilldate}</if>
            <if test="fMarks != null  and fMarks != ''">and leg.f_marks = #{fMarks}</if>
            <if test="fQtyblc != null ">and leg.f_qtyblc = #{fQtyblc}</if>
            <if test="fGrossweightc != null ">and leg.f_grossweightC = #{fGrossweightc}</if>
            <if test="fNetweightc != null ">and leg.f_netweightC = #{fNetweightc}</if>
            <if test="fGrossweightblc != null ">and leg.f_grossweightblc = #{fGrossweightblc}</if>
            <if test="fNetweightblc != null ">and leg.f_netweightblc = #{fNetweightblc}</if>
            <if test="fCntrno != null  and fCntrno != ''">and leg.f_cntrno = #{fCntrno}</if>
            <if test="fStatus != null  and fStatus != ''">and leg.f_status = #{fStatus}</if>
            <if test="fWarehouseid != null ">and leg.f_warehouseid = #{fWarehouseid} </if>
            <if test="fLocation != null  and fLocation ==1 ">
                and leg.f_warehouse_locationid = #{fWarehouseLocationid}
            </if>
            <if test="fLocation != null  and fLocation ==0 ">
                and ware.ancestors  LIKE  concat('%', #{fWarehouseLocationid}, '%')
            </if>
        </where>
    </select>

</mapper>