<?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.hw.wms.mapper.WmsProductStockSaleorderMapper">

    <resultMap type="WmsProductStockSaleorder" id="WmsProductStockSaleorderResult">
        <result property="productStockSaleorderId"    column="product_stock_saleorder_id"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="warehouseFloor"    column="warehouse_floor"    />
        <result property="stockType"    column="stock_type"    />
        <result property="productId"    column="product_id"    />
        <result property="saleOrderId"    column="sale_order_id"    />
        <result property="saleorderCode"    column="saleorder_code"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="occupyAmount"    column="occupy_amount"    />
        <result property="frozenAmount"    column="frozen_amount"    />
        <result property="applyAmount"    column="apply_amount"    />
        <result property="outstockAmount"    column="outstock_amount"    />
        <result property="confirmAmount"    column="confirm_amount"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="activeFlag"    column="active_flag"    />
    </resultMap>

    <sql id="selectWmsProductStockSaleorderVo">
        select product_stock_saleorder_id, warehouse_id, warehouse_floor, stock_type, product_id, sale_order_id, saleorder_code, total_amount, occupy_amount, frozen_amount, apply_amount, outstock_amount, confirm_amount, create_by, create_date, update_by, update_date, active_flag from wms_product_stock_saleorder
    </sql>

    <select id="selectWmsProductStockSaleorderList" parameterType="WmsProductStockSaleorder" resultMap="WmsProductStockSaleorderResult">
        <include refid="selectWmsProductStockSaleorderVo"/>
        <where>
            <if test="warehouseId != null "> and warehouse_id = #{warehouseId}</if>
            <if test="warehouseFloor != null "> and warehouse_floor = #{warehouseFloor}</if>
            <if test="stockType != null  and stockType != ''"> and stock_type = #{stockType}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="saleOrderId != null "> and sale_order_id = #{saleOrderId}</if>
            <if test="saleorderCode != null  and saleorderCode != ''"> and saleorder_code = #{saleorderCode}</if>
            <if test="totalAmount != null "> and total_amount = #{totalAmount}</if>
            <if test="occupyAmount != null "> and occupy_amount = #{occupyAmount}</if>
            <if test="frozenAmount != null "> and frozen_amount = #{frozenAmount}</if>
            <if test="applyAmount != null "> and apply_amount = #{applyAmount}</if>
            <if test="outstockAmount != null "> and outstock_amount = #{outstockAmount}</if>
            <if test="confirmAmount != null "> and confirm_amount = #{confirmAmount}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="activeFlag != null  and activeFlag != ''"> and active_flag = #{activeFlag}</if>
        </where>
    </select>

    <select id="selectWmsProductStockSaleorderByProductStockSaleorderId" parameterType="Long" resultMap="WmsProductStockSaleorderResult">
        <include refid="selectWmsProductStockSaleorderVo"/>
        where product_stock_saleorder_id = #{productStockSaleorderId}
    </select>

    <insert id="insertWmsProductStockSaleorder" parameterType="WmsProductStockSaleorder" useGeneratedKeys="true" keyProperty="productStockSaleorderId">
        insert into wms_product_stock_saleorder
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="warehouseFloor != null">warehouse_floor,</if>
            <if test="stockType != null and stockType != ''">stock_type,</if>
            <if test="productId != null">product_id,</if>
            <if test="saleOrderId != null">sale_order_id,</if>
            <if test="saleorderCode != null">saleorder_code,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="occupyAmount != null">occupy_amount,</if>
            <if test="frozenAmount != null">frozen_amount,</if>
            <if test="applyAmount != null">apply_amount,</if>
            <if test="outstockAmount != null">outstock_amount,</if>
            <if test="confirmAmount != null">confirm_amount,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="activeFlag != null">active_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="warehouseFloor != null">#{warehouseFloor},</if>
            <if test="stockType != null and stockType != ''">#{stockType},</if>
            <if test="productId != null">#{productId},</if>
            <if test="saleOrderId != null">#{saleOrderId},</if>
            <if test="saleorderCode != null">#{saleorderCode},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="occupyAmount != null">#{occupyAmount},</if>
            <if test="frozenAmount != null">#{frozenAmount},</if>
            <if test="applyAmount != null">#{applyAmount},</if>
            <if test="outstockAmount != null">#{outstockAmount},</if>
            <if test="confirmAmount != null">#{confirmAmount},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="activeFlag != null">#{activeFlag},</if>
        </trim>
    </insert>

    <update id="updateWmsProductStockSaleorder" parameterType="WmsProductStockSaleorder">
        update wms_product_stock_saleorder
        <trim prefix="SET" suffixOverrides=",">
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
            <if test="warehouseFloor != null">warehouse_floor = #{warehouseFloor},</if>
            <if test="stockType != null and stockType != ''">stock_type = #{stockType},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="saleOrderId != null">sale_order_id = #{saleOrderId},</if>
            <if test="saleorderCode != null">saleorder_code = #{saleorderCode},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="occupyAmount != null">occupy_amount = #{occupyAmount},</if>
            <if test="frozenAmount != null">frozen_amount = #{frozenAmount},</if>
            <if test="applyAmount != null">apply_amount = #{applyAmount},</if>
            <if test="outstockAmount != null">outstock_amount = #{outstockAmount},</if>
            <if test="confirmAmount != null">confirm_amount = #{confirmAmount},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="activeFlag != null">active_flag = #{activeFlag},</if>
        </trim>
        where product_stock_saleorder_id = #{productStockSaleorderId}
    </update>

    <delete id="deleteWmsProductStockSaleorderByProductStockSaleorderId" parameterType="Long">
        delete from wms_product_stock_saleorder where product_stock_saleorder_id = #{productStockSaleorderId}
    </delete>

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










    <select id="selectWmsProductStockSaleorderJoinList" parameterType="WmsProductStockSaleorder" resultMap="WmsProductStockSaleorderResult">
        select wpss.product_stock_saleorder_id, wpss.warehouse_id, wpss.warehouse_floor, wpss.stock_type, wpss.product_id, wpss.saleorder_code,
        wpss.total_amount,wpss.apply_amount, wpss.occupy_amount,wpss.frozen_amount,wpss.outstock_amount, wpss.confirm_amount,
        mso.order_amount,wbw.warehouse_name,mbmi.material_code,mbmi.material_name
        from wms_product_stock_saleorder wpss left join mes_sale_order mso on wpss.sale_order_id = mso.sale_order_id
        left join wms_base_warehouse wbw on wpss.warehouse_id=wbw.warehouse_id
        left join mes_base_material_info mbmi on mbmi.material_id=wpss.product_id

        <where>
            <if test="saleorderCode != null  and saleorderCode != ''"> and wpss.saleorder_code = #{saleorderCode}</if>
            <if test="warehouseId != null ">and wpss.warehouse_id = #{warehouseId}</if>
            <if test="productId != null ">and wpss.product_id = #{productId}</if>
        </where>
    </select>

</mapper>
