<?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.SysBlockinfoDao">

    <select id="selectByUnitField" resultType="SysBlockinfo" fetchSize="200">
        select distinct sb.BLOCKCODE, sb.BLOCKNAME
        from SYS_BLOCKINFO sb, water_well_basic wb
        where sb.BLOCKCODE = wb.BLOCKCODE
        and wb.unitcode in
        (select unitcode
        from SYS_UNITINFO
        start with UNITCODE = #{unitcode}
        connect by prior UNITCODE = P_UNITCODE)
        <if test="fieldcode != null and fieldcode != ''">
            and wb.fieldcode = #{fieldcode}
        </if>
        order by sb.BLOCKCODE
    </select>


    <select id="selectByUnitBlock" resultType="SysBlockinfo" fetchSize="20">
        select distinct sb.BLOCKCODE, sb.BLOCKNAME
        from SYS_BLOCKINFO sb, water_well_basic wb
        where sb.BLOCKCODE = wb.QKDM
        and wb.DWDM in
        (select unitcode
        from SYS_UNITINFO
        start with UNITCODE = #{unitcode}
        connect by prior UNITCODE = P_UNITCODE)
        <if test="blockname != null and blockname != ''">
            and sb.BLOCKNAME like '%' || #{blockname} || '%'
        </if>
        order by (case when sb.BLOCKCODE = sb.BLOCKNAME then 1 else 0 end),
        sb.BLOCKNAME
    </select>
</mapper>