Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
51958add
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,体验更适合开发者的 AI 搜索 >>
提交
51958add
编写于
7月 31, 2022
作者:
郝
郝先瑞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 自定义异常类重命名
上级
6ca4ee3f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
57 addition
and
23 deletion
+57
-23
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java
...ava/com/youlai/mall/oms/service/impl/CartServiceImpl.java
+6
-6
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java
...va/com/youlai/mall/oms/service/impl/OrderServiceImpl.java
+10
-10
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java
...a/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java
+2
-2
youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java
...urity/extension/mobile/SmsCodeAuthenticationProvider.java
+2
-3
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java
...va/com/youlai/common/web/exception/BusinessException.java
+35
-0
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
...m/youlai/common/web/exception/GlobalExceptionHandler.java
+2
-2
未找到文件。
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java
浏览文件 @
51958add
...
...
@@ -3,7 +3,7 @@ package com.youlai.mall.oms.service.impl;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.lang.Assert
;
import
com.youlai.common.result.ResultCode
;
import
com.youlai.common.web.exception.B
iz
Exception
;
import
com.youlai.common.web.exception.B
usiness
Exception
;
import
com.youlai.common.web.util.MemberUtils
;
import
com.youlai.mall.oms.constant.OmsConstants
;
import
com.youlai.mall.oms.pojo.dto.CartItemDTO
;
...
...
@@ -64,7 +64,7 @@ public class CartServiceImpl implements ICartService {
try
{
memberId
=
MemberUtils
.
getMemberId
();
}
catch
(
Exception
e
)
{
throw
new
B
iz
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
throw
new
B
usiness
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
}
BoundHashOperations
cartHashOperations
=
getCartHashOperations
(
memberId
);
String
hKey
=
skuId
+
""
;
...
...
@@ -105,7 +105,7 @@ public class CartServiceImpl implements ICartService {
try
{
memberId
=
MemberUtils
.
getMemberId
();
}
catch
(
Exception
e
)
{
throw
new
B
iz
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
throw
new
B
usiness
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
}
BoundHashOperations
cartHashOperations
=
getCartHashOperations
(
memberId
);
String
hKey
=
cartItem
.
getSkuId
()
+
""
;
...
...
@@ -131,7 +131,7 @@ public class CartServiceImpl implements ICartService {
try
{
memberId
=
MemberUtils
.
getMemberId
();
}
catch
(
Exception
e
)
{
throw
new
B
iz
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
throw
new
B
usiness
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
}
BoundHashOperations
cartHashOperations
=
getCartHashOperations
(
memberId
);
String
hKey
=
skuId
+
""
;
...
...
@@ -149,7 +149,7 @@ public class CartServiceImpl implements ICartService {
try
{
memberId
=
MemberUtils
.
getMemberId
();
}
catch
(
Exception
e
)
{
throw
new
B
iz
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
throw
new
B
usiness
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
}
BoundHashOperations
cartHashOperations
=
getCartHashOperations
(
memberId
);
for
(
Object
value
:
cartHashOperations
.
values
())
{
...
...
@@ -172,7 +172,7 @@ public class CartServiceImpl implements ICartService {
try
{
memberId
=
MemberUtils
.
getMemberId
();
}
catch
(
Exception
e
)
{
throw
new
B
iz
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
throw
new
B
usiness
Exception
(
ResultCode
.
TOKEN_INVALID_OR_EXPIRED
);
}
BoundHashOperations
cartHashOperations
=
getCartHashOperations
(
memberId
);
for
(
Object
value
:
cartHashOperations
.
values
())
{
...
...
mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java
浏览文件 @
51958add
...
...
@@ -24,7 +24,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
import
com.youlai.common.enums.BusinessTypeEnum
;
import
com.youlai.common.redis.BusinessNoGenerator
;
import
com.youlai.common.result.Result
;
import
com.youlai.common.web.exception.B
iz
Exception
;
import
com.youlai.common.web.exception.B
usiness
Exception
;
import
com.youlai.common.web.util.MemberUtils
;
import
com.youlai.mall.oms.config.WxPayProperties
;
import
com.youlai.mall.oms.dto.OrderInfoDTO
;
...
...
@@ -208,7 +208,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
Assert
.
isTrue
(
result
,
"订单提交失败"
);
}
catch
(
Exception
e
)
{
redisTemplate
.
opsForValue
().
set
(
ORDER_TOKEN_PREFIX
+
orderToken
,
orderToken
);
throw
new
B
iz
Exception
(
e
);
throw
new
B
usiness
Exception
(
e
);
}
// 成功响应返回值构建
OrderSubmitVO
submitVO
=
new
OrderSubmitVO
();
...
...
@@ -287,7 +287,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
wxPayService
.
closeOrderV3
(
order
.
getOutTradeNo
());
}
catch
(
WxPayException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
B
iz
Exception
(
"微信关单异常"
);
throw
new
B
usiness
Exception
(
"微信关单异常"
);
}
}
// 用户id前补零保证五位,对超出五位的保留后五位
...
...
@@ -310,7 +310,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
jsapiResult
=
wxPayService
.
createOrderV3
(
TradeTypeEnum
.
JSAPI
,
wxRequest
);
}
catch
(
WxPayException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
B
iz
Exception
(
"微信统一下单异常"
);
throw
new
B
usiness
Exception
(
"微信统一下单异常"
);
}
return
jsapiResult
;
}
...
...
@@ -329,7 +329,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
order
.
setOutTradeNo
(
null
);
}
catch
(
WxPayException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
B
iz
Exception
(
"微信关单异常"
);
throw
new
B
usiness
Exception
(
"微信关单异常"
);
}
}
order
.
setStatus
(
OrderStatusEnum
.
AUTO_CANCEL
.
getCode
());
...
...
@@ -341,11 +341,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
log
.
info
(
"订单超时取消,订单ID:{}"
,
id
);
OmsOrder
order
=
this
.
getById
(
id
);
if
(
order
==
null
)
{
throw
new
B
iz
Exception
(
"订单不存在"
);
throw
new
B
usiness
Exception
(
"订单不存在"
);
}
if
(!
OrderStatusEnum
.
PENDING_PAYMENT
.
getCode
().
equals
(
order
.
getStatus
()))
{
throw
new
B
iz
Exception
(
"取消失败,订单状态不支持取消"
);
// 通过自定义异常,将异常信息抛出由异常处理器捕获显示给前端页面
throw
new
B
usiness
Exception
(
"取消失败,订单状态不支持取消"
);
// 通过自定义异常,将异常信息抛出由异常处理器捕获显示给前端页面
}
// 如果已经有outTradeNo了就先进行关单
if
(
PayTypeEnum
.
WX_JSAPI
.
getValue
().
equals
(
order
.
getPayType
())
&&
StrUtil
.
isNotBlank
(
order
.
getOutTradeNo
()))
{
...
...
@@ -354,7 +354,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
order
.
setOutTradeNo
(
null
);
}
catch
(
WxPayException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
B
iz
Exception
(
"微信关单异常"
);
throw
new
B
usiness
Exception
(
"微信关单异常"
);
}
}
order
.
setStatus
(
OrderStatusEnum
.
USER_CANCEL
.
getCode
());
...
...
@@ -363,7 +363,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
// 释放被锁定的库存
Result
<?>
unlockResult
=
skuFeignClient
.
unlockStock
(
order
.
getOrderSn
());
if
(!
Result
.
isSuccess
(
unlockResult
))
{
throw
new
B
iz
Exception
(
unlockResult
.
getMsg
());
throw
new
B
usiness
Exception
(
unlockResult
.
getMsg
());
}
}
return
result
;
...
...
@@ -375,7 +375,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
log
.
info
(
"=======================订单删除,订单ID:{}======================="
,
id
);
OmsOrder
order
=
this
.
getById
(
id
);
if
(
order
!=
null
&&
!
OrderStatusEnum
.
AUTO_CANCEL
.
getCode
().
equals
(
order
.
getStatus
())
&&
!
OrderStatusEnum
.
USER_CANCEL
.
getCode
().
equals
(
order
.
getStatus
()))
{
throw
new
B
iz
Exception
(
"订单删除失败,订单不存在或订单状态不支持删除"
);
throw
new
B
usiness
Exception
(
"订单删除失败,订单不存在或订单状态不支持删除"
);
}
return
this
.
removeById
(
id
);
}
...
...
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java
浏览文件 @
51958add
...
...
@@ -6,7 +6,7 @@ import cn.hutool.json.JSONUtil;
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.B
iz
Exception
;
import
com.youlai.common.web.exception.B
usiness
Exception
;
import
com.youlai.mall.pms.common.constant.PmsConstants
;
import
com.youlai.mall.pms.mapper.PmsSkuMapper
;
import
com.youlai.mall.pms.pojo.dto.CheckPriceDTO
;
...
...
@@ -127,7 +127,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
.
setSql
(
"locked_stock_num = locked_stock_num - "
+
item
.
getCount
())
);
if
(!
result
)
{
throw
new
B
iz
Exception
(
"扣减库存失败,商品"
+
item
.
getSkuId
()
+
"库存不足"
);
throw
new
B
usiness
Exception
(
"扣减库存失败,商品"
+
item
.
getSkuId
()
+
"库存不足"
);
}
});
...
...
youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java
浏览文件 @
51958add
...
...
@@ -2,9 +2,8 @@ package com.youlai.auth.security.extension.mobile;
import
cn.hutool.core.util.StrUtil
;
import
com.youlai.auth.security.core.userdetails.member.MemberUserDetailsServiceImpl
;
import
com.youlai.auth.security.extension.wechat.WechatAuthenticationToken
;
import
com.youlai.common.constant.SecurityConstants
;
import
com.youlai.common.web.exception.B
iz
Exception
;
import
com.youlai.common.web.exception.B
usiness
Exception
;
import
com.youlai.mall.ums.api.MemberFeignClient
;
import
lombok.Data
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
...
...
@@ -40,7 +39,7 @@ public class SmsCodeAuthenticationProvider implements AuthenticationProvider {
String
correctCode
=
redisTemplate
.
opsForValue
().
get
(
codeKey
);
// 验证码比对
if
(
StrUtil
.
isBlank
(
correctCode
)
||
!
code
.
equals
(
correctCode
))
{
throw
new
B
iz
Exception
(
"验证码不正确"
);
throw
new
B
usiness
Exception
(
"验证码不正确"
);
}
// 比对成功删除缓存的验证码
redisTemplate
.
delete
(
codeKey
);
...
...
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/B
iz
Exception.java
→
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/B
usiness
Exception.java
浏览文件 @
51958add
...
...
@@ -3,25 +3,33 @@ package com.youlai.common.web.exception;
import
com.youlai.common.result.IResultCode
;
import
lombok.Getter
;
/**
* 自定义业务异常
*
* @author haoxr
* @date 2022/7/31
*/
@Getter
public
class
B
iz
Exception
extends
RuntimeException
{
public
class
B
usiness
Exception
extends
RuntimeException
{
public
IResultCode
resultCode
;
public
B
iz
Exception
(
IResultCode
errorCode
)
{
public
B
usiness
Exception
(
IResultCode
errorCode
)
{
super
(
errorCode
.
getMsg
());
this
.
resultCode
=
errorCode
;
}
public
B
iz
Exception
(
String
message
){
public
B
usiness
Exception
(
String
message
){
super
(
message
);
}
public
B
iz
Exception
(
String
message
,
Throwable
cause
){
public
B
usiness
Exception
(
String
message
,
Throwable
cause
){
super
(
message
,
cause
);
}
public
B
iz
Exception
(
Throwable
cause
){
public
B
usiness
Exception
(
Throwable
cause
){
super
(
cause
);
}
}
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
浏览文件 @
51958add
...
...
@@ -184,8 +184,8 @@ public class GlobalExceptionHandler {
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
B
iz
Exception
.
class
)
public
<
T
>
Result
<
T
>
handleBizException
(
B
iz
Exception
e
)
{
@ExceptionHandler
(
B
usiness
Exception
.
class
)
public
<
T
>
Result
<
T
>
handleBizException
(
B
usiness
Exception
e
)
{
log
.
error
(
"业务异常,异常原因:{}"
,
e
.
getMessage
(),
e
);
if
(
e
.
getResultCode
()
!=
null
)
{
return
Result
.
failed
(
e
.
getResultCode
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录