<?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.hchyun.test.dao.AssFatherDao">
    
    <resultMap type="com.hchyun.test.entity.AssFather" id="AssFatherResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="info"    column="info"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>
    <resultMap id="AssFatherAssSunResult" type="com.hchyun.test.entity.AssFather" extends="AssFatherResult">
        <collection property="assSun" notNullColumn="id" javaType="com.hchyun.test.entity.AssSun" resultMap="AssSunResult" />
    </resultMap>
    <resultMap type="com.hchyun.test.entity.AssSun" id="AssSunResult">
        <result property="id"    column="id"    />
        <result property="fId"    column="f_id"    />
        <result property="sname"    column="sname"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectAssFatherVo">
        select id, name, info, create_time from test_ass_father
    </sql>
    <select id="selectAssFatherList" parameterType="AssFather" resultMap="AssFatherAssSunResult">
        select taf.id, taf.name, taf.info, taf.create_time,
        tas.f_id, tas.sname
        from test_ass_father taf
        left join test_ass_sun tas on tas.f_id = taf.id
        <where>
            <if test="name != null  and name != ''"> and taf.name like concat('%', #{name}, '%')</if>
            <if test="info != null  and info != ''"> and taf.info = #{info}</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and taf.create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
            <if test="assSun.sname != null  and assSun.sname != ''"> and tas.sname like concat('%', #{assSun.sname}, '%')</if>
            <if test="params.assbeginCreateTime != null and params.assbeginCreateTime != '' and params.assendCreateTime != null and params.assendCreateTime != ''"> and tas.create_time between #{params.assbeginCreateTime} and #{params.assendCreateTime}</if>
        </where>
    </select>
    
    <select id="selectAssFatherById" parameterType="Long" resultMap="AssFatherResult">
        select taf.id, taf.name, taf.info, taf.create_time,
        tas.f_id, tas.sname
        from test_ass_father taf
        left join test_ass_sun tas on tas.f_id = taf.id
        where taf.id = #{id}
    </select>
        
    <insert id="insertAssFather" parameterType="AssFather">
        insert into test_ass_father
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="info != null and info != ''">info,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="info != null and info != ''">#{info},</if>
         </trim>
    </insert>

    <update id="updateAssFather" parameterType="AssFather">
        update test_ass_father
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="info != null and info != ''">info = #{info},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAssFatherById" parameterType="Long">
        delete from test_ass_father where id = #{id}
    </delete>

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