提交 51958add 编写于 作者: 郝先瑞

refactor: 自定义异常类重命名

上级 6ca4ee3f
......@@ -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.BizException;
import com.youlai.common.web.exception.BusinessException;
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 BizException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
throw new BusinessException(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 BizException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
throw new BusinessException(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 BizException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
throw new BusinessException(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 BizException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
throw new BusinessException(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 BizException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
throw new BusinessException(ResultCode.TOKEN_INVALID_OR_EXPIRED);
}
BoundHashOperations cartHashOperations = getCartHashOperations(memberId);
for (Object value : cartHashOperations.values()) {
......
......@@ -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.BizException;
import com.youlai.common.web.exception.BusinessException;
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 BizException(e);
throw new BusinessException(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 BizException("微信关单异常");
throw new BusinessException("微信关单异常");
}
}
// 用户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 BizException("微信统一下单异常");
throw new BusinessException("微信统一下单异常");
}
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 BizException("微信关单异常");
throw new BusinessException("微信关单异常");
}
}
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 BizException("订单不存在");
throw new BusinessException("订单不存在");
}
if (!OrderStatusEnum.PENDING_PAYMENT.getCode().equals(order.getStatus())) {
throw new BizException("取消失败,订单状态不支持取消"); // 通过自定义异常,将异常信息抛出由异常处理器捕获显示给前端页面
throw new BusinessException("取消失败,订单状态不支持取消"); // 通过自定义异常,将异常信息抛出由异常处理器捕获显示给前端页面
}
// 如果已经有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 BizException("微信关单异常");
throw new BusinessException("微信关单异常");
}
}
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 BizException(unlockResult.getMsg());
throw new BusinessException(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 BizException("订单删除失败,订单不存在或订单状态不支持删除");
throw new BusinessException("订单删除失败,订单不存在或订单状态不支持删除");
}
return this.removeById(id);
}
......
......@@ -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.BizException;
import com.youlai.common.web.exception.BusinessException;
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 BizException("扣减库存失败,商品" + item.getSkuId() + "库存不足");
throw new BusinessException("扣减库存失败,商品" + item.getSkuId() + "库存不足");
}
});
......
......@@ -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.BizException;
import com.youlai.common.web.exception.BusinessException;
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 BizException("验证码不正确");
throw new BusinessException("验证码不正确");
}
// 比对成功删除缓存的验证码
redisTemplate.delete(codeKey);
......
......@@ -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 BizException extends RuntimeException {
public class BusinessException extends RuntimeException {
public IResultCode resultCode;
public BizException(IResultCode errorCode) {
public BusinessException(IResultCode errorCode) {
super(errorCode.getMsg());
this.resultCode = errorCode;
}
public BizException(String message){
public BusinessException(String message){
super(message);
}
public BizException(String message, Throwable cause){
public BusinessException(String message, Throwable cause){
super(message, cause);
}
public BizException(Throwable cause){
public BusinessException(Throwable cause){
super(cause);
}
}
......@@ -184,8 +184,8 @@ public class GlobalExceptionHandler {
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BizException.class)
public <T> Result<T> handleBizException(BizException e) {
@ExceptionHandler(BusinessException.class)
public <T> Result<T> handleBizException(BusinessException 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.
先完成此消息的编辑!
想要评论请 注册