diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java index 32cba063c5..27636e435a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java @@ -440,4 +440,8 @@ public class RedisUtils { public Long bitCount(String key, int start, int end) { return redisTemplate.execute((RedisCallback) con -> con.bitCount(key.getBytes(), start, end)); } + + public Long getTTL(String treeCacheKey) { + return redisTemplate.getExpire(treeCacheKey); + } } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java index c5ac865c4c..77a9c8325d 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java @@ -12,8 +12,11 @@ import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.form.DingTextBriefNessFormDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.redis.common.CustomerOrgRedis; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; @@ -60,6 +63,7 @@ import java.io.OutputStream; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; /** @@ -95,6 +99,10 @@ public class GovOrgServiceImpl implements GovOrgService { private IcBuildingDao icBuildingDao; @Autowired private EvaluationIndexService evaluationIndexService; + @Autowired + private RedisUtils redisUtils; + @Autowired + private ExecutorService executorService; /** * @param staffId @@ -583,12 +591,34 @@ public class GovOrgServiceImpl implements GovOrgService { @Override public List getAgencyTree(TokenDto tokenDto, SubOrgFormDTO formDTO) { CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); + if (staffInfo == null || StringUtils.isBlank(staffInfo.getAgencyId())){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"工作人员所属组织不存在"); + } + //组织缓存key + String treeCacheKey = RedisKeys.getOrgTreeCacheKey(formDTO.getAgencyId()).concat(StrConstant.COLON).concat(formDTO.getClient()); + Long expiryTime = redisUtils.getTTL(treeCacheKey); + List orgTreeResultDTOS = (List) redisUtils.get(treeCacheKey); + String agencyId = staffInfo.getAgencyId(); + String client = formDTO.getClient(); + //如果接近过期或已经过期且缓存数据不为空 则异步查询 + if ((expiryTime == null || expiryTime <= NumConstant.ONE_THOUSAND) && CollectionUtils.isNotEmpty(orgTreeResultDTOS)) { + executorService.submit(() -> { + List list = buildTempOrgTree(agencyId, client); + redisUtils.set(treeCacheKey, list, RedisUtils.HOUR_FOUR_EXPIRE); + }); + } else { + orgTreeResultDTOS = buildTempOrgTree(staffInfo.getAgencyId(), formDTO.getClient()); + redisUtils.set(treeCacheKey, orgTreeResultDTOS, RedisUtils.HOUR_FOUR_EXPIRE); + } + return orgTreeResultDTOS; + } + private List buildTempOrgTree(String agencyId, String client){ List list = new ArrayList<>(); - if ("resi".equals(formDTO.getClient())) { - list.add(customerAgencyDao.getResiOrgTree(staffInfo.getAgencyId())); + if ("resi".equals(client)) { + list.add(customerAgencyDao.getResiOrgTree(agencyId)); return list; } - list.add(customerAgencyDao.getOrgTree(staffInfo.getAgencyId())); + list.add(customerAgencyDao.getOrgTree(agencyId)); return list; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StatsResiWarnServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StatsResiWarnServiceImpl.java index 26da3f073d..8a1648fdb4 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StatsResiWarnServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StatsResiWarnServiceImpl.java @@ -376,7 +376,7 @@ public class StatsResiWarnServiceImpl implements StatsResiWarnService { continue; } String categoryName = StringUtils.isBlank(configMap.get(dto.getConfigId())) ? StrConstant.EPMETY_STR : configMap.get(dto.getConfigId()); - dto.setNoticeContent(String.format("%s%s%s%s超出预警!", infoCache.getGridName(), infoCache.getNeighborHoodName(), infoCache.getBuildingName(), categoryName)); + dto.setNoticeContent(String.format("%s-%s%s【%s】超出预警!", infoCache.getGridName(), infoCache.getNeighborHoodName(), infoCache.getBuildingName(), categoryName)); resList.add(dto); } return resList;