system_role.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package model
  2. import (
  3. operationPb "kpt-tmr-group/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() []*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. }
  45. return res
  46. }
  47. func (s *SystemRole) ToPb() *operationPb.AddRoleRequest {
  48. return &operationPb.AddRoleRequest{
  49. Id: uint32(s.Id),
  50. Name: s.Name,
  51. CreateUser: s.CreateUser,
  52. IsShow: s.IsShow,
  53. CreatedAt: uint32(s.CreatedAt),
  54. CreatedAtFormat: time.Unix(s.CreatedAt, 0).Format(LayoutTime),
  55. }
  56. }