system_role.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. const (
  7. LayoutTime = "2006-01-02 15:04:05"
  8. LayoutDate = "20060102"
  9. LayoutDate2 = "2006-01-02"
  10. LayoutMonth = "2006-01"
  11. LayoutHour = "2006-01-02 15"
  12. LayoutMinute = "2006-01-02 15:04"
  13. LayoutYear = "2006"
  14. LayoutTime2 = "2006/1/2 15:04:05"
  15. )
  16. type SystemRole struct {
  17. Id int64 `json:"id"`
  18. PastureId int64 `json:"pastureId"`
  19. Name string `json:"name"`
  20. Remarks string `json:"remarks"`
  21. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  22. IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (s *SystemRole) TableName() string {
  27. return "system_role"
  28. }
  29. func (s *SystemRole) RoleUpdate(req *pasturePb.SearchRoleRequest) {
  30. s.Name = req.Name
  31. s.Remarks = req.Remarks
  32. s.IsShow = req.IsShow
  33. }
  34. func NewSystemRole(pastureId int64, req *pasturePb.SearchRoleRequest) *SystemRole {
  35. return &SystemRole{
  36. PastureId: pastureId,
  37. Name: req.Name,
  38. Remarks: req.Remarks,
  39. IsShow: pasturePb.IsShow_Ok,
  40. IsDelete: pasturePb.IsShow_Ok,
  41. }
  42. }
  43. type SystemRoleSlice []*SystemRole
  44. func (s SystemRoleSlice) ToPB() []*pasturePb.SearchRoleRequest {
  45. res := make([]*pasturePb.SearchRoleRequest, len(s))
  46. for i, v := range s {
  47. res[i] = &pasturePb.SearchRoleRequest{
  48. Id: int32(v.Id),
  49. Name: v.Name,
  50. Remarks: v.Remarks,
  51. IsShow: v.IsShow,
  52. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Local().Format(LayoutTime),
  53. UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Local().Format(LayoutTime),
  54. }
  55. }
  56. return res
  57. }