初始化项目

This commit is contained in:
2025-12-09 16:10:45 +08:00
parent 2ccbf71b60
commit 339dd97f66
42 changed files with 93 additions and 106 deletions

View File

@@ -1,9 +1,9 @@
package service
import (
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"context"
"time"

View File

@@ -1,9 +1,9 @@
package service
import (
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"context"
"github.com/gogf/gf/v2/errors/gerror"
)

View File

@@ -6,9 +6,9 @@ import (
"sort"
"time"
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
)
var AdStatistics = new(adStatistics)

View File

@@ -1,9 +1,9 @@
package service
import (
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"context"
"time"

View File

@@ -7,9 +7,9 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/util/gconv"
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
)
var Advertiser = new(advertiser)

View File

@@ -5,9 +5,9 @@ import (
"crypto/rand"
"encoding/hex"
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"github.com/gogf/gf/v2/errors/gerror"
)

View File

@@ -1,10 +1,10 @@
package service
import (
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cidservice/model/types"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"cid/model/types"
"context"
"encoding/json"
"fmt"
@@ -19,10 +19,10 @@ import (
)
var (
CID = cidService{}
CID = cid{}
)
type cidService struct{}
type cid struct{}
// AdMatchingStrategy 广告匹配策略
type AdMatchingStrategy struct {
@@ -34,7 +34,7 @@ type AdMatchingStrategy struct {
}
// getMatchingStrategy 获取匹配策略
func (s *cidService) getMatchingStrategy(ctx context.Context, tenantLevel string) (*AdMatchingStrategy, error) {
func (s *cid) getMatchingStrategy(ctx context.Context, tenantLevel string) (*AdMatchingStrategy, error) {
// 从数据库获取策略
strategyEntity, err := Strategy.GetStrategyByTenantLevel(ctx, tenantLevel)
if err != nil {
@@ -72,7 +72,7 @@ func (s *cidService) getMatchingStrategy(ctx context.Context, tenantLevel string
}
// GenerateCID 生成CID广告
func (s *cidService) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
func (s *cid) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
// 获取当前用户信息
userInfo, err := utils.GetUserInfo(ctx)
if err != nil {
@@ -123,7 +123,7 @@ func (s *cidService) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (
}
// getTenantByUser 根据用户获取租户信息
func (s *cidService) getTenantByUser(ctx context.Context, userId int64) (*types.Tenant, error) {
func (s *cid) getTenantByUser(ctx context.Context, userId int64) (*types.Tenant, error) {
// 通过common模块获取用户信息包含租户ID
userInfo, err := utils.GetUserInfo(ctx)
if err != nil {
@@ -164,7 +164,7 @@ func (s *cidService) getTenantByUser(ctx context.Context, userId int64) (*types.
}
// matchAds 根据策略匹配广告
func (s *cidService) matchAds(ctx context.Context, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy) ([]*dto.AdInfo, error) {
func (s *cid) matchAds(ctx context.Context, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy) ([]*dto.AdInfo, error) {
var matchedAds []*dto.AdInfo
// 根据策略权重从不同源获取广告
@@ -202,7 +202,7 @@ func (s *cidService) matchAds(ctx context.Context, req *dto.GenerateCIDReq, stra
}
// getAdsFromSource 从指定广告源获取广告
func (s *cidService) getAdsFromSource(ctx context.Context, source string, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy, weight int) ([]*dto.AdInfo, error) {
func (s *cid) getAdsFromSource(ctx context.Context, source string, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy, weight int) ([]*dto.AdInfo, error) {
switch source {
case "self":
return s.getSelfServiceAds(ctx, req, weight)
@@ -216,7 +216,7 @@ func (s *cidService) getAdsFromSource(ctx context.Context, source string, req *d
}
// getSelfServiceAds 获取自营广告
func (s *cidService) getSelfServiceAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
func (s *cid) getSelfServiceAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
// 这里应该从数据库查询自营广告
// 暂时返回模拟数据
ads := make([]*dto.AdInfo, 0)
@@ -236,7 +236,7 @@ func (s *cidService) getSelfServiceAds(ctx context.Context, req *dto.GenerateCID
}
// getGoogleAds 获取Google广告
func (s *cidService) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
func (s *cid) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
// 这里应该调用Google Ads API
// 暂时返回模拟数据
ads := make([]*dto.AdInfo, 0)
@@ -256,7 +256,7 @@ func (s *cidService) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq,
}
// getFacebookAds 获取Facebook广告
func (s *cidService) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
func (s *cid) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
// 这里应该调用Facebook Ads API
// 暂时返回模拟数据
ads := make([]*dto.AdInfo, 0)
@@ -276,14 +276,14 @@ func (s *cidService) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq
}
// generateUniqueCID 生成唯一CID
func (s *cidService) generateUniqueCID() string {
func (s *cid) generateUniqueCID() string {
timestamp := time.Now().Unix()
random := rand.Intn(8999) + 1000
return fmt.Sprintf("CID_%d_%d", timestamp, random)
}
// recordCIDRequest 记录CID请求
func (s *cidService) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDReq, tenant *types.Tenant, ads []*dto.AdInfo) {
func (s *cid) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDReq, tenant *types.Tenant, ads []*dto.AdInfo) {
// 转换dto.AdInfo到entity.Ad
var entityAds []entity.Ad
for _, ad := range ads {
@@ -312,7 +312,7 @@ func (s *cidService) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDR
}
// GetCIDHistory 获取CID请求历史
func (s *cidService) GetCIDHistory(ctx context.Context, userId int64, page, size int) (res *dto.GetCIDHistoryRes, err error) {
func (s *cid) GetCIDHistory(ctx context.Context, userId int64, page, size int) (res *dto.GetCIDHistoryRes, err error) {
history, total, err := dao.CIDRequest.GetHistory(ctx, userId, page, size)
if err != nil {
return nil, err

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"cidservice/consts"
"cid/consts"
"github.com/gogf/gf/v2/frame/g"
)

View File

@@ -6,8 +6,8 @@ import (
"sync"
"time"
"cidservice/dao"
"cidservice/model/entity"
"cid/dao"
"cid/model/entity"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"

View File

@@ -5,9 +5,9 @@ import (
"fmt"
"time"
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"

View File

@@ -1,9 +1,9 @@
package service
import (
"cidservice/dao"
"cidservice/model/dto"
"cidservice/model/entity"
"cid/dao"
"cid/model/dto"
"cid/model/entity"
"context"
"encoding/json"
"strconv"