package operationsreport import ( "context" "time" "github.com/break/junhong_cmp_fiber/pkg/constants" ) // PurchaseCountSource 是采购数量口径的取值端口。 // 由基础设施层实现为只读查询(截至快照日系统内未删除的设备数)。 type PurchaseCountSource interface { CountUndeletedDevicesAsOf(ctx context.Context, snapshotDate time.Time) (int64, error) } // PurchaseCountAsOf 返回截至快照日的采购数量,是采购数量口径的**唯一实现点**(设计 D6)。 // // 采用口径:采购数量 = 截至快照日(上海自然日)系统内未删除的设备数, // 与 `111.md` §22.4.1「系统录入的设备数量」同读法,不新建采购或入库台账。 // // 被拒绝的字面口径:`tb_device_import_task` 中 `operation_type='import'` 且已完成任务的 // `success_count` 之和。生产库实测该值为 474,而系统内未删除设备为 18,970; // 差额来自老系统迁移脚本直接写入设备表、绕过导入任务,按字面口径激活率约 1,399%,指标不可用。 // // 切换口径只需替换本函数体内的取值方式(一行),调用方与快照表结构都不需要改动。 func PurchaseCountAsOf(ctx context.Context, source PurchaseCountSource, snapshotDate time.Time) (int64, error) { return source.CountUndeletedDevicesAsOf(ctx, snapshotDate) } // ValidMainPackageStatuses 是「有效主套餐」的状态集合:生效中与已用完。 // 「有效」的完整口径为:主套餐(master_usage_id IS NULL)、状态属于本集合、未退款(refund_id IS NULL), // 既有先例见 internal/query/packageexpiry/list.go、internal/query/assetautorenewal/query.go // 与 internal/infrastructure/packagetrafficalert/scanner.go。 var ValidMainPackageStatuses = []int{ constants.PackageUsageStatusActive, constants.PackageUsageStatusDepleted, }