system_user.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. const InitManagerPassword = "kpt123456"
  9. type SystemUser struct {
  10. Id int64 `json:"id"`
  11. Name string `json:"name"`
  12. NickName string `json:"nick_name"`
  13. Mobile string `json:"mobile"`
  14. Password string `json:"password"`
  15. Avatar string `json:"avatar"`
  16. RoleId int64 `json:"role_id"`
  17. DeptId int64 `json:"dept_id"`
  18. Remarks string `json:"remarks"`
  19. Gender pasturePb.Genders_Kind `json:"gender"`
  20. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  21. IsDelete pasturePb.IsShow_Kind `json:"is_delete"`
  22. CreatedAt int64 `json:"created_at"`
  23. UpdatedAt int64 `json:"updated_at"`
  24. }
  25. func (s *SystemUser) TableName() string {
  26. return "system_user"
  27. }
  28. func (s *SystemUser) SystemUserFormat(userRoles []*SystemRole, pastures []*operationPb.UserPasture) *operationPb.UserAuth {
  29. roles := make([]*operationPb.UserRole, len(userRoles))
  30. for k, v := range userRoles {
  31. roles[k] = &operationPb.UserRole{
  32. Id: int32(v.Id),
  33. Name: v.Name,
  34. }
  35. }
  36. return &operationPb.UserAuth{
  37. Code: http.StatusOK,
  38. Msg: "ok",
  39. Data: &operationPb.UserAuthData{
  40. UserName: s.Name,
  41. Roles: roles,
  42. Pastures: pastures,
  43. },
  44. }
  45. }
  46. type SystemUserSlice []*SystemUser
  47. func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole) []*pasturePb.SearchUserRequest {
  48. res := make([]*pasturePb.SearchUserRequest, len(s))
  49. for i, v := range s {
  50. deptName := ""
  51. for _, d := range deptList {
  52. if v.DeptId == d.Id {
  53. deptName = d.Name
  54. break
  55. }
  56. }
  57. roleName := ""
  58. for _, r := range roleList {
  59. if v.RoleId == r.Id {
  60. roleName += r.Name
  61. break
  62. }
  63. }
  64. res[i] = &pasturePb.SearchUserRequest{
  65. Id: int32(v.Id),
  66. Name: v.Name,
  67. Mobile: v.Mobile,
  68. NickName: v.NickName,
  69. Avatar: v.Avatar,
  70. Gender: v.Gender,
  71. IsShow: v.IsShow,
  72. IsDelete: v.IsDelete,
  73. Remarks: v.Remarks,
  74. DeptId: int32(v.DeptId),
  75. DeptName: deptName,
  76. RoleId: int32(v.RoleId),
  77. RoleName: roleName,
  78. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  79. UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Format(LayoutTime),
  80. }
  81. }
  82. return res
  83. }
  84. func (s *SystemUser) ToPb() *operationPb.AddSystemUser {
  85. return &operationPb.AddSystemUser{
  86. Id: int32(s.Id),
  87. Name: s.Name,
  88. CreatedAt: int32(s.CreatedAt),
  89. CreatedAtFormat: time.Unix(s.CreatedAt, 0).Format(LayoutTime),
  90. RoleIds: []int32{},
  91. }
  92. }