forage_category.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. import (
  3. operationPb "kpt-tmr-group/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. ParentId: req.ParentId,
  28. ParentName: req.ParentName,
  29. Name: req.Name,
  30. Number: req.Number,
  31. IsShow: operationPb.IsShow_OK,
  32. IsDelete: operationPb.IsShow_OK,
  33. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  34. Remarks: "集团新增数据",
  35. }
  36. }
  37. type ForageCategorySlice []*ForageCategory
  38. func (f ForageCategorySlice) ToPB() []*operationPb.AddForageCategoryRequest {
  39. res := make([]*operationPb.AddForageCategoryRequest, len(f))
  40. for i, v := range f {
  41. res[i] = &operationPb.AddForageCategoryRequest{
  42. Id: uint32(v.Id),
  43. Name: v.Name,
  44. ParentId: v.ParentId,
  45. ParentName: v.ParentName,
  46. Number: v.Number,
  47. IsShow: v.IsShow,
  48. CreatedAt: uint32(v.CreatedAt),
  49. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  50. }
  51. }
  52. return res
  53. }
  54. func (f *ForageCategory) ToPb() *operationPb.AddForageCategoryRequest {
  55. return &operationPb.AddForageCategoryRequest{
  56. Id: uint32(f.Id),
  57. Name: f.Name,
  58. Number: f.Number,
  59. ParentId: f.ParentId,
  60. ParentName: f.ParentName,
  61. IsShow: f.IsShow,
  62. CreatedAt: uint32(f.CreatedAt),
  63. }
  64. }
  65. func NewPastureForageCategory(req *operationPb.CategorySyncRequest, pastureDetail *GroupPasture) *ForageCategory {
  66. return &ForageCategory{
  67. ParentId: operationPb.ForageCategoryParent_Kind(req.ParentId),
  68. ParentName: req.ParentName,
  69. PastureId: int64(req.PastureId),
  70. PastureName: pastureDetail.Name,
  71. Name: req.Name,
  72. Number: req.Number,
  73. IsShow: req.IsShow,
  74. IsDelete: operationPb.IsShow_NO,
  75. DataSource: operationPb.DataSource_FROM_PASTURE,
  76. Remarks: "牧场端数据同步",
  77. }
  78. }