feed_formula.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. import (
  3. operationPb "kpt-tmr-group/proto/go/backend/operation"
  4. "time"
  5. )
  6. type FeedFormula struct {
  7. Id int64 `json:"id"`
  8. Name string `json:"name"`
  9. Colour string `json:"colour"`
  10. EncodeNumber string `json:"encode_number"`
  11. CattleCategoryId operationPb.CattleCategoryParent_Kind `json:"cattle_category_id"`
  12. CattleCategoryName string `json:"cattle_category_name"`
  13. FormulaTypeId int32 `json:"formula_type_id"`
  14. FormulaTypeName string `json:"formula_type_name"`
  15. DataSourceId operationPb.DataSource_Kind `json:"data_source_id"`
  16. DataSourceName string `json:"data_source_name"`
  17. Remarks string `json:"remarks"`
  18. Version int64 `json:"version"`
  19. PastureId int64 `json:"pasture_id"`
  20. PastureName string `json:"pasture_name"`
  21. IsShow operationPb.IsShow_Kind `json:"is_show"`
  22. IsModify operationPb.IsShow_Kind `json:"is_modify"`
  23. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  24. CreatedAt int64 `json:"created_at"`
  25. UpdatedAt int64 `json:"updated_at"`
  26. }
  27. func (f *FeedFormula) TableName() string {
  28. return "feed_formula"
  29. }
  30. func NewFeedFormula(req *operationPb.AddFeedFormulaRequest) *FeedFormula {
  31. return &FeedFormula{
  32. Name: req.Name,
  33. Colour: req.Colour,
  34. EncodeNumber: req.EncodeNumber,
  35. CattleCategoryId: req.CattleCategoryId,
  36. CattleCategoryName: req.CattleCategoryName,
  37. FormulaTypeId: req.FormulaTypeId,
  38. FormulaTypeName: req.FormulaTypeName,
  39. DataSourceId: req.DataSourceId,
  40. DataSourceName: req.DataSourceName,
  41. Remarks: req.Remarks,
  42. Version: 0,
  43. PastureId: 0,
  44. PastureName: "",
  45. IsShow: req.IsShow,
  46. IsDelete: operationPb.IsShow_OK,
  47. IsModify: operationPb.IsShow_OK,
  48. }
  49. }
  50. type FeedFormulaSlice []*FeedFormula
  51. func (f FeedFormulaSlice) ToPB() []*operationPb.AddFeedFormulaRequest {
  52. res := make([]*operationPb.AddFeedFormulaRequest, len(f))
  53. for i, v := range f {
  54. res[i] = &operationPb.AddFeedFormulaRequest{
  55. Id: int32(v.Id),
  56. Name: v.Name,
  57. Colour: v.Colour,
  58. EncodeNumber: v.EncodeNumber,
  59. CattleCategoryId: v.CattleCategoryId,
  60. CattleCategoryName: v.CattleCategoryName,
  61. FormulaTypeId: v.FormulaTypeId,
  62. FormulaTypeName: v.FormulaTypeName,
  63. DataSourceName: v.DataSourceName,
  64. DataSourceId: v.DataSourceId,
  65. Remarks: v.Remarks,
  66. Version: int32(v.Version),
  67. PastureName: v.PastureName,
  68. IsShow: v.IsShow,
  69. IsModify: v.IsModify,
  70. CreatedAt: int32(v.CreatedAt),
  71. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  72. }
  73. }
  74. return res
  75. }
  76. type DistributeData struct {
  77. PastureList []*GroupPasture
  78. FeedFormulaList []*FeedFormula
  79. }