forage_category.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package model
  2. import (
  3. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  4. "time"
  5. )
  6. type ForageCategory struct {
  7. Id int64 `json:"id"`
  8. ParentId operationPb.ForageCategoryParent_Kind `json:"parent_id"`
  9. ParentName string `json:"parent_name"`
  10. PastureId int64 `json:"pasture_id"`
  11. PastureName string `json:"pasture_name"`
  12. DataId int64 `json:"data_id"`
  13. Name string `json:"name"`
  14. Number string `json:"number"`
  15. IsShow operationPb.IsShow_Kind `json:"is_show"`
  16. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  17. DataSource operationPb.DataSource_Kind `json:"data_source"`
  18. Remarks string `json:"remarks"`
  19. CreatedAt int64 `json:"created_at"`
  20. UpdatedAt int64 `json:"updated_at"`
  21. }
  22. func (s *ForageCategory) TableName() string {
  23. return "forage_category"
  24. }
  25. func NewForageCategory(req *operationPb.AddForageCategoryRequest) *ForageCategory {
  26. return &ForageCategory{
  27. PastureId: 0,
  28. PastureName: "集团",
  29. ParentId: req.ParentId,
  30. ParentName: req.ParentName,
  31. Name: req.Name,
  32. Number: req.Number,
  33. IsShow: operationPb.IsShow_OK,
  34. IsDelete: operationPb.IsShow_OK,
  35. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  36. Remarks: "集团新增数据",
  37. }
  38. }
  39. type ForageCategorySlice []*ForageCategory
  40. func (f ForageCategorySlice) ToPB() []*operationPb.AddForageCategoryRequest {
  41. res := make([]*operationPb.AddForageCategoryRequest, len(f))
  42. for i, v := range f {
  43. res[i] = &operationPb.AddForageCategoryRequest{
  44. Id: uint32(v.Id),
  45. Name: v.Name,
  46. ParentId: v.ParentId,
  47. ParentName: v.ParentName,
  48. Number: v.Number,
  49. IsShow: v.IsShow,
  50. CreatedAt: uint32(v.CreatedAt),
  51. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  52. DataSource: v.PastureName,
  53. }
  54. }
  55. return res
  56. }
  57. func (f *ForageCategory) ToPb() *operationPb.AddForageCategoryRequest {
  58. return &operationPb.AddForageCategoryRequest{
  59. Id: uint32(f.Id),
  60. Name: f.Name,
  61. Number: f.Number,
  62. ParentId: f.ParentId,
  63. ParentName: f.ParentName,
  64. IsShow: f.IsShow,
  65. CreatedAt: uint32(f.CreatedAt),
  66. }
  67. }
  68. func NewPastureForageCategory(req *operationPb.CategorySyncRequest, pastureDetail *GroupPasture) *ForageCategory {
  69. return &ForageCategory{
  70. ParentId: operationPb.ForageCategoryParent_Kind(req.ParentId),
  71. ParentName: req.ParentName,
  72. PastureId: int64(req.PastureId),
  73. PastureName: pastureDetail.Name,
  74. Name: req.Name,
  75. Number: req.Number,
  76. IsShow: req.IsShow,
  77. IsDelete: operationPb.IsShow_NO,
  78. DataSource: operationPb.DataSource_FROM_PASTURE,
  79. Remarks: "牧场端数据同步",
  80. }
  81. }