<?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.model.mapper.AppletOrderItemMapper">
    
    <resultMap type="AppletOrderItem" id="AppletOrderItemResult">
        <result property="id" column="id"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="payTime" column="pay_time"/>
        <result property="status" column="status"/>
        <result property="price" column="price"/>
        <result property="address" column="address"/>
        <result property="type" column="type"/>
        <result property="reason" column="reason"/>
        <result property="userId" column="user_id"/>
        <result property="petId" column="pet_id"/>
        <result property="num" column="num"/>
        <result property="userIdJson" column="user_id_json"/>
        <result property="orderSn" column="order_sn"/>
        <result property="orderId" column="order_id"/>
        <result property="startTime" column="start_time"/>
        <result property="name" column="name"/>
        <result property="phone" column="phone"/>
        <result property="orderStatus" column="order_status"/>
        <result property="orderGiveProportion" column="order_give_proportion"/>
        <result property="orderGivePrice" column="order_give_price"/>
        <result property="isDate" column="is_date"/>
        <result property="isAddress" column="is_address"/>
        <result property="isPet" column="is_pet"/>

    </resultMap>

    <sql id="selectAppletOrderItemVo">
        select id, create_time, create_by, update_time, update_by, pay_time, status, price, address, type, reason, user_id, pet_id, num, user_id_json, order_sn, order_id, start_time, name, phone, order_status, order_give_proportion, order_give_price, is_date, is_address, is_pet  from applet_order_item
    </sql>


    <select id="selectAppletOrderItemList" parameterType="AppletOrderItem" resultMap="AppletOrderItemResult">
        <include refid="selectAppletOrderItemVo"/>
        <where>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="petId != null "> and pet_id = #{petId}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="userIdJson != null  and userIdJson != ''"> and user_id_json = #{userIdJson}</if>
            <if test="orderSn != null  and orderSn != ''"> and order_sn = #{orderSn}</if>
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="orderStatus != null "> and order_status = #{orderStatus}</if>
            <if test="orderGiveProportion != null "> and order_give_proportion = #{orderGiveProportion}</if>
            <if test="orderGivePrice != null "> and order_give_price = #{orderGivePrice}</if>
            <if test="isDate != null "> and is_date = #{isDate}</if>
            <if test="isAddress != null "> and is_address = #{isAddress}</if>
            <if test="isPet != null "> and is_pet = #{isPet}</if>
        </where>
        order by create_time desc

    </select>

    <select id="selectAppletOrderItemListLikeUserIdJson" parameterType="AppletOrderItem" resultMap="AppletOrderItemResult">

        <include refid="selectAppletOrderItemVo"/>
        <where>
            <!-- 根据具体需求选择方案 -->
            <!-- 方案1：自动添加通配符 -->
           type = #{type} and user_id_json like concat('%', #{userIdJson}, '%')

            <!-- 方案2：使用JSON函数查询（MySQL示例） -->
            <!-- JSON_CONTAINS(user_id_json, #{userIdJson}) -->
        </where>
        order by create_time desc

    </select>












    
    <select id="selectAppletOrderItemById" parameterType="AppletOrderItem" resultMap="AppletOrderItemResult">
        <include refid="selectAppletOrderItemVo"/>
        where id = #{id}
    </select>

    <select id="selectAppletOrderItemByOrderId" parameterType="AppletOrderItem" resultMap="AppletOrderItemResult">
        <include refid="selectAppletOrderItemVo"/>
        where order_id = #{orderId}
    </select>


    <select id="selectAppletOrderItemByOrderIdUserId" parameterType="AppletOrderItem" resultMap="AppletOrderItemResult">
        <include refid="selectAppletOrderItemVo"/>
        where order_id = #{orderId} And user_id = #{userId}
    </select>




    <insert id="insertAppletOrderItem" parameterType="AppletOrderItem" useGeneratedKeys="true" keyProperty="id">
        insert into applet_order_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="status != null">status,</if>
            <if test="price != null">price,</if>
            <if test="address != null">address,</if>
            <if test="type != null">type,</if>
            <if test="reason != null">reason,</if>
            <if test="userId != null">user_id,</if>
            <if test="petId != null">pet_id,</if>
            <if test="num != null">num,</if>
            <if test="userIdJson != null">user_id_json,</if>
            <if test="orderSn != null">order_sn,</if>
            <if test="orderId != null">order_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="name != null">name,</if>
            <if test="phone != null">phone,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="orderGiveProportion != null">order_give_proportion,</if>
            <if test="orderGivePrice != null">order_give_price,</if>
            <if test="isDate != null">is_date,</if>
            <if test="isAddress != null">is_address,</if>
            <if test="isPet != null">is_pet,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="status != null">#{status},</if>
            <if test="price != null">#{price},</if>
            <if test="address != null">#{address},</if>
            <if test="type != null">#{type},</if>
            <if test="reason != null">#{reason},</if>
            <if test="userId != null">#{userId},</if>
            <if test="petId != null">#{petId},</if>
            <if test="num != null">#{num},</if>
            <if test="userIdJson != null">#{userIdJson},</if>
            <if test="orderSn != null">#{orderSn},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="name != null">#{name},</if>
            <if test="phone != null">#{phone},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="orderGiveProportion != null">#{orderGiveProportion},</if>
            <if test="orderGivePrice != null">#{orderGivePrice},</if>
            <if test="isDate != null">#{isDate},</if>
            <if test="isAddress != null">#{isAddress},</if>
            <if test="isPet != null">#{isPet},</if>
        </trim>

    </insert>

    <update id="updateAppletOrderItem" parameterType="AppletOrderItem">
        update applet_order_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="price != null">price = #{price},</if>
            <if test="address != null">address = #{address},</if>
            <if test="type != null">type = #{type},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="petId != null">pet_id = #{petId},</if>
            <if test="num != null">num = #{num},</if>
            <if test="userIdJson != null">user_id_json = #{userIdJson},</if>
            <if test="orderSn != null">order_sn = #{orderSn},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="name != null">name = #{name},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="orderGiveProportion != null">order_give_proportion = #{orderGiveProportion},</if>
            <if test="orderGivePrice != null">order_give_price = #{orderGivePrice},</if>
            <if test="isDate != null">is_date = #{isDate},</if>
            <if test="isAddress != null">is_address = #{isAddress},</if>
            <if test="isPet != null">is_pet = #{isPet},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppletOrderItemById" parameterType="Long">
        delete from applet_order_item where id = #{id}
    </delete>

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