From 6627e284863e47ab362010ce6b6166c7d53446dd Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Wed, 5 Jan 2022 09:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/StaffPatrolRecordServiceImpl.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java index 860aa91c3d..bcb27c0410 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java @@ -1,13 +1,17 @@ package com.epmet.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.rocketmq.messages.StaffPatrolMQMsg; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; 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.security.dto.TokenDto; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; @@ -42,9 +46,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -73,6 +75,8 @@ public class StaffPatrolRecordServiceImpl extends BaseServiceImpl orgIds = result.getList().stream().map(PcworkRecordListResultDTO.StaffPatrol::getGridId).collect(Collectors.toList()); - orgIds = orgIds.stream().distinct().collect(Collectors.toList()); - org.setOrgIds(orgIds); - org.setOrgType("grid"); - Result> orgResult = govOrgOpenFeignClient.selectOrgInfo(org); - if (!orgResult.success()) { - throw new RenException("获取网格基础信息失败......"); + //2.查询网格信息并赋值 + Map map = new HashMap<>(); + for (PcworkRecordListResultDTO.StaffPatrol r : result.getList()) { + if (map.containsKey(r.getGridId())) { + r.setGridName(map.get(r.getGridId()).getGridName()); + continue; + } + String redisKey = RedisKeys.getGridInfoKey(r.getGridId()); + Map gridCache = redisUtils.hGetAll(redisKey); + if (gridCache != null && gridCache.size() > 0) { + // 直接取缓存中的 + CustomerGridDTO dto = BeanUtil.mapToBean(gridCache, CustomerGridDTO.class, true); + r.setGridName(dto.getGridName()); + map.put(r.getGridId(), dto); + } else { + CustomerGridFormDTO form = new CustomerGridFormDTO(); + form.setGridId(r.getGridId()); + Result resultGrid = govOrgOpenFeignClient.getGridBaseInfoByGridId(form); + if (!resultGrid.success()) { + throw new RenException("调用org服务获取网格基础信息失败......"); + } + r.setGridName(resultGrid.getData().getGridName()); + map.put(r.getGridId(), resultGrid.getData()); + } } - //3.封装数据并返回 - result.getList().forEach(r -> orgResult.getData().stream().filter(u -> r.getGridId().equals(u.getOrgId())).forEach(u -> r.setGridName(u.getOrgName()))); resultDTO.setTotal((int)result.getTotal()); resultDTO.setList(result.getList()); return resultDTO;