2024-11-21 12:18:28 +08:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-04-09 15:58:06 +08:00
|
|
|
"tyc-server/common/xerr"
|
|
|
|
|
2024-11-21 12:18:28 +08:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2025-04-27 12:17:18 +08:00
|
|
|
"tyc-server/app/main/api/internal/svc"
|
|
|
|
"tyc-server/app/main/api/internal/types"
|
2024-11-21 12:18:28 +08:00
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QueryRetryLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewQueryRetryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryRetryLogic {
|
|
|
|
return &QueryRetryLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *QueryRetryLogic) QueryRetry(req *types.QueryRetryReq) (resp *types.QueryRetryResp, err error) {
|
|
|
|
|
|
|
|
query, err := l.svcCtx.QueryModel.FindOne(l.ctx, req.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询重试, 查找报告失败, %+v", err)
|
|
|
|
}
|
|
|
|
if query.QueryState == "success" {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.LOGIN_FAILED, "该报告不能重试"), "报告查询重试, 该报告不能重试, %d", query.Id)
|
|
|
|
}
|
|
|
|
|
|
|
|
if asyncErr := l.svcCtx.AsynqService.SendQueryTask(query.OrderId); asyncErr != nil {
|
|
|
|
logx.Errorf("异步任务调度失败: %v", asyncErr)
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询重试, 异步任务调度失败, %+v", asyncErr)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|