system_role.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 LayoutTime = "2006-01-02 15:04:05"
  19. func NewSystemRole(req *operationPb.AddRoleRequest) *SystemRole {
  20. systemRole := &SystemRole{
  21. Name: req.Name,
  22. Remarks: req.Remarks,
  23. IsShow: operationPb.IsShow_OK,
  24. CreateUser: req.CreateUser,
  25. }
  26. return systemRole
  27. }
  28. type SystemRoleSlice []*SystemRole
  29. func (s SystemRoleSlice) ToPB() []*operationPb.AddRoleRequest {
  30. res := make([]*operationPb.AddRoleRequest, len(s))
  31. for i, v := range s {
  32. res[i] = &operationPb.AddRoleRequest{
  33. Id: uint32(v.Id),
  34. Name: v.Name,
  35. Remarks: v.Remarks,
  36. CreateUser: v.CreateUser,
  37. IsShow: v.IsShow,
  38. CreatedAt: uint32(v.CreatedAt),
  39. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  40. }
  41. }
  42. return res
  43. }
  44. func (s *SystemRole) ToPb() *operationPb.AddRoleRequest {
  45. return &operationPb.AddRoleRequest{
  46. Id: uint32(s.Id),
  47. Name: s.Name,
  48. CreateUser: s.CreateUser,
  49. IsShow: s.IsShow,
  50. CreatedAt: uint32(s.CreatedAt),
  51. CreatedAtFormat: time.Unix(s.CreatedAt, 0).Format(LayoutTime),
  52. }
  53. }