system_user.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package model
  2. import (
  3. "net/http"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  7. )
  8. type SystemUser struct {
  9. Id int64 `json:"id"`
  10. PastureId int64 `json:"pastureId"`
  11. Name string `json:"name"`
  12. NickName string `json:"nickName"`
  13. Mobile string `json:"mobile"`
  14. Password string `json:"password"`
  15. Avatar string `json:"avatar"`
  16. RoleId int64 `json:"roleId"`
  17. DeptId int64 `json:"deptId"`
  18. IndicatorsKinds string `json:"indicatorsKinds"`
  19. Gender pasturePb.Genders_Kind `json:"gender"`
  20. PastureIds string `json:"pastureIds"`
  21. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  22. IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
  23. Remarks string `json:"remarks"`
  24. CreatedAt int64 `json:"created_at"`
  25. UpdatedAt int64 `json:"updated_at"`
  26. }
  27. func (s *SystemUser) TableName() string {
  28. return "system_user"
  29. }
  30. func (s *SystemUser) SystemUserFormat(userRoles []*SystemRole, pastures []*operationPb.UserPasture) *operationPb.UserAuth {
  31. roles := make([]*operationPb.UserRole, len(userRoles))
  32. for k, v := range userRoles {
  33. roles[k] = &operationPb.UserRole{
  34. Id: int32(v.Id),
  35. Name: v.Name,
  36. }
  37. }
  38. return &operationPb.UserAuth{
  39. Code: http.StatusOK,
  40. Msg: "ok",
  41. Data: &operationPb.UserAuthData{
  42. UserName: s.Name,
  43. Roles: roles,
  44. Pastures: pastures,
  45. },
  46. }
  47. }
  48. type UserModel struct {
  49. SystemUser *SystemUser
  50. AppPasture *AppPastureList
  51. }
  52. type SystemUserSlice []*SystemUser
  53. func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole) []*pasturePb.SearchUserRequest {
  54. res := make([]*pasturePb.SearchUserRequest, len(s))
  55. for i, v := range s {
  56. deptName := ""
  57. for _, d := range deptList {
  58. if v.DeptId == d.Id {
  59. deptName = d.Name
  60. break
  61. }
  62. }
  63. roleName := ""
  64. for _, r := range roleList {
  65. if v.RoleId == r.Id {
  66. roleName += r.Name
  67. break
  68. }
  69. }
  70. res[i] = &pasturePb.SearchUserRequest{
  71. Id: int32(v.Id),
  72. Name: v.Name,
  73. Mobile: v.Mobile,
  74. NickName: v.NickName,
  75. Avatar: v.Avatar,
  76. Gender: v.Gender,
  77. IsShow: v.IsShow,
  78. IsDelete: v.IsDelete,
  79. Remarks: v.Remarks,
  80. DeptId: int32(v.DeptId),
  81. DeptName: deptName,
  82. RoleId: int32(v.RoleId),
  83. RoleName: roleName,
  84. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Local().Format(LayoutTime),
  85. UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Local().Format(LayoutTime),
  86. }
  87. }
  88. return res
  89. }
  90. func (s *SystemUser) ToPb() *operationPb.AddSystemUser {
  91. return &operationPb.AddSystemUser{
  92. Id: int32(s.Id),
  93. Name: s.Name,
  94. CreatedAt: int32(s.CreatedAt),
  95. CreatedAtFormat: time.Unix(s.CreatedAt, 0).Local().Format(LayoutTime),
  96. RoleIds: []int32{},
  97. }
  98. }
  99. func (s SystemUserSlice) ToPB2() []*pasturePb.ConfigOptionsList {
  100. res := make([]*pasturePb.ConfigOptionsList, len(s))
  101. for i, d := range s {
  102. res[i] = &pasturePb.ConfigOptionsList{
  103. Value: int32(d.Id),
  104. Label: d.Name,
  105. Disabled: true,
  106. }
  107. }
  108. return res
  109. }