gomod引用
This commit is contained in:
@@ -46,8 +46,8 @@ func (c *application) GetApplication(ctx context.Context, req *dto.GetApplicatio
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将字符串ID转换为int64
|
// 将ObjectId的十六进制字符串转换为int64,如果失败则使用0
|
||||||
id, _ := strconv.ParseInt(app.Id, 10, 64)
|
id, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
|
||||||
// Application实体中没有TenantId字段,暂时设为0
|
// Application实体中没有TenantId字段,暂时设为0
|
||||||
tenantID := int64(0)
|
tenantID := int64(0)
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ func (c *application) ListApplications(ctx context.Context, req *dto.ListApplica
|
|||||||
// 转换为响应格式
|
// 转换为响应格式
|
||||||
appItems := make([]dto.ApplicationItem, len(list))
|
appItems := make([]dto.ApplicationItem, len(list))
|
||||||
for i, app := range 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{
|
appItems[i] = dto.ApplicationItem{
|
||||||
ID: id,
|
ID: id,
|
||||||
Name: app.Name,
|
Name: app.Name,
|
||||||
@@ -129,8 +129,8 @@ func (c *application) ValidateApplication(ctx context.Context, req *dto.Validate
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将字符串ID转换为int64
|
// 将ObjectId的十六进制字符串转换为int64,如果失败则使用0
|
||||||
appID, _ := strconv.ParseInt(app.Id, 10, 64)
|
appID, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
|
||||||
// Application实体中没有TenantId字段,暂时设为0
|
// Application实体中没有TenantId字段,暂时设为0
|
||||||
tenantID := int64(0)
|
tenantID := int64(0)
|
||||||
tentantName := ""
|
tentantName := ""
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"gitee.com/red-future---jilin-g/common/do"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const AdSourceCollection = "ad_source"
|
||||||
|
|
||||||
// AdSource 广告源实体
|
// AdSource 广告源实体
|
||||||
type AdSource struct {
|
type AdSource struct {
|
||||||
Id string `json:"id"` // 主键ID
|
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
|
|
||||||
Creator string `json:"creator"` // 创建者
|
|
||||||
Updater string `json:"updater"` // 更新者
|
|
||||||
IsDeleted bool `json:"isDeleted"` // 是否删除
|
|
||||||
|
|
||||||
// 基本信息
|
// 基本信息
|
||||||
Name string `json:"name"` // 广告源名称
|
Name string `json:"name"` // 广告源名称
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"gitee.com/red-future---jilin-g/common/do"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ApplicationCollection = "application"
|
||||||
|
|
||||||
// Application 应用实体
|
// Application 应用实体
|
||||||
type Application struct {
|
type Application struct {
|
||||||
Id string `json:"_id,omitempty" bson:"_id,omitempty"` // 主键ID
|
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
|
|
||||||
Creator string `json:"creator"` // 创建者
|
|
||||||
Updater string `json:"updater"` // 更新者
|
|
||||||
IsDeleted bool `json:"isDeleted"` // 是否删除
|
|
||||||
|
|
||||||
// 应用信息
|
// 应用信息
|
||||||
Name string `json:"name"` // 应用名称
|
Name string `json:"name"` // 应用名称
|
||||||
|
|||||||
@@ -2,19 +2,17 @@ package entity
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitee.com/red-future---jilin-g/common/do"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const StatReportCollection = "stat_report"
|
||||||
|
|
||||||
// StatReport 统计报表实体
|
// StatReport 统计报表实体
|
||||||
type StatReport struct {
|
type StatReport struct {
|
||||||
Id string `json:"_id,omitempty" bson:"_id,omitempty"` // 主键ID
|
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
|
|
||||||
Creator string `json:"creator"` // 创建者
|
|
||||||
Updater string `json:"updater"` // 更新者
|
|
||||||
IsDeleted bool `json:"isDeleted"` // 是否删除
|
|
||||||
|
|
||||||
// 报表基本信息
|
// 报表基本信息
|
||||||
TenantId int64 `json:"tenantId"` // 租户ID
|
|
||||||
AppID string `json:"appId"` // 应用ID (空字符串表示所有应用)
|
AppID string `json:"appId"` // 应用ID (空字符串表示所有应用)
|
||||||
ReportType string `json:"reportType"` // 报表类型:daily, weekly, monthly, quarterly, yearly
|
ReportType string `json:"reportType"` // 报表类型:daily, weekly, monthly, quarterly, yearly
|
||||||
ReportDate time.Time `json:"reportDate"` // 报表日期
|
ReportDate time.Time `json:"reportDate"` // 报表日期
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"gitee.com/red-future---jilin-g/common/do"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const StrategyCollection = "strategy"
|
||||||
|
|
||||||
// Strategy 匹配策略表
|
// Strategy 匹配策略表
|
||||||
type Strategy struct {
|
type Strategy struct {
|
||||||
Id int64 `json:"id" orm:"id,primary"` // ID
|
do.MongoBaseDO `bson:",inline" json:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||||
Name string `json:"name" orm:"name"` // 策略名称
|
|
||||||
Description string `json:"description" orm:"description"` // 描述
|
// 策略基本信息
|
||||||
MinConversion float64 `json:"min_conversion" orm:"min_conversion"` // 最低转化率
|
Name string `bson:"name" json:"name"` // 策略名称
|
||||||
MaxConversion float64 `json:"max_conversion" orm:"max_conversion"` // 最高转化率
|
Description string `bson:"description" json:"description"` // 描述
|
||||||
SourceWeights string `json:"source_weights" orm:"source_weights"` // 广告源权重 (JSON格式)
|
MinConversion float64 `bson:"minConversion" json:"minConversion"` // 最低转化率
|
||||||
MaxAdsPerReq int `json:"max_ads_per_req" orm:"max_ads_per_req"` // 每次请求最大广告数
|
MaxConversion float64 `bson:"maxConversion" json:"maxConversion"` // 最高转化率
|
||||||
MaxReqPerHour int `json:"max_req_per_hour" orm:"max_req_per_hour"` // 每小时最大请求次数
|
SourceWeights string `bson:"sourceWeights" json:"sourceWeights"` // 广告源权重 (JSON格式)
|
||||||
Priority int `json:"priority" orm:"priority"` // 优先级
|
MaxAdsPerReq int `bson:"maxAdsPerReq" json:"maxAdsPerReq"` // 每次请求最大广告数
|
||||||
Status string `json:"status" orm:"status"` // 状态: active, inactive
|
MaxReqPerHour int `bson:"maxReqPerHour" json:"maxReqPerHour"` // 每小时最大请求次数
|
||||||
CreatedAt *gtime.Time `json:"created_at" orm:"created_at"` // 创建时间
|
Priority int `bson:"priority" json:"priority"` // 优先级
|
||||||
UpdatedAt *gtime.Time `json:"updated_at" orm:"updated_at"` // 更新时间
|
Status string `bson:"status" json:"status"` // 状态: active, inactive
|
||||||
CreatedBy int64 `json:"created_by" orm:"created_by"` // 创建人
|
|
||||||
UpdatedBy int64 `json:"updated_by" orm:"updated_by"` // 更新人
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func (s *applicationService) UpdateApplication(ctx context.Context, id string, r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if conflictApp != nil && conflictApp.Id != id {
|
if conflictApp != nil && conflictApp.Id.Hex() != id {
|
||||||
return 0, gerror.New("应用名称已存在")
|
return 0, gerror.New("应用名称已存在")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,7 +307,6 @@ func (s *StatReportScheduler) generateDailyReportForDate(ctx context.Context, da
|
|||||||
|
|
||||||
// 保存日报表
|
// 保存日报表
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: tenantID,
|
|
||||||
AppID: "0", // 0表示所有应用
|
AppID: "0", // 0表示所有应用
|
||||||
ReportType: "daily",
|
ReportType: "daily",
|
||||||
ReportDate: date,
|
ReportDate: date,
|
||||||
@@ -359,7 +358,6 @@ func (s *StatReportScheduler) generateMonthlyReportFromDaily(ctx context.Context
|
|||||||
reportData := s.aggregateDailyReportsToMonthly(dailyReports)
|
reportData := s.aggregateDailyReportsToMonthly(dailyReports)
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: tenantID,
|
|
||||||
AppID: "0",
|
AppID: "0",
|
||||||
ReportType: "monthly",
|
ReportType: "monthly",
|
||||||
ReportDate: date,
|
ReportDate: date,
|
||||||
@@ -414,7 +412,6 @@ func (s *StatReportScheduler) generateQuarterlyReportFromMonthly(ctx context.Con
|
|||||||
reportData := s.aggregateMonthlyReportsToQuarterly(monthlyReports)
|
reportData := s.aggregateMonthlyReportsToQuarterly(monthlyReports)
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: tenantID,
|
|
||||||
AppID: "0",
|
AppID: "0",
|
||||||
ReportType: "quarterly",
|
ReportType: "quarterly",
|
||||||
ReportDate: date,
|
ReportDate: date,
|
||||||
@@ -468,7 +465,6 @@ func (s *StatReportScheduler) generateYearlyReportFromQuarterly(ctx context.Cont
|
|||||||
reportData := s.aggregateQuarterlyReportsToYearly(quarterlyReports)
|
reportData := s.aggregateQuarterlyReportsToYearly(quarterlyReports)
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: tenantID,
|
|
||||||
AppID: "0",
|
AppID: "0",
|
||||||
ReportType: "yearly",
|
ReportType: "yearly",
|
||||||
ReportDate: date,
|
ReportDate: date,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (s *StatReportService) GenerateDailyReport(ctx context.Context, req *dto.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: existingReport.Id,
|
ReportID: existingReport.Id.Hex(),
|
||||||
ReportType: "daily",
|
ReportType: "daily",
|
||||||
ReportDate: reportDate.Format("2006-01-02"),
|
ReportDate: reportDate.Format("2006-01-02"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -54,7 +54,6 @@ func (s *StatReportService) GenerateDailyReport(ctx context.Context, req *dto.Re
|
|||||||
|
|
||||||
// 保存报表
|
// 保存报表
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: req.TenantID,
|
|
||||||
AppID: strconv.FormatInt(req.AppID, 10),
|
AppID: strconv.FormatInt(req.AppID, 10),
|
||||||
ReportType: "daily",
|
ReportType: "daily",
|
||||||
ReportDate: reportDate,
|
ReportDate: reportDate,
|
||||||
@@ -69,7 +68,7 @@ func (s *StatReportService) GenerateDailyReport(ctx context.Context, req *dto.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: report.Id,
|
ReportID: report.Id.Hex(),
|
||||||
ReportType: "daily",
|
ReportType: "daily",
|
||||||
ReportDate: reportDate.Format("2006-01-02"),
|
ReportDate: reportDate.Format("2006-01-02"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -95,7 +94,7 @@ func (s *StatReportService) GenerateMonthlyReport(ctx context.Context, req *dto.
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: existingReport.Id,
|
ReportID: existingReport.Id.Hex(),
|
||||||
ReportType: "monthly",
|
ReportType: "monthly",
|
||||||
ReportDate: reportDate.Format("2006-01"),
|
ReportDate: reportDate.Format("2006-01"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -108,7 +107,6 @@ func (s *StatReportService) GenerateMonthlyReport(ctx context.Context, req *dto.
|
|||||||
}
|
}
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: req.TenantID,
|
|
||||||
AppID: strconv.FormatInt(req.AppID, 10),
|
AppID: strconv.FormatInt(req.AppID, 10),
|
||||||
ReportType: "monthly",
|
ReportType: "monthly",
|
||||||
ReportDate: reportDate,
|
ReportDate: reportDate,
|
||||||
@@ -123,7 +121,7 @@ func (s *StatReportService) GenerateMonthlyReport(ctx context.Context, req *dto.
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: report.Id,
|
ReportID: report.Id.Hex(),
|
||||||
ReportType: "monthly",
|
ReportType: "monthly",
|
||||||
ReportDate: reportDate.Format("2006-01"),
|
ReportDate: reportDate.Format("2006-01"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -150,7 +148,7 @@ func (s *StatReportService) GenerateWeeklyReport(ctx context.Context, req *dto.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: existingReport.Id,
|
ReportID: existingReport.Id.Hex(),
|
||||||
ReportType: "weekly",
|
ReportType: "weekly",
|
||||||
ReportDate: reportDate.Format("2006-W01"),
|
ReportDate: reportDate.Format("2006-W01"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -163,7 +161,6 @@ func (s *StatReportService) GenerateWeeklyReport(ctx context.Context, req *dto.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: req.TenantID,
|
|
||||||
AppID: strconv.FormatInt(req.AppID, 10),
|
AppID: strconv.FormatInt(req.AppID, 10),
|
||||||
ReportType: "weekly",
|
ReportType: "weekly",
|
||||||
ReportDate: reportDate,
|
ReportDate: reportDate,
|
||||||
@@ -178,7 +175,7 @@ func (s *StatReportService) GenerateWeeklyReport(ctx context.Context, req *dto.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: report.Id,
|
ReportID: report.Id.Hex(),
|
||||||
ReportType: "weekly",
|
ReportType: "weekly",
|
||||||
ReportDate: reportDate.Format("2006-W01"),
|
ReportDate: reportDate.Format("2006-W01"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -204,7 +201,7 @@ func (s *StatReportService) GenerateQuarterlyReport(ctx context.Context, req *dt
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: existingReport.Id,
|
ReportID: existingReport.Id.Hex(),
|
||||||
ReportType: "quarterly",
|
ReportType: "quarterly",
|
||||||
ReportDate: reportDate.Format("2006-Q1"),
|
ReportDate: reportDate.Format("2006-Q1"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -217,7 +214,6 @@ func (s *StatReportService) GenerateQuarterlyReport(ctx context.Context, req *dt
|
|||||||
}
|
}
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: req.TenantID,
|
|
||||||
AppID: strconv.FormatInt(req.AppID, 10),
|
AppID: strconv.FormatInt(req.AppID, 10),
|
||||||
ReportType: "quarterly",
|
ReportType: "quarterly",
|
||||||
ReportDate: reportDate,
|
ReportDate: reportDate,
|
||||||
@@ -232,7 +228,7 @@ func (s *StatReportService) GenerateQuarterlyReport(ctx context.Context, req *dt
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: report.Id,
|
ReportID: report.Id.Hex(),
|
||||||
ReportType: "quarterly",
|
ReportType: "quarterly",
|
||||||
ReportDate: reportDate.Format("2006-Q1"),
|
ReportDate: reportDate.Format("2006-Q1"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -258,7 +254,7 @@ func (s *StatReportService) GenerateYearlyReport(ctx context.Context, req *dto.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: existingReport.Id,
|
ReportID: existingReport.Id.Hex(),
|
||||||
ReportType: "yearly",
|
ReportType: "yearly",
|
||||||
ReportDate: reportDate.Format("2006"),
|
ReportDate: reportDate.Format("2006"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -271,7 +267,6 @@ func (s *StatReportService) GenerateYearlyReport(ctx context.Context, req *dto.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
report := &entity.StatReport{
|
report := &entity.StatReport{
|
||||||
TenantId: req.TenantID,
|
|
||||||
AppID: strconv.FormatInt(req.AppID, 10),
|
AppID: strconv.FormatInt(req.AppID, 10),
|
||||||
ReportType: "yearly",
|
ReportType: "yearly",
|
||||||
ReportDate: reportDate,
|
ReportDate: reportDate,
|
||||||
@@ -286,7 +281,7 @@ func (s *StatReportService) GenerateYearlyReport(ctx context.Context, req *dto.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ReportGenerateResp{
|
return &dto.ReportGenerateResp{
|
||||||
ReportID: report.Id,
|
ReportID: report.Id.Hex(),
|
||||||
ReportType: "yearly",
|
ReportType: "yearly",
|
||||||
ReportDate: reportDate.Format("2006"),
|
ReportDate: reportDate.Format("2006"),
|
||||||
Data: reportData,
|
Data: reportData,
|
||||||
@@ -596,10 +591,17 @@ func (s *StatReportService) GetReportList(ctx context.Context, req *dto.ReportLi
|
|||||||
var reportDTOs []*dto.ReportDTO
|
var reportDTOs []*dto.ReportDTO
|
||||||
for _, report := range reports {
|
for _, report := range reports {
|
||||||
appID, _ := strconv.ParseInt(report.AppID, 10, 64)
|
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{
|
reportDTOs = append(reportDTOs, &dto.ReportDTO{
|
||||||
ID: id,
|
ID: idInt64,
|
||||||
TenantID: report.TenantId,
|
TenantID: report.TenantId,
|
||||||
AppID: appID,
|
AppID: appID,
|
||||||
ReportType: report.ReportType,
|
ReportType: report.ReportType,
|
||||||
@@ -635,10 +637,16 @@ func (s *StatReportService) GetReportDetail(ctx context.Context, reportID int64)
|
|||||||
}
|
}
|
||||||
|
|
||||||
appID, _ := strconv.ParseInt(report.AppID, 10, 64)
|
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{
|
return &dto.ReportDetailResp{
|
||||||
ID: id,
|
ID: idInt64,
|
||||||
TenantID: report.TenantId,
|
TenantID: report.TenantId,
|
||||||
AppID: appID,
|
AppID: appID,
|
||||||
ReportType: report.ReportType,
|
ReportType: report.ReportType,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/utils"
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"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, "权重配置序列化失败")
|
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{
|
strategy := &entity.Strategy{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
@@ -64,22 +49,15 @@ func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStr
|
|||||||
MaxAdsPerReq: req.MaxAdsPerReq,
|
MaxAdsPerReq: req.MaxAdsPerReq,
|
||||||
Priority: req.Priority,
|
Priority: req.Priority,
|
||||||
Status: req.Status,
|
Status: req.Status,
|
||||||
CreatedBy: userId,
|
|
||||||
UpdatedBy: userId,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idStr, err := dao.Strategy.Create(ctx, strategy)
|
_, err = dao.Strategy.Create(ctx, strategy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将字符串ID转换为int64
|
// MongoDB使用ObjectId,创建成功后返回成功状态
|
||||||
parsedId, err := strconv.ParseInt(idStr, 10, 64)
|
return 1, nil
|
||||||
if err != nil {
|
|
||||||
return 0, gerror.Wrap(err, "ID转换失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsedId, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStrategy 更新策略
|
// UpdateStrategy 更新策略
|
||||||
@@ -115,22 +93,7 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
|
|||||||
return 0, gerror.Wrap(err, "权重配置序列化失败")
|
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{
|
strategy := &entity.Strategy{
|
||||||
Id: req.Id,
|
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
MinConversion: req.MinConversion,
|
MinConversion: req.MinConversion,
|
||||||
@@ -139,7 +102,6 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
|
|||||||
MaxAdsPerReq: req.MaxAdsPerReq,
|
MaxAdsPerReq: req.MaxAdsPerReq,
|
||||||
Priority: req.Priority,
|
Priority: req.Priority,
|
||||||
Status: req.Status,
|
Status: req.Status,
|
||||||
UpdatedBy: userId,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dao.Strategy.Update(ctx, strategy)
|
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{
|
return &dto.StrategyRes{
|
||||||
Id: entity.Id,
|
Id: idInt64,
|
||||||
Name: entity.Name,
|
Name: entity.Name,
|
||||||
Description: entity.Description,
|
Description: entity.Description,
|
||||||
TenantLevel: "", // Strategy实体中没有TenantLevel字段,暂时设为空字符串
|
TenantLevel: "", // Strategy实体中没有TenantLevel字段,暂时设为空字符串
|
||||||
@@ -191,8 +159,8 @@ func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strate
|
|||||||
Status: entity.Status,
|
Status: entity.Status,
|
||||||
CreatedAt: entity.CreatedAt.String(),
|
CreatedAt: entity.CreatedAt.String(),
|
||||||
UpdatedAt: entity.UpdatedAt.String(),
|
UpdatedAt: entity.UpdatedAt.String(),
|
||||||
CreatedBy: entity.CreatedBy,
|
CreatedBy: 0, // 这些字段在MongoBaseDO中不存在,暂时设为0
|
||||||
UpdatedBy: entity.UpdatedBy,
|
UpdatedBy: 0,
|
||||||
}, nil
|
}, 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{
|
strategyList = append(strategyList, &dto.StrategyRes{
|
||||||
Id: entity.Id,
|
Id: idInt64,
|
||||||
Name: entity.Name,
|
Name: entity.Name,
|
||||||
Description: entity.Description,
|
Description: entity.Description,
|
||||||
TenantLevel: "", // Strategy实体中没有TenantLevel字段,暂时设为空字符串
|
TenantLevel: "", // Strategy实体中没有TenantLevel字段,暂时设为空字符串
|
||||||
@@ -228,8 +202,8 @@ func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrat
|
|||||||
Status: entity.Status,
|
Status: entity.Status,
|
||||||
CreatedAt: entity.CreatedAt.String(),
|
CreatedAt: entity.CreatedAt.String(),
|
||||||
UpdatedAt: entity.UpdatedAt.String(),
|
UpdatedAt: entity.UpdatedAt.String(),
|
||||||
CreatedBy: entity.CreatedBy,
|
CreatedBy: 0, // 这些字段在MongoBaseDO中不存在,暂时设为0
|
||||||
UpdatedBy: entity.UpdatedBy,
|
UpdatedBy: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user