forage.go 3.5 KB

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