linwe
2024-08-09 8b7258c9427882bb1798f1502eaa35184c6e374e
src/main/java/org/springblade/modules/grid/mapper/GridMapper.xml
@@ -4,8 +4,268 @@
    <!--自定义分页查询-->
    <select id="selectGridPage" resultType="org.springblade.modules.grid.vo.GridVO">
        select * from jczz_grid where is_deleted = 0
        select
        jg.id,
        jg.community_code,
        jg.grid_name,
        jg.grid_code,
        jg.principal,
        jg.principal_phone,
        jg.remark,
        br.name as communityName,br.town_name as townName
        from jczz_grid jg
        left join blade_region br on br.code = jg.community_code
        where jg.is_deleted = 0
        <if test="grid.communityCode!=null and grid.communityCode!=''">
            and jg.community_code = #{grid.communityCode}
        </if>
        <if test="grid.gridName!=null and grid.gridName!=''">
            and jg.grid_name like concat('%',#{grid.gridName},'%')
        </if>
        <if test="grid.principal!=null and grid.principal!=''">
            and jg.principal like concat('%',#{grid.principal},'%')
        </if>
        <if test="grid.gridCode!=null and grid.gridCode!=''">
            and jg.grid_code like concat('%',#{grid.gridCode},'%')
        </if>
        <if test="grid.principalPhone!=null and grid.principalPhone!=''">
            and jg.principal_phone like concat('%',#{grid.principalPhone},'%')
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                    and jg.community_code in
                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
                <otherwise>
                    and jg.community_code in ('')
                </otherwise>
            </choose>
        </if>
        <if test="grid.communityName != null and grid.communityName !='' ">
            and br.name like concat('%',#{grid.communityName},'%')
        </if>
        <if test="grid.townName != null and grid.townName !='' ">
            and br.town_name like concat('%',#{grid.townName},'%')
        </if>
        order by community_code asc,grid_code asc
    </select>
    <!--根据地址编号查询网格数据-->
    <select id="getPlaceGridDetailByHouseCode" resultType="org.springblade.modules.grid.vo.GridVO">
        select jg.id,jg.grid_name,br.town_name AS townStreetName,br.name AS community_name,
        bu.real_name as realName,bu.phone as gridPhone
        from jczz_grid jg
        left join jczz_place jp on jp.grid_code = jg.grid_code and jp.is_deleted = 0
        left join jczz_gridman jgm on jg.grid_code = jgm.grid_code and jgm.is_deleted = 0
        left join blade_user bu on bu.id = jgm.user_id and bu.is_deleted = 0
        left join blade_region br ON br.code = jg.community_code
        where jg.is_deleted = 0
        and jp.house_code like concat('%',#{houseCode},'%')
        limit 1
    </select>
    <!--根据用户id(网格员)查询对应的房屋地址code-->
    <select id="getAddressCodeListByUserId" resultType="java.lang.String">
        select jgr.house_code from jczz_grid_range jgr
        left join jczz_grid jg on jg.id = jgr.grid_id and jg.is_deleted = 0
        left join jczz_gridman jgm on jgm.grid_id = jg.id and jgm.is_deleted = 0
        where 1=1
        and jgm.user_id = #{userId}
        <if test="addressCode!=null and addressCode!=''">
            and jgr.house_code = #{addressCode}
        </if>
    </select>
    <!--判断该小区点在哪个派出所-->
    <select id="spatialAnalysis" resultType="org.springblade.modules.grid.entity.GridEntity">
        SELECT * FROM jczz_grid WHERE ST_Intersects(geom, ST_GeomFromText(${point},0))
    </select>
    <!--根据地址编号查询网格数据-->
    <select id="getGridDetailByParam" resultType="org.springblade.modules.grid.vo.GridVO">
        SELECT
            jg.id,
            jg.grid_code,
            jg.grid_name,
            br.name as community_name,
            jg.sort,
            bu.real_name AS realName,
            bu.phone AS gridPhone
        FROM
            jczz_grid jg
                LEFT JOIN jczz_gridman jgm on jg.grid_code = jgm.grid_code
                LEFT JOIN blade_region br on br.code = jg.community_code
                LEFT JOIN jczz_place_rel jpr ON locate( jpr.community_name, br.name )> 0
                AND locate( jpr.grid_name, jg.grid_name )> 0
                AND jpr.is_deleted = 0
                LEFT JOIN blade_user bu ON bu.id = jgm.user_id
                AND bu.is_deleted = 0
        WHERE
          jg.is_deleted = 0
          and jpr.place_id = #{place.id}
          limit 1
    </select>
    <!--自定义详情查询-->
    <select id="getGridDetail" resultType="org.springblade.modules.grid.vo.GridVO">
        select id,grid_code,community_code,grid_name,principal,principal_phone,remark,sort from jczz_grid
         where is_deleted = 0 and id = #{grid.id}
    </select>
    <!--查询全部-->
    <select id="selectGridAll" resultType="org.springblade.modules.grid.entity.GridEntity">
        select id,grid_code,community_code,grid_name,principal,principal_phone,remark,sort from jczz_grid
         where is_deleted = 0
    </select>
    <!--网格树-->
    <select id="getGridTree" resultType="org.springblade.common.node.TreeStringNode">
        SELECT code        as id,
               parent_code as parentId,
               name
        FROM blade_region
        where district_code = '361102000000'
        union all
        (select id,
                community_code as parentId,
                grid_name      as name
         from jczz_grid
         where is_deleted = 0)
    </select>
    <select id="gridInfo" resultType="org.springblade.modules.grid.entity.GridmanEntity">
        SELECT jg.id,
               jg.grid_name,
               jgm.pic_url,
               jgm.mobile,
               jgm.gridman_name
        FROM jczz_grid jg
                 LEFT JOIN jczz_gridman jgm ON jgm.grid_id = jg.id
                 LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
        WHERE jgr.house_code = #{houseCode}
          AND jg.is_deleted = '0'
          AND jgm.is_deleted = '0'
    </select>
    <select id="gridAoiName"
            resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        SELECT aoi_name,
               GROUP_CONCAT(building_name) building_name
        FROM (SELECT DISTINCT aoi_name,
                              building_name
              FROM jczz_doorplate_address
              WHERE address_code IN (SELECT jgr.house_code
                                     FROM jczz_grid jg
                                              LEFT JOIN jczz_gridman jgm ON jgm.grid_id = jg.id
                                              LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
                                     WHERE jg.id = #{id})) a
        GROUP BY aoi_name
    </select>
    <!--网格集合查询-->
    <select id="getGridList" resultType="org.springblade.modules.grid.entity.GridEntity">
        SELECT * from jczz_grid
        where is_deleted = 0
        <if test="grid.communityCode!=null and grid.communityCode!=''">
            and community_code = #{grid.communityCode}
        </if>
        order by sort asc
    </select>
    <!--查询小区网格绑定-->
    <select id="getGridListByAoiCode" resultType="org.springblade.modules.grid.vo.GridVO">
        SELECT jg.grid_name from jczz_grid jg
        left join jczz_grid_range jgr on jg.id = jgr.grid_id
        where jg.is_deleted = 0
        and jgr.district_code = #{aoiCode}
        GROUP BY jg.grid_name
    </select>
    <!--查询对应网格人对应的网格-->
    <select id="getGridByUserId" resultType="org.springblade.modules.grid.entity.GridEntity">
        select
        jg.*
        from jczz_grid jg
        where jg.grid_code in
        (
        select * from (select grid_code from jczz_gridman  where is_deleted = 0 and user_id = #{userId} limit 1) a
        )
    </select>
    <!--根据网格名称,社区名称查询对应的网格-->
    <select id="getGridByNames" resultType="org.springblade.modules.grid.entity.GridEntity">
        select jg.* from jczz_grid jg
        left join blade_region br on br.village_code = jg.community_code
        where jg.is_deleted = 0
        and jg.grid_name = #{gridName}
        and br.name = #{communityName}
    </select>
    <!--查询用户对应的网格-->
    <select id="getGridListByUserId" resultType="java.lang.String">
        select jg.grid_code from jczz_grid jg
        left join jczz_gridman jgm on jgm.grid_code = jg.grid_code and jgm.is_deleted = 0
        where jg.is_deleted = 0
        and jgm.user_id = #{userId}
    </select>
    <!--查询对应的房屋地址code(更加网格编号集合)-->
    <select id="getAddressCodeListByGridCodeList" resultType="java.lang.String">
        select jgr.house_code from jczz_grid_range jgr
        left join jczz_grid jg on jg.grid_code = jgr.grid_code and jg.is_deleted = 0
        where 1=1
        <if test="communityCode!=null and communityCode!=''">
            and jg.community_code = #{communityCode}
        </if>
        <choose>
            <when test="gridCodeList!=null and gridCodeList.size()>0">
                and jg.grid_code in
                <foreach collection="gridCodeList" item="gridCode" separator="," open="(" close=")">
                     #{gridCode}
                </foreach>
            </when>
            <otherwise>
                and jg.grid_code in ('')
            </otherwise>
        </choose>
    </select>
    <!--根据社区编号及网格编号集合查询对应的网格信息-->
    <select id="getGridListByComAndList" resultType="org.springblade.modules.grid.vo.GridVO">
        select
        jg.*,br.name as communityName
        from jczz_grid jg
        left join blade_region br on jg.community_code = br.code
        where jg.is_deleted = 0
        <if test="communityCode!=null and communityCode!=''">
            and jg.community_code = #{communityCode}
        </if>
        <choose>
            <when test="gridCodeList!=null and gridCodeList.size()>0">
                and jg.grid_code in
                <foreach collection="gridCodeList" item="gridCode" separator="," open="(" close=")">
                     #{gridCode}
                </foreach>
            </when>
            <otherwise>
                and jgr.house_code in ('')
            </otherwise>
        </choose>
    </select>
    <!--根据社区名称和网格名称查询对应的网格信息-->
    <select id="getGridInfoByParam" resultType="org.springblade.modules.grid.entity.GridEntity">
        select
        jg.*
        from jczz_grid jg
        left join blade_region br on jg.community_code = br.code
        where jg.is_deleted = 0
        and jg.grid_name = #{gridName}
        and br.name = #{communityName}
    </select>
</mapper>