<?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.da.dangan.mapper.DaCzrkdjMapper">
    
    <resultMap type="DaCzrkdj" id="DaCzrkdjResult">
        <result property="id"    column="id"    />
        <result property="muId"    column="mu_id"    />
        <result property="name"    column="name"    />
        <result property="hzName"    column="hz_name"    />
        <result property="relation"    column="relation"    />
        <result property="birthday"    column="birthday"    />
        <result property="address"    column="address"    />
        <result property="jiguan"    column="jiguan"    />
        <result property="cardId"    column="card_id"    />
        <result property="pictures"    column="pictures"    />
        <result property="remark"    column="remark"    />
        <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="selectDaCzrkdjVo">
        select id, mu_id, name, hz_name, relation, birthday, address, jiguan, card_id, pictures, remark, create_by, create_time, update_by, update_time from da_czrkdj
    </sql>

    <select id="selectDaCzrkdjList" parameterType="DaCzrkdj" resultMap="DaCzrkdjResult">
        <include refid="selectDaCzrkdjVo"/>
        <where>  
            <if test="muId != null "> and mu_id = #{muId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="hzName != null  and hzName != ''"> and hz_name like concat('%', #{hzName}, '%')</if>
            <if test="relation != null  and relation != ''"> and relation = #{relation}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="jiguan != null  and jiguan != ''"> and jiguan = #{jiguan}</if>
            <if test="cardId != null  and cardId != ''"> and card_id = #{cardId}</if>
            <if test="pictures != null  and pictures != ''"> and pictures = #{pictures}</if>
        </where>
    </select>
    
    <select id="selectDaCzrkdjById" parameterType="Long" resultMap="DaCzrkdjResult">
        <include refid="selectDaCzrkdjVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDaCzrkdj" parameterType="DaCzrkdj" useGeneratedKeys="true" keyProperty="id">
        insert into da_czrkdj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="muId != null">mu_id,</if>
            <if test="name != null">name,</if>
            <if test="hzName != null">hz_name,</if>
            <if test="relation != null">relation,</if>
            <if test="birthday != null">birthday,</if>
            <if test="address != null">address,</if>
            <if test="jiguan != null">jiguan,</if>
            <if test="cardId != null">card_id,</if>
            <if test="pictures != null">pictures,</if>
            <if test="remark != null">remark,</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="muId != null">#{muId},</if>
            <if test="name != null">#{name},</if>
            <if test="hzName != null">#{hzName},</if>
            <if test="relation != null">#{relation},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="address != null">#{address},</if>
            <if test="jiguan != null">#{jiguan},</if>
            <if test="cardId != null">#{cardId},</if>
            <if test="pictures != null">#{pictures},</if>
            <if test="remark != null">#{remark},</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="updateDaCzrkdj" parameterType="DaCzrkdj">
        update da_czrkdj
        <trim prefix="SET" suffixOverrides=",">
            <if test="muId != null">mu_id = #{muId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="hzName != null">hz_name = #{hzName},</if>
            <if test="relation != null">relation = #{relation},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="address != null">address = #{address},</if>
            <if test="jiguan != null">jiguan = #{jiguan},</if>
            <if test="cardId != null">card_id = #{cardId},</if>
            <if test="pictures != null">pictures = #{pictures},</if>
            <if test="remark != null">remark = #{remark},</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="deleteDaCzrkdjById" parameterType="Long">
        delete from da_czrkdj where id = #{id}
    </delete>

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