Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
5aec657f
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5aec657f
编写于
3月 20, 2021
作者:
H
haoxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:订单支付流程完成和验证,添加日志
上级
382fc871
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
55 addition
and
37 deletion
+55
-37
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/CartController.java
...va/com/youlai/mall/oms/controller/app/CartController.java
+18
-10
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/OrderController.java
...a/com/youlai/mall/oms/controller/app/OrderController.java
+10
-9
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/listener/OmsListener.java
...c/main/java/com/youlai/mall/oms/listener/OmsListener.java
+4
-3
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java
...va/com/youlai/mall/oms/service/impl/OrderServiceImpl.java
+6
-3
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/common/constant/PmsConstants.java
...ava/com/youlai/mall/pms/common/constant/PmsConstants.java
+1
-1
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java
...a/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java
+14
-10
youlai-common/common-web/src/main/resources/logback-spring.xml
...i-common/common-web/src/main/resources/logback-spring.xml
+2
-1
未找到文件。
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/CartController.java
浏览文件 @
5aec657f
package
com.youlai.mall.oms.controller.app
;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
import
com.youlai.common.result.Result
;
import
com.youlai.mall.oms.pojo.vo.CartVO
;
import
com.youlai.mall.oms.service.ICartService
;
...
...
@@ -27,30 +28,27 @@ public class CartController {
@ApiOperation
(
value
=
"查询购物车"
)
@GetMapping
@ApiOperationSupport
(
order
=
1
)
public
Result
getCart
()
{
CartVO
cart
=
cartService
.
getCart
();
return
Result
.
success
(
cart
);
}
@ApiOperation
(
value
=
"全选/全不选 购物车商品"
)
@ApiImplicitParam
(
name
=
"checked"
,
value
=
"全选/全不选"
,
required
=
true
,
paramType
=
"param"
,
dataType
=
"Boolean"
)
@PatchMapping
(
"/_check"
)
public
Result
check
(
boolean
checked
)
{
boolean
result
=
cartService
.
checkAll
(
checked
);
return
Result
.
judge
(
result
);
}
@ApiOperation
(
value
=
"清空购物车"
)
@ApiOperation
(
value
=
"删除购物车"
)
@DeleteMapping
@ApiOperationSupport
(
order
=
2
)
public
Result
deleteCart
()
{
boolean
result
=
cartService
.
deleteCart
();
return
Result
.
judge
(
result
);
}
@ApiOperation
(
value
=
"添加购物车商品"
)
@ApiImplicitParam
(
name
=
"skuId"
,
value
=
"SKU ID"
,
required
=
true
,
paramType
=
"param"
,
dataType
=
"Long"
)
@PostMapping
@ApiOperationSupport
(
order
=
3
)
public
Result
addCartItem
(
@RequestParam
Long
skuId
)
{
cartService
.
addCartItem
(
skuId
);
return
Result
.
success
();
...
...
@@ -58,20 +56,30 @@ public class CartController {
@ApiOperation
(
value
=
"更新购物车商品"
)
@PutMapping
(
"/skuId/{skuId}"
)
@ApiOperationSupport
(
order
=
4
)
public
Result
updateCartItem
(
@PathVariable
Long
skuId
,
@RequestBody
CartVO
.
CartItem
cartItem
)
{
cartItem
.
setSkuId
(
skuId
);
boolean
result
=
cartService
.
updateCartItem
(
cartItem
);
return
Result
.
judge
(
result
);
}
@ApiOperation
(
value
=
"删除购物车商品"
)
@ApiImplicitParam
(
name
=
"skuId"
,
value
=
"SKU ID"
,
required
=
true
,
paramType
=
"param"
,
dataType
=
"Long"
)
@DeleteMapping
(
"/skuId/{skuId}"
)
@ApiOperationSupport
(
order
=
5
)
public
Result
removeCartItem
(
@PathVariable
Long
skuId
)
{
boolean
result
=
cartService
.
removeCartItem
(
skuId
);
return
Result
.
judge
(
result
);
}
@ApiOperation
(
value
=
"全选/全不选购物车商品"
)
@ApiImplicitParam
(
name
=
"checked"
,
value
=
"全选/全不选"
,
required
=
true
,
paramType
=
"param"
,
dataType
=
"Boolean"
)
@PatchMapping
(
"/_check"
)
@ApiOperationSupport
(
order
=
6
)
public
Result
check
(
boolean
checked
)
{
boolean
result
=
cartService
.
checkAll
(
checked
);
return
Result
.
judge
(
result
);
}
}
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/OrderController.java
浏览文件 @
5aec657f
...
...
@@ -31,9 +31,17 @@ import java.util.List;
public
class
OrderController
{
private
IOrderService
orderService
;
private
IOrderPayService
orderPayService
;
@ApiOperation
(
"订单列表"
)
@GetMapping
@ApiImplicitParam
(
name
=
"status"
,
value
=
"订单状态"
,
required
=
true
,
defaultValue
=
"0"
)
public
Result
<
List
<
OrderListVO
>>
list
(
Integer
status
)
{
List
<
OrderListVO
>
orderList
=
orderService
.
list
(
status
);
return
Result
.
success
(
orderList
);
}
@ApiOperation
(
"订单确认"
)
@ApiImplicitParam
(
name
=
"orderConfirm"
,
value
=
"确认订单信息"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"OrderConfirmDTO"
)
@PostMapping
(
"/_confirm"
)
...
...
@@ -69,12 +77,5 @@ public class OrderController {
return
Result
.
success
();
}
@ApiOperation
(
"订单列表"
)
@GetMapping
public
Result
<
List
<
OrderListVO
>>
list
(
@ApiParam
(
name
=
"status"
,
value
=
"订单状态"
,
required
=
true
,
defaultValue
=
"0"
)
@RequestParam
(
value
=
"status"
,
defaultValue
=
"0"
)
Integer
status
)
{
List
<
OrderListVO
>
orderList
=
orderService
.
list
(
status
);
return
Result
.
success
(
orderList
);
}
}
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/listener/OmsListener.java
浏览文件 @
5aec657f
...
...
@@ -32,17 +32,18 @@ public class OmsListener {
*/
@RabbitListener
(
queues
=
"order.close.queue"
)
public
void
closeOrder
(
String
orderToken
,
Message
message
,
Channel
channel
)
{
log
.
info
(
"=======================订单超时未支付,开始系统自动关闭订单======================="
);
try
{
if
(
orderService
.
closeOrder
(
orderToken
))
{
// 如果关单成功,释放库存
log
.
info
(
"=======================关闭订单成功,开始释放已锁定的库存======================="
);
skuFeignService
.
unlockStock
(
orderToken
);
}
else
{
// 如果关单失败,则订单可能已经被处理,直接手动ACK确认消息
log
.
info
(
"=======================关单失败,订单状态已处理,手动确认消息处理完毕======================="
);
// basicAck(tag,multiple),multiple为true开启批量确认,小于tag值队列中未被消费的消息一次性确认
channel
.
basicAck
(
message
.
getMessageProperties
().
getDeliveryTag
(),
true
);
}
}
catch
(
IOException
e
)
{
// 消费失败后,重新入队
log
.
info
(
"=======================系统自动关闭订单消息消费失败,重新入队======================="
);
try
{
channel
.
basicReject
(
message
.
getMessageProperties
().
getDeliveryTag
(),
true
);
}
catch
(
IOException
ioException
)
{
...
...
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java
浏览文件 @
5aec657f
...
...
@@ -64,6 +64,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
*/
@Override
public
OrderConfirmVO
confirm
(
OrderConfirmDTO
orderConfirmDTO
)
{
log
.
info
(
"=======================订单确认======================="
);
OrderConfirmVO
orderConfirmVO
=
new
OrderConfirmVO
();
Long
memberId
=
RequestUtils
.
getUserId
();
// 获取购买商品信息
...
...
@@ -111,6 +112,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
},
threadPoolExecutor
);
CompletableFuture
.
allOf
(
orderItemsCompletableFuture
,
addressesCompletableFuture
,
orderTokenCompletableFuture
).
join
();
log
.
info
(
"获取确认信息"
,
orderConfirmVO
.
toString
());
return
orderConfirmVO
;
}
...
...
@@ -120,7 +122,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
@Override
@GlobalTransactional
public
OrderSubmitVO
submit
(
OrderSubmitDTO
submitDTO
)
{
log
.
info
(
"=======================订单提交======================="
);
// 订单重复提交校验
String
orderToken
=
submitDTO
.
getOrderToken
();
DefaultRedisScript
<
Long
>
redisScript
=
new
DefaultRedisScript
<>(
RELEASE_LOCK_LUA_SCRIPT
,
Long
.
class
);
...
...
@@ -188,6 +190,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
OrderSubmitVO
submitVO
=
new
OrderSubmitVO
();
submitVO
.
setOrderId
(
order
.
getId
());
submitVO
.
setOrderSn
(
order
.
getOrderSn
());
log
.
info
(
"订单提交返回结果:{}"
,
submitVO
.
toString
());
return
submitVO
;
}
...
...
@@ -259,10 +262,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
@Override
public
OmsOrder
getByOrderId
(
Long
id
)
{
Long
us
erId
=
RequestUtils
.
getUserId
();
Long
memb
erId
=
RequestUtils
.
getUserId
();
OmsOrder
order
=
this
.
getOne
(
new
LambdaQueryWrapper
<
OmsOrder
>()
.
eq
(
OmsOrder:
:
getId
,
id
)
.
eq
(
OmsOrder:
:
getMemberId
,
us
erId
));
.
eq
(
OmsOrder:
:
getMemberId
,
memb
erId
));
if
(
order
==
null
)
{
throw
new
BizException
(
"订单不存在,订单ID非法"
);
}
...
...
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/common/constant/PmsConstants.java
浏览文件 @
5aec657f
...
...
@@ -6,7 +6,7 @@ package com.youlai.mall.pms.common.constant;
*/
public
interface
PmsConstants
{
String
STOCK_LOCKED
_PREFIX
=
"stock:locked:"
;
String
LOCKED_STOCK
_PREFIX
=
"stock:locked:"
;
String
LOCK_SKU_PREFIX
=
"lock:sku:"
;
}
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java
浏览文件 @
5aec657f
...
...
@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.youlai.common.web.exception.BizException
;
import
com.youlai.mall.pms.common.constant.PmsConstants
;
import
com.youlai.mall.pms.mapper.PmsSkuMapper
;
import
com.youlai.mall.pms.pojo.domain.PmsSku
;
import
com.youlai.mall.pms.pojo.dto.SkuDTO
;
...
...
@@ -24,8 +23,8 @@ import org.springframework.stereotype.Service;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
static
com
.
youlai
.
mall
.
pms
.
common
.
constant
.
PmsConstants
.
LOCKED_STOCK_PREFIX
;
import
static
com
.
youlai
.
mall
.
pms
.
common
.
constant
.
PmsConstants
.
LOCK_SKU_PREFIX
;
import
static
com
.
youlai
.
mall
.
pms
.
common
.
constant
.
PmsConstants
.
STOCK_LOCKED_PREFIX
;
@Service
@Slf4j
...
...
@@ -41,7 +40,8 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
*/
@Override
public
boolean
lockStock
(
List
<
SkuLockDTO
>
skuLockList
)
{
log
.
info
(
"=======================创建订单,开始锁定商品库存======================="
);
log
.
info
(
"锁定商品信息:{}"
,
skuLockList
.
toString
());
if
(
CollectionUtil
.
isEmpty
(
skuLockList
))
{
throw
new
BizException
(
"锁定的商品列表为空"
);
}
...
...
@@ -80,7 +80,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
// 将锁定的商品保存至Redis中
String
orderToken
=
skuLockList
.
get
(
0
).
getOrderToken
();
redisTemplate
.
opsForValue
().
set
(
STOCK_LOCKED
_PREFIX
+
orderToken
,
JSONUtil
.
toJsonStr
(
skuLockList
));
redisTemplate
.
opsForValue
().
set
(
LOCKED_STOCK
_PREFIX
+
orderToken
,
JSONUtil
.
toJsonStr
(
skuLockList
));
return
true
;
}
...
...
@@ -89,7 +89,9 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
*/
@Override
public
boolean
unlockStock
(
String
orderToken
)
{
String
json
=
redisTemplate
.
opsForValue
().
get
(
STOCK_LOCKED_PREFIX
+
orderToken
);
log
.
info
(
"=======================订单超时未支付系统自动关单释放库存======================="
);
String
json
=
redisTemplate
.
opsForValue
().
get
(
LOCKED_STOCK_PREFIX
+
orderToken
);
log
.
info
(
"释放库存信息:{}"
,
json
);
if
(
StrUtil
.
isNotBlank
(
json
))
{
return
true
;
}
...
...
@@ -103,7 +105,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
);
// 删除redis中锁定的库存
redisTemplate
.
opsForValue
().
decrement
(
STOCK_LOCKED
_PREFIX
+
orderToken
);
redisTemplate
.
delete
(
LOCKED_STOCK
_PREFIX
+
orderToken
);
return
true
;
}
...
...
@@ -112,7 +114,9 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
*/
@Override
public
boolean
deductStock
(
String
orderToken
)
{
String
json
=
redisTemplate
.
opsForValue
().
get
(
STOCK_LOCKED_PREFIX
+
orderToken
);
log
.
info
(
"=======================支付成功扣减订单中商品库存======================="
);
String
json
=
redisTemplate
.
opsForValue
().
get
(
LOCKED_STOCK_PREFIX
+
orderToken
);
log
.
info
(
"订单商品信息:{}"
,
json
);
if
(
StrUtil
.
isBlank
(
json
))
{
return
true
;
}
...
...
@@ -131,7 +135,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
});
// 删除redis中锁定的库存
redisTemplate
.
opsForValue
().
decrement
(
STOCK_LOCKED
_PREFIX
+
orderToken
);
redisTemplate
.
delete
(
LOCKED_STOCK
_PREFIX
+
orderToken
);
return
true
;
}
...
...
@@ -148,7 +152,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
public
Integer
getStockById
(
Long
id
)
{
Integer
stock
=
0
;
// 读->缓存
Object
cacheVal
=
redisTemplate
.
opsForValue
().
get
(
STOCK_LOCKED
_PREFIX
+
id
);
Object
cacheVal
=
redisTemplate
.
opsForValue
().
get
(
LOCKED_STOCK
_PREFIX
+
id
);
if
(
cacheVal
!=
null
)
{
stock
=
Convert
.
toInt
(
cacheVal
);
return
stock
;
...
...
@@ -162,7 +166,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
if
(
pmsSku
!=
null
)
{
stock
=
pmsSku
.
getStock
();
// 写->缓存
redisTemplate
.
opsForValue
().
set
(
PmsConstants
.
STOCK_LOCKED
_PREFIX
+
id
,
String
.
valueOf
(
stock
));
redisTemplate
.
opsForValue
().
set
(
LOCKED_STOCK
_PREFIX
+
id
,
String
.
valueOf
(
stock
));
}
return
stock
;
...
...
youlai-common/common-web/src/main/resources/logback-spring.xml
浏览文件 @
5aec657f
...
...
@@ -60,7 +60,8 @@
</logger>
<!-- 根logger -->
<root
level=
"INFO"
>
<root>
<level>
INFO
</level>
<appender-ref
ref=
"CONSOLE"
/>
</root>
</configuration>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录