Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v3.13.2 #501

Merged
merged 4 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/controller/meta/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ func (c *AdminController) ExportDropReport(ctx *fiber.Ctx) error {
SourceCategory string `json:"sourceCategory" validate:"omitempty,sourcecategory"`
StartTime int64 `json:"start" swaggertype:"integer"`
EndTime int64 `json:"end" validate:"omitempty,gtfield=StartTime" swaggertype:"integer"`
Times int `json:"times" validate:"gte=0,lte=6"`
}
var request exportDropReportRequest
if err := rekuest.ValidBody(ctx, &request); err != nil {
Expand Down Expand Up @@ -675,7 +676,16 @@ func (c *AdminController) ExportDropReport(ctx *fiber.Ctx) error {
sourceCategory = constant.SourceCategoryAll
}

result, err := c.ExportService.ExportDropReportsAndPatterns(ctx.UserContext(), request.Server, &startTime, &endTime, stage.StageID, itemIds, accountId, request.SourceCategory)
// handle times, 0 means no filter on times
var times null.Int
if request.Times != 0 {
times.Int64 = int64(request.Times)
times.Valid = true
} else {
times.Valid = false
}

result, err := c.ExportService.ExportDropReportsAndPatterns(ctx.UserContext(), request.Server, &startTime, &endTime, times, stage.StageID, itemIds, accountId, request.SourceCategory)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions internal/model/drop_report_query_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DropReportQueryContext struct {
StageItemFilter *map[int][]int `json:"stageItemFilter"`
SourceCategory string `json:"sourceCategory"`
ExcludeNonOneTimes bool `json:"excludeNonOneTimes"`
Times null.Int `json:"times"`
}

func (queryCtx *DropReportQueryContext) GetStageIds() []int {
Expand Down
1 change: 1 addition & 0 deletions internal/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type ExportDropReportsAndPatternsResult struct {
}

type DropReportForExport struct {
Times int `json:"times"`
PatternID int `json:"pattern_id"`
CreatedAt int64 `json:"created_at"`
AccountID int `json:"account_id"`
Expand Down
8 changes: 7 additions & 1 deletion internal/repo/drop_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (s *DropReport) GetDropReports(ctx context.Context, queryCtx *model.DropRep
results := make([]*model.DropReport, 0)
query := s.DB.NewSelect().
TableExpr("drop_reports AS dr").
Column("pattern_id", "created_at", "account_id", "source_name", "version").
Column("pattern_id", "created_at", "account_id", "source_name", "version", "times").
Order("created_at")
s.handleServer(query, queryCtx.Server)
s.handleCreatedAtWithTime(query, queryCtx.StartTime, queryCtx.EndTime)
Expand All @@ -295,6 +295,12 @@ func (s *DropReport) GetDropReports(ctx context.Context, queryCtx *model.DropRep
s.handleAccountAndReliability(query, queryCtx.AccountID)
s.handleSourceName(query, queryCtx.SourceCategory)

if queryCtx.ExcludeNonOneTimes {
s.handleTimes(query, 1)
} else if queryCtx.Times.Valid {
s.handleTimes(query, int(queryCtx.Times.Int64))
}

if err := query.
Scan(ctx, &results); err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions internal/service/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewExport(
}

func (s *Export) ExportDropReportsAndPatterns(
ctx context.Context, server string, startTime *time.Time, endTime *time.Time, stageId int, itemIds []int, accountId null.Int, sourceCategory string,
ctx context.Context, server string, startTime *time.Time, endTime *time.Time, times null.Int, stageId int, itemIds []int, accountId null.Int, sourceCategory string,
) (*model.ExportDropReportsAndPatternsResult, error) {
stageIdItemIdMap := make(map[int][]int)
stageIdItemIdMap[stageId] = itemIds
Expand All @@ -39,7 +39,8 @@ func (s *Export) ExportDropReportsAndPatterns(
AccountID: accountId,
StageItemFilter: &stageIdItemIdMap,
SourceCategory: sourceCategory,
ExcludeNonOneTimes: true,
ExcludeNonOneTimes: false,
Times: times,
}
dropReports, err := s.DropReportService.GetDropReports(ctx, queryCtx)
if err != nil {
Expand All @@ -50,6 +51,7 @@ func (s *Export) ExportDropReportsAndPatterns(
dropReportForExportList := make([]*model.DropReportForExport, 0)
for _, dropReport := range dropReports {
dropReportForExportList = append(dropReportForExportList, &model.DropReportForExport{
Times: dropReport.Times,
PatternID: dropReport.PatternID,
CreatedAt: dropReport.CreatedAt.UnixMilli(),
AccountID: dropReport.AccountID,
Expand Down
Loading