<?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.supervision.peopleManage.mapper.FamilyInformationMapper">
    
    <resultMap type="FamilyInformation" id="FamilyInformationResult">
        <result property="id"    column="id"    />
        <result property="peopleId"    column="people_id"    />
        <result property="name"    column="name"    />
        <result property="characterRelationship"    column="character_relationship"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="unitName"    column="unit_name"    />
    </resultMap>

    <sql id="selectFamilyInformationVo">
        select id, people_id, name, character_relationship, phone_number, unit_name from family_information
    </sql>

    <select id="selectFamilyInformationList" parameterType="FamilyInformation" resultMap="FamilyInformationResult">
        <include refid="selectFamilyInformationVo"/>
        <where>  
            <if test="peopleId != null "> and people_id = #{peopleId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="characterRelationship != null  and characterRelationship != ''"> and character_relationship = #{characterRelationship}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
        </where>
    </select>
    
    <select id="selectFamilyInformationById" parameterType="Long" resultMap="FamilyInformationResult">
        <include refid="selectFamilyInformationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFamilyInformation" parameterType="FamilyInformation">
        insert into family_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="peopleId != null">people_id,</if>
            <if test="name != null">name,</if>
            <if test="characterRelationship != null">character_relationship,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="unitName != null">unit_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="peopleId != null">#{peopleId},</if>
            <if test="name != null">#{name},</if>
            <if test="characterRelationship != null">#{characterRelationship},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="unitName != null">#{unitName},</if>
         </trim>
    </insert>

    <update id="updateFamilyInformation" parameterType="FamilyInformation">
        update family_information
        <trim prefix="SET" suffixOverrides=",">
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="characterRelationship != null">character_relationship = #{characterRelationship},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFamilyInformationById" parameterType="Long">
        delete from family_information where id = #{id}
    </delete>

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