package com.atguigu.gulimall.order.service.impl;
import com.alibaba.fastjson.TypeReference;
import com.atguigu.common.exception.NoStockException;
import com.atguigu.common.to.mq.OrderTo;
import com.atguigu.common.to.mq.SeckillOrderTo;
import com.atguigu.common.utils.R;
import com.atguigu.common.vo.MemberRespVo;
//import com.atguigu.gulimall.order.feign.CartFeignService;
//import com.atguigu.gulimall.order.feign.MemberFeignService;
//import com.atguigu.gulimall.order.interceptor.LoginUserInterceptor;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.constant.OrderConstant;
import com.atguigu.gulimall.order.dao.OrderItemDao;
import com.atguigu.gulimall.order.entity.OrderItemEntity;
import com.atguigu.gulimall.order.entity.PaymentInfoEntity;
import com.atguigu.gulimall.order.enume.OrderStatusEnum;
import com.atguigu.gulimall.order.feign.CartFeignService;
import com.atguigu.gulimall.order.feign.MemberFeignService;
import com.atguigu.gulimall.order.feign.ProductFeignService;
import com.atguigu.gulimall.order.feign.WmsFeignService;
import com.atguigu.gulimall.order.interceptor.LoginUserInterceptor;
import com.atguigu.gulimall.order.service.OrderItemService;
import com.atguigu.gulimall.order.service.PaymentInfoService;
import com.atguigu.gulimall.order.to.OrderCreateTo;
import com.atguigu.gulimall.order.vo.*;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.atguigu.gulimall.order.dao.OrderDao;
import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.service.OrderService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {
private ThreadLocal<OrderSubmitVo> confirmVoThreadLocal = new ThreadLocal<>();
@Autowired
OrderDao orderDao;
@Autowired
OrderItemDao orderItemDao;
@Autowired
MemberFeignService memberFeignService;
@Autowired
CartFeignService cartFeignService;
@Autowired
ThreadPoolExecutor threadPoolExecutor;
@Autowired
WmsFeignService wmsFeignService;
@Autowired
RabbitTemplate rabbitTemplate;
@Autowired
StringRedisTemplate redisTemplate;
@Autowired
ProductFeignService productFeignService;
@Autowired
PaymentInfoService paymentInfoService;
@Autowired
OrderItemService orderItemService;
@Autowired
AlipayTemplate alipayTemplate;
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<OrderEntity> page = this.page(
new Query<OrderEntity>().getPage(params),
new QueryWrapper<OrderEntity>()
);
return new PageUtils(page);
}
@Override
public OrderConfirmVo confirmOrder() throws ExecutionException, InterruptedException {
OrderConfirmVo orderConfirmVo = new OrderConfirmVo();
MemberRespVo memberRespVo = LoginUserInterceptor.threadLocal.get();
System.out.println("herer");
//每一个线程都来共享之前的请求数据
//每一个线程都来共享之前的请求数据
//1、远程查询收获列表
//获取之前的请求
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
CompletableFuture<Void> getAddress = CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
List<MemberAddressVo> address = memberFeignService.getAddress(memberRespVo.getId());//会员id
orderConfirmVo.setAddressVos(address);
System.out.println("微服务地址" + address);
}, threadPoolExecutor);
//2、远程查询购物车所有选定的购物项
CompletableFuture<Void> getItems = CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
List<OrderItemVo> currentUserCartItems = cartFeignService.getCurrentUserCartItems();
orderConfirmVo.setItems(currentUserCartItems);
}, threadPoolExecutor).thenRunAsync(() -> {
List<OrderItemVo> items = orderConfirmVo.getItems();
List<Long> collect = items.stream().map(item -> item.getSkuId()).collect(Collectors.toList());
R skusHasStock = wmsFeignService.getSkusHasStock(collect);
List<SkuStockVo> data = skusHasStock.getData(new TypeReference<List<SkuStockVo>>() {
});
if (data != null) {
Map<Long, Boolean> map = data.stream().collect(Collectors.toMap(SkuStockVo::getSkuId, SkuStockVo::getHasStock));
orderConfirmVo.setStocks(map);
}
});
//在远程调用之前,会调用很多的拦截器 创建一个新的request请求
//http1.1协议
//请求头中也根本没有数据 丢失请求头
// 有很多拦截器可以增强,但是feign中没有拦截器,需要我们自己构造一个拦截器,调用apply
//拦截器拦截后,重新调用
//
//3、查询用户积分
Integer integration = memberRespVo.getIntegration();
orderConfirmVo.setIntegration(integration);
//其他数据自动计算
CompletableFuture.allOf(getAddress, getItems).get();
// 防重令牌
String token = UUID.randomUUID().toString().replace("-", "");
redisTemplate.opsForValue().set(OrderConstant.USER_ORDER_TOKEN_PREFIX + memberRespVo.getId(), token, 30, TimeUnit.MINUTES);
orderConfirmVo.setOrderToken(token);
return orderConfirmVo;
}
//下单操作
@Transactional //本地事物,在分布式系统,只能控制自己的回滚,控制不了其他服务的回滚。
//分布式事物:最大愿意:网络问题。 分布式机器,
@Override
public SubmitOrderResponseVo submitOrder(OrderSubmitVo vo) {
SubmitOrderResponseVo responseVo = new SubmitOrderResponseVo();
MemberRespVo memberRespVo = LoginUserInterceptor.threadLocal.get();
responseVo.setCode(0);
confirmVoThreadLocal.set(vo);
//下单
//1、验证令牌(原子性)
//0令牌失败 1令牌正确 删除成功
String script = "if redis.call('get',KEY[1])==ARGV[1] then return redis.call('del',KETS[1] else return 0 ";
String orderToken = vo.getOrderToken();
Long result = redisTemplate.execute(new DefaultRedisScript<Long>(script, Long.class), Arrays.asList(OrderConstant.USER_ORDER_TOKEN_PREFIX + memberRespVo.getId()));
//原子验证令牌和删除令牌
if (result == 0L) {
//令牌验证失败
responseVo.setCode(1);
return responseVo;
} else {
//令牌验证成功
/
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot和SpringCloud Alibaba的Java高并发区块链保税商品交易系统设计源码
共1094个文件
java:706个
xml:98个
vue:96个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 115 浏览量
2024-10-04
11:57:15
上传
评论
收藏 10.93MB ZIP 举报
温馨提示
本项目为基于SpringBoot和SpringCloud Alibaba框架构建的Java高并发区块链保税商品交易系统,源码共计1095个文件。其中,包含706个Java源文件、98个XML配置文件、96个Vue组件文件、38个JavaScript文件、27个属性文件、22个HTML文件、17个YAML文件、16个CSS样式文件、11个PNG图片文件和11个VM模板文件。系统采用多语言开发,支持Java、Vue、JavaScript和HTML/CSS技术栈,旨在实现高效、安全的保税商品交易管理。
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot和SpringCloud Alibaba的Java高并发区块链保税商品交易系统设计源码 (1094个子文件)
bootstrap.min.css 118KB
AdminLTE.min.css 88KB
screen.css 43KB
print.css 41KB
all-skins.min.css 40KB
font-awesome.min.css 30KB
swagger-ui.css 26KB
ui.jqgrid-bootstrap.css 18KB
ui.jqgrid.css 17KB
layer.css 14KB
layer.css 5KB
style.css 3KB
style.css 3KB
main.css 1KB
reset.css 773B
ui.jqgrid-bootstrap-ui.css 662B
typography.css 0B
Dockerfile 134B
fontawesome-webfont.eot 162KB
glyphicons-halflings-regular.eot 20KB
throbber.gif 9KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
expand.gif 73B
collapse.gif 69B
.gitignore 327B
reg.html 460KB
list.html 102KB
item.html 72KB
detail.html 46KB
list.html 34KB
orderList.html 34KB
confirm.html 34KB
cartList.html 24KB
index.html 22KB
login.html 7KB
pay.html 6KB
success.html 5KB
success.html 4KB
index.html 4KB
index.html 4KB
oauth2-redirect.html 2KB
generator.html 1KB
main.html 1KB
o2c.html 479B
login.html 409B
list.html 267B
list.html 267B
favicon.ico 5KB
favicon.ico 4KB
favicon.ico 4KB
gulimall-common.iml 38KB
gulimall.iml 3KB
gulimall.ipr 5KB
gulimall.iws 20KB
javax.persistence.jar 127KB
javax.servlet.jsp.jar 77KB
javax.servlet.jar 68KB
javax.ejb.jar 46KB
javax.resource.jar 43KB
javax.servlet.jsp.jstl.jar 27KB
javax.jms.jar 25KB
javax.transaction.jar 9KB
OrderServiceImpl.java 21KB
HTMLFilter.java 20KB
HTMLFilter.java 20KB
CategoryServiceImpl.java 17KB
MallSearchServiceImpl.java 17KB
GenUtils.java 14KB
SpuInfoServiceImpl.java 13KB
SecKillServiceImpl.java 12KB
WareSkuServiceImpl.java 12KB
MongoScanner.java 12KB
AttrServiceImpl.java 11KB
HttpUtils.java 10KB
CartServiceImpl.java 8KB
GulimallAuthServerApplicationTests.java 8KB
ThreadTest.java 8KB
SmsComponent.java 8KB
AlipayTemplate.java 7KB
PurchaseServiceImpl.java 6KB
LoginController.java 6KB
SkuInfoServiceImpl.java 6KB
MemberServiceImpl.java 6KB
DataSourceProperties.java 5KB
ScheduleUtils.java 5KB
SysMenuController.java 5KB
DateUtils.java 5KB
MyRabbitConfig.java 4KB
SysUserServiceImpl.java 4KB
AttrGroupController.java 4KB
XssHttpServletRequestWrapper.java 4KB
OssController.java 4KB
OrderEntity.java 4KB
ScheduleJobServiceImpl.java 4KB
OAuth2Controller.java 4KB
MemberController.java 4KB
CartController.java 4KB
SysUserController.java 4KB
共 1094 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
wjs2024
- 粉丝: 2368
- 资源: 5478
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功