feed_formula.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. CattleCategoryId: v.CattleCategoryId,
  58. CattleCategoryName: v.CattleCategoryName,
  59. FormulaTypeId: v.FormulaTypeId,
  60. FormulaTypeName: v.FormulaTypeName,
  61. DataSourceName: v.DataSourceName,
  62. DataSourceId: v.DataSourceId,
  63. Remarks: v.Remarks,
  64. Version: int32(v.Version),
  65. PastureName: v.PastureName,
  66. IsShow: v.IsShow,
  67. IsModify: v.IsModify,
  68. CreatedAt: int32(v.CreatedAt),
  69. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  70. }
  71. }
  72. return res
  73. }