- Introduced BetStatStore, BranchStatStore, and WalletStatStore interfaces for handling statistics. - Implemented repository methods for fetching and updating bet, branch, and wallet statistics. - Created reporting services for generating interval reports for bets, branches, companies, and wallets. - Enhanced CSV writing functionality to support dynamic struct to CSV conversion. - Added cron jobs for periodic updates of branch and wallet statistics. - Updated wallet handler to include transaction statistics in the response.
89 lines
2.7 KiB
Go
89 lines
2.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
)
|
|
|
|
// Branch-level aggregated report
|
|
type BranchStat struct {
|
|
IntervalStart time.Time
|
|
BranchID int64
|
|
BranchName string
|
|
CompanyID int64
|
|
CompanyName string
|
|
CompanySlug string
|
|
TotalBets int64
|
|
TotalStake Currency
|
|
DeductedStake Currency
|
|
TotalCashOut Currency
|
|
TotalCashBacks Currency
|
|
NumberOfUnsettled int64
|
|
TotalUnsettledAmount Currency
|
|
TotalCashiers int64
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type BranchStatFilter struct {
|
|
Interval ValidDateInterval
|
|
BranchID ValidInt64
|
|
CompanyID ValidInt64
|
|
}
|
|
|
|
func ConvertDBBranchStats(branch dbgen.BranchStat) BranchStat {
|
|
return BranchStat{
|
|
IntervalStart: branch.IntervalStart.Time,
|
|
BranchID: branch.BranchID,
|
|
BranchName: branch.BranchName,
|
|
CompanyID: branch.CompanyID,
|
|
CompanyName: branch.CompanyName,
|
|
CompanySlug: branch.CompanySlug,
|
|
TotalBets: branch.TotalBets,
|
|
TotalStake: Currency(branch.TotalStake),
|
|
DeductedStake: Currency(branch.DeductedStake),
|
|
TotalCashOut: Currency(branch.TotalCashOut),
|
|
TotalCashBacks: Currency(branch.TotalCashBacks),
|
|
NumberOfUnsettled: branch.NumberOfUnsettled,
|
|
TotalUnsettledAmount: Currency(branch.TotalUnsettledAmount),
|
|
TotalCashiers: branch.TotalCashiers,
|
|
UpdatedAt: branch.UpdatedAt.Time,
|
|
}
|
|
}
|
|
|
|
func ConvertDBBranchStatsList(stats []dbgen.BranchStat) []BranchStat {
|
|
result := make([]BranchStat, len(stats))
|
|
for i, stat := range stats {
|
|
result[i] = ConvertDBBranchStats(stat)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ConvertDBBranchStatsByInterval(branch dbgen.GetBranchStatsRow) BranchStat {
|
|
return BranchStat{
|
|
IntervalStart: branch.IntervalStart.Time,
|
|
BranchID: branch.BranchID,
|
|
BranchName: branch.BranchName,
|
|
CompanyID: branch.CompanyID,
|
|
CompanyName: branch.CompanyName,
|
|
CompanySlug: branch.CompanySlug,
|
|
TotalBets: branch.TotalBets,
|
|
TotalStake: Currency(branch.TotalStake),
|
|
DeductedStake: Currency(branch.DeductedStake),
|
|
TotalCashOut: Currency(branch.TotalCashOut),
|
|
TotalCashBacks: Currency(branch.TotalCashBacks),
|
|
NumberOfUnsettled: branch.NumberOfUnsettled,
|
|
TotalUnsettledAmount: Currency(branch.TotalUnsettledAmount),
|
|
TotalCashiers: branch.TotalCashiers,
|
|
UpdatedAt: branch.UpdatedAt.Time,
|
|
}
|
|
}
|
|
|
|
func ConvertDBBranchStatsByIntervalList(stats []dbgen.GetBranchStatsRow) []BranchStat {
|
|
result := make([]BranchStat, len(stats))
|
|
for i, stat := range stats {
|
|
result[i] = ConvertDBBranchStatsByInterval(stat)
|
|
}
|
|
return result
|
|
}
|