fix(common-web): 引入Apache HttpClient替换Feign原生的HttpURLConnection修复feign转发请求头拦截器写入输出流报错

Closes I40PH7
This commit is contained in:
有来技术 2021-08-14 19:14:02 +08:00
parent 0e81424236
commit c1288de2d2
8 changed files with 34 additions and 63 deletions

View File

@ -61,7 +61,7 @@
| 微服务后台 | [youlai-mall](https://gitee.com/youlaitech/youlai-mall) | 微信小程序 | [youlai-mall-weapp](https://gitee.com/youlaitech/youlai-mall-weapp) |
| 管理前端 | [youlai-mall-admin](https://gitee.com/youlaitech/youlai-mall-admin) |APP应用 | [youlai-mall-app](https://gitee.com/youlaitech/youlai-mall-app) |
#### 项目结构
#### 项目结构
``` lua
youlai-mall
@ -174,6 +174,8 @@ youlai-mall
## 联系信息
因为微信交流群满200人只能通过邀请进入如果想进入交流群学习可添加以下开发人员备注“**有来**“由其拉进群。
| ![](https://gitee.com/haoxr/image/raw/master/default/113__6c5ed5b1b73ea9cd4cf32848ed350c07_b9b214638a2a406e52dbf51e9bf9a2ef.png) | ![](https://gitee.com/haoxr/image/raw/master/hxr.jpg) | ![](https://gitee.com/haoxr/image/raw/master/huawei.jpg) | ![](https://gitee.com/haoxr/image/raw/master/default/1625149769(1).png) |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ![](https://gitee.com/haoxr/image/raw/master/default/7488479b1e2c193b04b56d1e0ff640c.jpg) | ![image-20210701232803265](https://gitee.com/haoxr/image/raw/master/default/image-20210701232803265.png) | ![](https://gitee.com/haoxr/image/raw/master/default/20210701234946.png) | ![](https://gitee.com/haoxr/image/raw/master/default/image-20210702002909113.png) |

Binary file not shown.

View File

@ -138,7 +138,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
orderConfirmVO.setAddresses(addresses);
}, threadPoolExecutor);
// 生成唯一标识防止订单重复提交
CompletableFuture<Void> orderTokenCompletableFuture = CompletableFuture.runAsync(() -> {
String orderToken = businessNoGenerator.generate(BusinessTypeEnum.ORDER);
@ -155,6 +154,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
* 订单提交
*/
@Override
@GlobalTransactional
public OrderSubmitVO submit(OrderSubmitDTO submitDTO) {
log.info("=======================订单提交=======================\n订单提交信息{}", submitDTO);
// 订单重复提交校验
@ -311,15 +311,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
if (!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
throw new BizException("支付失败,请检查订单状态");
}
Long userId = JwtUtils.getUserId();
T result;
switch (payTypeEnum) {
case WEIXIN_JSAPI:
result = (T) wxJsapiPay(appId, order, userId);
result = (T) wxJsapiPay(appId, order);
break;
default:
case BALANCE:
result = (T) balancePay(order, userId);
result = (T) balancePay(order);
}
// 扣减库存
@ -334,10 +333,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
return result;
}
private Boolean balancePay(OmsOrder order, Long userId) {
private Boolean balancePay(OmsOrder order) {
// 扣减余额
Long payAmount = order.getPayAmount();
Result<?> deductBalanceResult = memberFeignClient.deductBalance(userId, payAmount);
Result<?> deductBalanceResult = memberFeignClient.deductBalance(payAmount);
if (!Result.isSuccess(deductBalanceResult)) {
throw new BizException("扣减账户余额失败");
}
@ -353,7 +352,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
return Boolean.TRUE;
}
private WxPayUnifiedOrderV3Result.JsapiResult wxJsapiPay(String appId, OmsOrder order, Long userId) {
private WxPayUnifiedOrderV3Result.JsapiResult wxJsapiPay(String appId, OmsOrder order) {
Long userId = JwtUtils.getUserId();
Result<UmsMember> userInfoResult = memberFeignClient.getUserEntityById(userId);
if (!Result.isSuccess(userInfoResult)) {
throw new BizException("用户查询失败");

View File

@ -34,24 +34,11 @@ public interface MemberFeignClient {
@GetMapping("/app-api/v1/members/openid/{openid}")
Result<UmsMember> getByOpenid(@PathVariable String openid);
/**
* 修改会员积分
*/
@PutMapping("/app-api/v1/members/{id}/points")
<T> Result<T> updatePoint(@PathVariable Long id, @RequestParam Integer num);
/**
* 扣减会员余额
*/
@PutMapping("/app-api/v1/members/{id}/deduct-balance")
<T> Result<T> deductBalance(@PathVariable Long id, @RequestParam Long balance);
/**
* 获取会员余额
*/
@GetMapping("/app-api/v1/members/{id}/balance")
Result<Long> getBalance(@PathVariable Long id);
@PutMapping("/app-api/v1/members/current/balances/_deduct")
<T> Result<T> deductBalance( @RequestParam Long balances);
/**
* 添加浏览记录
*/

View File

@ -88,7 +88,6 @@ public class MemberController {
}
@ApiOperation(value = "修改会员")
@ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember")
@PutMapping("/{id}")
public <T> Result<T> add(@PathVariable Long id, @RequestBody UmsMember user) {
boolean status = iUmsMemberService.updateById(user);
@ -110,10 +109,6 @@ public class MemberController {
@ApiOperation(value = "修改会员积分")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "num", value = "积分数量", required = true, paramType = "query", dataType = "Integer")
})
@PutMapping("/{id}/points")
public <T> Result<T> updatePoint(@PathVariable Long id, @RequestParam Integer num) {
UmsMember user = iUmsMemberService.getById(id);
@ -123,31 +118,16 @@ public class MemberController {
}
@ApiOperation(value = "扣减会员余额")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "balance", value = "会员余额", required = true, paramType = "query", dataType = "Long")
})
@PutMapping("/{id}/deduct-balance")
public <T> Result<T> updateBalance(@PathVariable Long id, @RequestParam Long balance) {
@PutMapping("/current/balances/_deduct")
public <T> Result<T> deductBalance(@RequestParam Long balances) {
Long userId = JwtUtils.getUserId();
boolean result = iUmsMemberService.update(new LambdaUpdateWrapper<UmsMember>()
.setSql("balance = balance - " + balance)
.eq(UmsMember::getId, id)
.setSql("balance = balance - " + balances)
.eq(UmsMember::getId, userId)
);
return Result.judge(result);
}
@ApiOperation(value = "获取会员余额")
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}/balance")
public Result<Long> updateBalance(@PathVariable Long id) {
Long balance = 0L;
UmsMember user = iUmsMemberService.getById(id);
if (user != null) {
balance = user.getBalance();
}
return Result.success(balance);
}
@ApiOperation(value = "添加浏览历史")
@PostMapping("/view/history")
public <T> Result<T> addProductViewHistory(@RequestBody ProductHistoryVO product) {

View File

@ -54,11 +54,15 @@
<artifactId>dozer-core</artifactId>
</dependency>
<!--TODO feign远程调用返回报错-->
<!-- <dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
</dependency>-->
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,4 @@
/*
package com.youlai.common.web.config;
import feign.RequestInterceptor;
@ -12,36 +12,33 @@ import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
*/
/**
* Feign相关配置类
*
*
* @author Gadfly
* @since 2021-08-06 9:47
*//*
*/
@Configuration
public class FeignConfig {
*/
/**
/**
* 让DispatcherServlet向子线程传递RequestContext
*
* @param servlet servlet
* @return 注册bean
*//*
*/
@Bean
public ServletRegistrationBean<DispatcherServlet> dispatcherRegistration(DispatcherServlet servlet) {
servlet.setThreadContextInheritable(true);
return new ServletRegistrationBean<>(servlet, "/**");
}
*/
/**
/**
* 覆写拦截器在feign发送请求前取出原来的header并转发
*
* @return 拦截器
*//*
*/
@Bean
public RequestInterceptor requestInterceptor() {
@ -62,4 +59,4 @@ public class FeignConfig {
};
}
}
*/

View File

@ -1,4 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.youlai.common.web.config.WebMvcConfig,\
com.youlai.common.web.config.FeignConfig,\
com.youlai.common.web.exception.GlobalExceptionHandler,\
com.youlai.common.web.aspect.LoginLogAspect