<?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.AppOrderMapper">
    
    <resultMap type="AppOrder" id="AppOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="certificationId"    column="certification_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="deiFlag"    column="dei_flag"    />
        <result property="orderAmount"    column="order_amount"    />
        <result property="orderPlaceTime"    column="order_place_time"    />
        <result property="orderQuantity"    column="order_quantity"    />
        <result property="orderServiceContent"    column="order_service_content"    />
        <result property="orderServiceDate"    column="order_service_date"    />
        <result property="orderServiceTime"    column="order_service_time"    />
        <result property="orderState"    column="order_state"    />
        <result property="orderTotalAmount"    column="order_total_amount"    />
        <result property="orderVisitAddress"    column="order_visit_address"    />
        <result property="petId"    column="pet_id"    />
        <result property="remark"    column="remark"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAppOrderVo">
        select order_id, certification_id, create_by, create_time, dei_flag, order_amount, order_place_time, order_quantity, order_service_content, order_service_date, order_service_time, order_state, order_total_amount, order_visit_address, pet_id, remark, update_by, update_time from app_order
    </sql>

    <select id="selectAppOrderList" parameterType="AppOrder" resultMap="AppOrderResult">
        <include refid="selectAppOrderVo"/>
        <where>  
            <if test="certificationId != null "> and certification_id = #{certificationId}</if>
            <if test="deiFlag != null "> and dei_flag = #{deiFlag}</if>
            <if test="orderAmount != null "> and order_amount = #{orderAmount}</if>
            <if test="orderPlaceTime != null "> and order_place_time = #{orderPlaceTime}</if>
            <if test="orderQuantity != null "> and order_quantity = #{orderQuantity}</if>
            <if test="orderServiceContent != null  and orderServiceContent != ''"> and order_service_content = #{orderServiceContent}</if>
            <if test="orderServiceDate != null "> and order_service_date = #{orderServiceDate}</if>
            <if test="orderServiceTime != null "> and order_service_time = #{orderServiceTime}</if>
            <if test="orderState != null "> and order_state = #{orderState}</if>
            <if test="orderTotalAmount != null "> and order_total_amount = #{orderTotalAmount}</if>
            <if test="orderVisitAddress != null  and orderVisitAddress != ''"> and order_visit_address = #{orderVisitAddress}</if>
            <if test="petId != null "> and pet_id = #{petId}</if>
        </where>
    </select>
    
    <select id="selectAppOrderByOrderId" parameterType="Long" resultMap="AppOrderResult">
        <include refid="selectAppOrderVo"/>
        where order_id = #{orderId}
    </select>
    <select id="getAppOrderList" resultType="com.ruoyi.model.domain.AppOrder">
        <include refid="selectAppOrderVo"/>
    </select>

    <insert id="insertAppOrder" parameterType="AppOrder">
        insert into app_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="certificationId != null">certification_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="deiFlag != null">dei_flag,</if>
            <if test="orderAmount != null">order_amount,</if>
            <if test="orderPlaceTime != null">order_place_time,</if>
            <if test="orderQuantity != null">order_quantity,</if>
            <if test="orderServiceContent != null">order_service_content,</if>
            <if test="orderServiceDate != null">order_service_date,</if>
            <if test="orderServiceTime != null">order_service_time,</if>
            <if test="orderState != null">order_state,</if>
            <if test="orderTotalAmount != null">order_total_amount,</if>
            <if test="orderVisitAddress != null">order_visit_address,</if>
            <if test="petId != null">pet_id,</if>
            <if test="remark != null">remark,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="certificationId != null">#{certificationId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="deiFlag != null">#{deiFlag},</if>
            <if test="orderAmount != null">#{orderAmount},</if>
            <if test="orderPlaceTime != null">#{orderPlaceTime},</if>
            <if test="orderQuantity != null">#{orderQuantity},</if>
            <if test="orderServiceContent != null">#{orderServiceContent},</if>
            <if test="orderServiceDate != null">#{orderServiceDate},</if>
            <if test="orderServiceTime != null">#{orderServiceTime},</if>
            <if test="orderState != null">#{orderState},</if>
            <if test="orderTotalAmount != null">#{orderTotalAmount},</if>
            <if test="orderVisitAddress != null">#{orderVisitAddress},</if>
            <if test="petId != null">#{petId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAppOrder" parameterType="AppOrder">
        update app_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="certificationId != null">certification_id = #{certificationId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="deiFlag != null">dei_flag = #{deiFlag},</if>
            <if test="orderAmount != null">order_amount = #{orderAmount},</if>
            <if test="orderPlaceTime != null">order_place_time = #{orderPlaceTime},</if>
            <if test="orderQuantity != null">order_quantity = #{orderQuantity},</if>
            <if test="orderServiceContent != null">order_service_content = #{orderServiceContent},</if>
            <if test="orderServiceDate != null">order_service_date = #{orderServiceDate},</if>
            <if test="orderServiceTime != null">order_service_time = #{orderServiceTime},</if>
            <if test="orderState != null">order_state = #{orderState},</if>
            <if test="orderTotalAmount != null">order_total_amount = #{orderTotalAmount},</if>
            <if test="orderVisitAddress != null">order_visit_address = #{orderVisitAddress},</if>
            <if test="petId != null">pet_id = #{petId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where order_id = #{orderId}
    </update>

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

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