<?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.GoodsOrderMapper">
    
    <resultMap type="GoodsOrder" id="GoodsOrderResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="mainOrderId"    column="main_order_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="transactionId"    column="transaction_id"    />
        <result property="uid"    column="uid"    />
        <result property="productId"    column="product_id"    />
        <result property="name"    column="name"    />
        <result property="phone"    column="phone"    />
        <result property="address"    column="address"    />
        <result property="num"    column="num"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="goodPrice"    column="good_price"    />
        <result property="servicePrice"    column="service_price"    />
        <result property="payPrice"    column="pay_price"    />
        <result property="deduction"    column="deduction"    />
        <result property="postage"    column="postage"    />
        <result property="payTime"    column="pay_time"    />
        <result property="status"    column="status"    />
        <result property="deliveryId"    column="delivery_id"    />
        <result property="deliveryNum"    column="delivery_num"    />
        <result property="sendTime"    column="send_time"    />
        <result property="mark"    column="mark"    />
        <result property="addressId"    column="address_id"    />
        <result property="sku"    column="sku"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="deletedAt"    column="deleted_at"    />
    </resultMap>

    <sql id="selectGoodsOrderVo">
        select id, type, main_order_id, order_id, transaction_id, uid, product_id, name, phone, address, num, total_price, good_price, service_price, pay_price, deduction, postage, pay_time, status, delivery_id, delivery_num, send_time, mark, address_id, sku, created_at, updated_at, deleted_at from goods_order
    </sql>

    <select id="selectGoodsOrderList" parameterType="GoodsOrder" resultMap="GoodsOrderResult">
        <include refid="selectGoodsOrderVo"/>
        <where>
            <if test="payPriceMin != null and payPriceMax != null">
                and pay_price BETWEEN #{payPriceMin} AND #{payPriceMax}
            </if>
            <if test="startdate != null and enddate != null">
                and created_at BETWEEN #{startdate} AND #{enddate}
            </if>
            <if test="paystartdate != null and payenddate != null">
                and pay_time BETWEEN #{paystartdate} AND #{payenddate}
            </if>
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="transactionId != null  and transactionId != ''"> and transaction_id = #{transactionId}</if>
            <if test="mainOrderId != null  and mainOrderId != ''"> and main_order_id = #{mainOrderId}</if>
        </where>
    </select>
    
    <select id="selectGoodsOrderById" parameterType="Long" resultMap="GoodsOrderResult">
        <include refid="selectGoodsOrderVo"/>
        where id = #{id}
    </select>

    <insert id="insertGoodsOrder" parameterType="GoodsOrder" useGeneratedKeys="true" keyProperty="id">
        insert into goods_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="mainOrderId != null">main_order_id,</if>
            <if test="orderId != null and orderId != ''">order_id,</if>
            <if test="transactionId != null">transaction_id,</if>
            <if test="uid != null">uid,</if>
            <if test="productId != null">product_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="num != null">num,</if>
            <if test="totalPrice != null">total_price,</if>
            <if test="goodPrice != null">good_price,</if>
            <if test="servicePrice != null">service_price,</if>
            <if test="payPrice != null">pay_price,</if>
            <if test="deduction != null">deduction,</if>
            <if test="postage != null">postage,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="status != null">status,</if>
            <if test="deliveryId != null">delivery_id,</if>
            <if test="deliveryNum != null">delivery_num,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="mark != null">mark,</if>
            <if test="addressId != null">address_id,</if>
            <if test="sku != null">sku,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="deletedAt != null">deleted_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="mainOrderId != null">#{mainOrderId},</if>
            <if test="orderId != null and orderId != ''">#{orderId},</if>
            <if test="transactionId != null">#{transactionId},</if>
            <if test="uid != null">#{uid},</if>
            <if test="productId != null">#{productId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="num != null">#{num},</if>
            <if test="totalPrice != null">#{totalPrice},</if>
            <if test="goodPrice != null">#{goodPrice},</if>
            <if test="servicePrice != null">#{servicePrice},</if>
            <if test="payPrice != null">#{payPrice},</if>
            <if test="deduction != null">#{deduction},</if>
            <if test="postage != null">#{postage},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="status != null">#{status},</if>
            <if test="deliveryId != null">#{deliveryId},</if>
            <if test="deliveryNum != null">#{deliveryNum},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="mark != null">#{mark},</if>
            <if test="addressId != null">#{addressId},</if>
            <if test="sku != null">#{sku},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="deletedAt != null">#{deletedAt},</if>
         </trim>
    </insert>

    <update id="updateGoodsOrder" parameterType="GoodsOrder">
        update goods_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="mainOrderId != null">main_order_id = #{mainOrderId},</if>
            <if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
            <if test="transactionId != null">transaction_id = #{transactionId},</if>
            <if test="uid != null">uid = #{uid},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="num != null">num = #{num},</if>
            <if test="totalPrice != null">total_price = #{totalPrice},</if>
            <if test="goodPrice != null">good_price = #{goodPrice},</if>
            <if test="servicePrice != null">service_price = #{servicePrice},</if>
            <if test="payPrice != null">pay_price = #{payPrice},</if>
            <if test="deduction != null">deduction = #{deduction},</if>
            <if test="postage != null">postage = #{postage},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deliveryId != null">delivery_id = #{deliveryId},</if>
            <if test="deliveryNum != null">delivery_num = #{deliveryNum},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="addressId != null">address_id = #{addressId},</if>
            <if test="sku != null">sku = #{sku},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="deletedAt != null">deleted_at = #{deletedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGoodsOrderById" parameterType="Long">
        delete from goods_order where id = #{id}
    </delete>

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