From 54acd649311ea0f50d16220afa58707b8bc997ec Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 18 Aug 2021 17:04:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9:CPAuthxxx=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8D=B0header=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E7=BB=99gateway=E6=97=A5=E5=BF=97=E7=BB=91=E5=AE=9Atr?= =?UTF-8?q?anSerail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/CpAuthGatewayFilterFactory.java | 60 +++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java index 6513d27f04..538467d2e1 100644 --- a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java +++ b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java @@ -68,18 +68,25 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory tranSerials = request.getHeaders().get(AppClientConstant.TRANSACTION_SERIAL_KEY); - if (CollectionUtils.isEmpty(tranSerials) || StringUtils.isBlank(tranSerials.get(0))) { - request.mutate().header(AppClientConstant.TRANSACTION_SERIAL_KEY, new String[]{getTransactionSerial()}); + + //0.添加流水号 + String tranSerial = getTranserialFromRequestHeader(request); + if (StringUtils.isBlank(tranSerial)) { + tranSerial = generateTransactionSerial(); + // 设置当前线程名 + request.mutate().header(AppClientConstant.TRANSACTION_SERIAL_KEY, new String[]{tranSerial}); } + Thread.currentThread().setName(tranSerial); + + //1.打印请求信息 + logRequest(request); //2.获取请求路径,参数 String requestUri = request.getPath().pathWithinApplication().value(); MultiValueMap queryParams = request.getQueryParams(); String queryParamsStr = convertQueryParams2String(queryParams); - logger.info("CpAuthGatewayFilterFactory当前requestUri=[" + requestUri.concat(queryParamsStr) + "],CpAuthGatewayFilterFactory拦截成功,客户端Id:{}", IpUtils.getClientIp(request)); + logger.info("当前requestUri=[" + requestUri.concat(queryParamsStr) + "],客户端Id:{}", IpUtils.getClientIp(request)); //3.认证 String authType = getAuthType(request); @@ -109,6 +116,36 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory> entry : headers.entrySet()) { + String headerKey = entry.getKey(); + List headerValue = entry.getValue(); + sb.append(headerKey).append(":").append(headerValue).append(","); + } + logger.info(sb.toString()); + } + + /** + * @Description 从request请求头中获取传递过来的流水号 + * @param request + * @return java.lang.String + * @author wxz + * @date 2021.08.18 15:55:30 + */ + private String getTranserialFromRequestHeader(ServerHttpRequest request) { + List tranSerials = request.getHeaders().get(AppClientConstant.TRANSACTION_SERIAL_KEY); + return CollectionUtils.isEmpty(tranSerials) ? null : tranSerials.get(0); + } + /** * @return * @Description 将url参数转化为String @@ -181,23 +218,12 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory Date: Thu, 19 Aug 2021 13:58:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E6=9F=A5=E8=AF=A2=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E4=BA=BA=E5=A4=A7=E4=BB=A3=E8=A1=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=AE=A2=E6=88=B7=E4=B8=8B=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=BA=BA=E5=A4=A7=E4=BB=A3=E8=A1=A8=EF=BC=8C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=A9=BA=E5=88=97=E8=A1=A8=EF=BC=8C=E8=80=8C=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2org=E6=9C=8D=E5=8A=A1,=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/service/impl/ResiEventServiceImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/epmet-module/resi-home/resi-home-server/src/main/java/com/epmet/service/impl/ResiEventServiceImpl.java b/epmet-module/resi-home/resi-home-server/src/main/java/com/epmet/service/impl/ResiEventServiceImpl.java index bd6a1c4376..295c8bb6a1 100644 --- a/epmet-module/resi-home/resi-home-server/src/main/java/com/epmet/service/impl/ResiEventServiceImpl.java +++ b/epmet-module/resi-home/resi-home-server/src/main/java/com/epmet/service/impl/ResiEventServiceImpl.java @@ -13,6 +13,7 @@ import com.epmet.enums.OrgLevelEnums; import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.service.ResiEventService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -44,6 +45,8 @@ public class ResiEventServiceImpl implements ResiEventService, ResultDataResolve //String parentAgencyId = gridInfoData.getParentAgencyId(); //String pids = gridInfoData.getPids(); + List npcResultList = new ArrayList<>(); + //查询人大代表列表 ListUserByBadgeFormDTO npcForm = new ListUserByBadgeFormDTO(customerId, BadgeConstant.BADGE_KEY_NPC); Result> npcResult = epmetUserOpenFeignClient.listUsersByBadge(npcForm); @@ -55,9 +58,13 @@ public class ResiEventServiceImpl implements ResiEventService, ResultDataResolve Result> npcGridInfoResult = govOrgOpenFeignClient.selectOrgInfo(form); List npcGridInfos = getResultDataOrThrowsException(npcGridInfoResult, ServiceConstant.GOV_ORG_SERVER, null, null); + if(CollectionUtils.isEmpty(npcGridInfos)) { + // 没有人大代表,直接返回空列表即可 + return npcResultList; + } + Map npcGridInfoMap = convertNpcGridInfos2Map(npcGridInfos); - List npcResultList = new ArrayList<>(); npcData.stream().forEach(npc -> { if (StringUtils.isBlank(excludeUserId) || !npc.getUserId().equals(excludeUserId)) { OrgInfoResultDTO gridInfo = npcGridInfoMap.get(npc.getGridId());