8.8 增加业务异常处理,让提示更清晰
This commit is contained in:
parent
5ac1485f32
commit
b36f572239
@ -14,7 +14,7 @@ app:
|
||||
notify-url: http://127.0.0.1:8092/api/v1/alipay/group_buy_notify
|
||||
notify-type: MQ
|
||||
source: s01
|
||||
chanel: c01
|
||||
channel: c01
|
||||
rpc:
|
||||
mode: DUBBO
|
||||
|
||||
|
@ -26,6 +26,9 @@ public class WeixinLoginService implements ILoginService {
|
||||
return loginPort.createQrCodeTicket();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成登录二维码的 ticket(带浏览器指纹)
|
||||
*/
|
||||
@Override
|
||||
public String createQrCodeTicket(String sceneStr) throws Exception {
|
||||
String ticket = loginPort.createQrCodeTicket(sceneStr);
|
||||
|
@ -98,6 +98,7 @@ public abstract class AbstractOrderService implements IOrderService {
|
||||
}
|
||||
|
||||
// ———— 以下为“全新下单”流程 ————
|
||||
log.info("创建新订单...");
|
||||
|
||||
// 2. 查询商品信息
|
||||
ProductEntity productEntity = port.queryProductByProductId(shopCartEntity.getProductId());
|
||||
|
@ -46,6 +46,7 @@ public class OrderService extends AbstractOrderService{
|
||||
|
||||
@Override
|
||||
protected MarketPayDiscountEntity lockMarketPayOrder(String userId, String teamId, Long activityId, String productId, String orderId) {
|
||||
log.info("尝试开启/参与拼团,获取优惠,进行锁单");
|
||||
return port.lockMarketPayOrder(userId, teamId, activityId, productId, orderId);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class LoginPort implements ILoginPort {
|
||||
*/
|
||||
@Override
|
||||
public String createQrCodeTicket(String sceneStr) throws IOException {
|
||||
// 1. 获取 access_token,优先从缓存读取,缓存失效时调用微信接口获取并更新缓存
|
||||
// 1. 获取 access_token身份凭证,后端才好调用微信接口;优先从缓存读取,缓存失效时调用微信接口获取并更新缓存
|
||||
String accessToken = weixinAccessToken.getIfPresent(appid);
|
||||
if (null == accessToken) {
|
||||
Call<WeixinTokenResponseDTO> call = weixinApiService.getToken("client_credential", appid, appSecret);
|
||||
|
@ -15,6 +15,7 @@ import edu.whut.domain.order.model.entity.ShopCartEntity;
|
||||
import edu.whut.domain.order.model.valobj.MarketTypeVO;
|
||||
import edu.whut.domain.order.service.IOrderService;
|
||||
import edu.whut.types.common.Constants;
|
||||
import edu.whut.types.exception.AppException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -51,11 +52,12 @@ public class AliPayController implements IPayService {
|
||||
@Override
|
||||
public Response<String> createPayOrder(@RequestBody CreatePayRequestDTO createPayRequestDTO) {
|
||||
try {
|
||||
log.info("商品下单,根据商品ID创建支付单开始 userId:{} productId:{}", createPayRequestDTO.getUserId(), createPayRequestDTO.getUserId());
|
||||
log.info("商品下单,根据商品ID创建支付单开始 userId:{} productId:{}", createPayRequestDTO.getUserId(), createPayRequestDTO.getProductId());
|
||||
String userId = createPayRequestDTO.getUserId();
|
||||
String productId = createPayRequestDTO.getProductId();
|
||||
String teamId = createPayRequestDTO.getTeamId();
|
||||
Integer marketType = createPayRequestDTO.getMarketType();
|
||||
|
||||
// 下单
|
||||
PayOrderEntity payOrderEntity = orderService.createOrder(ShopCartEntity.builder()
|
||||
.userId(userId)
|
||||
@ -66,13 +68,24 @@ public class AliPayController implements IPayService {
|
||||
.build());
|
||||
|
||||
log.info("商品下单,根据商品ID创建支付单完成 userId:{} productId:{} orderId:{}", userId, productId, payOrderEntity.getOrderId());
|
||||
|
||||
return Response.<String>builder()
|
||||
.code(Constants.ResponseCode.SUCCESS.getCode())
|
||||
.info(Constants.ResponseCode.SUCCESS.getInfo())
|
||||
.data(payOrderEntity.getPayUrl())
|
||||
.build();
|
||||
} catch (AppException e) {
|
||||
// 业务异常,返回业务错误信息
|
||||
log.error("商品下单,发生业务异常 userId:{} productId:{} errorCode:{} errorInfo:{}",
|
||||
createPayRequestDTO.getUserId(), createPayRequestDTO.getProductId(), e.getCode(), e.getInfo());
|
||||
return Response.<String>builder()
|
||||
.code(e.getCode()) // 使用业务异常中的 code
|
||||
.info(e.getInfo()) // 使用业务异常中的 info
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.error("商品下单,根据商品ID创建支付单失败 userId:{} productId:{}", createPayRequestDTO.getUserId(), createPayRequestDTO.getProductId(), e);
|
||||
// 通用异常,返回通用错误信息
|
||||
log.error("商品下单,发生未知异常 userId:{} productId:{}", createPayRequestDTO.getUserId(), createPayRequestDTO.getProductId(), e);
|
||||
|
||||
return Response.<String>builder()
|
||||
.code(Constants.ResponseCode.UN_ERROR.getCode())
|
||||
.info(Constants.ResponseCode.UN_ERROR.getInfo())
|
||||
@ -80,6 +93,7 @@ public class AliPayController implements IPayService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拼团完成(目标人数已达成)后的回调地址,由group_buy_market调用
|
||||
* 仅HTTP方式下触发,MQ方式下不会触发。
|
||||
|
Loading…
x
Reference in New Issue
Block a user