forage.go 3.9 KB

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