<?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="io.renren.dao.SysPeopleEquipmentMapper">

    <resultMap type="SysPeopleEquipment" id="SysPeopleEquipmentResult">
        <result property="id"    column="id"    />
        <result property="peopleId"    column="people_id"    />
        <result property="equipmentId"    column="equipment_id"    />
        <result property="guid"    column="guid"    />
        <result property="faceGuid"    column="face_guid"    />
        <result property="visitorId"    column="visitor_id"    />

    </resultMap>

    <sql id="selectSysPeopleEquipmentVo">
        select id, people_id, equipment_id, guid, face_guid,visitor_id from sys_people_equipment
    </sql>

    <select id="selectSysPeopleEquipmentList" parameterType="SysPeopleEquipment" resultMap="SysPeopleEquipmentResult">
        <include refid="selectSysPeopleEquipmentVo"/>
        <where>
            <if test="peopleId != null "> and people_id = #{peopleId}</if>
            <if test="equipmentId != null "> and equipment_id = #{equipmentId}</if>
            <if test="guid != null  and guid != ''"> and guid = #{guid}</if>
            <if test="faceGuid != null  and faceGuid != ''"> and face_guid = #{faceGuid}</if>
            <if test="visitorId != null "> and visitor_id = #{visitorId}</if>

        </where>
    </select>

    <select id="selectSysPeopleEquipmentById" parameterType="Long" resultMap="SysPeopleEquipmentResult">
        <include refid="selectSysPeopleEquipmentVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysPeopleEquipment" parameterType="SysPeopleEquipment" useGeneratedKeys="true" keyProperty="id">
        insert into sys_people_equipment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="peopleId != null">people_id,</if>
            <if test="equipmentId != null">equipment_id,</if>
            <if test="guid != null">guid,</if>
            <if test="faceGuid != null">face_guid,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="peopleId != null">#{peopleId},</if>
            <if test="equipmentId != null">#{equipmentId},</if>
            <if test="guid != null">#{guid},</if>
            <if test="faceGuid != null">#{faceGuid},</if>
         </trim>
    </insert>

    <update id="updateSysPeopleEquipment" parameterType="SysPeopleEquipment">
        update sys_people_equipment
        <trim prefix="SET" suffixOverrides=",">
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="guid != null">guid = #{guid},</if>
            <if test="faceGuid != null">face_guid = #{faceGuid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysPeopleEquipmentById" parameterType="Long">
        delete from sys_people_equipment where id = #{id}
    </delete>

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

    <select id="selectSysPeopleEquipmentByGuId" parameterType="String" resultMap="SysPeopleEquipmentResult">
        <include refid="selectSysPeopleEquipmentVo"/>
        where guid = #{guid}
    </select>

    <select id="selectSysPeopleEquipmentByPeopleId" parameterType="String" resultMap="SysPeopleEquipmentResult">
        <include refid="selectSysPeopleEquipmentVo"/>
        where people_id = #{peopleId}
    </select>

    <select id="selectSysPeopleEquipmentByVisitorId" parameterType="String" resultMap="SysPeopleEquipmentResult">
        <include refid="selectSysPeopleEquipmentVo"/>
        where visitor_id = #{visitorId}
    </select>

    <delete id="deleteSysPeopleEquipment" parameterType="SysPeopleEquipment">
        delete from sys_people_equipment where people_id = #{peopleId} and  equipment_id = #{equipmentId}
    </delete>

</mapper>
