<?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.cyl.manager.ums.mapper.PetMapper">

    <resultMap type="Pet" id="PetResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="petType" column="pet_type"/>
        <result property="gender" column="gender"/>
        <result property="birthDate" column="birth_date"/>
        <result property="remark" column="remark"/>
        <result property="photo" column="photo"/>
        <result property="breed" column="breed"/>
        <result property="bodyType" column="body_type"/>
        <result property="personality" column="personality"/>
        <result property="vaccineStatus" column="vaccine_status"/>
        <result property="sterilization" column="sterilization"/>

        <result property="dewormingStatus" column="deworming_status"/>
        <result property="doglicenseStatus" column="dogLicense_status"/>
        <result property="healthStatus" column="health_status"/>
        <result property="owner" column="owner"/>
        <result property="delFlag"    column="del_flag"    />
        <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="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="selectPetVo">
        select id, pet_type,name, gender, birth_date, remark, photo, breed, body_type, personality, vaccine_status, deworming_status, dogLicense_status, health_status, owner,del_flag, create_by, create_time, update_by, update_time , create_by, create_time, update_by, update_time from ums_pet
    </sql>

    <select id="" parameterType="Integer" resultMap="PetResult">
        <include refid="selectPetVo"/>
        where id = #{id}
    </select>

    <insert id="insert" parameterType="Pet" useGeneratedKeys="true" keyProperty="id">
        insert into ums_pet
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="petType != null and petType != ''">pet_type,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="gender != null">gender,</if>
            <if test="birthDate != null">birth_date,</if>
            <if test="remark != null">remark,</if>
            <if test="photo != null">photo,</if>
            <if test="breed != null">breed,</if>
            <if test="bodyType != null">body_type,</if>
            <if test="personality != null">personality,</if>
            <if test="vaccineStatus != null">vaccine_status,</if>
            <if test="sterilization != null">sterilization, </if>
            <if test="dewormingStatus != null">deworming_status,</if>
            <if test="doglicenseStatus != null">dogLicense_status,</if>
            <if test="healthStatus != null">health_status,</if>
            <if test="owner != null">owner,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="petType != null and petType != ''">#{petType},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="gender != null">#{gender},</if>
            <if test="birthDate != null">#{birthDate},</if>
            <if test="remark != null">#{remark},</if>
            <if test="photo != null">#{photo},</if>
            <if test="breed != null">#{breed},</if>
            <if test="bodyType != null">#{bodyType},</if>
            <if test="personality != null">#{personality},</if>
            <if test="vaccineStatus != null">#{vaccineStatus},</if>
            <if test="sterilization != null">#{sterilization}, </if>
            <if test="dewormingStatus != null">#{dewormingStatus},</if>
            <if test="doglicenseStatus != null">#{doglicenseStatus},</if>
            <if test="healthStatus != null">#{healthStatus},</if>
            <if test="owner != null">#{owner},</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>
         </trim>
    </insert>

    <update id="update" parameterType="Pet">
        update ums_pet
        <trim prefix="SET" suffixOverrides=",">
            <if test="petType != null and petType != ''">pet_type = #{petType},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="birthDate != null">birth_date = #{birthDate},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="photo != null">photo = #{photo},</if>
            <if test="breed != null">breed = #{breed},</if>
            <if test="bodyType != null">body_type = #{bodyType},</if>
            <if test="personality != null">personality = #{personality},</if>
            <if test="vaccineStatus != null">vaccine_status = #{vaccineStatus},</if>
            <if test="sterilization != null">sterilization = #{sterilization},</if>
            <if test="dewormingStatus != null">deworming_status = #{dewormingStatus},</if>
            <if test="doglicenseStatus != null">dogLicense_status = #{doglicenseStatus},</if>
            <if test="healthStatus != null">health_status = #{healthStatus},</if>
            <if test="owner != null">owner = #{owner},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteById" parameterType="Integer">
        delete from ums_pet where id = #{id}
    </delete>

    <delete id="deleteByIds" parameterType="String">
       update ums_pet set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertOrUpdate" parameterType="Pet" useGeneratedKeys="true" keyProperty="id">
        insert into ums_pet
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
             pet_type,name, gender, birth_date, remark, photo, breed, body_type, personality, vaccine_status,sterilization deworming_status, dogLicense_status, health_status, owner, del_flag,create_by, create_time, update_by, update_time,
            create_by, create_time, update_by, update_time
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id, jdbcType=INTEGER},
        </if>
            #{petType, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR},#{gender, jdbcType=VARCHAR},#{birthDate, jdbcType=VARCHAR},#{remark, jdbcType=VARCHAR},#{photo, jdbcType=VARCHAR},#{breed, jdbcType=VARCHAR},#{bodyType, jdbcType=VARCHAR},#{personality, jdbcType=VARCHAR},#{vaccineStatus, jdbcType=VARCHAR},#{sterilization, jdbcType=VARCHAR},#{dewormingStatus, jdbcType=VARCHAR},#{doglicenseStatus, jdbcType=VARCHAR},#{healthStatus, jdbcType=VARCHAR},#{owner, jdbcType=VARCHAR},#{delFlag, jdbcType=VARCHAR},#{createBy, jdbcType=BIGINT},#{createTime, jdbcType=DATE},#{updateBy, jdbcType=BIGINT},#{updateTime, jdbcType=DATE}

        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=INTEGER},
            </if>
            pet_type = #{petType, jdbcType=VARCHAR},
            name = #{name, jdbcType=VARCHAR},
            gender = #{gender, jdbcType=VARCHAR},
            birth_date = #{birthDate, jdbcType=VARCHAR},
            remark = #{remark, jdbcType=VARCHAR},
            photo = #{photo, jdbcType=VARCHAR},
            breed = #{breed, jdbcType=VARCHAR},
            body_type = #{bodyType, jdbcType=VARCHAR},
            personality = #{personality, jdbcType=VARCHAR},
            vaccine_status = #{vaccineStatus, jdbcType=VARCHAR},
            sterilization = #{sterilization, jdbcType=VARCHAR},
            deworming_status = #{dewormingStatus, jdbcType=VARCHAR},
            dogLicense_status = #{doglicenseStatus, jdbcType=VARCHAR},
            health_status = #{healthStatus, jdbcType=VARCHAR},
            owner = #{owner, jdbcType=VARCHAR},
            del_flag =  #{delFlag, jdbcType=VARCHAR},
            create_by = #{createBy, jdbcType=BIGINT},
            create_time = #{createTime, jdbcType=DATE},
            update_by = #{updateBy, jdbcType=BIGINT},
            update_time = #{updateTime, jdbcType=DATE}
        </trim>
    </insert>
</mapper>
