<?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.system.mapper.GoodsOrderCursorMapper">
    
    <resultMap type="GoodsOrderCursor" id="GoodsOrderCursorResult">
        <result property="id"    column="id"    />
        <result property="productId"    column="product_id"    />
        <result property="type"    column="type"    />
        <result property="num"    column="num"    />
        <result property="sku"    column="sku"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="postage"    column="postage"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectGoodsOrderCursorVo">
        select id, product_id, type, num, sku, total_price, postage, created_at, updated_at from goods_order_cursor
    </sql>

    <select id="selectGoodsOrderCursorList" parameterType="GoodsOrderCursor" resultMap="GoodsOrderCursorResult">
        <include refid="selectGoodsOrderCursorVo"/>
        <where>  
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="sku != null  and sku != ''"> and sku = #{sku}</if>
            <if test="totalPrice != null "> and total_price = #{totalPrice}</if>
            <if test="postage != null "> and postage = #{postage}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectGoodsOrderCursorById" parameterType="Long" resultMap="GoodsOrderCursorResult">
        <include refid="selectGoodsOrderCursorVo"/>
        where id = #{id}
    </select>

    <insert id="insertGoodsOrderCursor" parameterType="GoodsOrderCursor" useGeneratedKeys="true" keyProperty="id">
        insert into goods_order_cursor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productId != null">product_id,</if>
            <if test="type != null">type,</if>
            <if test="num != null">num,</if>
            <if test="sku != null">sku,</if>
            <if test="totalPrice != null">total_price,</if>
            <if test="postage != null">postage,</if>
            created_at,
            updated_at
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productId != null">#{productId},</if>
            <if test="type != null">#{type},</if>
            <if test="num != null">#{num},</if>
            <if test="sku != null">#{sku},</if>
            <if test="totalPrice != null">#{totalPrice},</if>
            <if test="postage != null">#{postage},</if>
            NOW(),
            NOW()

        </trim>
    </insert>

    <update id="updateGoodsOrderCursor" parameterType="GoodsOrderCursor">
        update goods_order_cursor
        <trim prefix="SET" suffixOverrides=",">
            <if test="productId != null">product_id = #{productId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="num != null">num = #{num},</if>
            <if test="sku != null">sku = #{sku},</if>
            <if test="totalPrice != null">total_price = #{totalPrice},</if>
            <if test="postage != null">postage = #{postage},</if>
            updated_at=NOW()
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGoodsOrderCursorById" parameterType="Long">
        delete from goods_order_cursor where id = #{id}
    </delete>

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