diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java index 2a23516c36ea2bfc70202f87965a40c7a5bed4c2..87be6599529f5714c88d9200b387fef2ca907472 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java @@ -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()) { diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java index def54fc2069aa1a09b68939048ea6f4cbfaf63c1..8c66a9f0a52de26138a1345ba5b02b93b40823fa 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java @@ -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 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 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 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 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 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 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 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 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); } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java index 874d920c826bdf8d71364aed8e78d754009cd83f..8820d65230553666e1cb7386759e5a86fc7854e5 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java @@ -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 impleme .setSql("locked_stock_num = locked_stock_num - " + item.getCount()) ); if (!result) { - throw new BizException("扣减库存失败,商品" + item.getSkuId() + "库存不足"); + throw new BusinessException("扣减库存失败,商品" + item.getSkuId() + "库存不足"); } }); diff --git a/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java b/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java index 4c1b6c36868becdd660cdfa2ee5602c0c6631cf3..9986018dd08d456bdc0133c4ad775c2a595dba83 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java +++ b/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java @@ -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); diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java deleted file mode 100644 index 679ee33fff9c42794927ff269ceb5bcfbbad940f..0000000000000000000000000000000000000000 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.youlai.common.web.exception; - -import com.youlai.common.result.IResultCode; -import lombok.Getter; - -@Getter -public class BizException extends RuntimeException { - - public IResultCode resultCode; - - public BizException(IResultCode errorCode) { - super(errorCode.getMsg()); - this.resultCode = errorCode; - } - - public BizException(String message){ - super(message); - } - - public BizException(String message, Throwable cause){ - super(message, cause); - } - - public BizException(Throwable cause){ - super(cause); - } -} diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java new file mode 100644 index 0000000000000000000000000000000000000000..75296e4e7341aef4292c21e44ad50443454d84ec --- /dev/null +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java @@ -0,0 +1,35 @@ +package com.youlai.common.web.exception; + +import com.youlai.common.result.IResultCode; +import lombok.Getter; + +/** + * 自定义业务异常 + * + * @author haoxr + * @date 2022/7/31 + */ +@Getter +public class BusinessException extends RuntimeException { + + public IResultCode resultCode; + + public BusinessException(IResultCode errorCode) { + super(errorCode.getMsg()); + this.resultCode = errorCode; + } + + public BusinessException(String message){ + super(message); + } + + public BusinessException(String message, Throwable cause){ + super(message, cause); + } + + public BusinessException(Throwable cause){ + super(cause); + } + + +} diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java index a265bdd818941ba7d647c1b3f341616d1860c8e5..46400671003e1f5a69e98da4345928e264c031b1 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java @@ -184,8 +184,8 @@ public class GlobalExceptionHandler { } @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(BizException.class) - public Result handleBizException(BizException e) { + @ExceptionHandler(BusinessException.class) + public Result handleBizException(BusinessException e) { log.error("业务异常,异常原因:{}", e.getMessage(), e); if (e.getResultCode() != null) { return Result.failed(e.getResultCode());