<?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="org.jeecg.modules.commonQueryConfig.mapper.CommonQueryConfigMapper">
    <select id="commonQuery" parameterType="hashmap" resultType="hashmap">
        select t.*, t.shape.GET_WKT() as wkt, SDO_GEOM.SDO_AREA(SDO_CS.TRANSFORM(t.shape, 4490), 0.05) as shapeArea
        from ${tablename} t
        where ${queryfield} like CONCAT(CONCAT('%', #{queryinfo}), '%')
    </select>
    <select id="commonQuery2" parameterType="hashmap" resultType="hashmap">
        select a.* from (select a.OBJECTID,b.id,b.dkbh,b.dk,b.${queryfield}, st_astext(ST_GeometryN(geom,
        generate_series(1, ST_NumGeometries(geom)))) as wkt
        from ${tablename} a
        left join ${reltablename} b on a.${fromfldname} = b.${tofldname}
        where b.${queryfield} like CONCAT(CONCAT('%', #{queryinfo}), '%')
        ) a
        ORDER BY A.OBJECTID
        <if test="pageno!=null and pagesize!=null">
            limit ${pagesize} offset ${pagesize * (pageno-1)}
        </if>
    </select>

<!--    &#45;&#45;         select count(1) from (-->
<!--    &#45;&#45;             select 	  A.OBJECTID,-->
<!--    &#45;&#45;                         b.ID,-->
<!--    &#45;&#45;                         b.dkbh,-->
<!--    &#45;&#45;                         b.dk,-->
<!--    &#45;&#45;                         st_astext ( ST_GeometryN ( geom, generate_series ( 1, ST_NumGeometries ( geom ) ) ) ) AS wkt-->
<!--    &#45;&#45;             from ${tablename} a-->
<!--    &#45;&#45;         left join ${reltablename} b on a.${fromfldname} = b.${tofldname}-->
<!--    &#45;&#45;         where b.${queryfield} like CONCAT(CONCAT('%', #{queryinfo}), '%')) a-->

    <select id="count" parameterType="hashmap" resultType="int">
        SELECT COUNT(1)
        FROM (
                 SELECT A.OBJECTID,
                        b.ID,
                        b.dkbh,
                        b.dk,
                        st_astext(ST_GeometryN(geom, generate_series(1, ST_NumGeometries(geom)))) AS wkt
                 FROM ${ tablename } A
                          LEFT JOIN ${ reltablename } b ON A.${ fromfldname } = b.${ tofldname }
                 WHERE b.${ queryfield } LIKE CONCAT(CONCAT('%', #{ queryinfo }), '%')
             ) A
    </select>

    <select id="commonQuery3" parameterType="hashmap" resultType="hashmap">
        select a.OBJECTID,
               a.${otherfield},
               b.${queryfield},
               b.*,
               a.shape.GET_WKT()                                        as wkt,
               SDO_GEOM.SDO_AREA(SDO_CS.TRANSFORM(a.shape, 4490), 0.05) as shapeArea
        from ${tablename} a
                 left join ${reltablename} b on a.${fromfldname} = b.${tofldname}
        where b.${queryfield} like CONCAT(CONCAT('%', #{queryinfo}), '%')
    </select>
    <select id="commonQuery4" parameterType="hashmap" resultType="hashmap">
        select distinct(${fromfldname}), t.${queryfield}
        from ${tablename} t
        where ${queryfield} like CONCAT(CONCAT('%', #{queryinfo}), '%')
    </select>
    <!--    <select id="commonQuery5" parameterType="hashmap" resultType="hashmap">-->
    <!--        select t.${otherfield},t.shape.GET_WKT(),SDO_GEOM.SDO_AREA(SDO_CS.TRANSFORM(t.shape,4527),0.05) as shapeArea-->
    <!--        from ${tablename} t-->
    <!--        where ${queryfield} = #{queryinfo}-->
    <!--    </select>-->
    <select id="commonQuery5" parameterType="hashmap" resultType="hashmap">
        select a.OBJECTID,
               a.${otherfield},
               b.*,
               a.shape.GET_WKT()                                        as wkt,
               SDO_GEOM.SDO_AREA(SDO_CS.TRANSFORM(a.shape, 4490), 0.05) as shapeArea
        from ${tablename} a
                 left join ${reltablename} b on a.${fromfldname} = b.${tofldname}
        where a.${fromfldname} = #{fromfldvalue}
    </select>
    <select id="identifyQuery" parameterType="hashmap" resultType="hashmap">
        select a.*, a.shape.GET_WKT() as wkt
        from ${tablename} a
        where a.OBJECTID = ${objectid}
    </select>
    <select id="identifyQuery2" parameterType="hashmap" resultType="hashmap">
        select a.OBJECTID, b.*, a.shape.GET_WKT() as wkt
        from ${tablename} a
                 left join ${reltablename} b on a.${fromfldname} = b.${tofldname}
        where a.OBJECTID = ${objectid}
    </select>
</mapper>