<?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.ruoyi.mall.mapper.MallOrderbackGoodsMapper">
    
    <resultMap type="MallOrderbackGoods" id="MallOrderbackGoodsResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="productId"    column="product_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="goodsImg"    column="goods_img"    />
        <result property="productName"    column="product_name"    />
        <result property="price"    column="price"    />
        <result property="total"    column="total"    />
        <result property="comment"    column="comment"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="commission"    column="commission"    />
        <result property="returnTotal"    column="return_total"    />
        <result property="returnStatus"    column="return_status"    />
        <result property="returnableQuantity"    column="returnable_quantity"    />
        <result property="integral"    column="integral"    />
        <result property="batchId"    column="batch_id"    />
    </resultMap>

    <sql id="selectMallOrderbackGoodsVo">
        select id, order_id, goods_id, product_id, goods_name, goods_img, product_name, price, total, comment, del_flag, commission, return_total, return_status, returnable_quantity, integral,batch_id from mall_orderback_goods
    </sql>

    <select id="selectMallOrderbackGoodsList" parameterType="MallOrderbackGoods" resultMap="MallOrderbackGoodsResult">
        <include refid="selectMallOrderbackGoodsVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="goodsImg != null  and goodsImg != ''"> and goods_img = #{goodsImg}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="total != null "> and total = #{total}</if>
            <if test="comment != null  and comment != ''"> and comment = #{comment}</if>
            <if test="commission != null "> and commission = #{commission}</if>
            <if test="returnTotal != null "> and return_total = #{returnTotal}</if>
            <if test="returnStatus != null  and returnStatus != ''"> and return_status = #{returnStatus}</if>
            <if test="returnableQuantity != null "> and returnable_quantity = #{returnableQuantity}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="batchId != null "> and batch_id = #{batchId}</if>
        </where>
    </select>
    
    <select id="selectMallOrderbackGoodsById" parameterType="Long" resultMap="MallOrderbackGoodsResult">
        <include refid="selectMallOrderbackGoodsVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallOrderbackGoods" parameterType="MallOrderbackGoods" useGeneratedKeys="true" keyProperty="id">
        insert into mall_orderback_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="productId != null">product_id,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="goodsImg != null">goods_img,</if>
            <if test="productName != null">product_name,</if>
            <if test="price != null">price,</if>
            <if test="total != null">total,</if>
            <if test="comment != null">comment,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="commission != null">commission,</if>
            <if test="returnTotal != null">return_total,</if>
            <if test="returnStatus != null">return_status,</if>
            <if test="returnableQuantity != null">returnable_quantity,</if>
            <if test="integral != null">integral,</if>
            <if test="batchId != null">batch_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="productId != null">#{productId},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="goodsImg != null">#{goodsImg},</if>
            <if test="productName != null">#{productName},</if>
            <if test="price != null">#{price},</if>
            <if test="total != null">#{total},</if>
            <if test="comment != null">#{comment},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="commission != null">#{commission},</if>
            <if test="returnTotal != null">#{returnTotal},</if>
            <if test="returnStatus != null">#{returnStatus},</if>
            <if test="returnableQuantity != null">#{returnableQuantity},</if>
            <if test="integral != null">#{integral},</if>
            <if test="batchId != null">#{batchId},</if>
         </trim>
    </insert>

    <update id="updateMallOrderbackGoods" parameterType="MallOrderbackGoods">
        update mall_orderback_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="goodsImg != null">goods_img = #{goodsImg},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="price != null">price = #{price},</if>
            <if test="total != null">total = #{total},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="commission != null">commission = #{commission},</if>
            <if test="returnTotal != null">return_total = #{returnTotal},</if>
            <if test="returnStatus != null">return_status = #{returnStatus},</if>
            <if test="returnableQuantity != null">returnable_quantity = #{returnableQuantity},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="batchId != null">batch_id = #{batchId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallOrderbackGoodsById" parameterType="Long">
        delete from mall_orderback_goods where id = #{id}
    </delete>

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

    <select id="selectMallOrderbackGoodsByOrderId" parameterType="Long" resultMap="MallOrderbackGoodsResult">
        <include refid="selectMallOrderbackGoodsVo"/>
        where order_id = #{orderId}
    </select>

    <select id="selectMallOrderbackGoodsByrefundno" parameterType="String" resultMap="MallOrderbackGoodsResult">
        <include refid="selectMallOrderbackGoodsVo"/>
        where batch_id = #{refundno}
    </select>
</mapper>