user.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package service
  2. import (
  3. "log"
  4. "app.yhyue.com/moapp/jybase/mongodb"
  5. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  6. cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
  7. "github.com/gogf/gf/v2/os/gctx"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. )
  10. type User struct {
  11. BaseUserIds []int64
  12. }
  13. func (this *User) GetUserId(entId int64) map[string]int64 {
  14. m := map[string]int64{}
  15. data, ok := cm.Mgo.Find("user", map[string]interface{}{
  16. "base_user_id": map[string]interface{}{
  17. "$in": this.BaseUserIds,
  18. },
  19. }, nil, `{"_id":1,"base_user_id":1}`, false, -1, -1)
  20. if ok && data != nil && len(*data) > 0 {
  21. for _, v := range *data {
  22. mdata := cm.BaseMysql.SelectBySql(`SELECT id FROM base_position WHERE user_id =? AND ent_id =? LIMIT 1`, gconv.Int64(v["base_user_id"]), entId)
  23. if mdata != nil && len(*mdata) > 0 {
  24. m[mongodb.BsonIdToSId(v["_id"])] = gconv.Int64((*mdata)[0]["id"])
  25. }
  26. }
  27. }
  28. return m
  29. }
  30. func (this *User) IdentityByPositionId(positionId int64) *pb.Identity {
  31. resp, err := cm.UserCenterRpc.IdentityByPositionId(gctx.New(), &pb.IdentityReq{
  32. Id: positionId,
  33. })
  34. if err != nil {
  35. log.Println("获取用户职位id信息出错", positionId, "的信息出错", err)
  36. return nil
  37. } else if resp == nil {
  38. log.Println("positionId用户", positionId, "没有找到职位信息")
  39. return nil
  40. }
  41. return resp
  42. }