实现资产预计最终到期时间
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
packageexpiry "github.com/break/junhong_cmp_fiber/internal/query/packageexpiry"
|
||||
assetAuditSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_audit"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
@@ -29,6 +30,11 @@ type IotCardRefresher interface {
|
||||
RefreshCardDataFromGateway(ctx context.Context, iccid string) error
|
||||
}
|
||||
|
||||
// PackageExpiryResolver 查询资产的套餐最终到期推算结果。
|
||||
type PackageExpiryResolver interface {
|
||||
Resolve(ctx context.Context, assetType string, assetID uint) (dto.PackageExpiryEstimate, error)
|
||||
}
|
||||
|
||||
// Service 资产查询与操作服务
|
||||
type Service struct {
|
||||
db *gorm.DB
|
||||
@@ -47,6 +53,12 @@ type Service struct {
|
||||
gatewayClient *gateway.Client
|
||||
assetIdentifierStore *postgres.AssetIdentifierStore
|
||||
assetAuditService assetAuditSvc.OperationLogger
|
||||
packageExpiryQuery PackageExpiryResolver
|
||||
}
|
||||
|
||||
// SetPackageExpiryQuery 注入套餐最终到期查询,供资产详情统一投影使用。
|
||||
func (s *Service) SetPackageExpiryQuery(query *packageexpiry.Query) {
|
||||
s.packageExpiryQuery = query
|
||||
}
|
||||
|
||||
// New 创建资产服务实例
|
||||
@@ -85,6 +97,7 @@ func New(
|
||||
gatewayClient: gatewayClient,
|
||||
assetIdentifierStore: assetIdentifierStore,
|
||||
assetAuditService: assetAuditService,
|
||||
packageExpiryQuery: packageexpiry.NewQuery(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,6 +259,9 @@ func (s *Service) buildDeviceResolveResponse(ctx context.Context, device *model.
|
||||
|
||||
// 查当前主套餐
|
||||
s.fillPackageInfo(ctx, resp, "device", device.ID)
|
||||
if err := s.fillPackageExpiryEstimate(ctx, resp, constants.AssetTypeDevice, device.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
activationStatuses, err := s.deviceStore.GetActivationStatusMap(ctx, []uint{device.ID})
|
||||
if err != nil {
|
||||
@@ -312,6 +328,9 @@ func (s *Service) buildCardResolveResponse(ctx context.Context, card *model.IotC
|
||||
|
||||
// 查当前主套餐
|
||||
s.fillPackageInfo(ctx, resp, "iot_card", card.ID)
|
||||
if err := s.fillPackageExpiryEstimate(ctx, resp, constants.AssetTypeIotCard, card.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 查 shop 名称
|
||||
s.fillShopName(ctx, resp)
|
||||
@@ -349,6 +368,19 @@ func (s *Service) fillPackageInfo(ctx context.Context, resp *dto.AssetResolveRes
|
||||
resp.EnableVirtualData = usage.EnableVirtualDataSnapshot
|
||||
}
|
||||
|
||||
// fillPackageExpiryEstimate 使用统一 Query 投影资产的最终套餐到期,不允许查询失败降级为无套餐。
|
||||
func (s *Service) fillPackageExpiryEstimate(ctx context.Context, resp *dto.AssetResolveResponse, assetType string, assetID uint) error {
|
||||
if s.packageExpiryQuery == nil {
|
||||
return errors.New(errors.CodeInternalError, "套餐最终到期查询未初始化")
|
||||
}
|
||||
estimate, err := s.packageExpiryQuery.Resolve(ctx, assetType, assetID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp.PackageExpiryEstimate = estimate
|
||||
return nil
|
||||
}
|
||||
|
||||
// fillUsageSummary 填充当前世代流量汇总字段。
|
||||
// 仅在 includeUsageSummary=true 时被调用,无套餐时返回 0.0(非 null)。
|
||||
func (s *Service) fillUsageSummary(ctx context.Context, resp *dto.AssetResolveResponse, carrierType string, carrierID uint) {
|
||||
|
||||
Reference in New Issue
Block a user