diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java index f687696494..d19a1145d2 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java @@ -3,6 +3,8 @@ package com.epmet.commons.tools.feign; import com.epmet.commons.tools.constant.ThreadLocalConstant; import feign.RequestInterceptor; import feign.RequestTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -15,12 +17,16 @@ import java.util.Map; public class EpmetBaseRequestInterceptor implements RequestInterceptor { + private static final Logger log = LoggerFactory.getLogger(EpmetBaseRequestInterceptor.class); + @Override public void apply(RequestTemplate template) { // 自定义追加的request header,可被子线程继承拷贝 - Map inheritableAdditionalHeaders = ThreadLocalConstant.inheritableAdditionalHeaders.get(); + Map inheritableAdditionalHeaders = FeignHystrixConcurrencyStrategy.hystrixAdditionHeaders.get(); Map requestHeaders = getHeadersFromRequest(); + log.info("EpmetBaseRequestInterceptor#apply#inheritableAdditionalHeaders:"+inheritableAdditionalHeaders); + if (requestHeaders != null && requestHeaders.size() > 0) { for (Map.Entry kv : requestHeaders.entrySet()) { template.header(kv.getKey(), kv.getValue()); diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignHystrixConcurrencyStrategy.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignHystrixConcurrencyStrategy.java index 5fef2a246d..0d2998ccd3 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignHystrixConcurrencyStrategy.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignHystrixConcurrencyStrategy.java @@ -1,5 +1,6 @@ package com.epmet.commons.tools.feign; +import com.epmet.commons.tools.constant.ThreadLocalConstant; import com.netflix.hystrix.HystrixThreadPoolKey; import com.netflix.hystrix.HystrixThreadPoolProperties; import com.netflix.hystrix.strategy.HystrixPlugins; @@ -17,6 +18,7 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; +import java.util.Map; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.ThreadPoolExecutor; @@ -35,6 +37,7 @@ import java.util.concurrent.TimeUnit; @Component public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { + public static final ThreadLocal> hystrixAdditionHeaders = new ThreadLocal<>(); private static final Logger log = LoggerFactory.getLogger(FeignHystrixConcurrencyStrategy.class); private HystrixConcurrencyStrategy delegate; @@ -74,8 +77,9 @@ public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy @Override public Callable wrapCallable(Callable callable) { + Map inheritableAdditionalHeaders = ThreadLocalConstant.inheritableAdditionalHeaders.get(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); - return new WrappedCallable<>(callable, requestAttributes); + return new WrappedCallable<>(callable, requestAttributes, inheritableAdditionalHeaders); } @Override @@ -105,15 +109,18 @@ public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy static class WrappedCallable implements Callable { private final Callable target; private final RequestAttributes requestAttributes; + private final Map inheritableAdditionalHeaders; - public WrappedCallable(Callable target, RequestAttributes requestAttributes) { + public WrappedCallable(Callable target, RequestAttributes requestAttributes, Map inheritableAdditionalHeaders) { this.target = target; this.requestAttributes = requestAttributes; + this.inheritableAdditionalHeaders = inheritableAdditionalHeaders; } @Override public T call() throws Exception { try { + hystrixAdditionHeaders.set(inheritableAdditionalHeaders); RequestContextHolder.setRequestAttributes(requestAttributes); return target.call(); } finally { diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java index c7da43dc5b..07c2df6679 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java @@ -51,24 +51,24 @@ public interface ResultDataResolver { // 考虑到:上游服务抛出的异常代码和错误消息并不一定适用于当前服务,并且上有服务的错误消息弹出之后可能给用户造成困扰, // 因此,当前服务抛出异常的时候,不再继承上游服务返回的错误码和错误消息 - /*if (!result.success()) { + if (!result.success()) { Integer finalErrorCode = errorCode == null ? result.getCode() : errorCode; String finalErrorInternalMsg = StringUtils.isBlank(errorInternalMsg) ? result.getInternalMsg() : errorInternalMsg; throw new RenException(finalErrorCode, finalErrorInternalMsg, showMsg, RenException.MessageMode.CODE_INTERNAL_EXTERNAL); - }*/ - - if (!result.success()) { - String j = JSON.toJSONString(result); - logger.info("远程调用出错,返回结果:{}", j); - - // 如果不通过参数指定code,则默认使用8000服务器开小差 - Integer finalErrorCode = errorCode == null ? EpmetErrorCode.SERVER_ERROR.getCode() : errorCode; - String finalErrorInternalMsg = StringUtils.isBlank(errorInternalMsg) ? "" : errorInternalMsg; - String finalShowMsg = StringUtils.isBlank(showMsg) ? "" : showMsg; - - throw new EpmetException(finalErrorCode, finalErrorInternalMsg, finalShowMsg); } +// if (!result.success()) { +// String j = JSON.toJSONString(result); +// logger.info("远程调用出错,返回结果:{}", j); +// +// // 如果不通过参数指定code,则默认使用8000服务器开小差 +// Integer finalErrorCode = errorCode == null ? EpmetErrorCode.SERVER_ERROR.getCode() : errorCode; +// String finalErrorInternalMsg = StringUtils.isBlank(errorInternalMsg) ? "" : errorInternalMsg; +// String finalShowMsg = StringUtils.isBlank(showMsg) ? "" : showMsg; +// +// throw new EpmetException(finalErrorCode, finalErrorInternalMsg, finalShowMsg); +// } + return result.getData(); } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/resolver/LoginUserHandlerMethodArgumentResolver.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/resolver/LoginUserHandlerMethodArgumentResolver.java index 79ee2d538a..cdfc906740 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/resolver/LoginUserHandlerMethodArgumentResolver.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/resolver/LoginUserHandlerMethodArgumentResolver.java @@ -34,6 +34,9 @@ import org.springframework.web.servlet.HandlerMapping; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; /** @@ -80,6 +83,20 @@ public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgu logger.info("【LoginUserHandlerMethodArgumentResolver】请求uri:{}", requestURI); + // todo delete + Iterator headerNames = request.getHeaderNames(); + if (headerNames != null) { + HashMap hm = new HashMap<>(); + while (headerNames.hasNext()) { + String name = headerNames.next(); + String[] headerValues = request.getHeaderValues(name); + hm.put(name, String.join(",", headerValues)); + } + + logger.info("LoginUserHandlerMethodArgumentResolver#resolveArgument:"+hm); + + } + //app-client-userId String redisKey = request.getHeader(Constant.APP_USER_KEY); if (StringUtils.isEmpty(redisKey)) { diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java index 7972ddbeef..62b7dbf697 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java @@ -415,12 +415,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String currUserAgencyId, Map checkBoxOptionColumnIdxAndLabel, String currUserAgencyPids, String currentUserId, String tableName) { - String loginUserApp = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); - String loginUserClient = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CLIENT); - String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); - String loginUserCustomerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); - - log.info("persistIcResiBaseInfo:: userId:{}, app:{}, client:{}, customerId:{}", loginUserId, loginUserApp, loginUserClient, loginUserCustomerId); + this.printLog("persistIcResiBaseInfo"); // 遍历每一行,将行内容转化为 for (Map row : dataRows) { @@ -477,7 +472,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res columnAndValues.put("AGENCY_ID", currUserAgencyId); columnAndValues.put("PIDS", currUserAgencyPids); - columnAndValues.put("CUSTOMER_ID", loginUserCustomerId); + columnAndValues.put("CUSTOMER_ID", ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase())); columnAndValues.put("UPDATED_BY", currentUserId); @@ -1005,7 +1000,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res List options = null; log.info("optionsUrl:{}, currUserAgencyId:{}", pureUri, currUserAgencyId); - + this.printLog("listRemoteOptions"); switch (pureUri) { case "/epmetuser/icresidemanddict/demandoption": options = getResultDataOrThrowsException(epmetUserOpenFeignClient.getDemandOptions(), ServiceConstant.EPMET_USER_SERVER, @@ -1045,6 +1040,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res nform.setAgencyId(currUserAgencyId); } nform.setGridId(gridId); + + this.printLog("listRemoteOptions#neighborhoodoption"); + log.info("neighborhoodoption:{},{}", currUserAgencyId, gridId); + options = getResultDataOrThrowsException(govOrgOpenFeignClient.getNeighborHoodOptions(nform), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null, null); break; case "/sys/dict/data/education":