<?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.ProdInventoryOrderMapper">
    <resultMap type="ProdInventoryOrder" id="ProdInventoryOrderResult">
        <result property="inventoryOrderId"    column="inventoryOrderId"    />
        <result property="ioFlag"    column="ioFlag"    />
        <result property="ioType"    column="ioType"    />
        <result property="inId"    column="inId"    />
        <result property="outId"    column="outId"    />
        <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="selectProdInventoryOrder">
        select inventoryOrderId, ioFlag, ioType, inId, outId, remark, delFlag, createUser, createTime, updateUser, updateTime from t_prod_inventory_order
    </sql>

    <sql id="selectProdInventoryOrderExt">
        select
            ${tableAlias}.inventoryOrderId,
            ${tableAlias}.ioFlag,
            ${tableAlias}.ioType,
            ${tableAlias}.inId,
            ${tableAlias}.outId,
            ${tableAlias}.remark,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_prod_inventory_order ${tableAlias}
    </sql>

    <select id="selectProdInventoryOrderList" parameterType="ProdInventoryOrder" resultMap="ProdInventoryOrderResult">
        <include refid="selectProdInventoryOrder"/>
        <where>  
            <if test="ioFlag != null  and ioFlag != ''"> and ioFlag = #{ioFlag}</if>
            <if test="ioType != null  and ioType != ''"> and ioType = #{ioType}</if>
            <if test="inId != null "> and inId = #{inId}</if>
            <if test="outId != null "> and outId = #{outId}</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="selectProdInventoryOrderByInventoryOrderId" parameterType="Long" resultMap="ProdInventoryOrderResult">
        <include refid="selectProdInventoryOrder"/>
        where inventoryOrderId = #{inventoryOrderId}
    </select>
        
    <insert id="insertProdInventoryOrder" parameterType="ProdInventoryOrder" useGeneratedKeys="true" keyProperty="inventoryOrderId">
        insert into t_prod_inventory_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ioFlag != null">ioFlag,</if>
            <if test="ioType != null">ioType,</if>
            <if test="inId != null">inId,</if>
            <if test="outId != null">outId,</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="ioFlag != null">#{ioFlag},</if>
            <if test="ioType != null">#{ioType},</if>
            <if test="inId != null">#{inId},</if>
            <if test="outId != null">#{outId},</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="batchInsertProdInventoryOrder">
        insert into t_prod_inventory_order( ioFlag, ioType, inId, outId, remark, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.ioFlag}, #{item.ioType}, #{item.inId}, #{item.outId}, #{item.remark}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdInventoryOrder" parameterType="ProdInventoryOrder">
        update t_prod_inventory_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="ioFlag != null">ioFlag = #{ioFlag},</if>
            <if test="ioType != null">ioType = #{ioType},</if>
            <if test="inId != null">inId = #{inId},</if>
            <if test="outId != null">outId = #{outId},</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 inventoryOrderId = #{inventoryOrderId}
    </update>

    <delete id="deleteProdInventoryOrderByInventoryOrderId" parameterType="Long">
        delete from t_prod_inventory_order where inventoryOrderId = #{inventoryOrderId}
    </delete>

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

    <update id="logicDeleteProdInventoryOrderByInventoryOrderId" parameterType="Long">
        update t_prod_inventory_order
            set delFlag = '1'
        where inventoryOrderId = #{inventoryOrderId}
    </update>

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

    <update id="logicDeleteProdInventoryOrderByCondition" parameterType="ProdInventoryOrder">
        update t_prod_inventory_order
        set delFlag = '1'
        <where>
            <if test="ioFlag != null  and ioFlag != ''"> and ioFlag = #{ioFlag}</if>
            <if test="ioType != null  and ioType != ''"> and ioType = #{ioType}</if>
            <if test="inId != null "> and inId = #{inId}</if>
            <if test="outId != null "> and outId = #{outId}</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>