forage.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package model
  2. import (
  3. operationPb "kpt-tmr-group/proto/go/backend/operation"
  4. "time"
  5. )
  6. type Forage struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pasture_id"`
  9. PastureName string `json:"pasture_name"`
  10. PastureDataId int64 `json:"pasture_data_id"`
  11. Name string `json:"name"`
  12. CategoryId int64 `json:"category_id"`
  13. CategoryName string `json:"category_name"`
  14. MaterialType int32 `json:"material_type"`
  15. UniqueEncode string `json:"unique_encode"`
  16. ForageSourceId operationPb.ForageSource_Kind `json:"forage_source_id"`
  17. ForageSourceName string `json:"forage_source_name"`
  18. PlanTypeId operationPb.ForagePlanType_Kind `json:"plan_type_id"`
  19. PlanTypeName string `json:"plan_type_name"`
  20. SmallMaterialScale string `json:"small_material_scale"`
  21. AllowError int64 `json:"allow_error"`
  22. PackageWeight int64 `json:"package_weight"`
  23. Price int64 `json:"price"`
  24. JumpWeight int64 `json:"jump_weight"`
  25. JumpDelay operationPb.JumpDelaType_Kind `json:"jump_delay"`
  26. ConfirmStart operationPb.IsShow_Kind `json:"confirm_start"`
  27. RelayLocations int64 `json:"relay_locations"`
  28. Jmp operationPb.IsShow_Kind `json:"jmp"`
  29. DataSource operationPb.DataSource_Kind `json:"data_source"`
  30. Sort int64 `json:"sort"`
  31. Backup1 string `json:"backup1"`
  32. Backup2 string `json:"backup2"`
  33. Backup3 string `json:"backup3"`
  34. IsShow operationPb.IsShow_Kind `json:"is_show"`
  35. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  36. CreatedAt int64 `json:"created_at"`
  37. UpdatedAt int64 `json:"updated_at"`
  38. }
  39. func (c *Forage) TableName() string {
  40. return "forage"
  41. }
  42. func NewForage(req *operationPb.AddForageRequest) *Forage {
  43. return &Forage{
  44. Name: req.Name,
  45. CategoryId: int64(req.CategoryId),
  46. CategoryName: req.CategoryName,
  47. UniqueEncode: req.UniqueEncode,
  48. ForageSourceId: req.ForageSourceId,
  49. ForageSourceName: req.ForageSourceName,
  50. PlanTypeId: req.PlanTypeId,
  51. PlanTypeName: req.PlanTypeName,
  52. MaterialType: req.MaterialType,
  53. SmallMaterialScale: req.SmallMaterialScale,
  54. AllowError: int64(req.AllowError),
  55. PackageWeight: int64(req.PackageWeight),
  56. Price: int64(req.Price),
  57. JumpWeight: int64(req.JumpWeight),
  58. JumpDelay: req.JumpDelay,
  59. ConfirmStart: req.ConfirmStart,
  60. RelayLocations: int64(req.RelayLocations),
  61. IsShow: operationPb.IsShow_OK,
  62. IsDelete: operationPb.IsShow_OK,
  63. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  64. Jmp: req.Jmp,
  65. Backup1: req.Backup1,
  66. Backup2: req.Backup2,
  67. Backup3: req.Backup3,
  68. }
  69. }
  70. type ForageSlice []*Forage
  71. func (f ForageSlice) ToPB() []*operationPb.AddForageRequest {
  72. res := make([]*operationPb.AddForageRequest, len(f))
  73. for i, v := range f {
  74. res[i] = &operationPb.AddForageRequest{
  75. Id: int32(v.Id),
  76. Name: v.Name,
  77. CategoryId: int32(v.CategoryId),
  78. CategoryName: v.CategoryName,
  79. MaterialType: int32(v.MaterialType),
  80. UniqueEncode: v.UniqueEncode,
  81. ForageSourceId: v.ForageSourceId,
  82. ForageSourceName: v.ForageSourceName,
  83. PlanTypeId: v.PlanTypeId,
  84. PlanTypeName: v.PlanTypeName,
  85. SmallMaterialScale: v.SmallMaterialScale,
  86. AllowError: int32(v.AllowError),
  87. PackageWeight: int32(v.PackageWeight),
  88. Price: int32(v.Price),
  89. JumpWeight: int32(v.JumpWeight),
  90. JumpDelay: v.JumpDelay,
  91. ConfirmStart: v.ConfirmStart,
  92. RelayLocations: int32(v.RelayLocations),
  93. Jmp: v.Jmp,
  94. IsShow: v.IsShow,
  95. Backup1: v.Backup1,
  96. Backup2: v.Backup2,
  97. Backup3: v.Backup3,
  98. CreatedAt: int32(v.CreatedAt),
  99. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  100. }
  101. }
  102. return res
  103. }