<?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.AppPetsMapper">
    
    <resultMap type="AppPets" id="AppPetsResult">
        <result property="petId"    column="pet_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="deiFlag"    column="dei_flag"    />
        <result property="petAge"    column="pet_age"    />
        <result property="petBirthday"    column="pet_birthday"    />
        <result property="petBread"    column="pet_bread"    />
        <result property="petImage"    column="pet_image"    />
        <result property="petName"    column="pet_name"    />
        <result property="petPersonality"    column="pet_personality"    />
        <result property="petSex"    column="pet_sex"    />
        <result property="petSpecies"    column="pet_species"    />
        <result property="petWeight"    column="pet_weight"    />
        <result property="remark"    column="remark"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectAppPetsVo">
        select pet_id, create_by, create_time, dei_flag, pet_age, pet_birthday, pet_bread, pet_image, pet_name, pet_personality, pet_sex, pet_species, pet_weight, remark, update_by, update_time, user_id from app_pets
    </sql>

    <select id="selectAppPetsList" parameterType="AppPets" resultMap="AppPetsResult">
        <include refid="selectAppPetsVo"/>
        <where>  
            <if test="deiFlag != null "> and dei_flag = #{deiFlag}</if>
            <if test="petAge != null "> and pet_age = #{petAge}</if>
            <if test="petBirthday != null "> and pet_birthday = #{petBirthday}</if>
            <if test="petBread != null  and petBread != ''"> and pet_bread = #{petBread}</if>
            <if test="petImage != null  and petImage != ''"> and pet_image = #{petImage}</if>
            <if test="petName != null  and petName != ''"> and pet_name like concat('%', #{petName}, '%')</if>
            <if test="petPersonality != null  and petPersonality != ''"> and pet_personality = #{petPersonality}</if>
            <if test="petSex != null  and petSex != ''"> and pet_sex = #{petSex}</if>
            <if test="petSpecies != null  and petSpecies != ''"> and pet_species = #{petSpecies}</if>
            <if test="petWeight != null "> and pet_weight = #{petWeight}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>
    
    <select id="selectAppPetsByPetId" parameterType="Long" resultMap="AppPetsResult">
        <include refid="selectAppPetsVo"/>
        where pet_id = #{petId}
    </select>
    <select id="getAppPetsList" resultType="com.ruoyi.model.domain.AppPets">
        <include refid="selectAppPetsVo"/>
    </select>

    <insert id="insertAppPets" parameterType="AppPets">
        insert into app_pets
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="petId != null">pet_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="petAge != null">pet_age,</if>
            <if test="petBirthday != null">pet_birthday,</if>
            <if test="petBread != null">pet_bread,</if>
            <if test="petImage != null">pet_image,</if>
            <if test="petName != null and petName != ''">pet_name,</if>
            <if test="petPersonality != null">pet_personality,</if>
            <if test="petSex != null">pet_sex,</if>
            <if test="petSpecies != null">pet_species,</if>
            <if test="petWeight != null">pet_weight,</if>
            <if test="remark != null">remark,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="petId != null">#{petId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="deiFlag != null">#{deiFlag},</if>
            <if test="petAge != null">#{petAge},</if>
            <if test="petBirthday != null">#{petBirthday},</if>
            <if test="petBread != null">#{petBread},</if>
            <if test="petImage != null">#{petImage},</if>
            <if test="petName != null and petName != ''">#{petName},</if>
            <if test="petPersonality != null">#{petPersonality},</if>
            <if test="petSex != null">#{petSex},</if>
            <if test="petSpecies != null">#{petSpecies},</if>
            <if test="petWeight != null">#{petWeight},</if>
            <if test="remark != null">#{remark},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updateAppPets" parameterType="AppPets">
        update app_pets
        <trim prefix="SET" suffixOverrides=",">
            <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="petAge != null">pet_age = #{petAge},</if>
            <if test="petBirthday != null">pet_birthday = #{petBirthday},</if>
            <if test="petBread != null">pet_bread = #{petBread},</if>
            <if test="petImage != null">pet_image = #{petImage},</if>
            <if test="petName != null and petName != ''">pet_name = #{petName},</if>
            <if test="petPersonality != null">pet_personality = #{petPersonality},</if>
            <if test="petSex != null">pet_sex = #{petSex},</if>
            <if test="petSpecies != null">pet_species = #{petSpecies},</if>
            <if test="petWeight != null">pet_weight = #{petWeight},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where pet_id = #{petId}
    </update>

    <delete id="deleteAppPetsByPetId" parameterType="Long">
        delete from app_pets where pet_id = #{petId}
    </delete>

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