feed_formula.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package model
  2. import (
  3. "time"
  4. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  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 operationPb.FormulaType_Kind `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. PastureDataId int64 `json:"pasture_data_id"`
  22. IsShow operationPb.IsShow_Kind `json:"is_show"`
  23. IsModify operationPb.IsShow_Kind `json:"is_modify"`
  24. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  25. CreatedAt int64 `json:"created_at"`
  26. UpdatedAt int64 `json:"updated_at"`
  27. }
  28. func (f *FeedFormula) TableName() string {
  29. return "feed_formula"
  30. }
  31. func NewFeedFormula(req *operationPb.AddFeedFormulaRequest) *FeedFormula {
  32. return &FeedFormula{
  33. Name: req.Name,
  34. Colour: req.Colour,
  35. EncodeNumber: req.EncodeNumber,
  36. CattleCategoryId: req.CattleCategoryId,
  37. CattleCategoryName: req.CattleCategoryName,
  38. FormulaTypeId: req.FormulaTypeId,
  39. FormulaTypeName: req.FormulaTypeName,
  40. DataSourceId: req.DataSourceId,
  41. DataSourceName: req.DataSourceName,
  42. Remarks: req.Remarks,
  43. Version: 1,
  44. PastureId: 0,
  45. PastureName: "集团",
  46. IsShow: req.IsShow,
  47. IsDelete: operationPb.IsShow_OK,
  48. IsModify: operationPb.IsShow_OK,
  49. }
  50. }
  51. type FeedFormulaSlice []*FeedFormula
  52. func (f FeedFormulaSlice) ToPB() []*operationPb.AddFeedFormulaRequest {
  53. res := make([]*operationPb.AddFeedFormulaRequest, len(f))
  54. for i, v := range f {
  55. res[i] = &operationPb.AddFeedFormulaRequest{
  56. Id: int32(v.Id),
  57. Name: v.Name,
  58. Colour: v.Colour,
  59. EncodeNumber: v.EncodeNumber,
  60. CattleCategoryId: v.CattleCategoryId,
  61. CattleCategoryName: v.CattleCategoryName,
  62. FormulaTypeId: v.FormulaTypeId,
  63. FormulaTypeName: v.FormulaTypeName,
  64. DataSourceName: v.DataSourceName,
  65. DataSourceId: v.DataSourceId,
  66. Remarks: v.Remarks,
  67. Version: int32(v.Version),
  68. PastureName: v.PastureName,
  69. IsShow: v.IsShow,
  70. IsModify: v.IsModify,
  71. CreatedAt: int32(v.CreatedAt),
  72. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  73. }
  74. }
  75. return res
  76. }
  77. func (f FeedFormulaSlice) ToDistributePB() []*operationPb.DistributeFeedRequest {
  78. res := make([]*operationPb.DistributeFeedRequest, len(f))
  79. for i, v := range f {
  80. res[i] = &operationPb.DistributeFeedRequest{
  81. Id: int32(v.Id),
  82. Name: v.Name,
  83. Colour: v.Colour,
  84. EncodeNumber: v.EncodeNumber,
  85. CattleCategoryId: v.CattleCategoryId,
  86. CattleCategoryName: v.CattleCategoryName,
  87. FormulaTypeId: v.FormulaTypeId,
  88. FormulaTypeName: v.FormulaTypeName,
  89. DataSourceName: v.DataSourceName,
  90. DataSourceId: v.DataSourceId,
  91. Remarks: v.Remarks,
  92. Version: int32(v.Version),
  93. PastureName: v.PastureName,
  94. IsShow: v.IsShow,
  95. IsModify: v.IsModify,
  96. CreatedAt: int32(v.CreatedAt),
  97. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  98. }
  99. }
  100. return res
  101. }
  102. func NewNewFeedFormulaByMixed(req *operationPb.MixedFeedFormulaRequest) *FeedFormula {
  103. return &FeedFormula{
  104. Name: req.Name,
  105. Colour: req.Colour,
  106. CattleCategoryId: operationPb.CattleCategoryParent_Kind(req.CattleCategoryId),
  107. CattleCategoryName: req.CattleCategoryName,
  108. FormulaTypeId: req.FormulaTypeId,
  109. FormulaTypeName: req.FormulaTypeName,
  110. DataSourceId: operationPb.DataSource_Kind(req.DataSourceId),
  111. DataSourceName: operationPb.DataSource_Kind_name[req.DataSourceId],
  112. Remarks: req.Remarks,
  113. PastureName: "集团",
  114. IsShow: operationPb.IsShow_OK,
  115. IsModify: operationPb.IsShow_OK,
  116. IsDelete: operationPb.IsShow_OK,
  117. }
  118. }