38 lines
852 B
Go
38 lines
852 B
Go
package admin_agent
|
||
|
||
import (
|
||
"context"
|
||
|
||
"qnc-server/app/main/api/internal/svc"
|
||
|
||
"github.com/Masterminds/squirrel"
|
||
)
|
||
|
||
// batchAgentCodesByIds 按代理主键批量查询 agent_code,用于列表软关联展示。
|
||
func batchAgentCodesByIds(ctx context.Context, svcCtx *svc.ServiceContext, ids []string) map[string]int64 {
|
||
out := make(map[string]int64)
|
||
uniq := make([]string, 0, len(ids))
|
||
seen := make(map[string]struct{}, len(ids))
|
||
for _, id := range ids {
|
||
if id == "" {
|
||
continue
|
||
}
|
||
if _, ok := seen[id]; ok {
|
||
continue
|
||
}
|
||
seen[id] = struct{}{}
|
||
uniq = append(uniq, id)
|
||
}
|
||
if len(uniq) == 0 {
|
||
return out
|
||
}
|
||
agents, err := svcCtx.AgentModel.FindAll(ctx, svcCtx.AgentModel.SelectBuilder().Where(squirrel.Eq{"id": uniq}), "")
|
||
if err != nil {
|
||
return out
|
||
}
|
||
for _, a := range agents {
|
||
out[a.Id] = a.AgentCode
|
||
}
|
||
return out
|
||
}
|