forage.go 4.5 KB

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