SysAreaMapper.xml 6.72 KB
<?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.glsx.usercenter.mapper.SysAreaMapper">
  <resultMap id="BaseResultMap" type="com.glsx.usercenter.pojo.user.SysArea">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="area_name" jdbcType="VARCHAR" property="areaName" />
    <result column="area_code" jdbcType="VARCHAR" property="areaCode" />
    <result column="parent_id" jdbcType="INTEGER" property="parentId" />
    <result column="init_date" jdbcType="TIMESTAMP" property="initDate" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, area_name, area_code, parent_id, init_date
  </sql>
  <select id="selectByExample" parameterType="com.glsx.usercenter.pojo.user.SysAreaExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from sys_area
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from sys_area
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from sys_area
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.glsx.usercenter.pojo.user.SysArea">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into sys_area (area_name, area_code, parent_id, 
      init_date)
    values (#{areaName,jdbcType=VARCHAR}, #{areaCode,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, 
      #{initDate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.glsx.usercenter.pojo.user.SysArea">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into sys_area
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="areaName != null">
        area_name,
      </if>
      <if test="areaCode != null">
        area_code,
      </if>
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="initDate != null">
        init_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="areaName != null">
        #{areaName,jdbcType=VARCHAR},
      </if>
      <if test="areaCode != null">
        #{areaCode,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null">
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="initDate != null">
        #{initDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.glsx.usercenter.pojo.user.SysAreaExample" resultType="java.lang.Long">
    select count(*) from sys_area
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.glsx.usercenter.pojo.user.SysArea">
    update sys_area
    <set>
      <if test="areaName != null">
        area_name = #{areaName,jdbcType=VARCHAR},
      </if>
      <if test="areaCode != null">
        area_code = #{areaCode,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="initDate != null">
        init_date = #{initDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.glsx.usercenter.pojo.user.SysArea">
    update sys_area
    set area_name = #{areaName,jdbcType=VARCHAR},
      area_code = #{areaCode,jdbcType=VARCHAR},
      parent_id = #{parentId,jdbcType=INTEGER},
      init_date = #{initDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

	<!-- //1.定义返回resultMap -->
	<resultMap id="chargeItemSelectMap" type="com.glsx.usercenter.pojo.user.SysArea" extends="BaseResultMap">
		<collection property="children" ofType="com.glsx.usercenter.pojo.user.SysArea" select="getSubChargeItem"
			column="id"></collection>
	</resultMap>
     <!--2.定义查询父的方法 -->
	<select id="getAllChargeItems" resultMap="chargeItemSelectMap">
		SELECT
		<include refid="Base_Column_List" />
				 from 	sys_area WHERE parent_id = 0 	
	</select>
	<!-- 3.定义查询子的方法 -->
	<select id="getSubChargeItem" resultMap="chargeItemSelectMap">
		SELECT
		<include refid="Base_Column_List" />
		from sys_area WHERE parent_id = #{id}
	</select>  
	<select id="getFullAreaByDistrictId" parameterType="java.lang.Integer"
		resultType="java.lang.String">
		SELECT
		CONCAT_WS('', sa2.area_name, sa1.area_name, sa.area_name) AS fullArea
		FROM sys_area sa
		LEFT JOIN sys_area sa1 ON sa.parent_id = sa1.id
		LEFT JOIN sys_area sa2 ON sa1.parent_id = sa2.id
		WHERE sa.id = #{districtId }
	</select>
	
	<select id="getAreaById" parameterType="java.lang.Integer"
		resultType="java.lang.String">
		SELECT
		CONCAT_WS('/', sa2.area_name, sa1.area_name, sa.area_name) AS fullArea
		FROM sys_area sa
		LEFT JOIN sys_area sa1 ON sa.parent_id = sa1.id
		LEFT JOIN sys_area sa2 ON sa1.parent_id = sa2.id
		WHERE sa.id = #{districtId }
	</select>
	
</mapper>