Commit f7ce1839 by pass商户管理员

Merge branch 'feature/X-Real-IP' into qa

# Conflicts:
#	order-application-service/src/main/java/cn/freemud/controller/ExposureOrderController.java
parents 1db90850 3fac2cd5
package cn.freemud.config;
import cn.freemud.interceptor.FeignInterceptor;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignSupportConfig {
/**
* feign请求拦截器
*
* @return
*/
@Bean
public RequestInterceptor requestInterceptor(){
return new FeignInterceptor();
}
}
package cn.freemud.interceptor;
import cn.freemud.utils.AppLogUtil;
import com.alibaba.fastjson.JSON;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
@Configuration
public class FeignInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
Map<String, String> headers = getHeaders(getHttpServletRequest());
for(String headerName : headers.keySet()){
requestTemplate.header(headerName, getHeaders(getHttpServletRequest()).get(headerName));
}
}
private HttpServletRequest getHttpServletRequest() {
try {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
} catch (Exception e) {
AppLogUtil.errorLog("FeignInterceptor error {}", "","", e);
return null;
}
}
private Map<String, String> getHeaders(HttpServletRequest request) {
Map<String, String> map = new LinkedHashMap<>();
Enumeration<String> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
if(needThisHeader(key)){
String value = request.getHeader(key);
map.put(key, value);
}
}
AppLogUtil.printLog("clientIp for feign client info:" + JSON.toJSONString(map), "","");
return map;
}
private boolean needThisHeader(String headerName){
// TODO:过滤哪些header需要传递,千万不能把所有的header传下去
return true;
}
}
...@@ -121,7 +121,10 @@ public class CalculationSharingEquallyService { ...@@ -121,7 +121,10 @@ public class CalculationSharingEquallyService {
Goods find = null; Goods find = null;
for (CartGoods product : shoppingCartGoodsResponseVo.getProducts()) { for (CartGoods product : shoppingCartGoodsResponseVo.getProducts()) {
if (goods!=null) { if (goods!=null) {
find = goods.stream().filter((k) -> k.getCartGoodsUid().equals(product.getCartGoodsUid())).findFirst().orElseGet(null); Optional<Goods> first = goods.stream().filter((k) -> k.getCartGoodsUid().equals(product.getCartGoodsUid())).findFirst();
if (first.isPresent()) {
find = first.get();
}
} }
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = calculationCommonService.convertCartGoods2DetailGoodsList(find, product,shoppingCartInfoRequestVo.getPartnerId()); ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = calculationCommonService.convertCartGoods2DetailGoodsList(find, product,shoppingCartInfoRequestVo.getPartnerId());
cartGoodsDetailDtoList.add(cartGoodsDetailDto); cartGoodsDetailDtoList.add(cartGoodsDetailDto);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment