diff --git a/ms-biz/src/main/java/com/ms/biz/exception/BaseRuntimeException.java b/ms-biz/src/main/java/com/ms/biz/exception/BaseRuntimeException.java new file mode 100644 index 0000000..ac61eb9 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/exception/BaseRuntimeException.java @@ -0,0 +1,17 @@ +package com.ms.biz.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +abstract public class BaseRuntimeException extends RuntimeException { + protected String code; + public BaseRuntimeException() { + super(); + } + + public BaseRuntimeException(String message) { + super(message); + } +} diff --git a/ms-biz/src/main/java/com/ms/biz/exception/BindMemberNotExistsException.java b/ms-biz/src/main/java/com/ms/biz/exception/BindMemberNotExistsException.java new file mode 100644 index 0000000..166e90d --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/exception/BindMemberNotExistsException.java @@ -0,0 +1,18 @@ +package com.ms.biz.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class BindMemberNotExistsException extends BaseRuntimeException { + protected String code = "100501"; + + public BindMemberNotExistsException() { + super("当前没有绑定的账号信息,请重试"); + } + + public BindMemberNotExistsException(String message) { + super(message); + } +} diff --git a/ms-biz/src/main/java/com/ms/biz/exception/BusinessException.java b/ms-biz/src/main/java/com/ms/biz/exception/BusinessException.java new file mode 100644 index 0000000..f8d85a7 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/exception/BusinessException.java @@ -0,0 +1,19 @@ +package com.ms.biz.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class BusinessException extends BaseRuntimeException { + protected String code = "100004"; + + public BusinessException(String message, String code) { + super(message); + this.code = code; + } + + public BusinessException(String message) { + super(message); + } +} diff --git a/ms-biz/src/main/java/com/ms/biz/exception/DeliveryNotReceivedException.java b/ms-biz/src/main/java/com/ms/biz/exception/DeliveryNotReceivedException.java index e46c5c6..0f52e54 100644 --- a/ms-biz/src/main/java/com/ms/biz/exception/DeliveryNotReceivedException.java +++ b/ms-biz/src/main/java/com/ms/biz/exception/DeliveryNotReceivedException.java @@ -8,7 +8,7 @@ import lombok.EqualsAndHashCode; */ @EqualsAndHashCode(callSuper = true) @Data -public class DeliveryNotReceivedException extends RuntimeException { +public class DeliveryNotReceivedException extends BaseRuntimeException { private Long shipTimestamp; public DeliveryNotReceivedException(String message, Long shipTimestamp) { super(message); diff --git a/ms-biz/src/main/java/com/ms/biz/exception/MemberAlreadyUnbindException.java b/ms-biz/src/main/java/com/ms/biz/exception/MemberAlreadyUnbindException.java new file mode 100644 index 0000000..1b448f7 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/exception/MemberAlreadyUnbindException.java @@ -0,0 +1,18 @@ +package com.ms.biz.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class MemberAlreadyUnbindException extends BaseRuntimeException { + protected String code = "100401"; + + public MemberAlreadyUnbindException() { + super("当前已解绑,无需再次解绑"); + } + + public MemberAlreadyUnbindException(String message) { + super(message); + } +} diff --git a/ms-biz/src/main/java/com/ms/biz/service/impl/ShopServiceImpl.java b/ms-biz/src/main/java/com/ms/biz/service/impl/ShopServiceImpl.java index e712153..ea57162 100644 --- a/ms-biz/src/main/java/com/ms/biz/service/impl/ShopServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/biz/service/impl/ShopServiceImpl.java @@ -16,6 +16,9 @@ import com.ms.biz.dto.openspi.request.QuerySupplyPlatformBindNameParam; import com.ms.biz.dto.openspi.request.UnbindParam; import com.ms.biz.dto.openspi.response.QuerySupplyPlatformAuthData; import com.ms.biz.dto.openspi.response.QuerySupplyPlatformBindNameData; +import com.ms.biz.exception.BindMemberNotExistsException; +import com.ms.biz.exception.BusinessException; +import com.ms.biz.exception.MemberAlreadyUnbindException; import com.ms.biz.service.DsApiService; import com.ms.biz.service.ShopService; import com.ms.biz.bo.ShopBO; @@ -168,8 +171,14 @@ public class ShopServiceImpl implements ShopService { public void querySupplyPlatformBindName(QuerySupplyPlatformBindNameParam param, QuerySupplyPlatformBindNameData data) { Long shopId = param.getShopId(); if (shopId == null || shopId == 0) { - throw new RuntimeException("店铺ID错误"); + throw new BusinessException("参数错误:请检查您的查询参数是否正确", "100500"); + } + + ShopTo1688DsMember member = shopTo1688DsMemberMapper.getDetailByShopId(shopId); + if (member == null) { + throw new BindMemberNotExistsException(); } + GetAuthInfoResponseDTO response = dsApiService.getAuthInfo(shopId); if (response.isSuccess()) { data.setBindName(response.getMemberName()); @@ -182,16 +191,16 @@ public class ShopServiceImpl implements ShopService { public void unbind(UnbindParam param) { Long shopId = param.getShopId(); if (shopId == null || shopId == 0) { - throw new RuntimeException("店铺ID错误"); + throw new BusinessException("参数错误:请检查您的查询参数是否正确", "100400"); } ShopTo1688DsMember member = shopTo1688DsMemberMapper.getDetailByShopId(shopId); if (member == null) { - throw new RuntimeException("该店铺未绑定"); + throw new MemberAlreadyUnbindException(); } CommonResponseDTO response = dsApiService.delAuthShop(shopId); if (!response.isSuccess()) { - throw new RuntimeException(response.getReason()); + throw new BusinessException(response.getReason()); } shopTo1688DsMemberMapper.deleteByPrimaryKey(member.getShopTo1688DsMemberId()); diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java index 7907573..96bb6bc 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchCreateService.java @@ -11,6 +11,7 @@ import com.ms.biz.common.SPIBaseService; import com.ms.biz.dto.openspi.request.BatchCreateParam; import com.ms.biz.dto.openspi.response.BatchCreateData; import com.ms.biz.dto.openspi.response.BatchPayData; +import com.ms.biz.exception.BaseRuntimeException; import com.ms.biz.service.DistributionOrderService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,6 +29,8 @@ public class BatchCreateService extends SPIBaseService implements ExtensionServi BatchCreateData data = new BatchCreateData(); distributionOrderService.batchCreate(param, data); return BaseResponse.builder().success(true).message("success").code("0").data(JSON.parseObject(JSON.toJSONString(data))).build(); + } catch (BaseRuntimeException e) { + return BaseResponse.builder().success(true).message(e.getMessage()).code(e.getCode()).build(); } catch (RuntimeException e) { log.error("batchCreate error1", e); String message = e.getMessage() == null ? "系统异常" : e.getMessage(); diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchPayService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchPayService.java index 7a64ed2..17bed3d 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchPayService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/BatchPayService.java @@ -11,6 +11,7 @@ import com.ms.biz.common.SPIBaseService; import com.ms.biz.dto.openspi.request.BatchPayParam; import com.ms.biz.dto.openspi.response.BatchPayData; import com.ms.biz.dto.openspi.response.QuerySupplyPlatformAuthData; +import com.ms.biz.exception.BaseRuntimeException; import com.ms.biz.service.DistributionOrderService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,6 +29,8 @@ public class BatchPayService extends SPIBaseService implements ExtensionServiceH BatchPayData data = new BatchPayData(); distributionOrderService.batchPay(param, data); return BaseResponse.builder().success(true).message("success").code("0").data(JSON.parseObject(JSON.toJSONString(data))).build(); + } catch (BaseRuntimeException e) { + return BaseResponse.builder().success(true).message(e.getMessage()).code(e.getCode()).build(); } catch (RuntimeException e) { return BaseResponse.builder().success(true).message(e.getMessage()).code("100003").build(); } catch (Throwable e) { diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformAuthService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformAuthService.java index 4a7f097..5262140 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformAuthService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformAuthService.java @@ -10,6 +10,7 @@ import com.ms.biz.common.R; import com.ms.biz.common.SPIBaseService; import com.ms.biz.dto.openspi.request.QuerySupplyPlatformAuthParam; import com.ms.biz.dto.openspi.response.QuerySupplyPlatformAuthData; +import com.ms.biz.exception.BaseRuntimeException; import com.ms.biz.service.ShopService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -27,6 +28,8 @@ public class QuerySupplyPlatformAuthService extends SPIBaseService implements Ex QuerySupplyPlatformAuthData data = new QuerySupplyPlatformAuthData(); shopService.querySupplyPlatformAuth(param, data); return BaseResponse.builder().success(true).message("success").code("0").data(JSON.parseObject(JSON.toJSONString(data))).build(); + } catch (BaseRuntimeException e) { + return BaseResponse.builder().success(true).message(e.getMessage()).code(e.getCode()).build(); } catch (RuntimeException e) { return BaseResponse.builder().success(true).message(e.getMessage()).code("100003").build(); } catch (Throwable e) { diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformBindNameService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformBindNameService.java index 46b72a1..6c56d5e 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformBindNameService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/QuerySupplyPlatformBindNameService.java @@ -9,6 +9,7 @@ import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.ms.biz.common.SPIBaseService; import com.ms.biz.dto.openspi.request.QuerySupplyPlatformBindNameParam; import com.ms.biz.dto.openspi.response.QuerySupplyPlatformBindNameData; +import com.ms.biz.exception.BaseRuntimeException; import com.ms.biz.service.ShopService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,6 +27,8 @@ public class QuerySupplyPlatformBindNameService extends SPIBaseService implement QuerySupplyPlatformBindNameData data = new QuerySupplyPlatformBindNameData(); shopService.querySupplyPlatformBindName(param, data); return BaseResponse.builder().success(true).message("success").code("0").data(JSON.parseObject(JSON.toJSONString(data))).build(); + } catch (BaseRuntimeException e) { + return BaseResponse.builder().success(true).message(e.getMessage()).code(e.getCode()).build(); } catch (RuntimeException e) { return BaseResponse.builder().success(true).message(e.getMessage()).code("100003").build(); } catch (Throwable e) { diff --git a/ms-biz/src/main/java/com/ms/biz/spi/callback/UnbindService.java b/ms-biz/src/main/java/com/ms/biz/spi/callback/UnbindService.java index 1ba464b..68b94a2 100644 --- a/ms-biz/src/main/java/com/ms/biz/spi/callback/UnbindService.java +++ b/ms-biz/src/main/java/com/ms/biz/spi/callback/UnbindService.java @@ -7,10 +7,9 @@ import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.ms.biz.common.SPIBaseService; -import com.ms.biz.dto.openspi.request.QuerySupplyPlatformBindNameParam; import com.ms.biz.dto.openspi.request.UnbindParam; -import com.ms.biz.dto.openspi.response.QuerySupplyPlatformBindNameData; import com.ms.biz.dto.openspi.response.UnbindData; +import com.ms.biz.exception.BaseRuntimeException; import com.ms.biz.service.ShopService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,6 +27,8 @@ public class UnbindService extends SPIBaseService implements ExtensionServiceHan UnbindData data = new UnbindData(); shopService.unbind(param); return BaseResponse.builder().success(true).message("success").code("0").data(JSON.parseObject(JSON.toJSONString(data))).build(); + } catch (BaseRuntimeException e) { + return BaseResponse.builder().success(true).message(e.getMessage()).code(e.getCode()).build(); } catch (RuntimeException e) { return BaseResponse.builder().success(true).message(e.getMessage()).code("100003").build(); } catch (Throwable e) {