<?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.yonge.cooleshow.biz.dal.mapper.SysAreaMapper">

	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.SysArea">
            <result column="id_" property="id" />
	        <result column="name_" property="name" />
	        <result column="code_" property="code" />
	        <result column="create_time_" property="createTime" />
	        <result column="update_time_" property="updateTime" />
	        <result column="del_flag_" property="delFlag" />
	        <result column="parent_organ_id_" property="parentOrganId" />
		</resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.name_ as name
        , t.code_ as code
        , t.create_time_ as createTime
        , t.update_time_ as updateTime
        , t.del_flag_ as delFlag
        , t.parent_organ_id_ as parentOrganId
    </sql>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.SysAreaWrapper$SysArea">
		SELECT
        	<include refid="baseColumns" />
		FROM sys_area t
		<where>
			<if test="param.parentId != null" >
				t.parent_organ_id_ = #{param.parentId}
			</if>
		</where>
	</select>

    <select id="queryByCodes" resultMap="BaseResultMap">
		SELECT t.* FROM sys_area t where t.code_ IN (<foreach collection="codeList" separator="," item="code">#{code}</foreach>)
	</select>

	<!--区域数统计-->
	<select id="selectProvinceAreaNumberStatInfo"
			resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
		SELECT t1.parent_organ_id_ AS id, COUNT(t1.id_) AS total FROM sys_area t1
		<where>
			<if test="areaIds != null">
				AND t1.parent_organ_id_ IN (<foreach collection="areaIds" separator="," item="item">#{item}</foreach>)
			</if>
			<if test="delFlag != null">
				AND t1.del_flag_ = #{delFlag}
			</if>
		</where>
		GROUP BY t1.parent_organ_id_
	</select>
    <select id="getNameMap" resultType="java.util.Map">
        select code_ 'key',name_ 'value' from sys_area where code_ IN
        <foreach collection="codeList" item="code" open="(" close=")" separator=",">
            #{code}
        </foreach>
    </select>
    <!--区域数统计-->

</mapper>
