fix(tenant): 收紧双站运营提号与录单边界
This commit is contained in:
@@ -535,9 +535,6 @@ func (r *Repository) tradingDailyOverview(ctx context.Context, now time.Time, da
|
||||
// 录单表是后来新增的功能表,若迁移尚未执行(表不存在)则降级为空统计,
|
||||
// 避免连带整个仪表盘不可用。
|
||||
func (r *Repository) manualEntryToday(ctx context.Context, now time.Time) ([]ManualEntryAgentStatsDTO, error) {
|
||||
if tenancy.IDFromContext(ctx) > 0 {
|
||||
return []ManualEntryAgentStatsDTO{}, nil
|
||||
}
|
||||
if r.db == nil || !r.db.Migrator().HasTable("cs_manual_entries") {
|
||||
return []ManualEntryAgentStatsDTO{}, nil
|
||||
}
|
||||
@@ -551,7 +548,11 @@ func (r *Repository) manualEntryToday(ctx context.Context, now time.Time) ([]Man
|
||||
Count int64
|
||||
}
|
||||
rows := make([]row, 0)
|
||||
if err := r.db.WithContext(ctx).Table("cs_manual_entries").
|
||||
query := r.db.WithContext(ctx).Table("cs_manual_entries")
|
||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||
query = query.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
if err := query.
|
||||
Select("admin_id, MAX(admin_name) AS admin_name, COUNT(*) AS count").
|
||||
Where("created_at >= ? AND created_at < ?", start, end).
|
||||
Group("admin_id").
|
||||
|
||||
@@ -3,16 +3,44 @@ package admindashboard
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
"hfb_sys/backend/internal/timeutil"
|
||||
)
|
||||
|
||||
func dashboardTenantContext(tenantID uint64) context.Context {
|
||||
return tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: tenantID})
|
||||
}
|
||||
|
||||
func TestManualEntryTodayScopesByTenant(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
now := time.Date(2026, 11, 16, 12, 0, 0, 0, timeutil.ShanghaiLocation())
|
||||
entries := []model.CSManualEntry{
|
||||
{TenantID: 101, EntryNo: "MT-A", EntryGroup: "collect", AdminID: 1, AdminName: "A客服", CreatedAt: now},
|
||||
{TenantID: 202, EntryNo: "MT-B", EntryGroup: "sell", AdminID: 2, AdminName: "B客服", CreatedAt: now},
|
||||
}
|
||||
if err := db.Create(&entries).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
repo := NewRepository(db)
|
||||
itemsA, err := repo.manualEntryToday(dashboardTenantContext(101), now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
itemsB, err := repo.manualEntryToday(dashboardTenantContext(202), now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(itemsA) != 1 || itemsA[0].AdminName != "A客服" ||
|
||||
len(itemsB) != 1 || itemsB[0].AdminName != "B客服" {
|
||||
t.Fatalf("tenant manual entry stats A=%+v B=%+v", itemsA, itemsB)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummaryScopesBuyerAndSourceMetricsByTenant(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
tenants := []model.Tenant{
|
||||
|
||||
Reference in New Issue
Block a user