<?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.rwk.system.mapper.RwkFamilyMemberMapper">
    
    <resultMap type="RwkFamilyMember" id="RwkFamilyMemberResult">
        <result property="id"    column="id"    />
        <result property="appellation"    column="appellation"    />
        <result property="name"    column="name"    />
        <result property="birthday"    column="birthday"    />
        <result property="politicalStatus"    column="political_status"    />
        <result property="unitJob"    column="unit_job"    />
        <result property="familyMemberCode"    column="family_member_code"    />
    </resultMap>

    <sql id="selectRwkFamilyMemberVo">
        select id, appellation, name, birthday, political_status, unit_job, family_member_code from rwk_family_member
    </sql>

    <select id="selectRwkFamilyMemberList" parameterType="RwkFamilyMember" resultMap="RwkFamilyMemberResult">
        <include refid="selectRwkFamilyMemberVo"/>
        <where>  
            <if test="appellation != null  and appellation != ''"> and appellation = #{appellation}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="politicalStatus != null  and politicalStatus != ''"> and political_status = #{politicalStatus}</if>
            <if test="unitJob != null  and unitJob != ''"> and unit_job = #{unitJob}</if>
            <if test="familyMemberCode != null  and familyMemberCode != ''"> and family_member_code = #{familyMemberCode}</if>
        </where>
    </select>
    
    <select id="selectRwkFamilyMemberById" parameterType="Long" resultMap="RwkFamilyMemberResult">
        <include refid="selectRwkFamilyMemberVo"/>
        where id = #{id}
    </select>

    <insert id="insertRwkFamilyMember" parameterType="RwkFamilyMember">
        insert into rwk_family_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="appellation != null">appellation,</if>
            <if test="name != null">name,</if>
            <if test="birthday != null">birthday,</if>
            <if test="politicalStatus != null">political_status,</if>
            <if test="unitJob != null">unit_job,</if>
            <if test="familyMemberCode != null">family_member_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="appellation != null">#{appellation},</if>
            <if test="name != null">#{name},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="politicalStatus != null">#{politicalStatus},</if>
            <if test="unitJob != null">#{unitJob},</if>
            <if test="familyMemberCode != null">#{familyMemberCode},</if>
         </trim>
    </insert>

    <update id="updateRwkFamilyMember" parameterType="RwkFamilyMember">
        update rwk_family_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="appellation != null">appellation = #{appellation},</if>
            <if test="name != null">name = #{name},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="politicalStatus != null">political_status = #{politicalStatus},</if>
            <if test="unitJob != null">unit_job = #{unitJob},</if>
            <if test="familyMemberCode != null">family_member_code = #{familyMemberCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRwkFamilyMemberById" parameterType="Long">
        delete from rwk_family_member where id = #{id}
    </delete>

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

</mapper>