chenlu
2024-05-23 0a567fd9c3baeb8022c77fa1a6a96d4c60cfa11c
north-glass-erp/src/main/resources/mapper/mm/FinishedGoodsInventory.xml
@@ -3,10 +3,10 @@
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.erp.mapper.mm.FinishedGoodsInventoryMapper" >
    <resultMap id="selectFinishedGoodsInventory" type="com.example.erp.entity.mm.FinishedGoodsInventory" >
        <id column="id" property="id"/>
<mapper namespace="com.example.erp.mapper.mm.FinishedGoodsInventoryMapper">
    <!--映射成品库存-->
    <resultMap id="selectFinishedGoodsInventory" type="com.example.erp.entity.mm.FinishedGoodsInventory">
        <id column="fid" property="id"/>
        <result column="inventory" property="inventory"/>
        <result column="area" property="area"/>
        <result column="actual_signal_area" property="actualSignalArea"/>
@@ -19,46 +19,825 @@
        <result column="update_time" property="updateTime"/>
        <result column="end_time" property="endTime"/>
            <result column="order_id" property="order.orderId"/>
            <result column="project" property="order.project"/>
            <result column="order_type" property="order.orderType"/>
        <result column="order_id" property="order.orderId"/>
        <result column="project" property="order.project"/>
        <result column="order_type" property="order.orderType"/>
            <result column="order_number" property="orderDetail.orderNumber"/>
            <result column="width" property="orderDetail.width"/>
            <result column="height" property="orderDetail.height"/>
            <result column="product_name" property="orderDetail.product.productName"/>
            <result column="product_id" property="orderDetail.product.id"/>
        <result column="order_number" property="orderDetail.orderNumber"/>
        <result column="width" property="orderDetail.width"/>
        <result column="height" property="orderDetail.height"/>
        <result column="product_name" property="orderDetail.productName"/>
        <result column="product_id" property="orderDetail.productId"/>
    </resultMap>
    <!--映射成品入库-->
    <resultMap id="selectFlowCard" type="com.example.erp.entity.pp.FlowCard">
        <id column="id" property="id"/>
        <result column="order_number" property="orderNumber"/>
        <result column="inventory_quantity" property="inventoryQuantity"/>
        <result column="process_id" property="processId"/>
        <result column="received_quantity" property="receivedQuantity"/>
        <result column="order_id" property="order.orderId"/>
        <result column="project" property="order.project"/>
        <result column="creator" property="order.creator"/>
        <result column="area" property="order.area"/>
        <result column="batch" property="order.batch"/>
        <result column="order_quantity" property="order.quantity"/>
        <result column="building_number" property="orderDetail.buildingNumber"/>
        <result column="width" property="orderDetail.width"/>
        <result column="height" property="orderDetail.height"/>
        <result column="product_name" property="orderDetail.productName"/>
        <result column="product_id" property="orderDetail.productId"/>
        <result column="quantity" property="orderDetail.quantity"/>
    </resultMap>
    <!--映射成品出库-->
    <resultMap id="selectDelivery" type="com.example.erp.entity.sd.OrderDetail">
        <id column="id" property="id"/>
        <result column="building_number" property="buildingNumber"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="product_name" property="productName"/>
        <result column="product_id" property="productId"/>
        <result column="warehouse_num" property="warehouseNum"/>
        <result column="delivery_num" property="deliveryNum"/>
        <result column="order_number" property="deliveryDetail.orderNumber"/>
        <result column="delivery_id" property="deliveryDetail.deliveryId"/>
        <result column="delivery_number" property="deliveryDetail.deliveryNumber"/>
        <result column="delivery_detail_remakes" property="deliveryDetail.deliveryDetailRemakes"/>
        <result column="order_id" property="deliveryDetail.orderId"/>
        <result column="create_time" property="deliveryDetail.createTime"/>
        <result column="dd_quantity" property="deliveryDetail.quantity"/>
        <result column="project" property="order.project"/>
        <result column="creator" property="delivery.creator"/>
        <result column="customer_name" property="delivery.customerName"/>
        <result column="d_quantity" property="delivery.quantity"/>
        <result column="area" property="delivery.area"/>
    </resultMap>
    <select id="defaultfinishedGoodsInventory" resultMap="selectFinishedGoodsInventory">
        select od.order_number,
               o.order_id,
    <!--映射订单调拨-->
    <resultMap id="selectDeliveryFinishedGoodsInventory" type="com.example.erp.entity.sd.OrderDetail">
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="product_name" property="productName"/>
        <result column="product_id" property="productId"/>
        <result column="order_id" property="finishedGoodsInventory.orderId"/>
        <result column="order_number" property="finishedGoodsInventory.orderNumber"/>
        <result column="quantity_available" property="finishedGoodsInventory.quantityAvailable"/>
        <result column="actual_signal_area" property="finishedGoodsInventory.actualSignalArea"/>
        <result column="area" property="finishedGoodsInventory.area"/>
        <result column="storage_region" property="finishedGoodsInventory.storageRegion"/>
        <result column="project" property="order.project"/>
        <result column="customer_id" property="order.customerId"/>
        <result column="customer_name" property="order.customerName"/>
    </resultMap>
    <update id="updateInventoryquantityAllocateInt">
        update mm.finished_goods_inventory
        set inventory=inventory+#{quantity},quantity_available=quantity_available+#{quantity},
            update_time=now(),area=actual_signal_area*quantity_available
        where order_number=#{orderNumber}  and order_id=#{orderId}
    </update>
    <update id="updateInventoryquantityAllocateOut">
        update mm.finished_goods_inventory
        set inventory=inventory-#{quantity},quantity_available=quantity_available-#{quantity},
            update_time=now(),area=actual_signal_area*quantity_available
        where order_number=#{orderNumber}  and order_id=#{orderId}
    </update>
    <update id="updateInventoryquantityInt">
        update mm.finished_goods_inventory
        set quantity_available=quantity_available+#{quantity},
            update_time=now(),area=actual_signal_area*quantity_available
        where order_number=#{orderNumber}  and order_id=#{orderId}
    </update>
    <update id="updateInventoryquantityOut">
        update mm.finished_goods_inventory
        set quantity_available=quantity_available-#{quantity},
            update_time=now(),area=actual_signal_area*quantity_available
        where order_number=#{orderNumber}  and order_id=#{orderId}
    </update>
    <update id="updateInventoryInventoryInt">
        update mm.finished_goods_inventory
        set inventory=inventory+#{quantity}
        where order_number=#{orderNumber}  and order_id=#{orderId}
    </update>
    <update id="updateInventoryInventoryOut">
        update mm.finished_goods_inventory
        set inventory=inventory-#{quantity}
        where order_number=#{orderNumber}  and order_id=#{orderId}
    </update>
    <select id="getSelectAllocate"  resultMap="selectDeliveryFinishedGoodsInventory">
        select fgi.order_id,
               o.project,
               o.order_type,
               od.product_name,
               fgi.order_number,
               fgi.quantity_available,
               od.product_id,
               od.product_name,
               od.width,
               od.height,
               fgi.inventory,
               fgi.quantity_available,
               o.customer_id,
               o.customer_name,
               fgi.actual_signal_area,
               fgi.area,
               fgi.warehouse_number,
               fgi.storage_region,
               fgi.`status`,
               fgi.update_time,
               fgi.enter_storage_time,
               fgi.end_time
        from finished_goods_inventory fgi
                 left join sd.order_detail od on fgi.order_number = od.order_number
                 inner join sd.`order` o on fgi.order_id = o.order_id
               fgi.storage_region
        from mm.finished_goods_inventory fgi
                 left join sd.order_detail od on fgi.order_id = od.order_id and fgi.order_number = od.order_number
                 left join sd.`order` o on fgi.order_id = o.order_id
        <where>
                and fgi.status = 0 and fgi.quantity_available>0
            <if test="orderDetail.finishedGoodsInventory.orderId != null and orderDetail.finishedGoodsInventory.orderId != ''">
                and fgi.order_id regexp #{orderDetail.finishedGoodsInventory.orderId}
            </if>
            <if test="orderDetail.order.project != null and orderDetail.order.project != ''">
                and o.project regexp #{orderDetail.order.project}
            </if>
            <if test="orderDetail.finishedGoodsInventory.orderNumber != null and orderDetail.finishedGoodsInventory.orderNumber != ''">
                and fgi.order_number regexp #{orderDetail.finishedGoodsInventory.orderNumber}
            </if>
            <if test="orderDetail.finishedGoodsInventory.quantityAvailable != null and orderDetail.finishedGoodsInventory.quantityAvailable != ''">
                and fgi.quantity_available regexp #{orderDetail.finishedGoodsInventory.quantityAvailable}
            </if>
            <if test="orderDetail.productId != null and orderDetail.productId != ''">
                and od.product_id regexp #{orderDetail.productId}
            </if>
            <if test="orderDetail.productName != null and orderDetail.productName != ''">
                and od.product_name regexp #{orderDetail.productName}
            </if>
            <if test="orderDetail.width != null and orderDetail.width != ''">
                and od.width regexp REGEXP_REPLACE(#{orderDetail.width},'\\.0+$','')
            </if>
            <if test="orderDetail.height != null and orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{orderDetail.height},'\\.0+$','')
            </if>
            <if test="orderDetail.order.customerId != null and orderDetail.order.customerId != ''">
                and o.customer_id regexp #{orderDetail.order.customerId}
            </if>
            <if test="orderDetail.order.customerName != null and orderDetail.order.customerName != ''">
                and o.customer_name regexp #{orderDetail.order.customerName}
            </if>
            <if test="orderDetail.finishedGoodsInventory.actualSignalArea != null and orderDetail.finishedGoodsInventory.actualSignalArea != ''">
                and fgi.actual_signal_area regexp REGEXP_REPLACE(#{orderDetail.finishedGoodsInventory.actualSignalArea},'\\.0+$','')
            </if>
            <if test="orderDetail.finishedGoodsInventory.area != null and orderDetail.finishedGoodsInventory.area != ''">
                and fgi.area regexp REGEXP_REPLACE(#{orderDetail.finishedGoodsInventory.area},'\\.0+$','')
            </if>
            <if test="orderDetail.finishedGoodsInventory.storageRegion != null and orderDetail.finishedGoodsInventory.storageRegion != ''">
                and fgi.storage_region regexp #{orderDetail.finishedGoodsInventory.storageRegion}
            </if>
        </where>
        group by fgi.order_id, fgi.order_number
        order by fgi.id
        limit #{offset},#{pageSize};
    </select>
    <select id="getSelectAllocatePageTotal"  >
        select CEILING(count(zu.order_number)/#{pageSize}) as 'pageTotal',
        count(zu.order_number) as 'total' from
            (select fgi.order_number as order_number
             from mm.finished_goods_inventory fgi
                      left join sd.order_detail od on fgi.order_id = od.order_id and fgi.order_number = od.order_number
                      left join sd.`order` o on fgi.order_id = o.order_id
        <where>
                and fgi.quantity_available>0
            <if test="orderDetail.finishedGoodsInventory.orderId != null and orderDetail.finishedGoodsInventory.orderId != ''">
                and fgi.order_id regexp #{orderDetail.finishedGoodsInventory.orderId}
            </if>
            <if test="orderDetail.order.project != null and orderDetail.order.project != ''">
                and o.project regexp #{orderDetail.order.project}
            </if>
            <if test="orderDetail.finishedGoodsInventory.orderNumber != null and orderDetail.finishedGoodsInventory.orderNumber != ''">
                and fgi.order_number regexp #{orderDetail.finishedGoodsInventory.orderNumber}
            </if>
            <if test="orderDetail.finishedGoodsInventory.quantityAvailable != null and orderDetail.finishedGoodsInventory.quantityAvailable != ''">
                and fgi.quantity_available regexp #{orderDetail.finishedGoodsInventory.quantityAvailable}
            </if>
            <if test="orderDetail.productId != null and orderDetail.productId != ''">
                and od.product_id regexp #{orderDetail.productId}
            </if>
            <if test="orderDetail.productName != null and orderDetail.productName != ''">
                and od.product_name regexp #{orderDetail.productName}
            </if>
            <if test="orderDetail.width != null and orderDetail.width != ''">
                and od.width regexp REGEXP_REPLACE(#{orderDetail.width},'\\.0+$','')
            </if>
            <if test="orderDetail.height != null and orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{orderDetail.height},'\\.0+$','')
            </if>
            <if test="orderDetail.order.customerId != null and orderDetail.order.customerId != ''">
                and o.customer_id regexp #{orderDetail.order.customerId}
            </if>
            <if test="orderDetail.order.customerName != null and orderDetail.order.customerName != ''">
                and o.customer_name regexp #{orderDetail.order.customerName}
            </if>
            <if test="orderDetail.finishedGoodsInventory.actualSignalArea != null and orderDetail.finishedGoodsInventory.actualSignalArea != ''">
                and fgi.actual_signal_area regexp REGEXP_REPLACE(#{orderDetail.finishedGoodsInventory.actualSignalArea},'\\.0+$','')
            </if>
            <if test="orderDetail.finishedGoodsInventory.area != null and orderDetail.finishedGoodsInventory.area != ''">
                and fgi.area regexp REGEXP_REPLACE(#{orderDetail.finishedGoodsInventory.area},'\\.0+$','')
            </if>
            <if test="orderDetail.finishedGoodsInventory.storageRegion != null and orderDetail.finishedGoodsInventory.storageRegion != ''">
                and fgi.storage_region regexp #{orderDetail.finishedGoodsInventory.storageRegion}
            </if>
        </where>
             group by fgi.order_id, fgi.order_number) as zu
        limit #{offset},#{pageSize};
    </select>
    <update id="updateDeliveryDetailState">
        update sd.delivery_detail
        set delivery_detail_state=#{state}
        where order_number=#{orderNumber}  and order_id=#{orderId} and delivery_id=#{deliveryId}
    </update>
    <update id="updateInventoryquantityavailable">
        update mm.finished_goods_inventory
        set inventory=0,quantity_available=0,
        update_time=now(),area=0,status=1
        where order_number=#{orderDetail.deliveryDetail.orderNumber}  and order_id=#{orderDetail.deliveryDetail.orderId}
    </update>
    <select id="getSelectDeliveryDetailPageTotal"  >
        select CEILING(count(dd.id)/#{pageSize}) as 'pageTotal',
        count(dd.id) as 'total'
        from sd.delivery_detail dd
                 left join sd.delivery d on dd.delivery_id = d.delivery_id
                 left join sd.order_detail od on od.order_id = dd.order_id and dd.order_number = od.order_number
                 left join sd.`order` o on o.order_id = dd.order_id
        <where>
                and dd.delivery_detail_state=1
            <if test="orderDetail.deliveryDetail.deliveryId != null and orderDetail.deliveryDetail.deliveryId != ''">
                and dd.delivery_id regexp #{orderDetail.deliveryDetail.deliveryId}
            </if>
            <if test="orderDetail.deliveryDetail.orderId != null and orderDetail.deliveryDetail.orderId != ''">
                and dd.order_id regexp #{orderDetail.deliveryDetail.orderId}
            </if>
            <if test="orderDetail.order.project != null and orderDetail.order.project != ''">
                and o.project regexp #{orderDetail.order.project}
            </if>
            <if test="orderDetail.productId != null and orderDetail.productId != ''">
                and od.product_id regexp #{orderDetail.productId}
            </if>
            <if test="orderDetail.productName != null and orderDetail.productName != ''">
                and od.product_name regexp #{orderDetail.productName}
            </if>
            <if test="orderDetail.delivery.customerName != null and orderDetail.delivery.customerName != ''">
                and d.customer_name regexp #{orderDetail.delivery.customerName}
            </if>
            <if test="orderDetail.width != null and orderDetail.width != ''">
                and od.width regexp REGEXP_REPLACE(#{orderDetail.width},'\\.0+$','')
            </if>
            <if test="orderDetail.height != null and orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{orderDetail.height},'\\.0+$','')
            </if>
            <if test="orderDetail.delivery.quantity != null and orderDetail.delivery.quantity != ''">
                and d.quantity regexp #{orderDetail.delivery.quantity}
            </if>
            <if test="orderDetail.warehouseNum != null and orderDetail.warehouseNum != ''">
                and od.warehouse_num regexp #{orderDetail.warehouseNum}
            </if>
            <if test="orderDetail.buildingNumber != null and orderDetail.buildingNumber != ''">
                and od.building_number regexp #{orderDetail.buildingNumber}
            </if>
            <if test="orderDetail.delivery.area != null and orderDetail.delivery.area != ''">
                and d.area regexp REGEXP_REPLACE(#{orderDetail.delivery.area},'\\.0+$','')
            </if>
            <if test="orderDetail.deliveryDetail.orderNumber != null and orderDetail.deliveryDetail.orderNumber != ''">
                and dd.order_number regexp #{orderDetail.deliveryDetail.orderNumber}
            </if>
            <if test="orderDetail.delivery.creator != null and orderDetail.delivery.creator != ''">
                and d.creator regexp #{orderDetail.delivery.creator}
            </if>
            <if test="orderDetail.deliveryDetail.createTime != null and orderDetail.deliveryDetail.createTime != ''">
                and dd.create_time regexp #{orderDetail.deliveryDetail.createTime}
            </if>
            <if test="orderDetail.deliveryDetail.deliveryDetailRemakes != null and orderDetail.deliveryDetail.deliveryDetailRemakes != ''">
                and dd.delivery_detail_remakes regexp #{orderDetail.deliveryDetail.deliveryDetailRemakes}
            </if>
        </where>
        order by dd.id desc
        limit #{offset},#{pageSize};
    </select>
    <select id="getSelectDeliveryDetail"  resultMap="selectDelivery">
        select dd.delivery_id,
               dd.order_number,
               dd.order_id,
               o.project,
               od.product_id,
               od.product_name,
               d.customer_name,
               od.width,
               od.height,
               dd.quantity as dd_quantity,
               od.warehouse_num,
               od.delivery_num,
               d.area,
               od.building_number,
               d.creator,
               dd.delivery_detail_remakes,
               dd.create_time
        from sd.delivery_detail dd
                 left join sd.delivery d on dd.delivery_id = d.delivery_id
                 left join sd.order_detail od on od.order_id = dd.order_id and dd.order_number = od.order_number
                 left join sd.`order` o on o.order_id = dd.order_id
        <where>
                and dd.delivery_detail_state=1 and d.delivery_state=2
            <if test="orderDetail.deliveryDetail.deliveryId != null and orderDetail.deliveryDetail.deliveryId != ''">
                and dd.delivery_id regexp #{orderDetail.deliveryDetail.deliveryId}
            </if>
            <if test="orderDetail.deliveryDetail.orderId != null and orderDetail.deliveryDetail.orderId != ''">
                and dd.order_id regexp #{orderDetail.deliveryDetail.orderId}
            </if>
            <if test="orderDetail.order.project != null and orderDetail.order.project != ''">
                and o.project regexp #{orderDetail.order.project}
            </if>
            <if test="orderDetail.productId != null and orderDetail.productId != ''">
                and od.product_id regexp #{orderDetail.productId}
            </if>
            <if test="orderDetail.productName != null and orderDetail.productName != ''">
                and od.product_name regexp #{orderDetail.productName}
            </if>
            <if test="orderDetail.delivery.customerName != null and orderDetail.delivery.customerName != ''">
                and d.customer_name regexp #{orderDetail.delivery.customerName}
            </if>
            <if test="orderDetail.width != null and orderDetail.width != ''">
                and od.width regexp REGEXP_REPLACE(#{orderDetail.width},'\\.0+$','')
            </if>
            <if test="orderDetail.height != null and orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{orderDetail.height},'\\.0+$','')
            </if>
            <if test="orderDetail.delivery.quantity != null and orderDetail.delivery.quantity != ''">
                and d.quantity regexp #{orderDetail.delivery.quantity}
            </if>
            <if test="orderDetail.warehouseNum != null and orderDetail.warehouseNum != ''">
                and od.warehouse_num regexp #{orderDetail.warehouseNum}
            </if>
            <if test="orderDetail.buildingNumber != null and orderDetail.buildingNumber != ''">
                and od.building_number regexp #{orderDetail.buildingNumber}
            </if>
            <if test="orderDetail.delivery.area != null and orderDetail.delivery.area != ''">
                and d.area regexp REGEXP_REPLACE(#{orderDetail.delivery.area},'\\.0+$','')
            </if>
            <if test="orderDetail.deliveryDetail.orderNumber != null and orderDetail.deliveryDetail.orderNumber != ''">
                and dd.order_number regexp #{orderDetail.deliveryDetail.orderNumber}
            </if>
            <if test="orderDetail.delivery.creator != null and orderDetail.delivery.creator != ''">
                and d.creator regexp #{orderDetail.delivery.creator}
            </if>
            <if test="orderDetail.deliveryDetail.createTime != null and orderDetail.deliveryDetail.createTime != ''">
                and dd.create_time regexp #{orderDetail.deliveryDetail.createTime}
            </if>
            <if test="orderDetail.deliveryDetail.deliveryDetailRemakes != null and orderDetail.deliveryDetail.deliveryDetailRemakes != ''">
                and dd.delivery_detail_remakes regexp #{orderDetail.deliveryDetail.deliveryDetailRemakes}
            </if>
        </where>
        order by dd.id desc
        limit #{offset},#{pageSize};
    </select>
    <select id="findOrderQuantity" >
        select quantity from sd.`order`  where order_id=#{orderId}
    </select>
    <select id="findOrderNumberdsum"  >
        select sum(warehouse_num) from sd.order_detail where order_id=#{orderId}
    </select>
    <select id="findOrderDeliveryQuantitySum"  >
        select sum(delivery_num) from sd.order_detail where order_id=#{orderId}
    </select>
    <select id="findDeliveryQuantity" >
        select quantity from sd.`delivery`  where delivery_id=#{deliveryId}
    </select>
    <select id="findDeliverydetailsum"  >
        select sum(quantity) from sd.`delivery_detail`  where delivery_id=#{deliveryId} and delivery_detail_state=#{deliveryDetailState}
    </select>
    <update id="updateOrderWarehousingState">
        update sd.`order`
        set warehousing=#{state}
        where order_id=#{orderId}
    </update>
    <update id="updateOrderDeliveryState">
        update sd.`order`
        set delivery=#{state}
        where order_id=#{orderId}
    </update>
    <update id="updateDeliveryDeliveryState">
        update sd.`delivery`
        set stock_state=#{state}
        where delivery_id=#{deliveryId}
    </update>
    <update id="updateIntOrderNumberConut">
        update sd.order_detail
        set warehouse_num=warehouse_num+${quantity}
        where order_number=#{orderNumber} and order_id=#{orderId}
    </update>
    <update id="updateOutOrderNumberConut">
        update sd.order_detail
        set warehouse_num=warehouse_num-${quantity}
        where order_number=#{orderNumber} and order_id=#{orderId}
    </update>
    <update id="updateflowcard">
        update pp.flow_card
        set received_quantity=received_quantity+${inventoryQuantity},storage_time=now()
        where order_number=#{orderNumber} and process_id=#{processId} and order_id=#{order.orderId}
    </update>
    <update id="updateflowcardOut">
        update pp.flow_card
        set received_quantity=received_quantity-${finishedOperateLog.quantity},storage_time=now()
        where order_number=#{finishedOperateLog.operationNumber} and process_id=#{finishedOperateLog.processId} and order_id=#{finishedOperateLog.orderId}
    </update>
    <update id="updateInventory">
        update mm.finished_goods_inventory
        set inventory=inventory+${flowCard.inventoryQuantity},quantity_available=quantity_available+${flowCard.inventoryQuantity},
            update_time=now(),area=actual_signal_area*quantity_available
        <if test="storageRegion != null and storageRegion != ''">
            , storage_region= #{storageRegion}
        </if>
        <if test="remark != null and remark != ''">
            , remark= #{remark}
        </if>
        where order_number=#{flowCard.orderNumber}  and order_id=#{flowCard.order.orderId}
    </update>
    <update id="updateInventoryOut">
        update mm.finished_goods_inventory
        set inventory=inventory-${finishedOperateLog.quantity},quantity_available=quantity_available-${finishedOperateLog.quantity},
        update_time=now(),area=actual_signal_area*quantity_available
        where order_number=#{finishedOperateLog.operationNumber}  and order_id=#{finishedOperateLog.orderId}
    </update>
    <insert id="insertFinishedGoodsInventory"  useGeneratedKeys="true"  >
        insert into mm.finished_goods_inventory (order_id,
                                                 order_number,
                                                 process_id,
                                                 inventory,
                                                 actual_signal_area,
                                                 area,
                                                 quantity_available,
                                                 warehouse_number,
                                                 storage_region,
                                                 `status`,
                                                 enter_storage_time,
                                                 update_time,
                                                 end_time,
                                                 remark
        )
        values (
                   #{flowCard.order.orderId} ,#{flowCard.orderNumber},#{flowCard.processId},#{flowCard.inventoryQuantity},ROUND(#{flowCard.orderDetail.width}*#{flowCard.orderDetail.height}/1000000,2),
                   ROUND(#{flowCard.orderDetail.width}*#{flowCard.orderDetail.height}*#{flowCard.inventoryQuantity}/1000000,2),
                #{flowCard.inventoryQuantity},null,#{storageRegion},
                0,now(),now(),null,#{remark}
               )
    </insert>
    <select id="findOrderNumberdcount" >
        select count(*)
        from  mm.`finished_goods_inventory`
        where order_number = #{orderNumber} and order_id=#{orderId};
    </select>
    <select id="finishedGoodsInventorybycount" >
        select quantity_available
        from  mm.`finished_goods_inventory`
        where order_number = #{orderNumber} and order_id=#{orderId};
    </select>
    <select id="getSelectWarehousing" resultMap="selectFlowCard">
        select
        fc.id,
        o.order_id,
        od.building_number,
        od.product_id,
        od.product_name,
        od.width,
        od.height,
        o.creator,
        o.project,
        fc.order_number,
        od.quantity,
        fc.inventory_quantity-fc.received_quantity as inventory_quantity,
        o.area,
        fc.process_id,
        fc.received_quantity,
        o.batch
        from pp.flow_card fc left join sd.order_detail od on fc.order_id=od.order_id and fc.order_number=od.order_number inner join sd.`order` o on
        o.order_id=fc.order_id
        <where>
                and fc.received_quantity <![CDATA[<]]> fc.inventory_quantity
            <if test="flowCard.order.orderId != null and flowCard.order.orderId != ''">
                and o.order_id regexp #{flowCard.order.orderId}
            </if>
            <if test="flowCard.orderDetail.buildingNumber != null and flowCard.orderDetail.buildingNumber != ''">
                and od.building_number regexp #{flowCard.orderDetail.buildingNumber}
            </if>
            <if test="flowCard.orderDetail.productId != null and flowCard.orderDetail.productId != ''">
                and od.product_id regexp #{flowCard.orderDetail.productId}
            </if>
            <if test="flowCard.orderDetail.productName != null and flowCard.orderDetail.productName != ''">
                and od.product_name regexp #{flowCard.orderDetail.productName}
            </if>
            <if test="flowCard.orderDetail.width != null and flowCard.orderDetail.width != ''">
                and od.width regexp REGEXP_REPLACE(#{flowCard.orderDetail.width},'\\.0+$','')
            </if>
            <if test="flowCard.orderDetail.height != null and flowCard.orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{flowCard.orderDetail.height},'\\.0+$','')
            </if>
            <if test="flowCard.order.creator != null and flowCard.order.creator != ''">
                and o.creator regexp #{flowCard.order.creator}
            </if>
            <if test="flowCard.order.project != null and flowCard.order.project != ''">
                and o.project regexp #{flowCard.order.project}
            </if>
            <if test="flowCard.orderNumber != null and flowCard.orderNumber != ''">
                and fc.order_number regexp #{flowCard.orderNumber}
            </if>
            <if test="flowCard.orderDetail.quantity != null and flowCard.orderDetail.quantity != ''">
                and od.quantity regexp #{flowCard.orderDetail.quantity}
            </if>
            <if test="flowCard.inventoryQuantity != null and flowCard.inventoryQuantity != ''">
                and fc.inventory_quantity regexp #{flowCard.inventoryQuantity}
            </if>
            <if test="flowCard.order.area != null and flowCard.order.area != ''">
                and o.area regexp REGEXP_REPLACE(#{flowCard.order.area},'\\.0+$','')
            </if>
            <if test="flowCard.order.batch != null and flowCard.order.batch != ''">
                and o.batch regexp #{flowCard.order.batch}
            </if>
            <if test="flowCard.processId != null and flowCard.processId != ''">
                and fc.process_id regexp #{flowCard.processId}
            </if>
            <if test="flowCard.receivedQuantity != null and flowCard.receivedQuantity != ''">
                and fc.received_quantity regexp #{flowCard.receivedQuantity}
            </if>
        </where>
        group by fc.order_id,fc.order_number,fc.process_id order by fc.create_time desc
        limit #{offset},#{pageSize};
    </select>
    <select id="getSelectWarehousingPageTotal" >
        select
        CEILING(count(zu.order_number)/#{pageSize}) as 'pageTotal',
        count(zu.order_number) as 'total' from (
        select fc.order_number as order_number,fc.process_id from pp.flow_card fc left join sd.order_detail od on
        fc.order_id=od.order_id and fc.order_number=od.order_number inner join sd.`order` o on o.order_id=fc.order_id
        <where>
            and fc.received_quantity <![CDATA[<]]> fc.inventory_quantity
            <if test="flowCard.order.orderId != null and flowCard.order.orderId != ''">
                and o.order_id regexp #{flowCard.order.orderId}
            </if>
            <if test="flowCard.orderDetail.buildingNumber != null and flowCard.orderDetail.buildingNumber != ''">
                and od.building_number regexp #{flowCard.orderDetail.buildingNumber}
            </if>
            <if test="flowCard.orderDetail.productId != null and flowCard.orderDetail.productId != ''">
                and od.product_id regexp #{flowCard.orderDetail.productId}
            </if>
            <if test="flowCard.orderDetail.productName != null and flowCard.orderDetail.productName != ''">
                and od.product_name regexp #{flowCard.orderDetail.productName}
            </if>
            <if test="flowCard.orderDetail.width != null and flowCard.orderDetail.width != ''">
                and od.width regexp REGEXP_REPLACE(#{flowCard.orderDetail.width},'\\.0+$','')
            </if>
            <if test="flowCard.orderDetail.height != null and flowCard.orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{flowCard.orderDetail.height},'\\.0+$','')
            </if>
            <if test="flowCard.order.creator != null and flowCard.order.creator != ''">
                and o.creator regexp #{flowCard.order.creator}
            </if>
            <if test="flowCard.order.project != null and flowCard.order.project != ''">
                and o.project regexp #{flowCard.order.project}
            </if>
            <if test="flowCard.orderNumber != null and flowCard.orderNumber != ''">
                and fc.order_number regexp #{flowCard.orderNumber}
            </if>
            <if test="flowCard.orderDetail.quantity != null and flowCard.orderDetail.quantity != ''">
                and od.quantity regexp #{flowCard.orderDetail.quantity}
            </if>
            <if test="flowCard.inventoryQuantity != null and flowCard.inventoryQuantity != ''">
                and fc.inventory_quantity regexp #{flowCard.inventoryQuantity}
            </if>
            <if test="flowCard.order.area != null and flowCard.order.area != ''">
                and o.area regexp REGEXP_REPLACE(#{flowCard.order.area},'\\.0+$','')
            </if>
            <if test="flowCard.order.batch != null and flowCard.order.batch != ''">
                and o.batch regexp #{flowCard.order.batch}
            </if>
            <if test="flowCard.processId != null and flowCard.processId != ''">
                and fc.process_id regexp #{flowCard.processId}
            </if>
            <if test="flowCard.receivedQuantity != null and flowCard.receivedQuantity != ''">
                and fc.received_quantity regexp #{flowCard.receivedQuantity}
            </if>
        </where>
        group by fc.order_id,fc.order_number,fc.process_id order by fc.create_time) as zu
    </select>
    <select id="defaultfinishedGoods" resultMap="selectFinishedGoodsInventory">
        select od.order_number,
        o.order_id,
        o.project,
        o.order_type,
        od.product_name,
        od.product_id,
        od.width,
        od.height,
        fgi.inventory,
        fgi.quantity_available,
        fgi.actual_signal_area,
        fgi.area,
        fgi.warehouse_number,
        fgi.storage_region,
        fgi.`status`,
        fgi.update_time,
        fgi.enter_storage_time,
        fgi.end_time,
        fgi.remark
        from finished_goods_inventory fgi
        left join sd.order_detail od on fgi.order_id = od.order_id and fgi.order_number = od.order_number
        left join sd.`order` o on fgi.order_id = o.order_id
        <where>
                and fgi.status = 0 and fgi.quantity_available>0
            <if test="finishedGoodsInventory.orderDetail.width != null and finishedGoodsInventory.orderDetail.width != ''">
                and od.width regexp #{finishedGoodsInventory.orderDetail.width}
            </if>
            <if test="finishedGoodsInventory.orderDetail.orderNumber != null and finishedGoodsInventory.orderDetail.orderNumber != ''">
                and od.order_number regexp #{finishedGoodsInventory.orderDetail.orderNumber}
            </if>
            <if test="finishedGoodsInventory.orderDetail.productName != null and finishedGoodsInventory.orderDetail.productName != ''">
                and od.product_name regexp #{finishedGoodsInventory.orderDetail.productName}
            </if>
            <if test="finishedGoodsInventory.orderDetail.productId != null and finishedGoodsInventory.orderDetail.productId != ''">
                and od.product_id regexp #{finishedGoodsInventory.orderDetail.productId}
            </if>
            <if test="finishedGoodsInventory.order.orderId != null and finishedGoodsInventory.order.orderId != ''">
                and o.order_id regexp #{finishedGoodsInventory.order.orderId}
            </if>
            <if test="finishedGoodsInventory.order.project != null and finishedGoodsInventory.order.project != ''">
                and o.project regexp #{finishedGoodsInventory.order.project}
            </if>
            <if test="finishedGoodsInventory.order.orderType != null and finishedGoodsInventory.order.orderType != ''">
                and o.order_type regexp #{finishedGoodsInventory.order.orderType}
            </if>
            <if test="finishedGoodsInventory.orderDetail.height != null and finishedGoodsInventory.orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{finishedGoodsInventory.orderDetail.height},'\\.0+$','')
            </if>
            <if test="finishedGoodsInventory.inventory != null and finishedGoodsInventory.inventory != ''">
                and fgi.inventory regexp #{finishedGoodsInventory.inventory}
            </if>
            <if test="finishedGoodsInventory.quantityAvailable != null and finishedGoodsInventory.quantityAvailable != ''">
                and fgi.quantity_available regexp #{finishedGoodsInventory.quantityAvailable}
            </if>
            <if test="finishedGoodsInventory.actualSignalArea != null and finishedGoodsInventory.actualSignalArea != ''">
                and fgi.actual_signal_area regexp REGEXP_REPLACE(#{finishedGoodsInventory.actualSignalArea},'\\.0+$','')
            </if>
            <if test="finishedGoodsInventory.area != null and finishedGoodsInventory.area != ''">
                and fgi.area regexp REGEXP_REPLACE(#{finishedGoodsInventory.area},'\\.0+$','')
            </if>
            <if test="finishedGoodsInventory.warehouseNumber != null and finishedGoodsInventory.warehouseNumber != ''">
                and fgi.warehouse_number regexp #{finishedGoodsInventory.warehouseNumber}
            </if>
            <if test="finishedGoodsInventory.storageRegion != null and finishedGoodsInventory.storageRegion != ''">
                and fgi.storage_region regexp #{finishedGoodsInventory.storageRegion}
            </if>
            <if test="finishedGoodsInventory.status != null and finishedGoodsInventory.status != ''">
                and fgi.`status` regexp #{finishedGoodsInventory.status}
            </if>
            <if test="finishedGoodsInventory.enterStorageTime != null and finishedGoodsInventory.enterStorageTime != ''">
                and fgi.enter_storage_time regexp #{finishedGoodsInventory.enterStorageTime}
            </if>
            <if test="finishedGoodsInventory.updateTime != null and finishedGoodsInventory.updateTime != ''">
                and fgi.update_time regexp #{finishedGoodsInventory.updateTime}
            </if>
            <if test="finishedGoodsInventory.endTime != null and finishedGoodsInventory.endTime != ''">
                and fgi.end_time regexp #{finishedGoodsInventory.endTime}
            </if>
            <if test="finishedGoodsInventory.remark != null and finishedGoodsInventory.remark != ''">
                and fgi.remark regexp #{finishedGoodsInventory.remark}
            </if>
        </where>
        order by fgi.id desc
        limit #{offset},#{pageSize};
    </select>
    <select id="getPageTotal">
        select
        CEILING(count(fgi.id)/#{pageSize}) as 'pageTotal',
        count(fgi.id) as 'total'
        from finished_goods_inventory fgi
        left join sd.order_detail od on fgi.order_id = od.order_id and fgi.order_number = od.order_number
        left join sd.`order` o on fgi.order_id = o.order_id
        <where>
                and fgi.status = 0 and  fgi.quantity_available>0
            <if test="finishedGoodsInventory.orderDetail.width != null and finishedGoodsInventory.orderDetail.width != ''">
                and od.width regexp #{finishedGoodsInventory.orderDetail.width}
            </if>
            <if test="finishedGoodsInventory.orderDetail.orderNumber != null and finishedGoodsInventory.orderDetail.orderNumber != ''">
                and od.order_number regexp #{finishedGoodsInventory.orderDetail.orderNumber}
            </if>
            <if test="finishedGoodsInventory.orderDetail.productName != null and finishedGoodsInventory.orderDetail.productName != ''">
                and od.product_name regexp #{finishedGoodsInventory.orderDetail.productName}
            </if>
            <if test="finishedGoodsInventory.orderDetail.productId != null and finishedGoodsInventory.orderDetail.productId != ''">
                and od.product_id regexp #{finishedGoodsInventory.orderDetail.productId}
            </if>
            <if test="finishedGoodsInventory.order.orderId != null and finishedGoodsInventory.order.orderId != ''">
                and o.order_id regexp #{finishedGoodsInventory.order.orderId}
            </if>
            <if test="finishedGoodsInventory.order.project != null and finishedGoodsInventory.order.project != ''">
                and o.project regexp #{finishedGoodsInventory.order.project}
            </if>
            <if test="finishedGoodsInventory.order.orderType != null and finishedGoodsInventory.order.orderType != ''">
                and o.order_type regexp #{finishedGoodsInventory.order.orderType}
            </if>
            <if test="finishedGoodsInventory.orderDetail.height != null and finishedGoodsInventory.orderDetail.height != ''">
                and od.height regexp REGEXP_REPLACE(#{finishedGoodsInventory.orderDetail.height},'\\.0+$','')
            </if>
            <if test="finishedGoodsInventory.inventory != null and finishedGoodsInventory.inventory != ''">
                and fgi.inventory regexp #{finishedGoodsInventory.inventory}
            </if>
            <if test="finishedGoodsInventory.quantityAvailable != null and finishedGoodsInventory.quantityAvailable != ''">
                and fgi.quantity_available regexp #{finishedGoodsInventory.quantityAvailable}
            </if>
            <if test="finishedGoodsInventory.actualSignalArea != null and finishedGoodsInventory.actualSignalArea != ''">
                and fgi.actual_signal_area regexp REGEXP_REPLACE(#{finishedGoodsInventory.actualSignalArea},'\\.0+$','')
            </if>
            <if test="finishedGoodsInventory.area != null and finishedGoodsInventory.area != ''">
                and fgi.area regexp REGEXP_REPLACE(#{finishedGoodsInventory.area},'\\.0+$','')
            </if>
            <if test="finishedGoodsInventory.warehouseNumber != null and finishedGoodsInventory.warehouseNumber != ''">
                and fgi.warehouse_number regexp #{finishedGoodsInventory.warehouseNumber}
            </if>
            <if test="finishedGoodsInventory.storageRegion != null and finishedGoodsInventory.storageRegion != ''">
                and fgi.storage_region regexp #{finishedGoodsInventory.storageRegion}
            </if>
            <if test="finishedGoodsInventory.status != null and finishedGoodsInventory.status != ''">
                and fgi.`status` regexp #{finishedGoodsInventory.status}
            </if>
            <if test="finishedGoodsInventory.enterStorageTime != null and finishedGoodsInventory.enterStorageTime != ''">
                and fgi.enter_storage_time regexp #{finishedGoodsInventory.enterStorageTime}
            </if>
            <if test="finishedGoodsInventory.updateTime != null and finishedGoodsInventory.updateTime != ''">
                and fgi.update_time regexp #{finishedGoodsInventory.updateTime}
            </if>
            <if test="finishedGoodsInventory.endTime != null and finishedGoodsInventory.endTime != ''">
                and fgi.end_time regexp #{finishedGoodsInventory.endTime}
            </if>
            <if test="finishedGoodsInventory.remark != null and finishedGoodsInventory.remark != ''">
                and fgi.remark regexp #{finishedGoodsInventory.remark}
            </if>
        </where>
        order by fgi.id desc
        limit #{offset},#{pageSize}
        ;
    </select>
</mapper>