<?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.MallAppOrderGoodsMapper">

    <resultMap type="MallAppOrderGoods" id="MallAppOrderGoodsResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="goodsImg"    column="goods_img"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="goodsProduct"    column="goods_product"    />
        <result property="goodsUnit"    column="goods_unit"    />
        <result property="goodsPrice"    column="goods_price"    />
        <result property="goodsTotal"    column="goods_total"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="commissionPrice"    column="commission_price"    />
        <result property="returnTotal"    column="return_total"    />
        <result property="returnStatus"    column="return_status"    />
        <result property="remarks"    column="remarks"    />
        <result property="content"    column="content"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMallAppOrderGoodsVo">
        select id, order_id, order_no, goods_img, goods_name, goods_product, goods_unit, goods_price, goods_total, total_price, commission_price, return_total, return_status, remarks, content, del_flag from mall_app_order_goods
    </sql>

    <select id="selectMallAppOrderGoodsList" parameterType="MallAppOrderGoods" resultMap="MallAppOrderGoodsResult">
        <include refid="selectMallAppOrderGoodsVo"/>
        <where>
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="orderNo != null  and orderNo != ''"> and order_no like concat('%', #{orderNo}, '%')</if>
            <if test="goodsImg != null  and goodsImg != ''"> and goods_img = #{goodsImg}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="goodsProduct != null  and goodsProduct != ''"> and goods_product = #{goodsProduct}</if>
            <if test="goodsUnit != null  and goodsUnit != ''"> and goods_unit = #{goodsUnit}</if>
            <if test="goodsPrice != null "> and goods_price = #{goodsPrice}</if>
            <if test="goodsTotal != null "> and goods_total = #{goodsTotal}</if>
            <if test="totalPrice != null "> and total_price = #{totalPrice}</if>
            <if test="commissionPrice != null "> and commission_price = #{commissionPrice}</if>
            <if test="returnTotal != null "> and return_total = #{returnTotal}</if>
            <if test="returnStatus != null  and returnStatus != ''"> and return_status = #{returnStatus}</if>
            <if test="remarks != null  and remarks != ''"> and remarks like concat('%', #{remarks}, '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
        </where>
    </select>

    <select id="selectMallAppOrderGoodsById" parameterType="Long" resultMap="MallAppOrderGoodsResult">
        <include refid="selectMallAppOrderGoodsVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallAppOrderGoods" parameterType="MallAppOrderGoods" useGeneratedKeys="true" keyProperty="id">
        insert into mall_app_order_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="goodsImg != null">goods_img,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="goodsProduct != null">goods_product,</if>
            <if test="goodsUnit != null">goods_unit,</if>
            <if test="goodsPrice != null">goods_price,</if>
            <if test="goodsTotal != null">goods_total,</if>
            <if test="totalPrice != null">total_price,</if>
            <if test="commissionPrice != null">commission_price,</if>
            <if test="returnTotal != null">return_total,</if>
            <if test="returnStatus != null">return_status,</if>
            <if test="remarks != null">remarks,</if>
            <if test="content != null">content,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="goodsImg != null">#{goodsImg},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="goodsProduct != null">#{goodsProduct},</if>
            <if test="goodsUnit != null">#{goodsUnit},</if>
            <if test="goodsPrice != null">#{goodsPrice},</if>
            <if test="goodsTotal != null">#{goodsTotal},</if>
            <if test="totalPrice != null">#{totalPrice},</if>
            <if test="commissionPrice != null">#{commissionPrice},</if>
            <if test="returnTotal != null">#{returnTotal},</if>
            <if test="returnStatus != null">#{returnStatus},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="content != null">#{content},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallAppOrderGoods" parameterType="MallAppOrderGoods">
        update mall_app_order_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="goodsImg != null">goods_img = #{goodsImg},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="goodsProduct != null">goods_product = #{goodsProduct},</if>
            <if test="goodsUnit != null">goods_unit = #{goodsUnit},</if>
            <if test="goodsPrice != null">goods_price = #{goodsPrice},</if>
            <if test="goodsTotal != null">goods_total = #{goodsTotal},</if>
            <if test="totalPrice != null">total_price = #{totalPrice},</if>
            <if test="commissionPrice != null">commission_price = #{commissionPrice},</if>
            <if test="returnTotal != null">return_total = #{returnTotal},</if>
            <if test="returnStatus != null">return_status = #{returnStatus},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="content != null">content = #{content},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallAppOrderGoodsById" parameterType="Long">
        delete from mall_app_order_goods where id = #{id}
    </delete>

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

<!--    <insert id="bachInsertMallAppOrderGoods">-->
<!--        <foreach collection="list" item="item" separator=";">-->
<!--            insert into mall_app_order_goods-->
<!--            <trim prefix="(" suffix=")" suffixOverrides=",">-->
<!--                <if test="item.orderId != null">order_id,</if>-->
<!--                <if test="item.orderNo != null">order_no,</if>-->
<!--                <if test="item.goodsImg != null">goods_img,</if>-->
<!--                <if test="item.goodsName != null">goods_name,</if>-->
<!--                <if test="item.goodsProduct != null">goods_product,</if>-->
<!--                <if test="item.goodsUnit != null">goods_unit,</if>-->
<!--                <if test="item.goodsPrice != null">goods_price,</if>-->
<!--                <if test="item.goodsTotal != null">goods_total,</if>-->
<!--                <if test="item.totalPrice != null">total_price,</if>-->
<!--                <if test="item.commissionPrice != null">commission_price,</if>-->
<!--                <if test="item.returnTotal != null">return_total,</if>-->
<!--                <if test="item.returnStatus != null">return_status,</if>-->
<!--                <if test="item.remarks != null">remarks,</if>-->
<!--                <if test="item.content != null">content,</if>-->
<!--                <if test="item.delFlag != null">del_flag,</if>-->
<!--            </trim>-->
<!--            <trim prefix="values (" suffix=")" suffixOverrides=",">-->
<!--                <if test="item.orderId != null">#{item.orderId},</if>-->
<!--                <if test="item.orderNo != null">#{item.orderNo},</if>-->
<!--                <if test="item.goodsImg != null">#{item.goodsImg},</if>-->
<!--                <if test="item.goodsName != null">#{item.goodsName},</if>-->
<!--                <if test="item.goodsProduct != null">#{item.goodsProduct},</if>-->
<!--                <if test="item.goodsUnit != null">#{item.goodsUnit},</if>-->
<!--                <if test="item.goodsPrice != null">#{item.goodsPrice},</if>-->
<!--                <if test="item.goodsTotal != null">#{item.goodsTotal},</if>-->
<!--                <if test="item.totalPrice != null">#{item.totalPrice},</if>-->
<!--                <if test="item.commissionPrice != null">#{item.commissionPrice},</if>-->
<!--                <if test="item.returnTotal != null">#{item.returnTotal},</if>-->
<!--                <if test="item.returnStatus != null">#{item.returnStatus},</if>-->
<!--                <if test="item.remarks != null">#{item.remarks},</if>-->
<!--                <if test="item.content != null">#{item.content},</if>-->
<!--                <if test="item.delFlag != null">#{item.delFlag},</if>-->
<!--            </trim>-->
<!--        </foreach>-->
<!--    </insert>-->

    <insert id="bachInsertMallAppOrderGoods">
        insert into mall_app_order_goods(order_id, order_no, goods_name, goods_product, goods_unit, goods_price, goods_total, total_price, commission_price, del_flag) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.orderId},#{item.orderNo},#{item.goodsName},#{item.goodsProduct},#{item.goodsUnit},#{item.goodsPrice},#{item.goodsTotal},#{item.totalPrice},#{item.commissionPrice}, '0')
        </foreach>
    </insert>

    <select id="selectMallAppOrderGoodsListByOrderId" resultMap="MallAppOrderGoodsResult">
        <include refid="selectMallAppOrderGoodsVo"/>
        where
            order_id = #{orderId}
            and del_flag = '0'
    </select>

    <delete id="deleteMallAppOrderGoodsByOrderId" parameterType="Long">
        delete from mall_app_order_goods where order_id = #{orderId}
    </delete>

    <select id="getAppGoodsNameList" resultType="map">
        select goods_name goodsName, goods_product goodsProduct, goods_unit goodsUnit, goods_price goodsPrice
        from mall_app_order_goods
        <where>
            <if test="keyword != null  and keyword != ''">
                and goods_name like concat('%', #{keyword}, '%')
            </if>
            and del_flag = '0'
        </where>
        group by goods_name
        order by goods_name desc
    </select>
</mapper>
