<?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.blueland.dao.AreaDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.blueland.bo.AreaEntity">
        <id column="id" property="id" />
        <result column="aname" property="aname" />
        <result column="pid" property="pid" />
        <result column="tid" property="tid" />
        <result column="create_time" property="createTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, aname, pid, tid, create_time as value
    </sql>
    <sql id="areaColemns">
        id, aname, pid, tid, create_time
    </sql>
    <sql id="where">
        <where>
            <if test="@Ognl@isNotBlank(bo.aname)">aname LIKE CONCAT('%',#{bo.aname},'%')</if>
            <if test="@Ognl@isNotEmpty(bo.tid)">and tid LIKE CONCAT('%',#{bo.tid},'%')</if>
        </where>
    </sql>

    <select id="getList" resultMap="BaseResultMap">
        select <include refid="areaColemns" /> from t_area
        <include refid="where"/>
    </select>

    <select id="findPage" resultMap="BaseResultMap">
        select <include refid="areaColemns" /> from t_area
        <include refid="where"/>
    </select>

    <select id="getbyid" resultMap="BaseResultMap">
        select <include refid="areaColemns" /> from t_area
        where id=#{id}
    </select>

    <select id="queryArea" resultMap="BaseResultMap">
        select <include refid="areaColemns" /> from t_area
        where pid=0 OR pid='-1'
    </select>

    <select id="queryall" resultMap="BaseResultMap">
        select <include refid="areaColemns" /> from t_area
        where  pid!='-1'
    </select>

    <select id="selectList" resultMap="BaseResultMap">
        select <include refid="areaColemns" /> from t_area
    </select>

    <insert id="insetArea">
        insert into t_area(<include refid="areaColemns"/>) values (
        #{id,jdbcType=VARCHAR},
        #{aname,jdbcType=VARCHAR},
        #{pid,jdbcType=VARCHAR},
        #{tid,jdbcType=VARCHAR},
        #{createTime}
        )
    </insert>

    <update id="updateArea">
        update t_area
        <set>
            <if test="aname != null">aname=#{aname,jdbcType=VARCHAR},</if>
            <if test="pid != null">pid=#{pid,jdbcType=VARCHAR},</if>
            <if test="tid!= null">tid=#{tid,jdbcType=VARCHAR},</if>
        </set>
        where id=#{id}
    </update>

    <delete id="deleteArea">
        DELETE FROM t_area WHERE
            id = #{id,jdbcType=VARCHAR}
    </delete>
    <!--批量插入-->
	<insert id="saveBatch">
		INSERT INTO t_area (<include refid="areaColemns"/>) VALUES
		<foreach collection="list" item="item" index="index" separator=",">
			(
				#{item.id,jdbcType=VARCHAR},
				#{item.aname,jdbcType=VARCHAR},
				#{item.pid,jdbcType=VARCHAR},
				#{item.tid,jdbcType=VARCHAR},
				#{item.createTime,jdbcType=TIMESTAMP}
			)
		</foreach>
	</insert>
</mapper>
