初始化项目

This commit is contained in:
2025-12-10 15:41:52 +08:00
parent 339dd97f66
commit 232009bbc2
25 changed files with 419 additions and 467 deletions

View File

@@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
"strconv"
"sync"
"time"
@@ -307,7 +308,7 @@ func (s *StatReportScheduler) generateDailyReportForDate(ctx context.Context, da
// 保存日报表
report := &entity.StatReport{
TenantId: tenantID,
AppID: 0, // 0表示所有应用
AppID: "0", // 0表示所有应用
ReportType: "daily",
ReportDate: date,
ReportData: gconv.String(reportData),
@@ -315,7 +316,7 @@ func (s *StatReportScheduler) generateDailyReportForDate(ctx context.Context, da
Status: "completed",
}
_, err = dao.StatReport.Create(ctx, report)
err = dao.StatReport.Create(ctx, report)
if err != nil {
g.Log().Errorf(ctx, "保存租户%d日报表失败: %v", tenantID, err)
continue
@@ -359,7 +360,7 @@ func (s *StatReportScheduler) generateMonthlyReportFromDaily(ctx context.Context
report := &entity.StatReport{
TenantId: tenantID,
AppID: 0,
AppID: "0",
ReportType: "monthly",
ReportDate: date,
ReportData: gconv.String(reportData),
@@ -367,7 +368,7 @@ func (s *StatReportScheduler) generateMonthlyReportFromDaily(ctx context.Context
Status: "completed",
}
_, err = dao.StatReport.Create(ctx, report)
err = dao.StatReport.Create(ctx, report)
if err != nil {
g.Log().Errorf(ctx, "保存租户%d月报表失败: %v", tenantID, err)
continue
@@ -414,7 +415,7 @@ func (s *StatReportScheduler) generateQuarterlyReportFromMonthly(ctx context.Con
report := &entity.StatReport{
TenantId: tenantID,
AppID: 0,
AppID: "0",
ReportType: "quarterly",
ReportDate: date,
ReportData: gconv.String(reportData),
@@ -422,7 +423,7 @@ func (s *StatReportScheduler) generateQuarterlyReportFromMonthly(ctx context.Con
Status: "completed",
}
_, err = dao.StatReport.Create(ctx, report)
err = dao.StatReport.Create(ctx, report)
if err != nil {
g.Log().Errorf(ctx, "保存租户%d季度报表失败: %v", tenantID, err)
continue
@@ -468,7 +469,7 @@ func (s *StatReportScheduler) generateYearlyReportFromQuarterly(ctx context.Cont
report := &entity.StatReport{
TenantId: tenantID,
AppID: 0,
AppID: "0",
ReportType: "yearly",
ReportDate: date,
ReportData: gconv.String(reportData),
@@ -476,7 +477,7 @@ func (s *StatReportScheduler) generateYearlyReportFromQuarterly(ctx context.Cont
Status: "completed",
}
_, err = dao.StatReport.Create(ctx, report)
err = dao.StatReport.Create(ctx, report)
if err != nil {
g.Log().Errorf(ctx, "保存租户%d年报表失败: %v", tenantID, err)
continue
@@ -499,7 +500,7 @@ func (s *StatReportScheduler) getDailyReportsForMonth(ctx context.Context, tenan
startDate := time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, time.Local)
endDate := startDate.AddDate(0, 1, -1)
reports, _, err := dao.StatReport.List(ctx, tenantID, 0, "daily", startDate.Format("2006-01-02"), endDate.Format("2006-01-02"), 1, 31)
reports, _, err := dao.StatReport.List(ctx, strconv.FormatInt(tenantID, 10), "0", "daily", startDate.Format("2006-01-02"), endDate.Format("2006-01-02"), 1, 31)
if err != nil {
return nil, err
}
@@ -525,7 +526,7 @@ func (s *StatReportScheduler) getMonthlyReportsForQuarter(ctx context.Context, t
monthDate := time.Date(date.Year(), quarterStartMonth+time.Month(i), 1, 0, 0, 0, 0, time.Local)
reportDate := monthDate.Format("2006-01")
report, err := dao.StatReport.GetByTenantAndDate(ctx, tenantID, "monthly", reportDate)
report, err := dao.StatReport.GetByTenantAndDate(ctx, strconv.FormatInt(tenantID, 10), "monthly", reportDate)
if err != nil || report == nil {
continue
}
@@ -546,7 +547,7 @@ func (s *StatReportScheduler) getQuarterlyReportsForYear(ctx context.Context, te
for quarter := 1; quarter <= 4; quarter++ {
reportDate := fmt.Sprintf("%d-Q%d", date.Year(), quarter)
report, err := dao.StatReport.GetByTenantAndDate(ctx, tenantID, "quarterly", reportDate)
report, err := dao.StatReport.GetByTenantAndDate(ctx, strconv.FormatInt(tenantID, 10), "quarterly", reportDate)
if err != nil || report == nil {
continue
}
@@ -600,7 +601,7 @@ func (s *StatReportScheduler) getAllTenants(ctx context.Context) ([]int64, error
// isReportGenerated 检查报表是否已生成
func (s *StatReportScheduler) isReportGenerated(ctx context.Context, tenantID int64, reportType, date string) bool {
report, err := dao.StatReport.GetByTenantAndDate(ctx, tenantID, reportType, date)
report, err := dao.StatReport.GetByTenantAndDate(ctx, strconv.FormatInt(tenantID, 10), reportType, date)
if err != nil {
return false
}