修复批量订购
This commit is contained in:
@@ -121,19 +121,13 @@ func (h *AssetPackageBatchOrderHandler) finishBatchOrderTask(ctx context.Context
|
||||
return err
|
||||
}
|
||||
rootID := audit.TaskEventID(constants.AuditResourceAssetPackageBatchOrderTask, taskRecord.ID, "completed")
|
||||
var childCount int64
|
||||
if err := tx.WithContext(ctx).Model(&model.AuditEvent{}).
|
||||
Where("parent_event_id = ? AND action_code = ?", rootID, constants.AuditActionOrderCreated).
|
||||
Count(&childCount).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
result := batchAuditResult(int(childCount), failCount)
|
||||
result := batchAuditResult(successCount, failCount)
|
||||
return h.auditWriter.WriteTask(ctx, tx, audit.TaskInput{
|
||||
EventID: rootID, ActionCode: constants.AuditActionAssetPackageBatchOrderTaskCompleted,
|
||||
Summary: "完成资产套餐批量订购任务", TaskID: taskRecord.ID, TaskNo: taskRecord.TaskNo,
|
||||
Result: result, CorrelationID: taskRecord.TaskNo,
|
||||
ParentEventID: audit.TaskEventID(constants.AuditResourceAssetPackageBatchOrderTask, taskRecord.ID, "created"),
|
||||
BatchTotal: len(items), SuccessCount: int(childCount), FailCount: failCount,
|
||||
BatchTotal: len(items), SuccessCount: successCount, FailCount: failCount,
|
||||
IdentitySnapshot: map[string]any{
|
||||
"id": taskRecord.ID, "task_no": taskRecord.TaskNo, "file_name": taskRecord.FileName,
|
||||
"package_id": taskRecord.PackageID, "package_code": taskRecord.PackageCode,
|
||||
|
||||
@@ -67,11 +67,15 @@ func (h *PollingCarddataHandler) Handle(ctx context.Context, task *asynq.Task) e
|
||||
}
|
||||
result, err := h.gateway.QueryFlow(ctx, &gateway.FlowQueryReq{CardNo: card.ICCID})
|
||||
if err != nil {
|
||||
_ = completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt)
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt); logErr != nil {
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "完成 Gateway 流量 Integration Log 失败", logErr)
|
||||
}
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "查询流量失败", err)
|
||||
}
|
||||
if strings.TrimSpace(result.ICCID) == "" {
|
||||
_ = completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt)
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt); logErr != nil {
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "完成 Gateway 流量 Integration Log 失败", logErr)
|
||||
}
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "流量查询响应缺少 ICCID", nil)
|
||||
}
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, true, attemptStartedAt); logErr != nil {
|
||||
|
||||
@@ -66,11 +66,15 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, task *asynq.Task)
|
||||
}
|
||||
result, err := h.gateway.QueryCardStatus(ctx, &gateway.CardStatusReq{CardNo: card.ICCID})
|
||||
if err != nil {
|
||||
_ = completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt)
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt); logErr != nil {
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "完成 Gateway 网络 Integration Log 失败", logErr)
|
||||
}
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "查询卡状态失败", err)
|
||||
}
|
||||
if strings.TrimSpace(result.ICCID) == "" {
|
||||
_ = completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt)
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt); logErr != nil {
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "完成 Gateway 网络 Integration Log 失败", logErr)
|
||||
}
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "卡状态查询响应缺少 ICCID", nil)
|
||||
}
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, true, attemptStartedAt); logErr != nil {
|
||||
|
||||
@@ -38,11 +38,13 @@ func completeGatewayAttempt(ctx context.Context, repository *integrationlog.Repo
|
||||
if repository == nil || attempt == nil {
|
||||
return errors.New(errors.CodeInternalError, "Gateway Integration Log 尝试不存在")
|
||||
}
|
||||
completionCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
|
||||
defer cancel()
|
||||
result := constants.IntegrationResultFailed
|
||||
if success {
|
||||
result = constants.IntegrationResultSuccess
|
||||
}
|
||||
_, err := repository.Complete(ctx, attempt.IntegrationID, integrationlog.Completion{
|
||||
_, err := repository.Complete(completionCtx, attempt.IntegrationID, integrationlog.Completion{
|
||||
Result: result, DurationMS: time.Since(startedAt).Milliseconds(), StateChanged: false,
|
||||
ResponseSummary: map[string]any{"success": success},
|
||||
})
|
||||
|
||||
@@ -58,11 +58,15 @@ func (h *PollingRealnameHandler) Handle(ctx context.Context, task *asynq.Task) e
|
||||
}
|
||||
result, err := h.gateway.QueryRealnameStatus(ctx, &gateway.CardStatusReq{CardNo: card.ICCID})
|
||||
if err != nil {
|
||||
_ = completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt)
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt); logErr != nil {
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "完成 Gateway 实名 Integration Log 失败", logErr)
|
||||
}
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "查询实名状态失败", err)
|
||||
}
|
||||
if strings.TrimSpace(result.ICCID) == "" {
|
||||
_ = completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt)
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, false, attemptStartedAt); logErr != nil {
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "完成 Gateway 实名 Integration Log 失败", logErr)
|
||||
}
|
||||
return h.failAndRequeue(ctx, cardID, startedAt, "实名查询响应缺少 ICCID", nil)
|
||||
}
|
||||
if logErr := completeGatewayAttempt(ctx, h.integration, attempt, true, attemptStartedAt); logErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user