<?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.ProdInventoryOrderDetailMapper">
    <resultMap type="ProdInventoryOrderDetail" id="ProdInventoryOrderDetailResult">
        <result property="inventoryOrderDetailId"    column="inventoryOrderDetailId"    />
        <result property="inventoryOrderId"    column="inventoryOrderId"    />
        <result property="prodId"    column="prodId"    />
        <result property="prodName"    column="prodName"    />
        <result property="prodAttrId"    column="prodAttrId"    />
        <result property="prodAttrName"    column="prodAttrName"    />
        <result property="quantity"    column="quantity"    />
        <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="selectProdInventoryOrderDetail">
        select inventoryOrderDetailId, inventoryOrderId, prodId, prodName, prodAttrId, prodAttrName, quantity, delFlag, createUser, createTime, updateUser, updateTime from t_prod_inventory_order_detail
    </sql>

    <sql id="selectProdInventoryOrderDetailExt">
        select
            ${tableAlias}.inventoryOrderDetailId,
            ${tableAlias}.inventoryOrderId,
            ${tableAlias}.prodId,
            ${tableAlias}.prodName,
            ${tableAlias}.prodAttrId,
            ${tableAlias}.prodAttrName,
            ${tableAlias}.quantity,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_prod_inventory_order_detail ${tableAlias}
    </sql>

    <select id="selectProdInventoryOrderDetailList" parameterType="ProdInventoryOrderDetail" resultMap="ProdInventoryOrderDetailResult">
        <include refid="selectProdInventoryOrderDetail"/>
        <where>  
            <if test="inventoryOrderId != null "> and inventoryOrderId = #{inventoryOrderId}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="prodName != null  and prodName != ''"> and prodName like concat('%', #{prodName}, '%')</if>
            <if test="prodAttrId != null "> and prodAttrId = #{prodAttrId}</if>
            <if test="prodAttrName != null  and prodAttrName != ''"> and prodAttrName like concat('%', #{prodAttrName}, '%')</if>
            <if test="quantity != null "> and quantity = #{quantity}</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="selectProdInventoryOrderDetailByInventoryOrderDetailId" parameterType="Long" resultMap="ProdInventoryOrderDetailResult">
        <include refid="selectProdInventoryOrderDetail"/>
        where inventoryOrderDetailId = #{inventoryOrderDetailId}
    </select>
        
    <insert id="insertProdInventoryOrderDetail" parameterType="ProdInventoryOrderDetail" useGeneratedKeys="true" keyProperty="inventoryOrderDetailId">
        insert into t_prod_inventory_order_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inventoryOrderId != null">inventoryOrderId,</if>
            <if test="prodId != null">prodId,</if>
            <if test="prodName != null">prodName,</if>
            <if test="prodAttrId != null">prodAttrId,</if>
            <if test="prodAttrName != null">prodAttrName,</if>
            <if test="quantity != null">quantity,</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="inventoryOrderId != null">#{inventoryOrderId},</if>
            <if test="prodId != null">#{prodId},</if>
            <if test="prodName != null">#{prodName},</if>
            <if test="prodAttrId != null">#{prodAttrId},</if>
            <if test="prodAttrName != null">#{prodAttrName},</if>
            <if test="quantity != null">#{quantity},</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="batchInsertProdInventoryOrderDetail">
        insert into t_prod_inventory_order_detail( inventoryOrderId, prodId, prodName, prodAttrId, prodAttrName, quantity, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.inventoryOrderId}, #{item.prodId}, #{item.prodName}, #{item.prodAttrId}, #{item.prodAttrName}, #{item.quantity}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdInventoryOrderDetail" parameterType="ProdInventoryOrderDetail">
        update t_prod_inventory_order_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="inventoryOrderId != null">inventoryOrderId = #{inventoryOrderId},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="prodName != null">prodName = #{prodName},</if>
            <if test="prodAttrId != null">prodAttrId = #{prodAttrId},</if>
            <if test="prodAttrName != null">prodAttrName = #{prodAttrName},</if>
            <if test="quantity != null">quantity = #{quantity},</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 inventoryOrderDetailId = #{inventoryOrderDetailId}
    </update>

    <delete id="deleteProdInventoryOrderDetailByInventoryOrderDetailId" parameterType="Long">
        delete from t_prod_inventory_order_detail where inventoryOrderDetailId = #{inventoryOrderDetailId}
    </delete>

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

    <update id="logicDeleteProdInventoryOrderDetailByInventoryOrderDetailId" parameterType="Long">
        update t_prod_inventory_order_detail
            set delFlag = '1'
        where inventoryOrderDetailId = #{inventoryOrderDetailId}
    </update>

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

    <update id="logicDeleteProdInventoryOrderDetailByCondition" parameterType="ProdInventoryOrderDetail">
        update t_prod_inventory_order_detail
        set delFlag = '1'
        <where>
            <if test="inventoryOrderId != null "> and inventoryOrderId = #{inventoryOrderId}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="prodName != null  and prodName != ''"> and prodName like concat('%', #{prodName}, '%')</if>
            <if test="prodAttrId != null "> and prodAttrId = #{prodAttrId}</if>
            <if test="prodAttrName != null  and prodAttrName != ''"> and prodAttrName like concat('%', #{prodAttrName}, '%')</if>
            <if test="quantity != null "> and quantity = #{quantity}</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>