forage.go 3.7 KB

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