<?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.xingxi.business.ProdInventory.mapper.ProdInventoryBillMapper">
    <resultMap type="ProdInventoryBill" id="ProdInventoryBillResult">
        <result property="inventoryBillId"    column="inventoryBillId"    />
        <result property="billTime"    column="billTime"    />
        <result property="billType"    column="billType"    />
        <result property="inventoryId"    column="inventoryId"    />
        <result property="quantity"    column="quantity"    />
        <result property="orderId"    column="orderId"    />
        <result property="orderNo"    column="orderNo"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectProdInventoryBill">
        select inventoryBillId, billTime, billType, inventoryId, quantity, orderId, orderNo, remark, delFlag, createUser, createTime, updateUser, updateTime from t_prod_inventory_bill
    </sql>

    <select id="selectProdInventoryBillList" parameterType="ProdInventoryBill" resultMap="ProdInventoryBillResult">
        <include refid="selectProdInventoryBill"/>
        <where>  
            <if test="billTime != null "> and billTime = #{billTime}</if>
            <if test="billType != null  and billType != ''"> and billType = #{billType}</if>
            <if test="inventoryId != null "> and inventoryId = #{inventoryId}</if>
            <if test="quantity != null "> and quantity = #{quantity}</if>
            <if test="orderId != null "> and orderId = #{orderId}</if>
            <if test="orderNo != null  and orderNo != ''"> and orderNo = #{orderNo}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectProdInventoryBillByInventoryBillId" parameterType="Long" resultMap="ProdInventoryBillResult">
        <include refid="selectProdInventoryBill"/>
        where inventoryBillId = #{inventoryBillId}
    </select>
        
    <insert id="insertProdInventoryBill" parameterType="ProdInventoryBill" useGeneratedKeys="true" keyProperty="inventoryBillId">
        insert into t_prod_inventory_bill
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="billTime != null">billTime,</if>
            <if test="billType != null">billType,</if>
            <if test="inventoryId != null">inventoryId,</if>
            <if test="quantity != null">quantity,</if>
            <if test="orderId != null">orderId,</if>
            <if test="orderNo != null">orderNo,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="billTime != null">#{billTime},</if>
            <if test="billType != null">#{billType},</if>
            <if test="inventoryId != null">#{inventoryId},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertProdInventoryBill">
        insert into t_prod_inventory_bill( billTime, billType, inventoryId, quantity, orderId, orderNo, remark, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.billTime}, #{item.billType}, #{item.inventoryId}, #{item.quantity}, #{item.orderId}, #{item.orderNo}, #{item.remark}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdInventoryBill" parameterType="ProdInventoryBill">
        update t_prod_inventory_bill
        <trim prefix="SET" suffixOverrides=",">
            <if test="billTime != null">billTime = #{billTime},</if>
            <if test="billType != null">billType = #{billType},</if>
            <if test="inventoryId != null">inventoryId = #{inventoryId},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="orderId != null">orderId = #{orderId},</if>
            <if test="orderNo != null">orderNo = #{orderNo},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where inventoryBillId = #{inventoryBillId}
    </update>

    <delete id="deleteProdInventoryBillByInventoryBillId" parameterType="Long">
        delete from t_prod_inventory_bill where inventoryBillId = #{inventoryBillId}
    </delete>

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

    <update id="logicDeleteProdInventoryBillByInventoryBillId" parameterType="Long">
        update t_prod_inventory_bill
            set delFlag = '1'
        where inventoryBillId = #{inventoryBillId}
    </update>

    <update id="logicDeleteProdInventoryBillByInventoryBillIds" parameterType="String">
        update t_prod_inventory_bill
        set delFlag = '1'
        where inventoryBillId in
        <foreach item="inventoryBillId" collection="array" open="(" separator="," close=")">
            #{inventoryBillId}
        </foreach>
    </update>

    <update id="logicDeleteProdInventoryBillByCondition" parameterType="ProdInventoryBill">
        update t_prod_inventory_bill
        set delFlag = '1'
        <where>
            <if test="billTime != null "> and billTime = #{billTime}</if>
            <if test="billType != null  and billType != ''"> and billType = #{billType}</if>
            <if test="inventoryId != null "> and inventoryId = #{inventoryId}</if>
            <if test="quantity != null "> and quantity = #{quantity}</if>
            <if test="orderId != null "> and orderId = #{orderId}</if>
            <if test="orderNo != null  and orderNo != ''"> and orderNo = #{orderNo}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>