fix(supplier): 修复飞鱼卡密提交及订单创建的异常处理

- 在飞鱼卡密提交接口添加频繁操作提示的错误处理逻辑
- 将发送请求重试次数设置为1,避免重复发送
- 增加循环创建订单与提交任务逻辑,处理重新下单场景
- 对提交订单异常进行分类,支持重新下单错误继续尝试
- 调整提交池大小由100改为300,提升并发处理能力
- 修复发布订单查询事件时的错误变量声明问题
This commit is contained in:
danial
2025-12-10 20:35:54 +08:00
parent 437f03671d
commit 6e26f1acb5
3 changed files with 31 additions and 24 deletions

View File

@@ -39,7 +39,7 @@ import (
var (
delayPool = gopool.NewPool("delayHandler", 20, gopool.NewConfig())
submitLimiterPool = gopool.NewPool("submitLimiterPool", 20, gopool.NewConfig())
submitPool = gopool.NewPool("submitPool", 100, gopool.NewConfig())
submitPool = gopool.NewPool("submitPool", 300, gopool.NewConfig())
)
var orderSubmitLimiter sync.Map

View File

@@ -107,7 +107,7 @@ func (s *SendCardTaskTypeFlyFishV2) HandleSendCardTask(ctx context.Context, orde
"Accept": "application/json, text/javascript, */*; q=0.01",
"user-agent": useragent.GetUserAgentByPlatform(useragent.PlatformPhone),
}).
SetHeader("user-agent", useragent.GetUserAgentByPlatform(useragent.PlatformPhone)).
SetRetryCount(1).
SetTimeout(time.Second * 30).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
proxy, err2 := utils.GetProxy(ctx, task.LocalOrderID, "SendCardTaskTypeFlyFishV2_cardTask")
otelTrace.Logger.WithContext(ctx).Info("获取代理", zap.String("proxy", proxy))
@@ -158,14 +158,14 @@ func (s *SendCardTaskTypeFlyFishV2) HandleSendCardTask(ctx context.Context, orde
return err
}
var respData struct {
respData := &struct {
Code int `json:"code"`
Message string `json:"message"`
}
}{}
err = json.Unmarshal(resp.Body(), &respData)
otelTrace.Logger.WithContext(ctx).Info("飞鱼查询返回", zap.Any("respData", resp.String()), zap.Any("formData", formData))
if err != nil {
return err
if strings.Contains(respData.Message, "频繁操作") {
return errors.New("重新下单提交卡密")
}
if respData.Code != 1 {
return errors.New(respData.Message)

View File

@@ -551,26 +551,33 @@ func (s *OrderPoolServiceImpl) SubmitOrder(ctx context.Context, task card_sender
trace.WithAttributes(attribute.String("task", convertor.ToString(task))),
)
defer span.End()
orderItem, err := task.SendCardTaskType.GetSendCardTaskType().
CreateOrder(ctx, task.RoadUid, task.CardInfo.GetFaceTypeFloat(ctx))
if err != nil {
return fmt.Errorf("创建订单失败: %v", err)
}
if err = task.SendCardTaskType.GetSendCardTaskType().BindPoolOrderId(ctx, orderItem, task); err != nil {
otelTrace.Logger.WithContext(ctx).Error("绑定订单ID和卡片信息ID失败", zap.Error(err))
return fmt.Errorf("绑定订单ID和卡片信息ID失败: %v", err)
}
var orderItem card_sender.OrderPoolItem
// 绑定订单ID和卡片信息ID
bindKey := fmt.Sprintf("%s:%s", s.config.OrderBindKey, orderItem.OrderID)
if err = s.redisClient.Set(ctx, bindKey, task.LocalOrderID, s.config.OrderBindKeyActiveTime); err != nil {
return fmt.Errorf("绑定订单ID和卡片信息ID失败: %v", err)
}
for range 10 {
orderItem, err := task.SendCardTaskType.GetSendCardTaskType().
CreateOrder(ctx, task.RoadUid, task.CardInfo.GetFaceTypeFloat(ctx))
err = task.SendCardTaskType.GetSendCardTaskType().HandleSendCardTask(ctx, orderItem, task)
if err != nil {
return fmt.Errorf("提交订单失败: %v", err)
if err != nil {
return fmt.Errorf("创建订单失败: %v", err)
}
if err = task.SendCardTaskType.GetSendCardTaskType().BindPoolOrderId(ctx, orderItem, task); err != nil {
otelTrace.Logger.WithContext(ctx).Error("绑定订单ID和卡片信息ID失败", zap.Error(err))
return fmt.Errorf("绑定订单ID和卡片信息ID失败: %v", err)
}
// 绑定订单ID和卡片信息ID
bindKey := fmt.Sprintf("%s:%s", s.config.OrderBindKey, orderItem.OrderID)
if err = s.redisClient.Set(ctx, bindKey, task.LocalOrderID, s.config.OrderBindKeyActiveTime); err != nil {
return fmt.Errorf("绑定订单ID和卡片信息ID失败: %v", err)
}
err = task.SendCardTaskType.GetSendCardTaskType().HandleSendCardTask(ctx, orderItem, task)
if err != nil {
if strings.Contains(err.Error(), "重新下单提交卡密") {
continue
}
return fmt.Errorf("提交订单失败: %v", err)
}
}
if task.NeedQuery {
@@ -587,7 +594,7 @@ func (s *OrderPoolServiceImpl) SubmitOrder(ctx context.Context, task card_sender
LastQueryTime: time.Now(),
RemoteOrderID: orderItem.RemoteOrderID,
}
if err = s.eventBus.Publish(ctx, queryEvent); err != nil {
if err := s.eventBus.Publish(ctx, queryEvent); err != nil {
otelTrace.Logger.WithContext(ctx).Error("发布订单查询事件失败", zap.Error(err))
}
}