<?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.AppletPetMapper">
    
    <resultMap type="AppletPet" id="AppletPetResult">
        <result property="id" column="id"/>
        <result property="headImage" column="head_image"/>
        <result property="nickName" column="nick_name"/>
        <result property="sex" column="sex"/>
        <result property="type" column="type"/>
        <result property="birthday" column="birthday"/>
        <result property="weight" column="weight"/>
        <result property="personality" column="personality"/>
        <result property="vaccine" column="vaccine"/>
        <result property="deworm" column="deworm"/>
        <result property="neutered" column="neutered"/>
        <result property="petType" column="pet_type"/>
        <result property="health" column="health"/>
        <result property="petCard" column="pet_card"/>
        <result property="healthOther" column="health_other"/>
        <result property="delFlag" column="del_flag"/>
        <result property="brief" column="brief"/>
        <result property="age" column="age"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="orderId" column="order_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectAppletPetVo">
        select id, head_image, nick_name, sex, type, birthday, weight, personality, vaccine, deworm, neutered, pet_type, health, pet_card, health_other, del_flag, brief, age create_by, create_time, update_by, update_time, order_id , create_by, create_time, update_by, update_time from applet_pet
    </sql>

    <select id="selectAppletPetList" parameterType="AppletPet" resultMap="AppletPetResult">
        <include refid="selectAppletPetVo"/>
        <where>
            <if test="headImage != null  and headImage != ''"> and head_image = #{headImage}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="weight != null "> and weight = #{weight}</if>
            <if test="personality != null  and personality != ''"> and personality = #{personality}</if>
            <if test="vaccine != null "> and vaccine = #{vaccine}</if>
            <if test="deworm != null "> and deworm = #{deworm}</if>
            <if test="neutered != null "> and neutered = #{neutered}</if>
            <if test="petType != null "> and pet_type = #{petType}</if>
            <if test="health != null "> and health = #{health}</if>
            <if test="petCard != null "> and pet_card = #{petCard}</if>
            <if test="healthOther != null  and healthOther != ''"> and health_other = #{healthOther}</if>
            <if test="orderId != null "> and order_id = #{orderId}</if>
        </where>
    </select>

    <select id="selectAppletPetListByOrderId" parameterType="AppletPet" resultMap="AppletPetResult">
        <include refid="selectAppletPetVo"/>
        where order_id = #{orderId}

    </select>

    
    <select id="selectAppletPetById" parameterType="AppletPet" resultMap="AppletPetResult">
        <include refid="selectAppletPetVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppletPet" parameterType="AppletPet" useGeneratedKeys="true" keyProperty="id">
        insert into applet_pet
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="headImage != null">head_image,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="sex != null">sex,</if>
            <if test="type != null">type,</if>
            <if test="birthday != null">birthday,</if>
            <if test="weight != null">weight,</if>
            <if test="personality != null">personality,</if>
            <if test="vaccine != null">vaccine,</if>
            <if test="deworm != null">deworm,</if>
            <if test="neutered != null">neutered,</if>
            <if test="petType != null">pet_type,</if>
            <if test="health != null">health,</if>
            <if test="petCard != null">pet_card,</if>
            <if test="healthOther != null">health_other,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="orderId != null">order_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="headImage != null">#{headImage},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="sex != null">#{sex},</if>
            <if test="type != null">#{type},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="weight != null">#{weight},</if>
            <if test="personality != null">#{personality},</if>
            <if test="vaccine != null">#{vaccine},</if>
            <if test="deworm != null">#{deworm},</if>
            <if test="neutered != null">#{neutered},</if>
            <if test="petType != null">#{petType},</if>
            <if test="health != null">#{health},</if>
            <if test="petCard != null">#{petCard},</if>
            <if test="healthOther != null">#{healthOther},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateAppletPet" parameterType="AppletPet">
        update applet_pet
        <trim prefix="SET" suffixOverrides=",">
            <if test="headImage != null">head_image = #{headImage},</if>
            <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="type != null">type = #{type},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="personality != null">personality = #{personality},</if>
            <if test="vaccine != null">vaccine = #{vaccine},</if>
            <if test="deworm != null">deworm = #{deworm},</if>
            <if test="neutered != null">neutered = #{neutered},</if>
            <if test="petType != null">pet_type = #{petType},</if>
            <if test="health != null">health = #{health},</if>
            <if test="petCard != null">pet_card = #{petCard},</if>
            <if test="healthOther != null">health_other = #{healthOther},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppletPetById" parameterType="Long">
        delete from applet_pet where id = #{id}
    </delete>

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