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

@@ -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,
})
}