forage_category.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. Name string `json:"name"`
  13. Number string `json:"number"`
  14. IsShow operationPb.IsShow_Kind `json:"is_show"`
  15. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  16. DataSource operationPb.DataSource_Kind `json:"data_source"`
  17. CreatedAt int64 `json:"created_at"`
  18. UpdatedAt int64 `json:"updated_at"`
  19. }
  20. func (s *ForageCategory) TableName() string {
  21. return "forage_category"
  22. }
  23. func NewForageCategory(req *operationPb.AddForageCategoryRequest) *ForageCategory {
  24. return &ForageCategory{
  25. ParentId: req.ParentId,
  26. ParentName: req.ParentName,
  27. Name: req.Name,
  28. Number: req.Number,
  29. IsShow: operationPb.IsShow_OK,
  30. IsDelete: operationPb.IsShow_OK,
  31. }
  32. }
  33. type ForageCategorySlice []*ForageCategory
  34. func (f ForageCategorySlice) ToPB() []*operationPb.AddForageCategoryRequest {
  35. res := make([]*operationPb.AddForageCategoryRequest, len(f))
  36. for i, v := range f {
  37. res[i] = &operationPb.AddForageCategoryRequest{
  38. Id: uint32(v.Id),
  39. Name: v.Name,
  40. ParentId: v.ParentId,
  41. ParentName: v.ParentName,
  42. Number: v.Number,
  43. IsShow: v.IsShow,
  44. CreatedAt: uint32(v.CreatedAt),
  45. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  46. }
  47. }
  48. return res
  49. }
  50. func (c *ForageCategory) ToPb() *operationPb.AddForageCategoryRequest {
  51. return &operationPb.AddForageCategoryRequest{
  52. Id: uint32(c.Id),
  53. Name: c.Name,
  54. Number: c.Number,
  55. ParentId: c.ParentId,
  56. ParentName: c.ParentName,
  57. IsShow: c.IsShow,
  58. CreatedAt: uint32(c.CreatedAt),
  59. }
  60. }