优化mongo,封装count逻辑,处理objectId

This commit is contained in:
2026-01-08 11:07:58 +08:00
parent 65c80ae56f
commit e85c8453de
34 changed files with 753 additions and 446 deletions

57
consts/ad_format_type.go Normal file
View File

@@ -0,0 +1,57 @@
package consts
// AdFormatType 广告格式类型枚举
type AdFormatType string
const (
AdFormatTypeBanner AdFormatType = "banner" // 横幅广告
AdFormatTypeVideo AdFormatType = "video" // 视频广告
AdFormatTypeNative AdFormatType = "native" // 原生广告
AdFormatTypeInterstitial AdFormatType = "interstitial" // 插屏广告
)
// GetAllAdFormatTypes 获取所有广告格式类型
func GetAllAdFormatTypes() []AdFormatType {
return []AdFormatType{
AdFormatTypeBanner,
AdFormatTypeVideo,
AdFormatTypeNative,
AdFormatTypeInterstitial,
}
}
type AdFormatTypeKeyValue struct {
Key AdFormatType
Value string
}
var (
AdFormatTypeBannerKeyValue = AdFormatTypeKeyValue{Key: AdFormatTypeBanner, Value: "横幅广告"}
AdFormatTypeVideoKeyValue = AdFormatTypeKeyValue{Key: AdFormatTypeVideo, Value: "视频广告"}
AdFormatTypeNativeKeyValue = AdFormatTypeKeyValue{Key: AdFormatTypeNative, Value: "原生广告"}
AdFormatTypeInterstitialKeyValue = AdFormatTypeKeyValue{Key: AdFormatTypeInterstitial, Value: "插屏广告"}
)
func GetAllAdFormatTypeKeyValue() []AdFormatTypeKeyValue {
return []AdFormatTypeKeyValue{
AdFormatTypeBannerKeyValue,
AdFormatTypeVideoKeyValue,
AdFormatTypeNativeKeyValue,
AdFormatTypeInterstitialKeyValue,
}
}
var adFormatTypeValueMap = map[AdFormatType]string{
AdFormatTypeBanner: AdFormatTypeBannerKeyValue.Value,
AdFormatTypeVideo: AdFormatTypeVideoKeyValue.Value,
AdFormatTypeNative: AdFormatTypeNativeKeyValue.Value,
AdFormatTypeInterstitial: AdFormatTypeInterstitialKeyValue.Value,
}
func GetAdFormatTypeValueByKey(key AdFormatType) (value string) {
value, exists := adFormatTypeValueMap[key]
if !exists {
value = "未知广告格式"
}
return
}

View File

@@ -0,0 +1,52 @@
package consts
// AdSourceHealth 广告源健康状态枚举
type AdSourceHealth string
const (
AdSourceHealthHealthy AdSourceHealth = "healthy" // 健康
AdSourceHealthDegraded AdSourceHealth = "degraded" // 降级
AdSourceHealthUnhealthy AdSourceHealth = "unhealthy" // 不健康
)
// GetAllAdSourceHealths 获取所有广告源健康状态
func GetAllAdSourceHealths() []AdSourceHealth {
return []AdSourceHealth{
AdSourceHealthHealthy,
AdSourceHealthDegraded,
AdSourceHealthUnhealthy,
}
}
type AdSourceHealthKeyValue struct {
Key AdSourceHealth
Value string
}
var (
AdSourceHealthHealthyKeyValue = AdSourceHealthKeyValue{Key: AdSourceHealthHealthy, Value: "健康"}
AdSourceHealthDegradedKeyValue = AdSourceHealthKeyValue{Key: AdSourceHealthDegraded, Value: "降级"}
AdSourceHealthUnhealthyKeyValue = AdSourceHealthKeyValue{Key: AdSourceHealthUnhealthy, Value: "不健康"}
)
func GetAllAdSourceHealthKeyValue() []AdSourceHealthKeyValue {
return []AdSourceHealthKeyValue{
AdSourceHealthHealthyKeyValue,
AdSourceHealthDegradedKeyValue,
AdSourceHealthUnhealthyKeyValue,
}
}
var adSourceHealthValueMap = map[AdSourceHealth]string{
AdSourceHealthHealthy: AdSourceHealthHealthyKeyValue.Value,
AdSourceHealthDegraded: AdSourceHealthDegradedKeyValue.Value,
AdSourceHealthUnhealthy: AdSourceHealthUnhealthyKeyValue.Value,
}
func GetAdSourceHealthValueByKey(key AdSourceHealth) (value string) {
value, exists := adSourceHealthValueMap[key]
if !exists {
value = "未知健康状态"
}
return
}

View File

@@ -0,0 +1,57 @@
package consts
// AdSourceProvider 广告源提供商枚举
type AdSourceProvider string
const (
AdSourceProviderGoogle AdSourceProvider = "google" // Google
AdSourceProviderBaidu AdSourceProvider = "baidu" // 百度
AdSourceProviderTencent AdSourceProvider = "tencent" // 腾讯
AdSourceProviderSelf AdSourceProvider = "self" // 自营
)
// GetAllAdSourceProviders 获取所有广告源提供商
func GetAllAdSourceProviders() []AdSourceProvider {
return []AdSourceProvider{
AdSourceProviderGoogle,
AdSourceProviderBaidu,
AdSourceProviderTencent,
AdSourceProviderSelf,
}
}
type AdSourceProviderKeyValue struct {
Key AdSourceProvider
Value string
}
var (
AdSourceProviderGoogleKeyValue = AdSourceProviderKeyValue{Key: AdSourceProviderGoogle, Value: "Google"}
AdSourceProviderBaiduKeyValue = AdSourceProviderKeyValue{Key: AdSourceProviderBaidu, Value: "百度"}
AdSourceProviderTencentKeyValue = AdSourceProviderKeyValue{Key: AdSourceProviderTencent, Value: "腾讯"}
AdSourceProviderSelfKeyValue = AdSourceProviderKeyValue{Key: AdSourceProviderSelf, Value: "自营"}
)
func GetAllAdSourceProviderKeyValue() []AdSourceProviderKeyValue {
return []AdSourceProviderKeyValue{
AdSourceProviderGoogleKeyValue,
AdSourceProviderBaiduKeyValue,
AdSourceProviderTencentKeyValue,
AdSourceProviderSelfKeyValue,
}
}
var adSourceProviderValueMap = map[AdSourceProvider]string{
AdSourceProviderGoogle: AdSourceProviderGoogleKeyValue.Value,
AdSourceProviderBaidu: AdSourceProviderBaiduKeyValue.Value,
AdSourceProviderTencent: AdSourceProviderTencentKeyValue.Value,
AdSourceProviderSelf: AdSourceProviderSelfKeyValue.Value,
}
func GetAdSourceProviderValueByKey(key AdSourceProvider) (value string) {
value, exists := adSourceProviderValueMap[key]
if !exists {
value = "未知提供商"
}
return
}

View File

@@ -0,0 +1,52 @@
package consts
// AdSourceStatus 广告源状态枚举
type AdSourceStatus string
const (
AdSourceStatusActive AdSourceStatus = "active" // 活跃
AdSourceStatusInactive AdSourceStatus = "inactive" // 非活跃
AdSourceStatusMaintenance AdSourceStatus = "maintenance" // 维护中
)
// GetAllAdSourceStatuses 获取所有广告源状态
func GetAllAdSourceStatuses() []AdSourceStatus {
return []AdSourceStatus{
AdSourceStatusActive,
AdSourceStatusInactive,
AdSourceStatusMaintenance,
}
}
type AdSourceStatusKeyValue struct {
Key AdSourceStatus
Value string
}
var (
AdSourceStatusActiveKeyValue = AdSourceStatusKeyValue{Key: AdSourceStatusActive, Value: "活跃"}
AdSourceStatusInactiveKeyValue = AdSourceStatusKeyValue{Key: AdSourceStatusInactive, Value: "非活跃"}
AdSourceStatusMaintenanceKeyValue = AdSourceStatusKeyValue{Key: AdSourceStatusMaintenance, Value: "维护中"}
)
func GetAllAdSourceStatusKeyValue() []AdSourceStatusKeyValue {
return []AdSourceStatusKeyValue{
AdSourceStatusActiveKeyValue,
AdSourceStatusInactiveKeyValue,
AdSourceStatusMaintenanceKeyValue,
}
}
var adSourceStatusValueMap = map[AdSourceStatus]string{
AdSourceStatusActive: AdSourceStatusActiveKeyValue.Value,
AdSourceStatusInactive: AdSourceStatusInactiveKeyValue.Value,
AdSourceStatusMaintenance: AdSourceStatusMaintenanceKeyValue.Value,
}
func GetAdSourceStatusValueByKey(key AdSourceStatus) (value string) {
value, exists := adSourceStatusValueMap[key]
if !exists {
value = "未知状态"
}
return
}

52
consts/ad_source_type.go Normal file
View File

@@ -0,0 +1,52 @@
package consts
// AdSourceType 广告源类型枚举
type AdSourceType string
const (
AdSourceTypeSelf AdSourceType = "self" // 自营
AdSourceTypeThirdParty AdSourceType = "third_party" // 第三方
AdSourceTypeExchange AdSourceType = "exchange" // 广告交易平台
)
// GetAllAdSourceTypes 获取所有广告源类型
func GetAllAdSourceTypes() []AdSourceType {
return []AdSourceType{
AdSourceTypeSelf,
AdSourceTypeThirdParty,
AdSourceTypeExchange,
}
}
type AdSourceTypeKeyValue struct {
Key AdSourceType
Value string
}
var (
AdSourceTypeSelfKeyValue = AdSourceTypeKeyValue{Key: AdSourceTypeSelf, Value: "自营"}
AdSourceTypeThirdPartyKeyValue = AdSourceTypeKeyValue{Key: AdSourceTypeThirdParty, Value: "第三方"}
AdSourceTypeExchangeKeyValue = AdSourceTypeKeyValue{Key: AdSourceTypeExchange, Value: "广告交易平台"}
)
func GetAllAdSourceTypeKeyValue() []AdSourceTypeKeyValue {
return []AdSourceTypeKeyValue{
AdSourceTypeSelfKeyValue,
AdSourceTypeThirdPartyKeyValue,
AdSourceTypeExchangeKeyValue,
}
}
var adSourceTypeValueMap = map[AdSourceType]string{
AdSourceTypeSelf: AdSourceTypeSelfKeyValue.Value,
AdSourceTypeThirdParty: AdSourceTypeThirdPartyKeyValue.Value,
AdSourceTypeExchange: AdSourceTypeExchangeKeyValue.Value,
}
func GetAdSourceTypeValueByKey(key AdSourceType) (value string) {
value, exists := adSourceTypeValueMap[key]
if !exists {
value = "未知类型"
}
return
}

52
consts/auth_type.go Normal file
View File

@@ -0,0 +1,52 @@
package consts
// AuthType 认证类型枚举
type AuthType string
const (
AuthTypeAPIKey AuthType = "api_key" // API密钥
AuthTypeOAuth AuthType = "oauth" // OAuth
AuthTypeBasic AuthType = "basic" // Basic认证
)
// GetAllAuthTypes 获取所有认证类型
func GetAllAuthTypes() []AuthType {
return []AuthType{
AuthTypeAPIKey,
AuthTypeOAuth,
AuthTypeBasic,
}
}
type AuthTypeKeyValue struct {
Key AuthType
Value string
}
var (
AuthTypeAPIKeyKeyValue = AuthTypeKeyValue{Key: AuthTypeAPIKey, Value: "API密钥"}
AuthTypeOAuthKeyValue = AuthTypeKeyValue{Key: AuthTypeOAuth, Value: "OAuth"}
AuthTypeBasicKeyValue = AuthTypeKeyValue{Key: AuthTypeBasic, Value: "Basic认证"}
)
func GetAllAuthTypeKeyValue() []AuthTypeKeyValue {
return []AuthTypeKeyValue{
AuthTypeAPIKeyKeyValue,
AuthTypeOAuthKeyValue,
AuthTypeBasicKeyValue,
}
}
var authTypeValueMap = map[AuthType]string{
AuthTypeAPIKey: AuthTypeAPIKeyKeyValue.Value,
AuthTypeOAuth: AuthTypeOAuthKeyValue.Value,
AuthTypeBasic: AuthTypeBasicKeyValue.Value,
}
func GetAuthTypeValueByKey(key AuthType) (value string) {
value, exists := authTypeValueMap[key]
if !exists {
value = "未知认证类型"
}
return
}

57
consts/bidding_type.go Normal file
View File

@@ -0,0 +1,57 @@
package consts
// BiddingType 竞价类型枚举
type BiddingType string
const (
BiddingTypeCPM BiddingType = "cpm" // 千次展示成本
BiddingTypeCPC BiddingType = "cpc" // 每次点击成本
BiddingTypeCPA BiddingType = "cpa" // 每次行动成本
BiddingTypeRTB BiddingType = "rtb" // 实时竞价
)
// GetAllBiddingTypes 获取所有竞价类型
func GetAllBiddingTypes() []BiddingType {
return []BiddingType{
BiddingTypeCPM,
BiddingTypeCPC,
BiddingTypeCPA,
BiddingTypeRTB,
}
}
type BiddingTypeKeyValue struct {
Key BiddingType
Value string
}
var (
BiddingTypeCPMKeyValue = BiddingTypeKeyValue{Key: BiddingTypeCPM, Value: "千次展示成本"}
BiddingTypeCPCKeypValue = BiddingTypeKeyValue{Key: BiddingTypeCPC, Value: "每次点击成本"}
BiddingTypeCPAKeyValue = BiddingTypeKeyValue{Key: BiddingTypeCPA, Value: "每次行动成本"}
BiddingTypeRTBKeyValue = BiddingTypeKeyValue{Key: BiddingTypeRTB, Value: "实时竞价"}
)
func GetAllBiddingTypeKeyValue() []BiddingTypeKeyValue {
return []BiddingTypeKeyValue{
BiddingTypeCPMKeyValue,
BiddingTypeCPCKeypValue,
BiddingTypeCPAKeyValue,
BiddingTypeRTBKeyValue,
}
}
var biddingTypeValueMap = map[BiddingType]string{
BiddingTypeCPM: BiddingTypeCPMKeyValue.Value,
BiddingTypeCPC: BiddingTypeCPCKeypValue.Value,
BiddingTypeCPA: BiddingTypeCPAKeyValue.Value,
BiddingTypeRTB: BiddingTypeRTBKeyValue.Value,
}
func GetBiddingTypeValueByKey(key BiddingType) (value string) {
value, exists := biddingTypeValueMap[key]
if !exists {
value = "未知竞价类型"
}
return
}

57
consts/billing_model.go Normal file
View File

@@ -0,0 +1,57 @@
package consts
// BillingModel 计费模式枚举
type BillingModel string
const (
BillingModelCPM BillingModel = "cpm" // 千次展示成本
BillingModelCPC BillingModel = "cpc" // 每次点击成本
BillingModelCPA BillingModel = "cpa" // 每次行动成本
BillingModelRevShare BillingModel = "rev_share" // 收入分成
)
// GetAllBillingModels 获取所有计费模式
func GetAllBillingModels() []BillingModel {
return []BillingModel{
BillingModelCPM,
BillingModelCPC,
BillingModelCPA,
BillingModelRevShare,
}
}
type BillingModelKeyValue struct {
Key BillingModel
Value string
}
var (
BillingModelCPMKeyValue = BillingModelKeyValue{Key: BillingModelCPM, Value: "千次展示成本"}
BillingModelCPCKeypValue = BillingModelKeyValue{Key: BillingModelCPC, Value: "每次点击成本"}
BillingModelCPAKeyValue = BillingModelKeyValue{Key: BillingModelCPA, Value: "每次行动成本"}
BillingModelRevShareKeyValue = BillingModelKeyValue{Key: BillingModelRevShare, Value: "收入分成"}
)
func GetAllBillingModelKeyValue() []BillingModelKeyValue {
return []BillingModelKeyValue{
BillingModelCPMKeyValue,
BillingModelCPCKeypValue,
BillingModelCPAKeyValue,
BillingModelRevShareKeyValue,
}
}
var billingModelValueMap = map[BillingModel]string{
BillingModelCPM: BillingModelCPMKeyValue.Value,
BillingModelCPC: BillingModelCPCKeypValue.Value,
BillingModelCPA: BillingModelCPAKeyValue.Value,
BillingModelRevShare: BillingModelRevShareKeyValue.Value,
}
func GetBillingModelValueByKey(key BillingModel) (value string) {
value, exists := billingModelValueMap[key]
if !exists {
value = "未知计费模式"
}
return
}

18
consts/collections.go Normal file
View File

@@ -0,0 +1,18 @@
package consts
// MongoDB集合名称常量
const (
AdPositionCollection = "ad_position" // 广告位集合
AdSourceCollection = "ad_source" // 广告源集合
AdvertisementCollection = "advertisement" // 广告集合
AdvertiserCollection = "advertiser" // 广告主集合
ApplicationCollection = "application" // 应用集合
CidRequestCollection = "cid_request" // CID请求集合
StrategyCollection = "strategy" // 策略集合
AdCreativeCollection = "ad_creative" // 广告创意集合
AdPlatformCollection = "ad_platform" // 广告平台集合
AdTypeCollection = "ad_type" // 广告类型集合
AppPlatformConfigCollection = "app_platform_config" // 应用平台配置集合
PlatformDeliveryRuleCollection = "platform_delivery_rule" // 平台投放规则集合
TargetingCollection = "targeting" // 定向规则集合
)

19
consts/config.go Normal file
View File

@@ -0,0 +1,19 @@
package consts
// 默认配置值
const (
DefaultTimeout = 5000 // 默认超时时间(毫秒)
DefaultRetryCount = 3 // 默认重试次数
DefaultPriority = 1 // 默认优先级
)
// 错误消息
const (
ErrAdSourceNotFound = "广告源不存在"
ErrAdSourceNameExists = "广告源名称已存在"
ErrAdSourceCodeExists = "广告源编码已存在"
ErrAdSourceInactive = "广告源非活跃状态"
ErrAdSourceUnhealthy = "广告源健康状态异常"
ErrRateLimitExceeded = "请求频率超限"
ErrInvalidConfiguration = "配置参数无效"
)

View File

@@ -1,86 +1,16 @@
package consts
// 广告源状态
const (
AdSourceStatusActive = "active" // 活跃
AdSourceStatusInactive = "inactive" // 非活跃
AdSourceStatusMaintenance = "maintenance" // 维护中
)
// 注意:以下枚举常量已迁移到单独的枚举文件中,请使用新的枚举类型:
// - AdSourceStatus -> consts.AdSourceStatus (ad_source_status.go)
// - AdSourceHealth -> consts.AdSourceHealth (ad_source_health.go)
// - AdSourceType -> consts.AdSourceType (ad_source_type.go)
// - AdSourceProvider -> consts.AdSourceProvider (ad_source_provider.go)
// - AuthType -> consts.AuthType (auth_type.go)
// - BiddingType -> consts.BiddingType (bidding_type.go)
// - AdFormatType -> consts.AdFormatType (ad_format_type.go)
// - BillingModel -> consts.BillingModel (billing_model.go)
// - PaymentTerms -> consts.PaymentTerms (payment_terms.go)
// 广告源健康状态
const (
AdSourceHealthHealthy = "healthy" // 健康
AdSourceHealthDegraded = "degraded" // 降级
AdSourceHealthUnhealthy = "unhealthy" // 不健康
)
// 广告源类型
const (
AdSourceTypeSelf = "self" // 自营
AdSourceTypeThirdParty = "third_party" // 第三方
AdSourceTypeExchange = "exchange" // 广告交易平台
)
// 广告源提供商
const (
AdSourceProviderGoogle = "google" // Google
AdSourceProviderBaidu = "baidu" // 百度
AdSourceProviderTencent = "tencent" // 腾讯
AdSourceProviderSelf = "self" // 自营
)
// 认证类型
const (
AuthTypeAPIKey = "api_key" // API密钥
AuthTypeOAuth = "oauth" // OAuth
AuthTypeBasic = "basic" // Basic认证
)
// 竞价类型
const (
BiddingTypeCPM = "cpm" // 千次展示成本
BiddingTypeCPC = "cpc" // 每次点击成本
BiddingTypeCPA = "cpa" // 每次行动成本
BiddingTypeRTB = "rtb" // 实时竞价
)
// 广告格式类型
const (
AdFormatTypeBanner = "banner" // 横幅广告
AdFormatTypeVideo = "video" // 视频广告
AdFormatTypeNative = "native" // 原生广告
AdFormatTypeInterstitial = "interstitial" // 插屏广告
)
// 计费模式
const (
BillingModelCPM = "cpm" // 千次展示成本
BillingModelCPC = "cpc" // 每次点击成本
BillingModelCPA = "cpa" // 每次行动成本
BillingModelRevShare = "rev_share" // 收入分成
)
// 支付条款
const (
PaymentTermsNet30 = "net_30" // 30天
PaymentTermsNet60 = "net_60" // 60天
PaymentTermsNet90 = "net_90" // 90天
)
// 默认配置值
const (
DefaultTimeout = 5000 // 默认超时时间(毫秒)
DefaultRetryCount = 3 // 默认重试次数
DefaultPriority = 1 // 默认优先级
)
// 错误消息
const (
ErrAdSourceNotFound = "广告源不存在"
ErrAdSourceNameExists = "广告源名称已存在"
ErrAdSourceCodeExists = "广告源编码已存在"
ErrAdSourceInactive = "广告源非活跃状态"
ErrAdSourceUnhealthy = "广告源健康状态异常"
ErrRateLimitExceeded = "请求频率超限"
ErrInvalidConfiguration = "配置参数无效"
)
// 配置值常量已迁移到 config.go 文件中
// 错误消息常量已迁移到 config.go 文件中
// MongoDB集合名称常量已迁移到 collections.go 文件中

52
consts/payment_terms.go Normal file
View File

@@ -0,0 +1,52 @@
package consts
// PaymentTerms 支付条款枚举
type PaymentTerms string
const (
PaymentTermsNet30 PaymentTerms = "net_30" // 30天
PaymentTermsNet60 PaymentTerms = "net_60" // 60天
PaymentTermsNet90 PaymentTerms = "net_90" // 90天
)
// GetAllPaymentTerms 获取所有支付条款
func GetAllPaymentTerms() []PaymentTerms {
return []PaymentTerms{
PaymentTermsNet30,
PaymentTermsNet60,
PaymentTermsNet90,
}
}
type PaymentTermsKeyValue struct {
Key PaymentTerms
Value string
}
var (
PaymentTermsNet30KeyValue = PaymentTermsKeyValue{Key: PaymentTermsNet30, Value: "30天"}
PaymentTermsNet60KeyValue = PaymentTermsKeyValue{Key: PaymentTermsNet60, Value: "60天"}
PaymentTermsNet90KeyValue = PaymentTermsKeyValue{Key: PaymentTermsNet90, Value: "90天"}
)
func GetAllPaymentTermsKeyValue() []PaymentTermsKeyValue {
return []PaymentTermsKeyValue{
PaymentTermsNet30KeyValue,
PaymentTermsNet60KeyValue,
PaymentTermsNet90KeyValue,
}
}
var paymentTermsValueMap = map[PaymentTerms]string{
PaymentTermsNet30: PaymentTermsNet30KeyValue.Value,
PaymentTermsNet60: PaymentTermsNet60KeyValue.Value,
PaymentTermsNet90: PaymentTermsNet90KeyValue.Value,
}
func GetPaymentTermsValueByKey(key PaymentTerms) (value string) {
value, exists := paymentTermsValueMap[key]
if !exists {
value = "未知支付条款"
}
return
}