gomod引用

This commit is contained in:
2025-12-18 17:51:33 +08:00
parent bdb356f300
commit 0814c6c819
9 changed files with 82 additions and 112 deletions

View File

@@ -46,8 +46,8 @@ func (c *application) GetApplication(ctx context.Context, req *dto.GetApplicatio
return nil, err
}
// 将字符串ID转换为int64
id, _ := strconv.ParseInt(app.Id, 10, 64)
// 将ObjectId的十六进制字符串转换为int64如果失败则使用0
id, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
// Application实体中没有TenantId字段暂时设为0
tenantID := int64(0)
@@ -81,7 +81,7 @@ func (c *application) ListApplications(ctx context.Context, req *dto.ListApplica
// 转换为响应格式
appItems := make([]dto.ApplicationItem, len(list))
for i, app := range list {
id, _ := strconv.ParseInt(app.Id, 10, 64)
id, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
appItems[i] = dto.ApplicationItem{
ID: id,
Name: app.Name,
@@ -129,8 +129,8 @@ func (c *application) ValidateApplication(ctx context.Context, req *dto.Validate
}, nil
}
// 将字符串ID转换为int64
appID, _ := strconv.ParseInt(app.Id, 10, 64)
// 将ObjectId的十六进制字符串转换为int64如果失败则使用0
appID, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
// Application实体中没有TenantId字段暂时设为0
tenantID := int64(0)
tentantName := ""

View File

@@ -1,17 +1,14 @@
package entity
import (
"time"
"gitee.com/red-future---jilin-g/common/do"
)
const AdSourceCollection = "ad_source"
// AdSource 广告源实体
type AdSource struct {
Id string `json:"id"` // 主键ID
CreatedAt time.Time `json:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
Creator string `json:"creator"` // 创建者
Updater string `json:"updater"` // 更新者
IsDeleted bool `json:"isDeleted"` // 是否删除
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
// 基本信息
Name string `json:"name"` // 广告源名称

View File

@@ -1,17 +1,14 @@
package entity
import (
"time"
"gitee.com/red-future---jilin-g/common/do"
)
const ApplicationCollection = "application"
// Application 应用实体
type Application struct {
Id string `json:"_id,omitempty" bson:"_id,omitempty"` // 主键ID
CreatedAt time.Time `json:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
Creator string `json:"creator"` // 创建者
Updater string `json:"updater"` // 更新者
IsDeleted bool `json:"isDeleted"` // 是否删除
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
// 应用信息
Name string `json:"name"` // 应用名称

View File

@@ -2,19 +2,17 @@ package entity
import (
"time"
"gitee.com/red-future---jilin-g/common/do"
)
const StatReportCollection = "stat_report"
// StatReport 统计报表实体
type StatReport struct {
Id string `json:"_id,omitempty" bson:"_id,omitempty"` // 主键ID
CreatedAt time.Time `json:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
Creator string `json:"creator"` // 创建者
Updater string `json:"updater"` // 更新者
IsDeleted bool `json:"isDeleted"` // 是否删除
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
// 报表基本信息
TenantId int64 `json:"tenantId"` // 租户ID
AppID string `json:"appId"` // 应用ID (空字符串表示所有应用)
ReportType string `json:"reportType"` // 报表类型daily, weekly, monthly, quarterly, yearly
ReportDate time.Time `json:"reportDate"` // 报表日期

View File

@@ -1,23 +1,23 @@
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
"gitee.com/red-future---jilin-g/common/do"
)
const StrategyCollection = "strategy"
// Strategy 匹配策略表
type Strategy struct {
Id int64 `json:"id" orm:"id,primary"` // ID
Name string `json:"name" orm:"name"` // 策略名称
Description string `json:"description" orm:"description"` // 描述
MinConversion float64 `json:"min_conversion" orm:"min_conversion"` // 最低转化率
MaxConversion float64 `json:"max_conversion" orm:"max_conversion"` // 最高转化率
SourceWeights string `json:"source_weights" orm:"source_weights"` // 广告源权重 (JSON格式)
MaxAdsPerReq int `json:"max_ads_per_req" orm:"max_ads_per_req"` // 每次请求最大广告数
MaxReqPerHour int `json:"max_req_per_hour" orm:"max_req_per_hour"` // 每小时最大请求次数
Priority int `json:"priority" orm:"priority"` // 优先级
Status string `json:"status" orm:"status"` // 状态: active, inactive
CreatedAt *gtime.Time `json:"created_at" orm:"created_at"` // 创建时间
UpdatedAt *gtime.Time `json:"updated_at" orm:"updated_at"` // 更新时间
CreatedBy int64 `json:"created_by" orm:"created_by"` // 创建人
UpdatedBy int64 `json:"updated_by" orm:"updated_by"` // 更新人
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
// 策略基本信息
Name string `bson:"name" json:"name"` // 策略名称
Description string `bson:"description" json:"description"` // 描述
MinConversion float64 `bson:"minConversion" json:"minConversion"` // 最低转化率
MaxConversion float64 `bson:"maxConversion" json:"maxConversion"` // 最高转化率
SourceWeights string `bson:"sourceWeights" json:"sourceWeights"` // 广告源权重 (JSON格式)
MaxAdsPerReq int `bson:"maxAdsPerReq" json:"maxAdsPerReq"` // 每次请求最大广告数
MaxReqPerHour int `bson:"maxReqPerHour" json:"maxReqPerHour"` // 每小时最大请求次数
Priority int `bson:"priority" json:"priority"` // 优先级
Status string `bson:"status" json:"status"` // 状态: active, inactive
}

View File

@@ -71,7 +71,7 @@ func (s *applicationService) UpdateApplication(ctx context.Context, id string, r
if err != nil {
return 0, err
}
if conflictApp != nil && conflictApp.Id != id {
if conflictApp != nil && conflictApp.Id.Hex() != id {
return 0, gerror.New("应用名称已存在")
}
}

View File

@@ -307,7 +307,6 @@ func (s *StatReportScheduler) generateDailyReportForDate(ctx context.Context, da
// 保存日报表
report := &entity.StatReport{
TenantId: tenantID,
AppID: "0", // 0表示所有应用
ReportType: "daily",
ReportDate: date,
@@ -359,7 +358,6 @@ func (s *StatReportScheduler) generateMonthlyReportFromDaily(ctx context.Context
reportData := s.aggregateDailyReportsToMonthly(dailyReports)
report := &entity.StatReport{
TenantId: tenantID,
AppID: "0",
ReportType: "monthly",
ReportDate: date,
@@ -414,7 +412,6 @@ func (s *StatReportScheduler) generateQuarterlyReportFromMonthly(ctx context.Con
reportData := s.aggregateMonthlyReportsToQuarterly(monthlyReports)
report := &entity.StatReport{
TenantId: tenantID,
AppID: "0",
ReportType: "quarterly",
ReportDate: date,
@@ -468,7 +465,6 @@ func (s *StatReportScheduler) generateYearlyReportFromQuarterly(ctx context.Cont
reportData := s.aggregateQuarterlyReportsToYearly(quarterlyReports)
report := &entity.StatReport{
TenantId: tenantID,
AppID: "0",
ReportType: "yearly",
ReportDate: date,

View File

@@ -39,7 +39,7 @@ func (s *StatReportService) GenerateDailyReport(ctx context.Context, req *dto.Re
}
return &dto.ReportGenerateResp{
ReportID: existingReport.Id,
ReportID: existingReport.Id.Hex(),
ReportType: "daily",
ReportDate: reportDate.Format("2006-01-02"),
Data: reportData,
@@ -54,7 +54,6 @@ func (s *StatReportService) GenerateDailyReport(ctx context.Context, req *dto.Re
// 保存报表
report := &entity.StatReport{
TenantId: req.TenantID,
AppID: strconv.FormatInt(req.AppID, 10),
ReportType: "daily",
ReportDate: reportDate,
@@ -69,7 +68,7 @@ func (s *StatReportService) GenerateDailyReport(ctx context.Context, req *dto.Re
}
return &dto.ReportGenerateResp{
ReportID: report.Id,
ReportID: report.Id.Hex(),
ReportType: "daily",
ReportDate: reportDate.Format("2006-01-02"),
Data: reportData,
@@ -95,7 +94,7 @@ func (s *StatReportService) GenerateMonthlyReport(ctx context.Context, req *dto.
}
return &dto.ReportGenerateResp{
ReportID: existingReport.Id,
ReportID: existingReport.Id.Hex(),
ReportType: "monthly",
ReportDate: reportDate.Format("2006-01"),
Data: reportData,
@@ -108,7 +107,6 @@ func (s *StatReportService) GenerateMonthlyReport(ctx context.Context, req *dto.
}
report := &entity.StatReport{
TenantId: req.TenantID,
AppID: strconv.FormatInt(req.AppID, 10),
ReportType: "monthly",
ReportDate: reportDate,
@@ -123,7 +121,7 @@ func (s *StatReportService) GenerateMonthlyReport(ctx context.Context, req *dto.
}
return &dto.ReportGenerateResp{
ReportID: report.Id,
ReportID: report.Id.Hex(),
ReportType: "monthly",
ReportDate: reportDate.Format("2006-01"),
Data: reportData,
@@ -150,7 +148,7 @@ func (s *StatReportService) GenerateWeeklyReport(ctx context.Context, req *dto.R
}
return &dto.ReportGenerateResp{
ReportID: existingReport.Id,
ReportID: existingReport.Id.Hex(),
ReportType: "weekly",
ReportDate: reportDate.Format("2006-W01"),
Data: reportData,
@@ -163,7 +161,6 @@ func (s *StatReportService) GenerateWeeklyReport(ctx context.Context, req *dto.R
}
report := &entity.StatReport{
TenantId: req.TenantID,
AppID: strconv.FormatInt(req.AppID, 10),
ReportType: "weekly",
ReportDate: reportDate,
@@ -178,7 +175,7 @@ func (s *StatReportService) GenerateWeeklyReport(ctx context.Context, req *dto.R
}
return &dto.ReportGenerateResp{
ReportID: report.Id,
ReportID: report.Id.Hex(),
ReportType: "weekly",
ReportDate: reportDate.Format("2006-W01"),
Data: reportData,
@@ -204,7 +201,7 @@ func (s *StatReportService) GenerateQuarterlyReport(ctx context.Context, req *dt
}
return &dto.ReportGenerateResp{
ReportID: existingReport.Id,
ReportID: existingReport.Id.Hex(),
ReportType: "quarterly",
ReportDate: reportDate.Format("2006-Q1"),
Data: reportData,
@@ -217,7 +214,6 @@ func (s *StatReportService) GenerateQuarterlyReport(ctx context.Context, req *dt
}
report := &entity.StatReport{
TenantId: req.TenantID,
AppID: strconv.FormatInt(req.AppID, 10),
ReportType: "quarterly",
ReportDate: reportDate,
@@ -232,7 +228,7 @@ func (s *StatReportService) GenerateQuarterlyReport(ctx context.Context, req *dt
}
return &dto.ReportGenerateResp{
ReportID: report.Id,
ReportID: report.Id.Hex(),
ReportType: "quarterly",
ReportDate: reportDate.Format("2006-Q1"),
Data: reportData,
@@ -258,7 +254,7 @@ func (s *StatReportService) GenerateYearlyReport(ctx context.Context, req *dto.R
}
return &dto.ReportGenerateResp{
ReportID: existingReport.Id,
ReportID: existingReport.Id.Hex(),
ReportType: "yearly",
ReportDate: reportDate.Format("2006"),
Data: reportData,
@@ -271,7 +267,6 @@ func (s *StatReportService) GenerateYearlyReport(ctx context.Context, req *dto.R
}
report := &entity.StatReport{
TenantId: req.TenantID,
AppID: strconv.FormatInt(req.AppID, 10),
ReportType: "yearly",
ReportDate: reportDate,
@@ -286,7 +281,7 @@ func (s *StatReportService) GenerateYearlyReport(ctx context.Context, req *dto.R
}
return &dto.ReportGenerateResp{
ReportID: report.Id,
ReportID: report.Id.Hex(),
ReportType: "yearly",
ReportDate: reportDate.Format("2006"),
Data: reportData,
@@ -596,10 +591,17 @@ func (s *StatReportService) GetReportList(ctx context.Context, req *dto.ReportLi
var reportDTOs []*dto.ReportDTO
for _, report := range reports {
appID, _ := strconv.ParseInt(report.AppID, 10, 64)
id, _ := strconv.ParseInt(report.Id, 10, 64)
// 使用ObjectId的十六进制字符串作为ID在DTO中保持为字符串
idStr := report.Id.Hex()
// 将ObjectId的十六进制字符串转换为int64如果失败则使用0
var idInt64 int64
if id, err := strconv.ParseInt(idStr, 16, 64); err == nil {
idInt64 = id
}
reportDTOs = append(reportDTOs, &dto.ReportDTO{
ID: id,
ID: idInt64,
TenantID: report.TenantId,
AppID: appID,
ReportType: report.ReportType,
@@ -635,10 +637,16 @@ func (s *StatReportService) GetReportDetail(ctx context.Context, reportID int64)
}
appID, _ := strconv.ParseInt(report.AppID, 10, 64)
id, _ := strconv.ParseInt(report.Id, 10, 64)
idStr := report.Id.Hex()
// 将ObjectId的十六进制字符串转换为int64如果失败则使用0
var idInt64 int64
if id, err := strconv.ParseInt(idStr, 16, 64); err == nil {
idInt64 = id
}
return &dto.ReportDetailResp{
ID: id,
ID: idInt64,
TenantID: report.TenantId,
AppID: appID,
ReportType: report.ReportType,

View File

@@ -8,7 +8,6 @@ import (
"encoding/json"
"strconv"
"gitee.com/red-future---jilin-g/common/utils"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
@@ -41,20 +40,6 @@ func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStr
return 0, gerror.Wrap(err, "权重配置序列化失败")
}
// 获取当前用户信息
userInfo, err := utils.GetUserInfo(ctx)
if err != nil {
return 0, gerror.Wrap(err, "获取用户信息失败")
}
// 将UserName转换为int64如果失败则使用0
var userId int64
if uid, ok := userInfo.UserName.(string); ok {
if parsedId, err := strconv.ParseInt(uid, 10, 64); err == nil {
userId = parsedId
}
}
strategy := &entity.Strategy{
Name: req.Name,
Description: req.Description,
@@ -64,22 +49,15 @@ func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStr
MaxAdsPerReq: req.MaxAdsPerReq,
Priority: req.Priority,
Status: req.Status,
CreatedBy: userId,
UpdatedBy: userId,
}
idStr, err := dao.Strategy.Create(ctx, strategy)
_, err = dao.Strategy.Create(ctx, strategy)
if err != nil {
return 0, err
}
// 将字符串ID转换为int64
parsedId, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
return 0, gerror.Wrap(err, "ID转换失败")
}
return parsedId, nil
// MongoDB使用ObjectId创建成功后返回成功状态
return 1, nil
}
// UpdateStrategy 更新策略
@@ -115,22 +93,7 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
return 0, gerror.Wrap(err, "权重配置序列化失败")
}
// 获取当前用户信息
userInfo, err := utils.GetUserInfo(ctx)
if err != nil {
return 0, gerror.Wrap(err, "获取用户信息失败")
}
// 将UserName转换为int64如果失败则使用0
var userId int64
if uid, ok := userInfo.UserName.(string); ok {
if parsedId, err := strconv.ParseInt(uid, 10, 64); err == nil {
userId = parsedId
}
}
strategy := &entity.Strategy{
Id: req.Id,
Name: req.Name,
Description: req.Description,
MinConversion: req.MinConversion,
@@ -139,7 +102,6 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
MaxAdsPerReq: req.MaxAdsPerReq,
Priority: req.Priority,
Status: req.Status,
UpdatedBy: userId,
}
return dao.Strategy.Update(ctx, strategy)
@@ -178,8 +140,14 @@ func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strate
}
}
// 将ObjectId的十六进制字符串转换为int64如果失败则使用0
var idInt64 int64
if id, err := strconv.ParseInt(entity.Id.Hex(), 16, 64); err == nil {
idInt64 = id
}
return &dto.StrategyRes{
Id: entity.Id,
Id: idInt64,
Name: entity.Name,
Description: entity.Description,
TenantLevel: "", // Strategy实体中没有TenantLevel字段暂时设为空字符串
@@ -191,8 +159,8 @@ func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strate
Status: entity.Status,
CreatedAt: entity.CreatedAt.String(),
UpdatedAt: entity.UpdatedAt.String(),
CreatedBy: entity.CreatedBy,
UpdatedBy: entity.UpdatedBy,
CreatedBy: 0, // 这些字段在MongoBaseDO中不存在暂时设为0
UpdatedBy: 0,
}, nil
}
@@ -215,8 +183,14 @@ func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrat
}
}
// 将ObjectId的十六进制字符串转换为int64如果失败则使用0
var idInt64 int64
if id, err := strconv.ParseInt(entity.Id.Hex(), 16, 64); err == nil {
idInt64 = id
}
strategyList = append(strategyList, &dto.StrategyRes{
Id: entity.Id,
Id: idInt64,
Name: entity.Name,
Description: entity.Description,
TenantLevel: "", // Strategy实体中没有TenantLevel字段暂时设为空字符串
@@ -228,8 +202,8 @@ func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrat
Status: entity.Status,
CreatedAt: entity.CreatedAt.String(),
UpdatedAt: entity.UpdatedAt.String(),
CreatedBy: entity.CreatedBy,
UpdatedBy: entity.UpdatedBy,
CreatedBy: 0, // 这些字段在MongoBaseDO中不存在暂时设为0
UpdatedBy: 0,
})
}