system_role.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package model
  2. import (
  3. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  4. "time"
  5. )
  6. type SystemRole struct {
  7. Id int64 `json:"id,omitempty"`
  8. Name string `json:"name,omitempty"`
  9. Remarks string `json:"remarks,omitempty"`
  10. IsShow operationPb.IsShow_Kind `json:"is_show,omitempty"`
  11. CreateUser string `json:"create_user,omitempty"`
  12. CreatedAt int64 `json:"created_at,omitempty"`
  13. UpdatedAt int64 `json:"updated_at,omitempty"`
  14. }
  15. func (s *SystemRole) TableName() string {
  16. return "system_role"
  17. }
  18. const (
  19. LayoutTime = "2006-01-02 15:04:05"
  20. LayoutDate = "20060102"
  21. )
  22. func NewSystemRole(req *operationPb.AddRoleRequest) *SystemRole {
  23. systemRole := &SystemRole{
  24. Name: req.Name,
  25. Remarks: req.Remarks,
  26. IsShow: operationPb.IsShow_OK,
  27. CreateUser: req.CreateUser,
  28. }
  29. return systemRole
  30. }
  31. type SystemRoleSlice []*SystemRole
  32. func (s SystemRoleSlice) ToPB(groupPastureList map[int64][]*GroupPasture, systemMenuList map[int64][]*SystemMenu) []*operationPb.AddRoleRequest {
  33. res := make([]*operationPb.AddRoleRequest, len(s))
  34. for i, v := range s {
  35. res[i] = &operationPb.AddRoleRequest{
  36. Id: uint32(v.Id),
  37. Name: v.Name,
  38. Remarks: v.Remarks,
  39. CreateUser: v.CreateUser,
  40. IsShow: v.IsShow,
  41. CreatedAt: uint32(v.CreatedAt),
  42. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  43. }
  44. groupPasture, ok := groupPastureList[v.Id]
  45. if ok {
  46. for _, g := range groupPasture {
  47. res[i].PastureList = append(res[i].PastureList, g.Name)
  48. res[i].PastureId = append(res[i].PastureId, uint32(g.Id))
  49. }
  50. }
  51. systemMenu, ok := systemMenuList[v.Id]
  52. if ok {
  53. for _, m := range systemMenu {
  54. res[i].MenuList = append(res[i].MenuList, m.Name)
  55. res[i].MenuId = append(res[i].MenuId, uint32(m.Id))
  56. }
  57. }
  58. }
  59. return res
  60. }
  61. func (s *SystemRole) ToPb() *operationPb.AddRoleRequest {
  62. return &operationPb.AddRoleRequest{
  63. Id: uint32(s.Id),
  64. Name: s.Name,
  65. CreateUser: s.CreateUser,
  66. IsShow: s.IsShow,
  67. CreatedAt: uint32(s.CreatedAt),
  68. CreatedAtFormat: time.Unix(s.CreatedAt, 0).Format(LayoutTime),
  69. }
  70. }