Browse Source

Merge branch 'dev_import' of http://git.elinkit.com.cn:7070/r/epmet-cloud into release_temp

dev
wangxianzhang 4 years ago
parent
commit
c97ad0124c
  1. 8
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java
  2. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignHystrixConcurrencyStrategy.java
  3. 26
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java
  4. 17
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/resolver/LoginUserHandlerMethodArgumentResolver.java
  5. 15
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java

8
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 com.epmet.commons.tools.constant.ThreadLocalConstant;
import feign.RequestInterceptor; import feign.RequestInterceptor;
import feign.RequestTemplate; import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
@ -15,12 +17,16 @@ import java.util.Map;
public class EpmetBaseRequestInterceptor implements RequestInterceptor { public class EpmetBaseRequestInterceptor implements RequestInterceptor {
private static final Logger log = LoggerFactory.getLogger(EpmetBaseRequestInterceptor.class);
@Override @Override
public void apply(RequestTemplate template) { public void apply(RequestTemplate template) {
// 自定义追加的request header,可被子线程继承拷贝 // 自定义追加的request header,可被子线程继承拷贝
Map<String, String> inheritableAdditionalHeaders = ThreadLocalConstant.inheritableAdditionalHeaders.get(); Map<String, String> inheritableAdditionalHeaders = FeignHystrixConcurrencyStrategy.hystrixAdditionHeaders.get();
Map<String, String> requestHeaders = getHeadersFromRequest(); Map<String, String> requestHeaders = getHeadersFromRequest();
log.info("EpmetBaseRequestInterceptor#apply#inheritableAdditionalHeaders:"+inheritableAdditionalHeaders);
if (requestHeaders != null && requestHeaders.size() > 0) { if (requestHeaders != null && requestHeaders.size() > 0) {
for (Map.Entry<String, String> kv : requestHeaders.entrySet()) { for (Map.Entry<String, String> kv : requestHeaders.entrySet()) {
template.header(kv.getKey(), kv.getValue()); template.header(kv.getKey(), kv.getValue());

11
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; package com.epmet.commons.tools.feign;
import com.epmet.commons.tools.constant.ThreadLocalConstant;
import com.netflix.hystrix.HystrixThreadPoolKey; import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties; import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.HystrixPlugins; 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.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import java.util.Map;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -35,6 +37,7 @@ import java.util.concurrent.TimeUnit;
@Component @Component
public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
public static final ThreadLocal<Map<String, String>> hystrixAdditionHeaders = new ThreadLocal<>();
private static final Logger log = LoggerFactory.getLogger(FeignHystrixConcurrencyStrategy.class); private static final Logger log = LoggerFactory.getLogger(FeignHystrixConcurrencyStrategy.class);
private HystrixConcurrencyStrategy delegate; private HystrixConcurrencyStrategy delegate;
@ -74,8 +77,9 @@ public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
@Override @Override
public <T> Callable<T> wrapCallable(Callable<T> callable) { public <T> Callable<T> wrapCallable(Callable<T> callable) {
Map<String, String> inheritableAdditionalHeaders = ThreadLocalConstant.inheritableAdditionalHeaders.get();
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
return new WrappedCallable<>(callable, requestAttributes); return new WrappedCallable<>(callable, requestAttributes, inheritableAdditionalHeaders);
} }
@Override @Override
@ -105,15 +109,18 @@ public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
static class WrappedCallable<T> implements Callable<T> { static class WrappedCallable<T> implements Callable<T> {
private final Callable<T> target; private final Callable<T> target;
private final RequestAttributes requestAttributes; private final RequestAttributes requestAttributes;
private final Map<String, String> inheritableAdditionalHeaders;
public WrappedCallable(Callable<T> target, RequestAttributes requestAttributes) { public WrappedCallable(Callable<T> target, RequestAttributes requestAttributes, Map<String, String> inheritableAdditionalHeaders) {
this.target = target; this.target = target;
this.requestAttributes = requestAttributes; this.requestAttributes = requestAttributes;
this.inheritableAdditionalHeaders = inheritableAdditionalHeaders;
} }
@Override @Override
public T call() throws Exception { public T call() throws Exception {
try { try {
hystrixAdditionHeaders.set(inheritableAdditionalHeaders);
RequestContextHolder.setRequestAttributes(requestAttributes); RequestContextHolder.setRequestAttributes(requestAttributes);
return target.call(); return target.call();
} finally { } finally {

26
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; Integer finalErrorCode = errorCode == null ? result.getCode() : errorCode;
String finalErrorInternalMsg = StringUtils.isBlank(errorInternalMsg) ? result.getInternalMsg() : errorInternalMsg; String finalErrorInternalMsg = StringUtils.isBlank(errorInternalMsg) ? result.getInternalMsg() : errorInternalMsg;
throw new RenException(finalErrorCode, finalErrorInternalMsg, showMsg, RenException.MessageMode.CODE_INTERNAL_EXTERNAL); 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(); return result.getData();
} }

17
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.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
/** /**
@ -80,6 +83,20 @@ public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgu
logger.info("【LoginUserHandlerMethodArgumentResolver】请求uri:{}", requestURI); logger.info("【LoginUserHandlerMethodArgumentResolver】请求uri:{}", requestURI);
// todo delete
Iterator<String> headerNames = request.getHeaderNames();
if (headerNames != null) {
HashMap<String, String> 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 //app-client-userId
String redisKey = request.getHeader(Constant.APP_USER_KEY); String redisKey = request.getHeader(Constant.APP_USER_KEY);
if (StringUtils.isEmpty(redisKey)) { if (StringUtils.isEmpty(redisKey)) {

15
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<Integer, String> checkBoxOptionColumnIdxAndLabel, String currUserAgencyId, Map<Integer, String> checkBoxOptionColumnIdxAndLabel,
String currUserAgencyPids, String currentUserId, String tableName) { String currUserAgencyPids, String currentUserId, String tableName) {
String loginUserApp = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); this.printLog("persistIcResiBaseInfo");
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);
// 遍历每一行,将行内容转化为 // 遍历每一行,将行内容转化为
for (Map<Integer, String> row : dataRows) { for (Map<Integer, String> row : dataRows) {
@ -477,7 +472,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
columnAndValues.put("AGENCY_ID", currUserAgencyId); columnAndValues.put("AGENCY_ID", currUserAgencyId);
columnAndValues.put("PIDS", currUserAgencyPids); 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); columnAndValues.put("UPDATED_BY", currentUserId);
@ -1005,7 +1000,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
List<OptionResultDTO> options = null; List<OptionResultDTO> options = null;
log.info("optionsUrl:{}, currUserAgencyId:{}", pureUri, currUserAgencyId); log.info("optionsUrl:{}, currUserAgencyId:{}", pureUri, currUserAgencyId);
this.printLog("listRemoteOptions");
switch (pureUri) { switch (pureUri) {
case "/epmetuser/icresidemanddict/demandoption": case "/epmetuser/icresidemanddict/demandoption":
options = getResultDataOrThrowsException(epmetUserOpenFeignClient.getDemandOptions(), ServiceConstant.EPMET_USER_SERVER, options = getResultDataOrThrowsException(epmetUserOpenFeignClient.getDemandOptions(), ServiceConstant.EPMET_USER_SERVER,
@ -1045,6 +1040,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
nform.setAgencyId(currUserAgencyId); nform.setAgencyId(currUserAgencyId);
} }
nform.setGridId(gridId); 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); options = getResultDataOrThrowsException(govOrgOpenFeignClient.getNeighborHoodOptions(nform), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null, null);
break; break;
case "/sys/dict/data/education": case "/sys/dict/data/education":

Loading…
Cancel
Save