fix: align business pages and detail drawers with prototype
This commit is contained in:
@@ -3,6 +3,7 @@ package business
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -140,11 +141,34 @@ func (r *channelRepo) List(ctx context.Context, scope business.UserScope, filter
|
||||
if filter.SortField == "createdAt" && filter.Ascending {
|
||||
order = "p.create_time ASC,p.id ASC,p.source_db ASC"
|
||||
}
|
||||
keysQuery := q.Select("p.id,p.source_db").Order(order).Offset(o.Offset).Limit(o.Limit)
|
||||
pageQuery := joinEffectiveness(db.Table("tab_promote p").Joins("JOIN (?) page_ids ON page_ids.id=p.id AND page_ids.source_db=p.source_db", keysQuery))
|
||||
if err := pageQuery.Select("p.*,e.qualified_at").Order(order).Scan(&pos).Error; err != nil {
|
||||
var pageQuery *gorm.DB
|
||||
var metricKeys []business.ChannelKey
|
||||
metricSort := filter.SortField == "playerCount" || filter.SortField == "totalPayAmount"
|
||||
if metricSort {
|
||||
metricKeys, err = channelMetricPage(db, q, filter, o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(metricKeys) == 0 {
|
||||
return page, nil
|
||||
}
|
||||
pageQuery = joinEffectiveness(db.Table("tab_promote p").Where("(p.source_db,p.id) IN ?", channelPairs(metricKeys)))
|
||||
} else {
|
||||
keysQuery := q.Select("p.id,p.source_db").Order(order).Offset(o.Offset).Limit(o.Limit)
|
||||
pageQuery = joinEffectiveness(db.Table("tab_promote p").Joins("JOIN (?) page_ids ON page_ids.id=p.id AND page_ids.source_db=p.source_db", keysQuery)).Order(order)
|
||||
}
|
||||
if err := pageQuery.Select("p.*,e.qualified_at").Scan(&pos).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
if metricSort {
|
||||
ranks := map[business.ChannelKey]int{}
|
||||
for i, key := range metricKeys {
|
||||
ranks[key] = i
|
||||
}
|
||||
sort.Slice(pos, func(i, j int) bool {
|
||||
return ranks[business.ChannelKey{SourceDB: pos[i].SourceDB, ID: pos[i].ID}] < ranks[business.ChannelKey{SourceDB: pos[j].SourceDB, ID: pos[j].ID}]
|
||||
})
|
||||
}
|
||||
if len(pos) == 0 {
|
||||
return page, nil
|
||||
}
|
||||
@@ -157,10 +181,19 @@ func (r *channelRepo) List(ctx context.Context, scope business.UserScope, filter
|
||||
PlatformBusierID uint64
|
||||
UserID uint
|
||||
PlatformBusierAccount, UserName string
|
||||
IDPath string
|
||||
}
|
||||
if err := channelBindingQuery(db, scope, filter).Select("b.source_db,b.platform_busier_id,b.user_id,b.platform_busier_account,u.username AS user_name").Where("(b.source_db,b.platform_busier_id) IN ?", pairs).Order("b.user_id").Scan(&bound).Error; err != nil {
|
||||
if err := channelBindingQuery(db, scope, filter).Select("b.source_db,b.platform_busier_id,b.user_id,b.platform_busier_account,u.username AS user_name,u.id_path").Where("(b.source_db,b.platform_busier_id) IN ?", pairs).Order("b.user_id").Scan(&bound).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
ownerPaths := map[uint]string{}
|
||||
for _, b := range bound {
|
||||
ownerPaths[b.UserID] = b.IDPath
|
||||
}
|
||||
paths, err := businessDisplayPaths(db, ownerPaths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
byKey := map[business.PlatformKey]int{}
|
||||
for i, b := range bound {
|
||||
key := business.PlatformKey{SourceDB: b.SourceDB, BusierID: b.PlatformBusierID}
|
||||
@@ -175,6 +208,7 @@ func (r *channelRepo) List(ctx context.Context, scope business.UserScope, filter
|
||||
c.BusierUserID = &b.UserID
|
||||
c.BindingAccount = b.PlatformBusierAccount
|
||||
c.BindingUserName = b.UserName
|
||||
c.BusinessPath = paths[b.UserID]
|
||||
}
|
||||
page.Rows = append(page.Rows, c)
|
||||
}
|
||||
@@ -205,7 +239,26 @@ func (r *channelRepo) Find(ctx context.Context, scope business.UserScope, key bu
|
||||
return nil, business.ErrChannelScope
|
||||
}
|
||||
}
|
||||
return toBizChannel(po), nil
|
||||
c := toBizChannel(po)
|
||||
var bindings []struct {
|
||||
UserID uint
|
||||
PlatformBusierAccount, UserName, IDPath string
|
||||
}
|
||||
if err := channelBindingQuery(db, scope, business.ChannelFilter{Sources: []string{key.SourceDB}}).
|
||||
Where("b.platform_busier_id = ?", po.BusierID).Order("b.user_id").Limit(1).
|
||||
Select("b.user_id,b.platform_busier_account,u.username AS user_name,u.id_path").Scan(&bindings).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
if len(bindings) > 0 {
|
||||
b := bindings[0]
|
||||
paths, err := businessDisplayPaths(db, map[uint]string{b.UserID: b.IDPath})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.BusierUserID, c.BindingAccount, c.BindingUserName = &b.UserID, b.PlatformBusierAccount, b.UserName
|
||||
c.BusinessPath = paths[b.UserID]
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
func channelPairs(keys []business.ChannelKey) [][]any {
|
||||
pairs := make([][]any, 0, len(keys))
|
||||
|
||||
Reference in New Issue
Block a user