identity.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package identity
  2. import (
  3. "strconv"
  4. "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
  5. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  6. )
  7. type IdentityInfo struct {
  8. Name string //名称
  9. PersonId int64 //自然人id
  10. UserName string //用户昵称
  11. AccountId int64 //账户id
  12. EntAccountId int64 //企业账户id
  13. PositionId int64 //职位id
  14. PositionType int64 //职位类型
  15. EntId int64 //企业id
  16. EntUserId int64 //企业员工id
  17. EntUserName string //企业员工姓名
  18. }
  19. func NewIdentityInfo(i *pb.Identity) *IdentityInfo {
  20. return &IdentityInfo{
  21. Name: i.Name,
  22. PersonId: i.PersonId,
  23. UserName: i.UserName,
  24. AccountId: i.AccountId,
  25. EntAccountId: i.EntAccountId,
  26. PositionId: i.PositionId,
  27. PositionType: i.PositionType,
  28. EntId: i.EntId,
  29. EntUserId: i.EntUserId,
  30. EntUserName: i.EntUserName,
  31. }
  32. }
  33. //切换身份
  34. func (i *IdentityInfo) Switch(sess *httpsession.Session) bool {
  35. ok := false
  36. m := map[string]interface{}{
  37. "personId": i.PersonId,
  38. "userName": i.UserName,
  39. "accountId": i.AccountId,
  40. "positionId": i.PositionId,
  41. "positionType": i.PositionType,
  42. }
  43. if i.PositionType == 0 {
  44. if sess.Del("entId", "entName", "entUserId", "entUserName", "entAccountId") {
  45. m["userId"] = sess.Get("mgoUserId")
  46. ok = true
  47. }
  48. } else {
  49. m["userId"] = strconv.FormatInt(i.PositionId, 10)
  50. m["entAccountId"] = i.EntAccountId
  51. ok = true
  52. }
  53. sess.SetMultiple(m)
  54. return ok
  55. }