feat: 迁移商务工作台指标和仪表盘榜单

This commit is contained in:
Yvan
2026-11-04 01:25:51 +08:00
parent 0bef29ae4f
commit cbf0ee9be3
26 changed files with 1220 additions and 22 deletions
+56
View File
@@ -0,0 +1,56 @@
package business
import (
"context"
"kra/internal/biz/business"
"kra/internal/service/dto"
"strings"
)
type WorkbenchUsecase interface {
Summary(context.Context, []string) (*business.WorkbenchSummary, error)
Ranks(context.Context, []string, string, business.WorkbenchRankKind) ([]*business.WorkbenchRankRow, error)
}
type WorkbenchService struct{ uc WorkbenchUsecase }
func NewWorkbenchService(uc *business.WorkbenchUsecase) *WorkbenchService {
return &WorkbenchService{uc: uc}
}
func workbenchRequest(req *dto.WorkbenchQuery) ([]string, error) {
if req == nil {
return nil, business.ErrWorkbenchSource
}
return normalizePlatforms(req.Sources)
}
func workbenchCardResponse(card *business.WorkbenchCard) *dto.WorkbenchCard {
return &dto.WorkbenchCard{Value: card.Value, CompareValue: card.CompareValue, ChangeRate: card.ChangeRate, CompareLabel: card.CompareLabel}
}
func (s *WorkbenchService) Summary(ctx context.Context, req *dto.WorkbenchQuery) (*dto.WorkbenchSummary, error) {
sources, err := workbenchRequest(req)
if err != nil {
return nil, err
}
data, err := s.uc.Summary(ctx, sources)
if err != nil {
return nil, err
}
return &dto.WorkbenchSummary{TodayRegister: workbenchCardResponse(data.TodayRegister), TodayActive: workbenchCardResponse(data.TodayActive), TodayPay: workbenchCardResponse(data.TodayPay), MonthPay: workbenchCardResponse(data.MonthPay), ActivePromote: workbenchCardResponse(data.ActivePromote), NewPromote: workbenchCardResponse(data.NewPromote), Available: data.Available}, nil
}
func (s *WorkbenchService) Ranks(ctx context.Context, req *dto.WorkbenchQuery, kind business.WorkbenchRankKind) ([]*dto.WorkbenchRankRow, error) {
sources, err := workbenchRequest(req)
if err != nil {
return nil, err
}
if kind == business.WorkbenchPayHigh && strings.EqualFold(strings.TrimSpace(req.Order), "asc") {
kind = business.WorkbenchPayLow
}
rows, err := s.uc.Ranks(ctx, sources, req.Period, kind)
if err != nil {
return nil, err
}
out := make([]*dto.WorkbenchRankRow, 0, len(rows))
for _, row := range rows {
out = append(out, &dto.WorkbenchRankRow{Rank: row.Rank, SourceDB: row.SourceDB, SourceDBLabel: business.PlatformName(row.SourceDB), PromoteID: row.ID, PromoteName: row.Name, Value: row.Value})
}
return out, nil
}
+31
View File
@@ -0,0 +1,31 @@
package dto
type WorkbenchQuery struct {
Sources []string `form:"sourceDbList"`
Period string `form:"period"`
Order string `form:"order"`
}
type WorkbenchCard struct {
Value *string `json:"value"`
CompareValue *string `json:"compareValue"`
ChangeRate *string `json:"changeRate"`
ChangeDiff *string `json:"changeDiff"`
CompareLabel string `json:"compareLabel"`
}
type WorkbenchSummary struct {
TodayRegister *WorkbenchCard `json:"todayRegister"`
TodayActive *WorkbenchCard `json:"todayActive"`
TodayPay *WorkbenchCard `json:"todayPay"`
MonthPay *WorkbenchCard `json:"monthPay"`
ActivePromote *WorkbenchCard `json:"activePromote"`
NewPromote *WorkbenchCard `json:"newPromote"`
Available bool `json:"available"`
}
type WorkbenchRankRow struct {
Rank int `json:"rank"`
SourceDB string `json:"sourceDb"`
SourceDBLabel string `json:"sourceDbLabel"`
PromoteID int64 `json:"promoteId"`
PromoteName string `json:"promoteName"`
Value string `json:"value"`
}
+1
View File
@@ -26,6 +26,7 @@ var ProviderSet = wire.NewSet(
businessservice.NewLedgerService,
businessservice.NewAnalyticsService,
businessservice.NewServerAnalysisService,
businessservice.NewWorkbenchService,
systemservice.ProviderSet,
paymentservice.ProviderSet,
integrationservice.ProviderSet,