<?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="cn.com.victorysoft.business.sys.dao.SysUnitinfoDao">
  <resultMap id="BaseResultMap" type="SysUnitinfo">
    <result column="UNITNAME" jdbcType="VARCHAR" property="unitname" />
    <result column="UNITCODE" jdbcType="VARCHAR" property="unitcode" />
    <result column="UNITLEVEL" jdbcType="NUMERIC" property="unitlevel" />
    <result column="UNITORDER" jdbcType="NUMERIC" property="unitorder" />
    <result column="P_UNITCODE" jdbcType="VARCHAR" property="pUnitcode" />
    <result column="FULLNAME" jdbcType="VARCHAR" property="fullname" />
  </resultMap>
  <sql id="Base_Column_List">
    nvl(shortname,unitname) UNITNAME, UNITCODE, UNITLEVEL, UNITORDER, P_UNITCODE, FULLNAME
  </sql>

  <select id="selectUnit" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where UNITCODE = #{value}
  </select>

  <select id="selectUnitAll" resultMap="BaseResultMap" fetchSize="1000">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    order by UNITLEVEL,UNITORDER
  </select>

  <select id="selectUnitTree" parameterType="java.lang.String" resultMap="BaseResultMap" fetchSize="1000">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    start with UNITCODE = #{value}
    connect by prior UNITCODE = P_UNITCODE
    order by UNITLEVEL,UNITORDER
  </select>

  <select id="selectUnitTreeLevel2" parameterType="java.lang.String" resultMap="BaseResultMap" fetchSize="1000">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where unitlevel &lt;= 2
    start with UNITCODE = #{value}
    connect by prior UNITCODE = P_UNITCODE
    order by UNITLEVEL,UNITORDER
  </select>

  <select id="selectUnitTreeLevel3" parameterType="java.lang.String" resultMap="BaseResultMap" fetchSize="1000">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where unitlevel &lt;= 3
    start with UNITCODE = #{value}
    connect by prior UNITCODE = P_UNITCODE
    order by UNITLEVEL,UNITORDER
  </select>

  <select id="selectChildren" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where P_UNITCODE = #{value}
    order by UNITLEVEL,UNITORDER
  </select>

  <select id="selectUnitByCode" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where UNITCODE = #{value}
  </select>

  <!-- 查询所属采油厂 -->
  <select id="selectParentCompany" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where UNITLEVEL = 2
    start with UNITCODE = #{value}
    connect by prior P_UNITCODE = UNITCODE
  </select>

  <!-- 查询采油厂列表 -->
  <select id="selectCompanyList" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from SYS_UNITINFO
    where UNITLEVEL = 2
    order by unitlevel
  </select>
</mapper>
