LibGeoLocationMapper.xml 7 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.laowu.mapper.LibGeoLocationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.laowu.model.LibGeoLocationDO">
        <id column="id" property="id" />
        <result column="create_date" property="createDate" />
        <result column="update_date" property="updateDate" />
        <result column="delete_date" property="deleteDate" />
        <result column="province" property="province" />
        <result column="city" property="city" />
        <result column="town" property="town" />
        <result column="village" property="village" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, province, city, town, village
    </sql>

    <select id="provinces" resultType="string">
        SELECT DISTINCT
            t.province
        FROM
            lib_geo_location t
        WHERE
            t.delete_date IS NULL
            AND t.province IS NOT NULL
    </select>

    <select id="cities" resultType="string">
        SELECT DISTINCT
            t.city
        FROM
            lib_geo_location t
        WHERE
            t.delete_date IS NULL
            AND t.city IS NOT NULL
            and t.province =#{province}
    </select>

    <select id="county" resultType="string">
        SELECT DISTINCT
            t.county
        FROM
            lib_geo_location t
        WHERE
            t.delete_date IS NULL
            AND t.county IS NOT NULL
            AND t.province = #{province}
            AND t.city = #{city}
    </select>

    <select id="towns" resultType="string">
        SELECT DISTINCT
            t.town
        FROM
            lib_geo_location t
        WHERE
            t.delete_date IS NULL
            AND t.county IS NOT NULL
            AND t.province = #{province}
            AND t.city = #{city}
            AND t.county = #{county}
            and town is not NULL
    </select>

    <select id="villages" resultType="string">
        SELECT DISTINCT
            t.village
        FROM
            lib_geo_location t
        WHERE
            t.delete_date IS NULL
            AND t.county IS NOT NULL
            AND t.province = #{province}
            AND t.city = #{city}
            AND t.county = #{county}
            AND t.town = #{town}
            and t.village is not null

    </select>

    <select id="geo" resultType="com.laowu.vo.geo.GeoVO">
       SELECT
            t1.province,
            t1.city,
            t1.county,
            t1.town,
            count(*) as cnt
        FROM
            lib_geo_location t1
        WHERE
            t1.delete_date IS NULL
            <if test="province != null and province != ''">
                AND t1.province = #{province}
            </if>
            <if test="city != null and city != ''">
                AND t1.city = #{city}
            </if>
            <if test="county != null and county != ''">
                AND t1.county = #{county}
            </if>
            <if test="town != null and town != ''">
                AND ( t1.town LIKE  concat('%', #{town}, '%') OR t1.village LIKE  concat('%', #{town}, '%') )
            </if>
        GROUP BY
        t1.province,
        t1.city,
        t1.county,
        t1.town
    </select>

    <select id="localVillages" parameterType="com.laowu.model.LibGeoLocationDO" resultType="string">
        SELECT
            distinct t.county
        FROM
            lib_geo_location t
        WHERE
            t.delete_date IS NULL
            AND t.province = #{province}
            AND t.city = #{city}
    </select>

    <select id="countyCounts" resultType="com.laowu.vo.geo.CountyCountsVO">
        SELECT
            t4.county as name,
            count( 0 ) as cnt
        FROM
            workstation_dict t1
            LEFT JOIN workstation_member_mapping t3 ON t1.id = t3.station_id
            LEFT JOIN member_dict t4 ON t3.member_id = t4.id
        WHERE
            t1.delete_date IS NULL
            AND t3.delete_date IS NULL
            AND t4.delete_date IS NULL
            AND t1.id = #{workStationId}
        GROUP BY
            t4.county
    </select>

    <select id="townCounts" resultType="com.laowu.vo.geo.TownCountsVO">
       SELECT
            t1.town as name,
            count( 0 ) as cnt
        FROM
            lib_geo_location t1
            LEFT JOIN (
            SELECT
                t4.id,
                t4.user_name AS NAME,
                t4.province AS m_pr,
                t4.city AS m_ci,
                t4.county AS m_co,
                t4.town AS m_to,
                t4.village AS m_vi
            FROM
                workstation_dict t1
                LEFT JOIN workstation_member_mapping t3 ON t1.id = t3.station_id
                LEFT JOIN member_dict t4 ON t3.member_id = t4.id
            WHERE
                t1.delete_date IS NULL
                AND t3.delete_date IS NULL
                AND t4.delete_date IS NULL
                AND t1.id = #{workStationId}
                <if test="town != null and town != ''">
                    AND t4.town = #{town}
                </if>
            ) t2 ON t1.province = t2.m_pr
            AND t1.city = t2.m_ci
            AND t1.county = t2.m_co
            AND t1.town = t2.m_to
        WHERE
            t2.id IS NOT NULL
            AND t1.delete_date IS NULL
        GROUP BY
	        t1.town
    </select>

    <select id="villageCounts" resultType="com.laowu.vo.geo.VillageCountsVO">
        SELECT
             t1.village as name,
             count(0) cnt
            FROM
             lib_geo_location t1
             LEFT JOIN (
             SELECT
              t4.id,
              t4.user_name AS NAME,
              t4.province AS m_pr,
              t4.city AS m_ci,
              t4.county AS m_co,
              t4.town AS m_to,
              t4.village AS m_vi
             FROM
              workstation_dict t1
              LEFT JOIN workstation_member_mapping t3 ON t1.id = t3.station_id
              LEFT JOIN member_dict t4 ON t3.member_id = t4.id
              AND t1.province = t4.province
              AND t1.city = t4.city
              AND t1.county = t4.county
             WHERE
              t1.delete_date IS NULL
              AND t3.delete_date IS NULL
              AND t4.delete_date IS NULL
              AND t1.id = #{workStationId}
             ) t2 ON t1.province = t2.m_pr
             AND t1.city = t2.m_ci
             AND t1.county = t2.m_co
             AND t1.town = t2.m_to
             AND t1.village = t2.m_vi
            WHERE
             t1.delete_date is null
             and t2.id IS NOT NULL
             <if  test="town != null and town != ''">
                 and t1.town = #{town}
             </if>
             <if test="village != null and village != ''">
                 and t1.village = #{village}
             </if>
            GROUP BY
             t1.village
    </select>

</mapper>