From 8b7258c9427882bb1798f1502eaa35184c6e374e Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 09 Aug 2024 14:29:18 +0800
Subject: [PATCH] 短信指定楼栋发送

---
 src/main/java/org/springblade/common/cache/SysCache.java |  155 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 109 insertions(+), 46 deletions(-)

diff --git a/src/main/java/org/springblade/common/cache/SysCache.java b/src/main/java/org/springblade/common/cache/SysCache.java
index a9a2e64..792babf 100644
--- a/src/main/java/org/springblade/common/cache/SysCache.java
+++ b/src/main/java/org/springblade/common/cache/SysCache.java
@@ -1,19 +1,3 @@
-/*
- *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- *
- *  Redistributions of source code must retain the above copyright notice,
- *  this list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright
- *  notice, this list of conditions and the following disclaimer in the
- *  documentation and/or other materials provided with the distribution.
- *  Neither the name of the dreamlu.net developer nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- *  Author: Chill 庄骞 (smallchill@163.com)
- */
 package org.springblade.common.cache;
 
 import org.apache.logging.log4j.util.Strings;
@@ -29,6 +13,7 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
+import static org.springblade.common.cache.CacheNames.ARTICLE_KEY;
 import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
 
 /**
@@ -334,7 +319,7 @@
 	 *
 	 * @return regionCode
 	 */
-	public static List<String> getRegionChildCodesByDeptId(String deptId) {
+	public static List<String> getRegionChildCodesByDeptId(String deptId,String communityCode) {
 		//多个部门按逗号分割
 		List<String> deptIdList = Arrays.asList(deptId.split(","));
 
@@ -345,7 +330,7 @@
 			// 查询对应的区域编号code
 			Dept dept = deptService.getById(id);
 			if (null!=dept && !Strings.isBlank(dept.getRegionCode()) && !AuthUtil.isAdministrator()){
-				list = getRegionChildCodes(dept.getRegionCode());
+				list = getRegionChildCodes(dept.getRegionCode(),communityCode);
 				//行政区划不为空添加进集合
 				if (list.size()>0){
 					allRegionList.addAll(list);
@@ -363,43 +348,103 @@
 	 *
 	 * @return regionCode
 	 */
-	public static List<String> getPoliceRegionChildCodesByDeptId(String deptId) {
-		//多个部门按逗号分割
-		List<String> deptIdList = Arrays.asList(deptId.split(","));
+	public static List<String> getPoliceRegionChildCodesByDeptId(String deptId,String communityCode) {
+		List<String> regionCodeList = new ArrayList<>();
+		if (!Strings.isBlank(deptId)) {
+			//多个部门按逗号分割
+			List<String> deptIdList = Arrays.asList(deptId.split(","));
 
-		//所有行政区划code
-		List<String> allRegionList = new ArrayList<>();
-		deptIdList.forEach(id->{
-			List<String> list = new ArrayList<>();
-			// 查询对应的区域编号code
-			Dept dept = deptService.getById(id);
-			if (null!=dept && !Strings.isBlank(dept.getRegionCode()) && !AuthUtil.isAdministrator()){
-				list = getPoliceRegionChildCodes(dept.getRegionCode());
-				//行政区划不为空添加进集合
-				if (list.size()>0){
-					allRegionList.addAll(list);
+			//所有行政区划code
+			List<String> allRegionList = new ArrayList<>();
+			deptIdList.forEach(id -> {
+				List<String> list = new ArrayList<>();
+				// 查询对应的区域编号code
+				Dept dept = deptService.getById(id);
+				// 只取公安的
+				if (dept.getDeptNature() == 1) {
+					if (null != dept && !Strings.isBlank(dept.getRegionCode()) && !AuthUtil.isAdministrator()) {
+						list = getPoliceRegionChildCodes(dept.getRegionCode(),communityCode);
+						//行政区划不为空添加进集合
+						if (list.size() > 0) {
+							allRegionList.addAll(list);
+						}
+					}
 				}
-			}
-		});
-
-		// 去重
-		List<String> collect = allRegionList.stream().distinct().collect(Collectors.toList());
-		return collect;
+			});
+			// 去重
+			regionCodeList = allRegionList.stream().distinct().collect(Collectors.toList());
+		}
+		return regionCodeList;
 	}
+
+
+	/**
+	 * 查询综治网格/公安相关的网格,社区编号集合
+	 * @param deptId
+	 * @param communityCode
+	 * @param roleName
+	 * @return
+	 */
+	public static List<String> getGridRegionChildCodesByDeptId(String deptId, String communityCode,String roleName) {
+		List<String> regionCodeList = new ArrayList<>();
+		if (!Strings.isBlank(deptId)) {
+			//多个部门按逗号分割
+			List<String> deptIdList = Arrays.asList(deptId.split(","));
+			List<String> finalRegionCodeList = regionCodeList;
+			String key = AuthUtil.getUserId().toString();
+			if (!Strings.isBlank(roleName)){
+				key = key + ":" + roleName;
+			}
+			String finalKey = key;
+			deptIdList.forEach(id -> {
+				List<String> list = new ArrayList<>();
+				// 查询对应的区域编号code
+				Dept dept = deptService.getById(id);
+				if (null != dept) {
+					if ((roleName.equals("mj") && dept.getDeptNature() == 1) ||
+						((roleName.equals("wgy") || roleName.equals("wzcj")) && dept.getDeptNature() == 2)) {
+						if (!AuthUtil.isAdministrator()) {
+							if (dept.getRegionCode() == null) {
+								return;
+							}
+							list = CacheUtil.get(SYS_CACHE, REGION_CHILDCODES_CODE, finalKey, List.class);
+							if (list == null || list.size() == 0) {
+								list = new ArrayList<>();
+								List<Region> deptChild = getGridRegionChild(dept.getRegionCode(), communityCode, roleName);
+								if (deptChild != null) {
+									List<String> collect = deptChild.stream().map(Region::getCode).collect(Collectors.toList());
+									list.addAll(collect);
+								}
+							}
+							//行政区划不为空添加进集合
+							if (list.size() > 0) {
+								finalRegionCodeList.addAll(list);
+							}
+						}
+					}
+				}
+			});
+			// 去重
+			regionCodeList = finalRegionCodeList.stream().distinct().collect(Collectors.toList());
+			CacheUtil.put(SYS_CACHE, REGION_CHILDCODES_CODE, key, regionCodeList);
+		}
+		return regionCodeList;
+	}
+
 
 	/**
 	 * 获取下级所有区域code
 	 *
 	 * @return regionCode
 	 */
-	public static List<String> getRegionChildCodes(String regionCode) {
+	public static List<String> getRegionChildCodes(String regionCode,String communityCode) {
 		if (regionCode == null) {
 			return null;
 		}
 		List<String> regionCodeList = CacheUtil.get(SYS_CACHE, REGION_CHILDCODES_CODE, regionCode, List.class);
 		if (regionCodeList == null || regionCodeList.size()==0) {
 			regionCodeList = new ArrayList<>();
-			List<Region> deptChild = getRegionChild(regionCode);
+			List<Region> deptChild = getRegionChild(regionCode,communityCode);
 			if (deptChild != null) {
 				List<String> collect = deptChild.stream().map(Region::getCode).collect(Collectors.toList());
 				regionCodeList.addAll(collect);
@@ -415,14 +460,14 @@
 	 *
 	 * @return regionCode
 	 */
-	public static List<String> getPoliceRegionChildCodes(String regionCode) {
+	public static List<String> getPoliceRegionChildCodes(String regionCode,String communityCode) {
 		if (regionCode == null) {
 			return null;
 		}
 		List<String> regionCodeList = CacheUtil.get(SYS_CACHE, REGION_CHILDCODES_CODE, regionCode, List.class);
 		if (regionCodeList == null || regionCodeList.size()==0) {
 			regionCodeList = new ArrayList<>();
-			List<Region> deptChild = getPoliceRegionChild(regionCode);
+			List<Region> deptChild = getPoliceRegionChild(regionCode,communityCode);
 			if (deptChild != null) {
 				List<String> collect = deptChild.stream().map(Region::getCode).collect(Collectors.toList());
 				regionCodeList.addAll(collect);
@@ -434,12 +479,21 @@
 	}
 
 	/**
+	 * 获取综治下级区域
+	 * @param regionCode
+	 * @return
+	 */
+	private static List<Region> getGridRegionChild(String regionCode, String communityCode,String roleName) {
+		return CacheUtil.get(SYS_CACHE, REGION_CHILD_CODE, regionCode, () -> regionService.getGridRegionChild(regionCode,communityCode,roleName));
+	}
+
+	/**
 	 * 获取民警下级区域
 	 * @param regionCode
 	 * @return
 	 */
-	private static List<Region> getPoliceRegionChild(String regionCode) {
-		return CacheUtil.get(SYS_CACHE, REGION_CHILD_CODE, regionCode, () -> regionService.getPoliceRegionChild(regionCode));
+	private static List<Region> getPoliceRegionChild(String regionCode,String communityCode) {
+		return CacheUtil.get(SYS_CACHE, REGION_CHILD_CODE, regionCode, () -> regionService.getPoliceRegionChild(regionCode,communityCode));
 	}
 
 	/**
@@ -447,7 +501,16 @@
 	 * @param regionCode
 	 * @return
 	 */
-	private static List<Region> getRegionChild(String regionCode) {
-		return CacheUtil.get(SYS_CACHE, REGION_CHILD_CODE, regionCode, () -> regionService.getRegionChild(regionCode));
+	private static List<Region> getRegionChild(String regionCode,String communityCode) {
+		return CacheUtil.get(SYS_CACHE, REGION_CHILD_CODE, regionCode, () -> regionService.getRegionChild(regionCode,communityCode));
+	}
+
+	/**
+	 * 查询当前文章范围对应的社区编号字符串集合
+	 * @param articleRange
+	 * @return
+	 */
+	public static String getAllCommunityNameListString(String articleRange,String id) {
+		return CacheUtil.get(ARTICLE_KEY, "id", id ,() -> regionService.getAllCommunityNameListString(articleRange));
 	}
 }

--
Gitblit v1.9.3