forage.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 int32 `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. Sort int64 `json:"sort"`
  30. Backup1 string `json:"backup1"`
  31. Backup2 string `json:"backup2"`
  32. Backup3 string `json:"backup3"`
  33. IsShow operationPb.IsShow_Kind `json:"is_show"`
  34. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  35. CreatedAt int64 `json:"created_at"`
  36. UpdatedAt int64 `json:"updated_at"`
  37. }
  38. func (c *Forage) TableName() string {
  39. return "forage"
  40. }
  41. func NewForage(req *operationPb.AddForageRequest) *Forage {
  42. return &Forage{
  43. Name: req.Name,
  44. CategoryId: int64(req.CategoryId),
  45. CategoryName: req.CategoryName,
  46. UniqueEncode: req.UniqueEncode,
  47. ForageSourceId: req.ForageSourceId,
  48. ForageSourceName: req.ForageSourceName,
  49. PlanTypeId: req.PlanTypeId,
  50. PlanTypeName: req.PlanTypeName,
  51. MaterialType: req.MaterialType,
  52. SmallMaterialScale: req.SmallMaterialScale,
  53. AllowError: int64(req.AllowError),
  54. PackageWeight: int64(req.PackageWeight),
  55. Price: int64(req.Price),
  56. JumpWeight: int64(req.JumpWeight),
  57. JumpDelay: req.JumpDelay,
  58. ConfirmStart: req.ConfirmStart,
  59. RelayLocations: int64(req.RelayLocations),
  60. IsShow: operationPb.IsShow_OK,
  61. IsDelete: operationPb.IsShow_OK,
  62. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  63. Jmp: req.Jmp,
  64. Backup1: req.Backup1,
  65. Backup2: req.Backup2,
  66. Backup3: req.Backup3,
  67. }
  68. }
  69. type ForageSlice []*Forage
  70. func (f ForageSlice) ToPB() []*operationPb.AddForageRequest {
  71. res := make([]*operationPb.AddForageRequest, len(f))
  72. for i, v := range f {
  73. res[i] = &operationPb.AddForageRequest{
  74. Id: int32(v.Id),
  75. Name: v.Name,
  76. CategoryId: int32(v.CategoryId),
  77. CategoryName: v.CategoryName,
  78. MaterialType: int32(v.MaterialType),
  79. UniqueEncode: v.UniqueEncode,
  80. ForageSourceId: v.ForageSourceId,
  81. ForageSourceName: v.ForageSourceName,
  82. PlanTypeId: v.PlanTypeId,
  83. PlanTypeName: v.PlanTypeName,
  84. SmallMaterialScale: v.SmallMaterialScale,
  85. AllowError: int32(v.AllowError),
  86. PackageWeight: int32(v.PackageWeight),
  87. Price: int32(v.Price),
  88. JumpWeight: int32(v.JumpWeight),
  89. JumpDelay: v.JumpDelay,
  90. ConfirmStart: v.ConfirmStart,
  91. RelayLocations: int32(v.RelayLocations),
  92. Jmp: v.Jmp,
  93. IsShow: v.IsShow,
  94. Backup1: v.Backup1,
  95. Backup2: v.Backup2,
  96. Backup3: v.Backup3,
  97. CreatedAt: int32(v.CreatedAt),
  98. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  99. }
  100. }
  101. return res
  102. }