<?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.dxhy.erp.dao.AreaDao">
	<resultMap id="areaResultMap" type="com.dxhy.erp.entity.sdny.area.Area">
		<id column="ID" property="id" jdbcType="BIGINT"/>
		<result column="PID" property="pid" jdbcType="BIGINT"/>
		<result column="AREA_NAME" property="areaName" jdbcType="VARCHAR"/>
		<result column="LEVEL" property="level" jdbcType="INTEGER"/>
		<result column="IS_MUNICIPALITY" property="isMunicipality" jdbcType="VARCHAR"/>
		<result column="IS_CHECK_BLOCK_CHAIN" property="isCheckBlockChain" jdbcType="VARCHAR"/>
	</resultMap>

	<!-- 新增区域信息 -->
	<insert id="addArea" parameterType="com.dxhy.erp.entity.sdny.area.Area">
		INSERT INTO
			sys_area (PID, AREA_NAME)
		VALUES
			(#{pid}, #{areaName})
	</insert>

  	<!-- 更新区域名称字段 -->
	<update id="updateArea" parameterType="com.dxhy.erp.entity.sdny.area.Area">
		UPDATE
			sys_area
		SET
			AREA_NAME = #{areaName}
		WHERE
			ID = #{id}
	</update>
	
  	<!-- 根据ID删除对应区域信息 -->
	<delete id="deleteAreaById" parameterType="java.lang.Long">
		DELETE FROM
			sys_area
		WHERE
			ID = #{id}
	</delete>
	
  	<!-- 根据pid查询区域信息 -->
	<select id="getAreaListByPid" resultMap="areaResultMap">
		SELECT
			ID,PID,AREA_NAME,LEVEL,IS_MUNICIPALITY
		FROM 
			sys_area WHERE PID = #{pid}
	</select>
	
	<!-- 根据id查询对应区域信息 -->
	<select id="getAreaById" resultMap="areaResultMap">
		SELECT
			ID,PID,AREA_NAME,LEVEL,IS_MUNICIPALITY
		FROM 
			sys_area WHERE ID = #{id}
	</select>
	
	<!-- 按名称查找其他城市中的城市 -->
	<select id="queryAreaByName" parameterType="java.lang.String" resultMap="areaResultMap">
		SELECT
			ID,PID,AREA_NAME,LEVEL,IS_MUNICIPALITY
		FROM
			sys_area
		WHERE
			#{areaName} LIKE CONCAT ('%',AREA_NAME,'%')
	</select>


	<select id="getAllAreaList" resultMap="areaResultMap">
		SELECT
		ID,PID,AREA_NAME,LEVEL,IS_MUNICIPALITY
		FROM
		sys_area
	</select>
	<select id="getBlockChainProviceList" resultMap="areaResultMap">
		SELECT
			ID,PID,AREA_NAME,LEVEL,IS_MUNICIPALITY,IS_CHECK_BLOCK_CHAIN
		FROM
			sys_area
		WHERE
			LEVEL in ('1','2')
		AND
			ID not in ('33', '34', '35')
	</select>
</mapper>