forage.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. PastureName: "集团",
  46. CategoryId: int64(req.CategoryId),
  47. CategoryName: req.CategoryName,
  48. UniqueEncode: req.UniqueEncode,
  49. ForageSourceId: req.ForageSourceId,
  50. ForageSourceName: req.ForageSourceName,
  51. PlanTypeId: req.PlanTypeId,
  52. PlanTypeName: req.PlanTypeName,
  53. MaterialType: req.MaterialType,
  54. SmallMaterialScale: req.SmallMaterialScale,
  55. AllowError: int64(req.AllowError),
  56. PackageWeight: int64(req.PackageWeight),
  57. Price: int64(req.Price),
  58. JumpWeight: int64(req.JumpWeight),
  59. JumpDelay: req.JumpDelay,
  60. ConfirmStart: req.ConfirmStart,
  61. RelayLocations: int64(req.RelayLocations),
  62. IsShow: operationPb.IsShow_OK,
  63. IsDelete: operationPb.IsShow_OK,
  64. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  65. Jmp: req.Jmp,
  66. Backup1: req.Backup1,
  67. Backup2: req.Backup2,
  68. Backup3: req.Backup3,
  69. }
  70. }
  71. type ForageSlice []*Forage
  72. func (f ForageSlice) ToPB() []*operationPb.AddForageRequest {
  73. res := make([]*operationPb.AddForageRequest, len(f))
  74. for i, v := range f {
  75. res[i] = &operationPb.AddForageRequest{
  76. Id: int32(v.Id),
  77. Name: v.Name,
  78. CategoryId: int32(v.CategoryId),
  79. CategoryName: v.CategoryName,
  80. MaterialType: int32(v.MaterialType),
  81. UniqueEncode: v.UniqueEncode,
  82. ForageSourceId: v.ForageSourceId,
  83. ForageSourceName: v.ForageSourceName,
  84. PlanTypeId: v.PlanTypeId,
  85. PlanTypeName: v.PlanTypeName,
  86. SmallMaterialScale: v.SmallMaterialScale,
  87. AllowError: int32(v.AllowError),
  88. PackageWeight: int32(v.PackageWeight),
  89. Price: int32(v.Price),
  90. JumpWeight: int32(v.JumpWeight),
  91. JumpDelay: v.JumpDelay,
  92. ConfirmStart: v.ConfirmStart,
  93. RelayLocations: int32(v.RelayLocations),
  94. Jmp: v.Jmp,
  95. IsShow: v.IsShow,
  96. Backup1: v.Backup1,
  97. Backup2: v.Backup2,
  98. Backup3: v.Backup3,
  99. CreatedAt: int32(v.CreatedAt),
  100. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  101. }
  102. }
  103. return res
  104. }