fix: remove unused preload/snapshot functions and fix gofmt
This commit is contained in:
@@ -2288,41 +2288,6 @@ func (s *adminServiceImpl) checkMixedChannelRisk(ctx context.Context, currentAcc
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *adminServiceImpl) preloadMixedChannelRiskData(ctx context.Context, groupIDs []int64) (map[int64][]Account, map[int64]string, error) {
|
|
||||||
accountsByGroup := make(map[int64][]Account)
|
|
||||||
groupNameByID := make(map[int64]string)
|
|
||||||
if len(groupIDs) == 0 {
|
|
||||||
return accountsByGroup, groupNameByID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
seen := make(map[int64]struct{}, len(groupIDs))
|
|
||||||
for _, groupID := range groupIDs {
|
|
||||||
if groupID <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok := seen[groupID]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
seen[groupID] = struct{}{}
|
|
||||||
|
|
||||||
accounts, err := s.accountRepo.ListByGroup(ctx, groupID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("get accounts in group %d: %w", groupID, err)
|
|
||||||
}
|
|
||||||
accountsByGroup[groupID] = accounts
|
|
||||||
|
|
||||||
group, err := s.groupRepo.GetByID(ctx, groupID)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if group != nil {
|
|
||||||
groupNameByID[groupID] = group.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return accountsByGroup, groupNameByID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *adminServiceImpl) validateGroupIDsExist(ctx context.Context, groupIDs []int64) error {
|
func (s *adminServiceImpl) validateGroupIDsExist(ctx context.Context, groupIDs []int64) error {
|
||||||
if len(groupIDs) == 0 {
|
if len(groupIDs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -2352,71 +2317,6 @@ func (s *adminServiceImpl) validateGroupIDsExist(ctx context.Context, groupIDs [
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *adminServiceImpl) checkMixedChannelRiskWithPreloaded(currentAccountID int64, currentAccountPlatform string, groupIDs []int64, accountsByGroup map[int64][]Account, groupNameByID map[int64]string) error {
|
|
||||||
currentPlatform := getAccountPlatform(currentAccountPlatform)
|
|
||||||
if currentPlatform == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, groupID := range groupIDs {
|
|
||||||
accounts := accountsByGroup[groupID]
|
|
||||||
for _, account := range accounts {
|
|
||||||
if currentAccountID > 0 && account.ID == currentAccountID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
otherPlatform := getAccountPlatform(account.Platform)
|
|
||||||
if otherPlatform == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentPlatform != otherPlatform {
|
|
||||||
groupName := fmt.Sprintf("Group %d", groupID)
|
|
||||||
if name := strings.TrimSpace(groupNameByID[groupID]); name != "" {
|
|
||||||
groupName = name
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MixedChannelError{
|
|
||||||
GroupID: groupID,
|
|
||||||
GroupName: groupName,
|
|
||||||
CurrentPlatform: currentPlatform,
|
|
||||||
OtherPlatform: otherPlatform,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateMixedChannelPreloadedAccounts(accountsByGroup map[int64][]Account, groupIDs []int64, accountID int64, platform string) {
|
|
||||||
if len(groupIDs) == 0 || accountID <= 0 || platform == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, groupID := range groupIDs {
|
|
||||||
if groupID <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
accounts := accountsByGroup[groupID]
|
|
||||||
found := false
|
|
||||||
for i := range accounts {
|
|
||||||
if accounts[i].ID != accountID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
accounts[i].Platform = platform
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
accounts = append(accounts, Account{
|
|
||||||
ID: accountID,
|
|
||||||
Platform: platform,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
accountsByGroup[groupID] = accounts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckMixedChannelRisk checks whether target groups contain mixed channels for the current account platform.
|
// CheckMixedChannelRisk checks whether target groups contain mixed channels for the current account platform.
|
||||||
func (s *adminServiceImpl) CheckMixedChannelRisk(ctx context.Context, currentAccountID int64, currentAccountPlatform string, groupIDs []int64) error {
|
func (s *adminServiceImpl) CheckMixedChannelRisk(ctx context.Context, currentAccountID int64, currentAccountPlatform string, groupIDs []int64) error {
|
||||||
return s.checkMixedChannelRisk(ctx, currentAccountID, currentAccountPlatform, groupIDs)
|
return s.checkMixedChannelRisk(ctx, currentAccountID, currentAccountPlatform, groupIDs)
|
||||||
|
|||||||
Reference in New Issue
Block a user