system_role.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. s.IsDelete = req.IsDelete
  34. }
  35. func NewSystemRole(pastureId int64, req *pasturePb.SearchRoleRequest) *SystemRole {
  36. return &SystemRole{
  37. PastureId: pastureId,
  38. Name: req.Name,
  39. Remarks: req.Remarks,
  40. IsShow: pasturePb.IsShow_Ok,
  41. IsDelete: pasturePb.IsShow_Ok,
  42. }
  43. }
  44. type SystemRoleSlice []*SystemRole
  45. func (s SystemRoleSlice) ToPB() []*pasturePb.SearchRoleRequest {
  46. res := make([]*pasturePb.SearchRoleRequest, len(s))
  47. for i, v := range s {
  48. res[i] = &pasturePb.SearchRoleRequest{
  49. Id: int32(v.Id),
  50. Name: v.Name,
  51. Remarks: v.Remarks,
  52. IsShow: v.IsShow,
  53. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Local().Format(LayoutTime),
  54. UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Local().Format(LayoutTime),
  55. }
  56. }
  57. return res
  58. }