<?xml version="1.0" encoding="UTF-8" ?>    
<!DOCTYPE mapper    
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"    
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">

<mapper namespace="com.platform.dao.IRegionalismCodeDao">
	<resultMap id="getEntityByText" type="com.platform.entities.RegionalismEntity">
		<id property="code" column="code" jdbcType="VARCHAR" />
		<result property="cityName" column="city_name" jdbcType="VARCHAR" />
		<result property="districtName" column="district_name" jdbcType="VARCHAR" />
	</resultMap>
	
	<sql id="Base_Column_List">
		code,city_name,district_name
	</sql>
	
	<!-- 获取数据全部记录信息 -->
	<select id="findAllRegionalism" resultMap="getEntityByText">
		SELECT
		<include refid="Base_Column_List" />
		FROM regionalism_info
		order by code
	</select>
	
	<select id="findSubRegionalism" parameterType="com.platform.entities.RegionalismEntity" resultMap="getEntityByText">
		SELECT
		<include refid="Base_Column_List" />
		FROM regionalism_info
		<where>
			<if test="code != null and code != ''">
				AND code LIKE CONCAT(CONCAT('%', #{code}), '%')
			</if>
			<if test="cityName != null and cityName != ''">
				AND city_name LIKE CONCAT(CONCAT('%', #{cityName}), '%')
			</if>
			<if test="districtName != null and districtName != ''">
				AND district_name LIKE CONCAT(CONCAT('%', #{districtName}), '%')
			</if>
		</where>
		order by code
	</select>
	
	<select id="findExistRegionalism" parameterType="java.util.List" resultMap="getEntityByText">
		SELECT
		<include refid="Base_Column_List" />
		FROM regionalism_info
		WHERE code in
		<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
	
	<!-- 批量插入 -->
	<select id="insertBatch" parameterType="java.util.List">
	    INSERT INTO regionalism_info (code,city_name,district_name) 
	    VALUES 
	    <foreach collection="list" item="item" index="index" separator=",">
	        (#{item.code},#{item.cityName},#{item.districtName})
	    </foreach>
	</select> 
</mapper>  