<?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.srs.comprehensive.mapper.CphFamilyMemberMapper">
    
    <resultMap type="CphFamilyMember" id="CphFamilyMemberResult">
        <result property="id"    column="id"    />
        <result property="familyName"    column="family_name"    />
        <result property="familyRelation"    column="family_relation"    />
        <result property="workPlace"    column="work_place"    />
        <result property="zzmm"    column="zzmm"    />
        <result property="birthday"    column="birthday"    />
        <result property="job"    column="job"    />
        <result property="yearMoney"    column="year_money"    />
        <result property="health"    column="health"    />
        <result property="status"    column="status"    />
        <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="delFlag"    column="del_flag"    />
        <result property="stuNo"    column="stu_no"    />
    </resultMap>

    <sql id="selectCphFamilyMemberVo">
        select id,stu_no, family_name, family_relation, work_place, zzmm, birthday, job, year_money, health, status, create_by, create_time, update_by, update_time, del_flag from cph_family_member
    </sql>

    <select id="selectCphFamilyMemberList" parameterType="CphFamilyMember" resultMap="CphFamilyMemberResult">
        <include refid="selectCphFamilyMemberVo"/>
        <where>  
            <if test="familyName != null  and familyName != ''"> and family_name like concat('%', #{familyName}, '%')</if>
            <if test="familyRelation != null  and familyRelation != ''"> and family_relation = #{familyRelation}</if>
            <if test="workPlace != null  and workPlace != ''"> and work_place = #{workPlace}</if>
            <if test="zzmm != null  and zzmm != ''"> and zzmm = #{zzmm}</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="job != null  and job != ''"> and job = #{job}</if>
            <if test="yearMoney != null "> and year_money = #{yearMoney}</if>
            <if test="health != null  and health != ''"> and health = #{health}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
        </where>
    </select>
    
    <select id="selectCphFamilyMemberById" parameterType="Long" resultMap="CphFamilyMemberResult">
        <include refid="selectCphFamilyMemberVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCphFamilyMember" parameterType="CphFamilyMember" useGeneratedKeys="true" keyProperty="id">
        insert into cph_family_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="familyName != null">family_name,</if>
            <if test="familyRelation != null">family_relation,</if>
            <if test="workPlace != null">work_place,</if>
            <if test="zzmm != null">zzmm,</if>
            <if test="birthday != null">birthday,</if>
            <if test="job != null">job,</if>
            <if test="yearMoney != null">year_money,</if>
            <if test="health != null">health,</if>
            <if test="status != null and status != ''">status,</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>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="stuNo != null and stuNo != ''">stu_no,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="age != null and age != ''">age,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="familyName != null">#{familyName},</if>
            <if test="familyRelation != null">#{familyRelation},</if>
            <if test="workPlace != null">#{workPlace},</if>
            <if test="zzmm != null">#{zzmm},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="job != null">#{job},</if>
            <if test="yearMoney != null">#{yearMoney},</if>
            <if test="health != null">#{health},</if>
            <if test="status != null and status != ''">#{status},</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>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="stuNo != null and stuNo != ''">#{stuNo},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="age != null and age != ''">#{age},</if>
         </trim>
    </insert>

    <update id="updateCphFamilyMember" parameterType="CphFamilyMember">
        update cph_family_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="familyName != null">family_name = #{familyName},</if>
            <if test="familyRelation != null">family_relation = #{familyRelation},</if>
            <if test="workPlace != null">work_place = #{workPlace},</if>
            <if test="zzmm != null">zzmm = #{zzmm},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="job != null">job = #{job},</if>
            <if test="yearMoney != null">year_money = #{yearMoney},</if>
            <if test="health != null">health = #{health},</if>
            <if test="status != null and status != ''">status = #{status},</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>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="stuNo != null and stuNo != ''">stu_no = #{stuNo},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="age != null and age != ''">age = #{age},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphFamilyMemberById" parameterType="Long">
        delete from cph_family_member where id = #{id}
    </delete>

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