team.go 850 B

1234567891011121314151617181920212223242526272829303132333435
  1. package repo
  2. import (
  3. "assetcenter/db/model"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. )
  6. // 获取用户的团队成员
  7. func TeamGetUserTeamers(ctx *RepoSession, userId string, includeSelf bool) []primitive.ObjectID {
  8. out := []primitive.ObjectID{}
  9. user := &model.User{}
  10. RepoSeachDoc(ctx, &DocSearchOptions{CollectName: CollectionUser, Query: Map{"_id": userId}, Project: []string{"teamId"}}, user)
  11. //没有团队
  12. if len(user.TeamId) < 1 {
  13. return out
  14. }
  15. uid, _ := primitive.ObjectIDFromHex(userId)
  16. if includeSelf {
  17. out = append(out, uid)
  18. }
  19. //团队人员
  20. ok, list := RepoSeachDocsMap(ctx, &DocsSearchOptions{CollectName: CollectionUser, Query: Map{"teamId": user.TeamId}, Project: []string{"_id"}})
  21. if !ok {
  22. return out
  23. }
  24. for _, item := range list {
  25. out = append(out, item["_id"].(primitive.ObjectID))
  26. }
  27. return out
  28. }