<?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.xhkjedu.sapi.mapper.system.AreazoneMapper">
  <!--获取地区列表-->
  <resultMap id="areazoneResult" type="java.util.Map">
    <result property="areaid" column="areaid"></result>
    <result property="areaname" column="areaname"></result>
    <result property="areapid" column="areapid"></result>
    <result property="areacode" column="areacode"></result>
    <result property="level" column="level"></result>
    <result property="createtime" column="createtime"></result>
    <result property="createname" column="createname"></result>
    <collection property="cities" javaType="java.util.List" select="listCity1" column="areaid">
    </collection>
  </resultMap>
  <resultMap id="areazoneResult2" type="java.util.Map">
    <result property="areaid" column="areaid"></result>
    <result property="areaname" column="areaname"></result>
    <result property="areapid" column="areapid"></result>
    <result property="areacode" column="areacode"></result>
    <result property="level" column="level"></result>
    <result property="createtime" column="createtime"></result>
    <result property="createname" column="createname"></result>
    <collection property="zones" javaType="java.util.List" select="listZone1" column="areaid">
    </collection>
  </resultMap>
  <select id="listCity1" resultMap="areazoneResult2">
    select a.areaid, a.areaname, a.areapid, a.areacode, a.level, a.createid, a.createtime,a.lcregion,a.areaall,u.username createname
    from t_areazone a left join t_user u on a.createid=u.userid
    where a.areapid=#{areaid} order by a.areacode
  </select>
  <select id="listZone1" resultType="java.util.Map">
    select a.areaid, a.areaname, a.areapid, a.areacode, a.level, a.createid, a.createtime,a.lcregion,a.areaall,u.username createname
    from t_areazone a left join t_user u on a.createid=u.userid
    where a.areapid=#{areaid} order by a.areacode
  </select>
  <select id="listAll" resultMap="areazoneResult">
    select a.areaid, a.areaname, a.areapid, a.areacode, a.level, a.createid, a.createtime,a.lcregion,a.areaall,u.username createname
    from t_areazone a left join t_user u on a.createid=u.userid
    where a.level=1 order by a.areacode
  </select>
  <!--获取地区选择列表-->
  <resultMap id="areaResult" type="java.util.Map">
    <result property="areaname" column="areaname"></result>
    <result property="areacode" column="areacode"></result>
    <collection property="cities" ofType="com.xhkjedu.sapi.vo.system.AreazoneVo" javaType="java.util.List" select="listCity" column="areaid">
    </collection>
  </resultMap>
  <resultMap id="areaResult2" type="java.util.Map">
    <result property="areaname" column="areaname"></result>
    <result property="areacode" column="areacode"></result>
    <result property="lcregion" column="lcregion"></result>
    <collection property="zones" ofType="com.xhkjedu.sapi.vo.system.AreazoneVo" javaType="java.util.List" select="listZone" column="areaid">
    </collection>
  </resultMap>
  <select id="listCity" resultMap="areaResult2">
    select areaid,areaname,areacode,lcregion,areaall
    from t_areazone where areapid=#{areaid} order by areacode
  </select>
  <select id="listZone" resultType="com.xhkjedu.sapi.vo.system.AreazoneVo">
    select areaid,areaname,areacode,lcregion,areaall
    from t_areazone where areapid=#{areaid} order by areacode
  </select>
  <select id="listForSel" resultMap="areaResult">
    select areaid,areaname,areacode,lcregion,areaall
    from t_areazone where level=1 order by areacode
  </select>

  <!--修改区域全名称-->
  <update id="updateAreaAll">
    update t_areazone a1 set a1.areaall=concat(#{areaall},a1.areaname)
    where a1.areapid=#{areaid}
  </update>
  <update id="updateAreaAll2">
    update t_areazone a1 left join t_areazone a2 on a1.areapid=a2.areaid
    set a1.areaall=concat(#{areaall},a2.areaname,a1.areaname)
    where a2.areapid=#{areaid}
  </update>
</mapper>
