improve:清除未使用的数据表

This commit is contained in:
qian committed 2026-06-04 08:10:06 +08:00
1 parent 16c50b2875
commit 62826d9140
22 files changed
+77 -947

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"github.com/qianfree/team-api/internal/dao/internal"
)
// bilDailyRevenueSummaryDao is the data access object for the table bil_daily_revenue_summary.
// You can define custom methods on it to extend its functionality as needed.
type bilDailyRevenueSummaryDao struct {
*internal.BilDailyRevenueSummaryDao
}
var (
// BilDailyRevenueSummary is a globally accessible object for table bil_daily_revenue_summary operations.
BilDailyRevenueSummary = bilDailyRevenueSummaryDao{internal.NewBilDailyRevenueSummaryDao()}
)
// Add your custom methods and functionality below.
-22
View File
@@ -1,22 +0,0 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"github.com/qianfree/team-api/internal/dao/internal"
)
// bilDailyUsageSummaryDao is the data access object for the table bil_daily_usage_summary.
// You can define custom methods on it to extend its functionality as needed.
type bilDailyUsageSummaryDao struct {
*internal.BilDailyUsageSummaryDao
}
var (
// BilDailyUsageSummary is a globally accessible object for table bil_daily_usage_summary operations.
BilDailyUsageSummary = bilDailyUsageSummaryDao{internal.NewBilDailyUsageSummaryDao()}
)
// Add your custom methods and functionality below.
@@ -1,22 +0,0 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"github.com/qianfree/team-api/internal/dao/internal"
)
// bilMonthlyRevenueSummaryDao is the data access object for the table bil_monthly_revenue_summary.
// You can define custom methods on it to extend its functionality as needed.
type bilMonthlyRevenueSummaryDao struct {
*internal.BilMonthlyRevenueSummaryDao
}
var (
// BilMonthlyRevenueSummary is a globally accessible object for table bil_monthly_revenue_summary operations.
BilMonthlyRevenueSummary = bilMonthlyRevenueSummaryDao{internal.NewBilMonthlyRevenueSummaryDao()}
)
// Add your custom methods and functionality below.
-22
View File
@@ -1,22 +0,0 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"github.com/qianfree/team-api/internal/dao/internal"
)
// bilMonthlyUsageSummaryDao is the data access object for the table bil_monthly_usage_summary.
// You can define custom methods on it to extend its functionality as needed.
type bilMonthlyUsageSummaryDao struct {
*internal.BilMonthlyUsageSummaryDao
}
var (
// BilMonthlyUsageSummary is a globally accessible object for table bil_monthly_usage_summary operations.
BilMonthlyUsageSummary = bilMonthlyUsageSummaryDao{internal.NewBilMonthlyUsageSummaryDao()}
)
// Add your custom methods and functionality below.
@@ -1,95 +0,0 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// BilDailyRevenueSummaryDao is the data access object for the table bil_daily_revenue_summary.
type BilDailyRevenueSummaryDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns BilDailyRevenueSummaryColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// BilDailyRevenueSummaryColumns defines and stores column names for the table bil_daily_revenue_summary.
type BilDailyRevenueSummaryColumns struct {
Id string //
Date string //
TotalRecharge string //
TotalConsumption string //
NetRevenue string //
NewOrders string //
PaidOrders string //
CreatedAt string //
UpdatedAt string //
}
// bilDailyRevenueSummaryColumns holds the columns for the table bil_daily_revenue_summary.
var bilDailyRevenueSummaryColumns = BilDailyRevenueSummaryColumns{
Id: "id",
Date: "date",
TotalRecharge: "total_recharge",
TotalConsumption: "total_consumption",
NetRevenue: "net_revenue",
NewOrders: "new_orders",
PaidOrders: "paid_orders",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewBilDailyRevenueSummaryDao creates and returns a new DAO object for table data access.
func NewBilDailyRevenueSummaryDao(handlers ...gdb.ModelHandler) *BilDailyRevenueSummaryDao {
return &BilDailyRevenueSummaryDao{
group: "default",
table: "bil_daily_revenue_summary",
columns: bilDailyRevenueSummaryColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *BilDailyRevenueSummaryDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *BilDailyRevenueSummaryDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *BilDailyRevenueSummaryDao) Columns() BilDailyRevenueSummaryColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *BilDailyRevenueSummaryDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *BilDailyRevenueSummaryDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *BilDailyRevenueSummaryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}
@@ -1,93 +0,0 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// BilDailyUsageSummaryDao is the data access object for the table bil_daily_usage_summary.
type BilDailyUsageSummaryDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns BilDailyUsageSummaryColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// BilDailyUsageSummaryColumns defines and stores column names for the table bil_daily_usage_summary.
type BilDailyUsageSummaryColumns struct {
Id string //
TenantId string //
Date string //
TotalRequests string //
TotalTokens string //
TotalCost string //
CreatedAt string //
UpdatedAt string //
}
// bilDailyUsageSummaryColumns holds the columns for the table bil_daily_usage_summary.
var bilDailyUsageSummaryColumns = BilDailyUsageSummaryColumns{
Id: "id",
TenantId: "tenant_id",
Date: "date",
TotalRequests: "total_requests",
TotalTokens: "total_tokens",
TotalCost: "total_cost",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewBilDailyUsageSummaryDao creates and returns a new DAO object for table data access.
func NewBilDailyUsageSummaryDao(handlers ...gdb.ModelHandler) *BilDailyUsageSummaryDao {
return &BilDailyUsageSummaryDao{
group: "default",
table: "bil_daily_usage_summary",
columns: bilDailyUsageSummaryColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *BilDailyUsageSummaryDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *BilDailyUsageSummaryDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *BilDailyUsageSummaryDao) Columns() BilDailyUsageSummaryColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *BilDailyUsageSummaryDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *BilDailyUsageSummaryDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *BilDailyUsageSummaryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}
@@ -1,91 +0,0 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// BilMonthlyRevenueSummaryDao is the data access object for the table bil_monthly_revenue_summary.
type BilMonthlyRevenueSummaryDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns BilMonthlyRevenueSummaryColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// BilMonthlyRevenueSummaryColumns defines and stores column names for the table bil_monthly_revenue_summary.
type BilMonthlyRevenueSummaryColumns struct {
Id string //
Month string //
TotalRecharge string //
TotalConsumption string //
NetRevenue string //
CreatedAt string //
UpdatedAt string //
}
// bilMonthlyRevenueSummaryColumns holds the columns for the table bil_monthly_revenue_summary.
var bilMonthlyRevenueSummaryColumns = BilMonthlyRevenueSummaryColumns{
Id: "id",
Month: "month",
TotalRecharge: "total_recharge",
TotalConsumption: "total_consumption",
NetRevenue: "net_revenue",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewBilMonthlyRevenueSummaryDao creates and returns a new DAO object for table data access.
func NewBilMonthlyRevenueSummaryDao(handlers ...gdb.ModelHandler) *BilMonthlyRevenueSummaryDao {
return &BilMonthlyRevenueSummaryDao{
group: "default",
table: "bil_monthly_revenue_summary",
columns: bilMonthlyRevenueSummaryColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *BilMonthlyRevenueSummaryDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *BilMonthlyRevenueSummaryDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *BilMonthlyRevenueSummaryDao) Columns() BilMonthlyRevenueSummaryColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *BilMonthlyRevenueSummaryDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *BilMonthlyRevenueSummaryDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *BilMonthlyRevenueSummaryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}
@@ -1,93 +0,0 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// BilMonthlyUsageSummaryDao is the data access object for the table bil_monthly_usage_summary.
type BilMonthlyUsageSummaryDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns BilMonthlyUsageSummaryColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// BilMonthlyUsageSummaryColumns defines and stores column names for the table bil_monthly_usage_summary.
type BilMonthlyUsageSummaryColumns struct {
Id string //
TenantId string //
Month string //
TotalRequests string //
TotalTokens string //
TotalCost string //
CreatedAt string //
UpdatedAt string //
}
// bilMonthlyUsageSummaryColumns holds the columns for the table bil_monthly_usage_summary.
var bilMonthlyUsageSummaryColumns = BilMonthlyUsageSummaryColumns{
Id: "id",
TenantId: "tenant_id",
Month: "month",
TotalRequests: "total_requests",
TotalTokens: "total_tokens",
TotalCost: "total_cost",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewBilMonthlyUsageSummaryDao creates and returns a new DAO object for table data access.
func NewBilMonthlyUsageSummaryDao(handlers ...gdb.ModelHandler) *BilMonthlyUsageSummaryDao {
return &BilMonthlyUsageSummaryDao{
group: "default",
table: "bil_monthly_usage_summary",
columns: bilMonthlyUsageSummaryColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *BilMonthlyUsageSummaryDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *BilMonthlyUsageSummaryDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *BilMonthlyUsageSummaryDao) Columns() BilMonthlyUsageSummaryColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *BilMonthlyUsageSummaryDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *BilMonthlyUsageSummaryDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *BilMonthlyUsageSummaryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}
-87
View File
@@ -1,87 +0,0 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// PlgExampleLogsDao is the data access object for the table plg_example_logs.
type PlgExampleLogsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns PlgExampleLogsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// PlgExampleLogsColumns defines and stores column names for the table plg_example_logs.
type PlgExampleLogsColumns struct {
Id string //
TenantId string //
Action string //
Detail string //
CreatedAt string //
}
// plgExampleLogsColumns holds the columns for the table plg_example_logs.
var plgExampleLogsColumns = PlgExampleLogsColumns{
Id: "id",
TenantId: "tenant_id",
Action: "action",
Detail: "detail",
CreatedAt: "created_at",
}
// NewPlgExampleLogsDao creates and returns a new DAO object for table data access.
func NewPlgExampleLogsDao(handlers ...gdb.ModelHandler) *PlgExampleLogsDao {
return &PlgExampleLogsDao{
group: "default",
table: "plg_example_logs",
columns: plgExampleLogsColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *PlgExampleLogsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *PlgExampleLogsDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *PlgExampleLogsDao) Columns() PlgExampleLogsColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *PlgExampleLogsDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *PlgExampleLogsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *PlgExampleLogsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}
-22
View File
@@ -1,22 +0,0 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"github.com/qianfree/team-api/internal/dao/internal"
)
// plgExampleLogsDao is the data access object for the table plg_example_logs.
// You can define custom methods on it to extend its functionality as needed.
type plgExampleLogsDao struct {
*internal.PlgExampleLogsDao
}
var (
// PlgExampleLogs is a globally accessible object for table plg_example_logs operations.
PlgExampleLogs = plgExampleLogsDao{internal.NewPlgExampleLogsDao()}
)
// Add your custom methods and functionality below.
-164
View File
@@ -1,164 +0,0 @@
package task
import (
"context"
"time"
"github.com/gogf/gf/v2/frame/g"
)
// DailyUsageSummary 每日用量汇总
func DailyUsageSummary(ctx context.Context) {
yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
_, err := g.DB().Exec(ctx, `
INSERT INTO bil_daily_usage_summary (tenant_id, date, total_requests, total_tokens, total_cost)
SELECT
tenant_id,
$1::date,
COUNT(*),
COALESCE(SUM(input_tokens + output_tokens), 0),
COALESCE(SUM(total_cost), 0)
FROM bil_usage_logs
WHERE created_at::date = $1::date
GROUP BY tenant_id
ON CONFLICT (tenant_id, date)
DO UPDATE SET
total_requests = EXCLUDED.total_requests,
total_tokens = EXCLUDED.total_tokens,
total_cost = EXCLUDED.total_cost,
updated_at = NOW()
`, yesterday)
if err != nil {
g.Log().Errorf(ctx, "[Summary] DailyUsageSummary: %v", err)
}
}
// DailyRevenueSummary 每日收入汇总
func DailyRevenueSummary(ctx context.Context) {
yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
var rechargeTotal struct {
Total float64 `json:"total"`
}
g.DB().Raw(`
SELECT COALESCE(SUM(amount), 0) as total
FROM bil_transactions
WHERE type = 'recharge' AND created_at::date = $1::date
`, yesterday).Scan(ctx, &rechargeTotal)
var consumptionTotal struct {
Total float64 `json:"total"`
}
g.DB().Raw(`
SELECT COALESCE(SUM(total_cost), 0) as total
FROM bil_usage_logs
WHERE created_at::date = $1::date
`, yesterday).Scan(ctx, &consumptionTotal)
var newOrders struct {
Count int `json:"count"`
}
g.DB().Raw(`
SELECT COUNT(*) as count
FROM ord_orders
WHERE created_at::date = $1::date
`, yesterday).Scan(ctx, &newOrders)
var paidOrders struct {
Count int `json:"count"`
}
g.DB().Raw(`
SELECT COUNT(*) as count
FROM ord_orders
WHERE status IN ('paid', 'fulfilled') AND paid_at::date = $1::date
`, yesterday).Scan(ctx, &paidOrders)
netRevenue := rechargeTotal.Total - consumptionTotal.Total
_, err := g.DB().Exec(ctx, `
INSERT INTO bil_daily_revenue_summary (date, total_recharge, total_consumption, net_revenue, new_orders, paid_orders)
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (date)
DO UPDATE SET
total_recharge = EXCLUDED.total_recharge,
total_consumption = EXCLUDED.total_consumption,
net_revenue = EXCLUDED.net_revenue,
new_orders = EXCLUDED.new_orders,
paid_orders = EXCLUDED.paid_orders,
updated_at = NOW()
`, yesterday, rechargeTotal.Total, consumptionTotal.Total, netRevenue, newOrders.Count, paidOrders.Count)
if err != nil {
g.Log().Errorf(ctx, "[Summary] DailyRevenueSummary: %v", err)
}
}
// MonthlyUsageSummary 每月用量汇总
func MonthlyUsageSummary(ctx context.Context) {
lastMonth := time.Now().AddDate(0, -1, 0).Format("2006-01")
lastMonthStart := lastMonth + "-01"
lastMonthEnd := time.Now().Format("2006-01") + "-01"
_, err := g.DB().Exec(ctx, `
INSERT INTO bil_monthly_usage_summary (tenant_id, month, total_requests, total_tokens, total_cost)
SELECT
tenant_id,
$1::date,
COUNT(*),
COALESCE(SUM(input_tokens + output_tokens), 0),
COALESCE(SUM(total_cost), 0)
FROM bil_usage_logs
WHERE created_at >= $1::date AND created_at < $2::date
GROUP BY tenant_id
ON CONFLICT (tenant_id, month)
DO UPDATE SET
total_requests = EXCLUDED.total_requests,
total_tokens = EXCLUDED.total_tokens,
total_cost = EXCLUDED.total_cost,
updated_at = NOW()
`, lastMonthStart, lastMonthEnd)
if err != nil {
g.Log().Errorf(ctx, "[Summary] MonthlyUsageSummary: %v", err)
}
}
// MonthlyRevenueSummary 每月收入汇总
func MonthlyRevenueSummary(ctx context.Context) {
lastMonth := time.Now().AddDate(0, -1, 0).Format("2006-01")
lastMonthStart := lastMonth + "-01"
lastMonthEnd := time.Now().Format("2006-01") + "-01"
var rechargeTotal struct {
Total float64 `json:"total"`
}
g.DB().Raw(`
SELECT COALESCE(SUM(amount), 0) as total
FROM bil_transactions
WHERE type = 'recharge' AND created_at >= $1::date AND created_at < $2::date
`, lastMonthStart, lastMonthEnd).Scan(ctx, &rechargeTotal)
var consumptionTotal struct {
Total float64 `json:"total"`
}
g.DB().Raw(`
SELECT COALESCE(SUM(total_cost), 0) as total
FROM bil_usage_logs
WHERE created_at >= $1::date AND created_at < $2::date
`, lastMonthStart, lastMonthEnd).Scan(ctx, &consumptionTotal)
netRevenue := rechargeTotal.Total - consumptionTotal.Total
_, err := g.DB().Exec(ctx, `
INSERT INTO bil_monthly_revenue_summary (month, total_recharge, total_consumption, net_revenue)
VALUES ($1, $2, $3, $4)
ON CONFLICT (month)
DO UPDATE SET
total_recharge = EXCLUDED.total_recharge,
total_consumption = EXCLUDED.total_consumption,
net_revenue = EXCLUDED.net_revenue,
updated_at = NOW()
`, lastMonthStart, rechargeTotal.Total, consumptionTotal.Total, netRevenue)
if err != nil {
g.Log().Errorf(ctx, "[Summary] MonthlyRevenueSummary: %v", err)
}
}
@@ -1,24 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// BilDailyRevenueSummary is the golang structure of table bil_daily_revenue_summary for DAO operations like Where/Data.
type BilDailyRevenueSummary struct {
g.Meta `orm:"table:bil_daily_revenue_summary, do:true"`
Id any //
Date *gtime.Time //
TotalRecharge any //
TotalConsumption any //
NetRevenue any //
NewOrders any //
PaidOrders any //
CreatedAt *gtime.Time //
UpdatedAt *gtime.Time //
}
@@ -1,23 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// BilDailyUsageSummary is the golang structure of table bil_daily_usage_summary for DAO operations like Where/Data.
type BilDailyUsageSummary struct {
g.Meta `orm:"table:bil_daily_usage_summary, do:true"`
Id any //
TenantId any //
Date *gtime.Time //
TotalRequests any //
TotalTokens any //
TotalCost any //
CreatedAt *gtime.Time //
UpdatedAt *gtime.Time //
}
@@ -1,22 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// BilMonthlyRevenueSummary is the golang structure of table bil_monthly_revenue_summary for DAO operations like Where/Data.
type BilMonthlyRevenueSummary struct {
g.Meta `orm:"table:bil_monthly_revenue_summary, do:true"`
Id any //
Month *gtime.Time //
TotalRecharge any //
TotalConsumption any //
NetRevenue any //
CreatedAt *gtime.Time //
UpdatedAt *gtime.Time //
}
@@ -1,23 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// BilMonthlyUsageSummary is the golang structure of table bil_monthly_usage_summary for DAO operations like Where/Data.
type BilMonthlyUsageSummary struct {
g.Meta `orm:"table:bil_monthly_usage_summary, do:true"`
Id any //
TenantId any //
Month *gtime.Time //
TotalRequests any //
TotalTokens any //
TotalCost any //
CreatedAt *gtime.Time //
UpdatedAt *gtime.Time //
}
-20
View File
@@ -1,20 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// PlgExampleLogs is the golang structure of table plg_example_logs for DAO operations like Where/Data.
type PlgExampleLogs struct {
g.Meta `orm:"table:plg_example_logs, do:true"`
Id any //
TenantId any //
Action any //
Detail any //
CreatedAt *gtime.Time //
}
@@ -1,22 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// BilDailyRevenueSummary is the golang structure for table bil_daily_revenue_summary.
type BilDailyRevenueSummary struct {
Id int64 `json:"id" orm:"id" description:""` //
Date *gtime.Time `json:"date" orm:"date" description:""` //
TotalRecharge float64 `json:"total_recharge" orm:"total_recharge" description:""` //
TotalConsumption float64 `json:"total_consumption" orm:"total_consumption" description:""` //
NetRevenue float64 `json:"net_revenue" orm:"net_revenue" description:""` //
NewOrders int `json:"new_orders" orm:"new_orders" description:""` //
PaidOrders int `json:"paid_orders" orm:"paid_orders" description:""` //
CreatedAt *gtime.Time `json:"created_at" orm:"created_at" description:""` //
UpdatedAt *gtime.Time `json:"updated_at" orm:"updated_at" description:""` //
}
@@ -1,21 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// BilDailyUsageSummary is the golang structure for table bil_daily_usage_summary.
type BilDailyUsageSummary struct {
Id int64 `json:"id" orm:"id" description:""` //
TenantId int64 `json:"tenant_id" orm:"tenant_id" description:""` //
Date *gtime.Time `json:"date" orm:"date" description:""` //
TotalRequests int64 `json:"total_requests" orm:"total_requests" description:""` //
TotalTokens int64 `json:"total_tokens" orm:"total_tokens" description:""` //
TotalCost float64 `json:"total_cost" orm:"total_cost" description:""` //
CreatedAt *gtime.Time `json:"created_at" orm:"created_at" description:""` //
UpdatedAt *gtime.Time `json:"updated_at" orm:"updated_at" description:""` //
}
@@ -1,20 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// BilMonthlyRevenueSummary is the golang structure for table bil_monthly_revenue_summary.
type BilMonthlyRevenueSummary struct {
Id int64 `json:"id" orm:"id" description:""` //
Month *gtime.Time `json:"month" orm:"month" description:""` //
TotalRecharge float64 `json:"total_recharge" orm:"total_recharge" description:""` //
TotalConsumption float64 `json:"total_consumption" orm:"total_consumption" description:""` //
NetRevenue float64 `json:"net_revenue" orm:"net_revenue" description:""` //
CreatedAt *gtime.Time `json:"created_at" orm:"created_at" description:""` //
UpdatedAt *gtime.Time `json:"updated_at" orm:"updated_at" description:""` //
}
@@ -1,21 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// BilMonthlyUsageSummary is the golang structure for table bil_monthly_usage_summary.
type BilMonthlyUsageSummary struct {
Id int64 `json:"id" orm:"id" description:""` //
TenantId int64 `json:"tenant_id" orm:"tenant_id" description:""` //
Month *gtime.Time `json:"month" orm:"month" description:""` //
TotalRequests int64 `json:"total_requests" orm:"total_requests" description:""` //
TotalTokens int64 `json:"total_tokens" orm:"total_tokens" description:""` //
TotalCost float64 `json:"total_cost" orm:"total_cost" description:""` //
CreatedAt *gtime.Time `json:"created_at" orm:"created_at" description:""` //
UpdatedAt *gtime.Time `json:"updated_at" orm:"updated_at" description:""` //
}
-18
View File
@@ -1,18 +0,0 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// PlgExampleLogs is the golang structure for table plg_example_logs.
type PlgExampleLogs struct {
Id int64 `json:"id" orm:"id" description:""` //
TenantId int64 `json:"tenant_id" orm:"tenant_id" description:""` //
Action string `json:"action" orm:"action" description:""` //
Detail string `json:"detail" orm:"detail" description:""` //
CreatedAt *gtime.Time `json:"created_at" orm:"created_at" description:""` //
}
+77
View File
@@ -0,0 +1,77 @@
-- +goose Up
-- 删除未使用的表:
-- plg_example_logs:插件示例日志,代码中零引用
-- bil_daily_usage_summary / bil_daily_revenue_summary:日汇总,只有写入无读取
-- bil_monthly_usage_summary / bil_monthly_revenue_summary:月汇总,只有写入无读取
DROP TABLE IF EXISTS plg_example_logs;
DROP TABLE IF EXISTS bil_daily_usage_summary;
DROP TABLE IF EXISTS bil_daily_revenue_summary;
DROP TABLE IF EXISTS bil_monthly_usage_summary;
DROP TABLE IF EXISTS bil_monthly_revenue_summary;
-- +goose Down
-- 回滚:重建被删除的表
CREATE TABLE plg_example_logs (
id BIGSERIAL PRIMARY KEY,
plugin_name VARCHAR(100) NOT NULL,
tenant_id BIGINT,
message TEXT,
level VARCHAR(20) DEFAULT 'info',
created_at TIMESTAMPTZ DEFAULT now() NOT NULL,
updated_at TIMESTAMPTZ DEFAULT now() NOT NULL
);
COMMENT ON TABLE plg_example_logs IS '插件示例日志表(已废弃)';
CREATE TABLE bil_daily_usage_summary (
id BIGSERIAL PRIMARY KEY,
tenant_id BIGINT NOT NULL,
date DATE NOT NULL,
total_requests INT NOT NULL DEFAULT 0,
total_tokens BIGINT NOT NULL DEFAULT 0,
total_cost NUMERIC(20,10) NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uk_bil_daily_usage_summary UNIQUE (tenant_id, date)
);
COMMENT ON TABLE bil_daily_usage_summary IS '每日用量汇总(已废弃)';
CREATE TABLE bil_daily_revenue_summary (
id BIGSERIAL PRIMARY KEY,
date DATE NOT NULL,
total_recharge NUMERIC(20,10) NOT NULL DEFAULT 0,
total_consumption NUMERIC(20,10) NOT NULL DEFAULT 0,
net_revenue NUMERIC(20,10) NOT NULL DEFAULT 0,
new_orders INT NOT NULL DEFAULT 0,
paid_orders INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uk_bil_daily_revenue_summary UNIQUE (date)
);
COMMENT ON TABLE bil_daily_revenue_summary IS '每日收入汇总(已废弃)';
CREATE TABLE bil_monthly_usage_summary (
id BIGSERIAL PRIMARY KEY,
tenant_id BIGINT NOT NULL,
month DATE NOT NULL,
total_requests INT NOT NULL DEFAULT 0,
total_tokens BIGINT NOT NULL DEFAULT 0,
total_cost NUMERIC(20,10) NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uk_bil_monthly_usage_summary UNIQUE (tenant_id, month)
);
COMMENT ON TABLE bil_monthly_usage_summary IS '每月用量汇总(已废弃)';
CREATE TABLE bil_monthly_revenue_summary (
id BIGSERIAL PRIMARY KEY,
month DATE NOT NULL,
total_recharge NUMERIC(20,10) NOT NULL DEFAULT 0,
total_consumption NUMERIC(20,10) NOT NULL DEFAULT 0,
net_revenue NUMERIC(20,10) NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uk_bil_monthly_revenue_summary UNIQUE (month)
);
COMMENT ON TABLE bil_monthly_revenue_summary IS '每月收入汇总(已废弃)';