forage.go 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. Name string `json:"name"`
  11. CategoryId int64 `json:"category_id"`
  12. MaterialType int64 `json:"material_type"`
  13. UniqueEncode string `json:"unique_encode"`
  14. ForageSourceId operationPb.ForageSource_Kind `json:"forage_source_id"`
  15. ForageSourceName string `json:"forage_source_name"`
  16. PlanTypeId operationPb.ForagePlanType_Kind `json:"plan_type_id"`
  17. PlanTypeName string `json:"plan_type_name"`
  18. SmallMaterialScale string `json:"small_material_scale"`
  19. AllowError int64 `json:"allow_error"`
  20. PackageWeight int64 `json:"package_weight"`
  21. Price int64 `json:"price"`
  22. JumpWeight int64 `json:"jump_weight"`
  23. JumpDelay operationPb.JumpDelaType_Kind `json:"jump_delay"`
  24. ConfirmStart operationPb.IsShow_Kind `json:"confirm_start"`
  25. RelayLocations int64 `json:"relay_locations"`
  26. Jmp operationPb.IsShow_Kind `json:"jmp"`
  27. DataSource operationPb.DataSource_Kind `json:"data_source"`
  28. Backup1 string `json:"backup1"`
  29. Backup2 string `json:"backup2"`
  30. Backup3 string `json:"backup3"`
  31. IsShow operationPb.IsShow_Kind `json:"is_show"`
  32. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  33. CreatedAt int64 `json:"created_at"`
  34. UpdatedAt int64 `json:"updated_at"`
  35. }
  36. func (c *Forage) TableName() string {
  37. return "forage"
  38. }
  39. func NewForage(req *operationPb.AddForageRequest) *Forage {
  40. return &Forage{
  41. Name: req.Name,
  42. CategoryId: int64(req.CategoryId),
  43. UniqueEncode: req.UniqueEncode,
  44. ForageSourceId: req.ForageSourceId,
  45. ForageSourceName: req.ForageSourceName,
  46. PlanTypeId: req.PlanTypeId,
  47. PlanTypeName: req.PlanTypeName,
  48. SmallMaterialScale: req.SmallMaterialScale,
  49. AllowError: int64(req.AllowError),
  50. PackageWeight: int64(req.PackageWeight),
  51. Price: int64(req.Price),
  52. JumpWeight: int64(req.JumpWeight),
  53. JumpDelay: req.JumpDelay,
  54. ConfirmStart: req.ConfirmStart,
  55. RelayLocations: int64(req.RelayLocations),
  56. IsShow: operationPb.IsShow_OK,
  57. IsDelete: operationPb.IsShow_OK,
  58. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  59. Jmp: req.Jmp,
  60. Backup1: req.Backup1,
  61. Backup2: req.Backup2,
  62. Backup3: req.Backup3,
  63. }
  64. }
  65. type ForageSlice []*Forage
  66. func (f ForageSlice) ToPB() []*operationPb.AddForageRequest {
  67. res := make([]*operationPb.AddForageRequest, len(f))
  68. for i, v := range f {
  69. res[i] = &operationPb.AddForageRequest{
  70. Id: int32(v.Id),
  71. Name: v.Name,
  72. CategoryId: int32(v.CategoryId),
  73. MaterialType: int32(v.MaterialType),
  74. UniqueEncode: v.UniqueEncode,
  75. ForageSourceId: v.ForageSourceId,
  76. PlanTypeId: v.PlanTypeId,
  77. SmallMaterialScale: v.SmallMaterialScale,
  78. AllowError: int32(v.AllowError),
  79. PackageWeight: int32(v.PackageWeight),
  80. Price: int32(v.Price),
  81. JumpWeight: int32(v.JumpWeight),
  82. JumpDelay: v.JumpDelay,
  83. ConfirmStart: v.ConfirmStart,
  84. RelayLocations: int32(v.RelayLocations),
  85. IsShow: v.IsShow,
  86. CreatedAt: int32(v.CreatedAt),
  87. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  88. }
  89. }
  90. return res
  91. }