<?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.Order.mapper.OrderDeliveryMapper">
    <resultMap type="OrderDelivery" id="OrderDeliveryResult">
        <result property="orderDeliveryId"    column="orderDeliveryId"    />
        <result property="orderId"    column="orderId"    />
        <result property="orderDetailId"    column="orderDetailId"    />
        <result property="orderDeliveryStatus"    column="orderDeliveryStatus"    />
        <result property="prodId"    column="prodId"    />
        <result property="prodName"    column="prodName"    />
        <result property="prodAttrId"    column="prodAttrId"    />
        <result property="prodAttrName"    column="prodAttrName"    />
        <result property="vendorId"    column="vendorId"    />
        <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="selectOrderDelivery">
        select orderDeliveryId, orderId, orderDetailId, orderDeliveryStatus, prodId, prodName, prodAttrId, prodAttrName, vendorId, quantity, delFlag, createUser, createTime, updateUser, updateTime from t_order_delivery
    </sql>

    <sql id="selectOrderDeliveryExt">
        select
            ${tableAlias}.orderDeliveryId,
            ${tableAlias}.orderId,
            ${tableAlias}.orderDetailId,
            ${tableAlias}.orderDeliveryStatus,
            ${tableAlias}.prodId,
            ${tableAlias}.prodName,
            ${tableAlias}.prodAttrId,
            ${tableAlias}.prodAttrName,
            ${tableAlias}.vendorId,
            ${tableAlias}.quantity,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_order_delivery ${tableAlias}
    </sql>

    <select id="selectOrderDeliveryList" parameterType="OrderDelivery" resultMap="OrderDeliveryResult">
        <include refid="selectOrderDelivery"/>
        <where>  
            <if test="orderId != null "> and orderId = #{orderId}</if>
            <if test="orderDetailId != null "> and orderDetailId = #{orderDetailId}</if>
            <if test="orderDeliveryStatus != null  and orderDeliveryStatus != ''"> and orderDeliveryStatus = #{orderDeliveryStatus}</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="vendorId != null "> and vendorId = #{vendorId}</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="selectOrderDeliveryByOrderDeliveryId" parameterType="Long" resultMap="OrderDeliveryResult">
        <include refid="selectOrderDelivery"/>
        where orderDeliveryId = #{orderDeliveryId}
    </select>
        
    <insert id="insertOrderDelivery" parameterType="OrderDelivery" useGeneratedKeys="true" keyProperty="orderDeliveryId">
        insert into t_order_delivery
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">orderId,</if>
            <if test="orderDetailId != null">orderDetailId,</if>
            <if test="orderDeliveryStatus != null">orderDeliveryStatus,</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="vendorId != null">vendorId,</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="orderId != null">#{orderId},</if>
            <if test="orderDetailId != null">#{orderDetailId},</if>
            <if test="orderDeliveryStatus != null">#{orderDeliveryStatus},</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="vendorId != null">#{vendorId},</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="batchInsertOrderDelivery">
        insert into t_order_delivery( orderId, orderDetailId, orderDeliveryStatus, prodId, prodName, prodAttrId, prodAttrName, vendorId, quantity, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.orderId}, #{item.orderDetailId}, #{item.orderDeliveryStatus}, #{item.prodId}, #{item.prodName}, #{item.prodAttrId}, #{item.prodAttrName}, #{item.vendorId}, #{item.quantity}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateOrderDelivery" parameterType="OrderDelivery">
        update t_order_delivery
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">orderId = #{orderId},</if>
            <if test="orderDetailId != null">orderDetailId = #{orderDetailId},</if>
            <if test="orderDeliveryStatus != null">orderDeliveryStatus = #{orderDeliveryStatus},</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="vendorId != null">vendorId = #{vendorId},</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 orderDeliveryId = #{orderDeliveryId}
    </update>

    <delete id="deleteOrderDeliveryByOrderDeliveryId" parameterType="Long">
        delete from t_order_delivery where orderDeliveryId = #{orderDeliveryId}
    </delete>

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

    <update id="logicDeleteOrderDeliveryByOrderDeliveryId" parameterType="Long">
        update t_order_delivery
            set delFlag = '1'
        where orderDeliveryId = #{orderDeliveryId}
    </update>

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

    <update id="logicDeleteOrderDeliveryByCondition" parameterType="OrderDelivery">
        update t_order_delivery
        set delFlag = '1'
        <where>
            <if test="orderId != null "> and orderId = #{orderId}</if>
            <if test="orderDetailId != null "> and orderDetailId = #{orderDetailId}</if>
            <if test="orderDeliveryStatus != null  and orderDeliveryStatus != ''"> and orderDeliveryStatus = #{orderDeliveryStatus}</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="vendorId != null "> and vendorId = #{vendorId}</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>