forage.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package model
  2. import (
  3. operationPb "gitee.com/xuyiping_admin/go_proto/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. MaterialTypeKey operationPb.FormulaType_Kind `json:"material_type_key"`
  15. MaterialTypeName string `json:"material_type_name"`
  16. UniqueEncode string `json:"unique_encode"`
  17. ForageSourceId operationPb.ForageSource_Kind `json:"forage_source_id"`
  18. ForageSourceName string `json:"forage_source_name"`
  19. PlanTypeId operationPb.ForagePlanType_Kind `json:"plan_type_id"`
  20. PlanTypeName string `json:"plan_type_name"`
  21. SmallMaterialScale string `json:"small_material_scale"`
  22. AllowError int64 `json:"allow_error"`
  23. PackageWeight int64 `json:"package_weight"`
  24. Price int64 `json:"price"`
  25. JumpWeight int64 `json:"jump_weight"`
  26. JumpDelay operationPb.JumpDelaType_Kind `json:"jump_delay"`
  27. ConfirmStart operationPb.IsShow_Kind `json:"confirm_start"`
  28. RelayLocations int64 `json:"relay_locations"`
  29. Jmp operationPb.IsShow_Kind `json:"jmp"`
  30. DataSource operationPb.DataSource_Kind `json:"data_source"`
  31. Sort int64 `json:"sort"`
  32. Backup1 string `json:"backup1"`
  33. Backup2 string `json:"backup2"`
  34. Backup3 string `json:"backup3"`
  35. IsShow operationPb.IsShow_Kind `json:"is_show"`
  36. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  37. CreatedAt int64 `json:"created_at"`
  38. UpdatedAt int64 `json:"updated_at"`
  39. }
  40. func (c *Forage) TableName() string {
  41. return "forage"
  42. }
  43. func NewForage(req *operationPb.AddForageRequest) *Forage {
  44. return &Forage{
  45. Name: req.Name,
  46. PastureName: "集团",
  47. CategoryId: int64(req.CategoryId),
  48. CategoryName: req.CategoryName,
  49. UniqueEncode: req.UniqueEncode,
  50. ForageSourceId: req.ForageSourceId,
  51. ForageSourceName: req.ForageSourceName,
  52. PlanTypeId: req.PlanTypeId,
  53. PlanTypeName: req.PlanTypeName,
  54. MaterialTypeKey: req.MaterialTypeKey,
  55. MaterialTypeName: req.MaterialTypeName,
  56. SmallMaterialScale: req.SmallMaterialScale,
  57. AllowError: int64(req.AllowError),
  58. PackageWeight: int64(req.PackageWeight),
  59. Price: int64(req.Price),
  60. JumpWeight: int64(req.JumpWeight),
  61. JumpDelay: req.JumpDelay,
  62. ConfirmStart: req.ConfirmStart,
  63. RelayLocations: int64(req.RelayLocations),
  64. IsShow: operationPb.IsShow_OK,
  65. IsDelete: operationPb.IsShow_OK,
  66. DataSource: operationPb.DataSource_BACKGROUND_ADD,
  67. Jmp: req.Jmp,
  68. Backup1: req.Backup1,
  69. Backup2: req.Backup2,
  70. Backup3: req.Backup3,
  71. }
  72. }
  73. type ForageSlice []*Forage
  74. func (f ForageSlice) ToPB() []*operationPb.AddForageRequest {
  75. res := make([]*operationPb.AddForageRequest, len(f))
  76. for i, v := range f {
  77. res[i] = &operationPb.AddForageRequest{
  78. Id: int32(v.Id),
  79. Name: v.Name,
  80. CategoryId: int32(v.CategoryId),
  81. CategoryName: v.CategoryName,
  82. MaterialTypeKey: v.MaterialTypeKey,
  83. MaterialTypeName: v.MaterialTypeName,
  84. UniqueEncode: v.UniqueEncode,
  85. ForageSourceId: v.ForageSourceId,
  86. ForageSourceName: v.ForageSourceName,
  87. PlanTypeId: v.PlanTypeId,
  88. PlanTypeName: v.PlanTypeName,
  89. SmallMaterialScale: v.SmallMaterialScale,
  90. AllowError: int32(v.AllowError),
  91. PackageWeight: int32(v.PackageWeight),
  92. Price: int32(v.Price),
  93. JumpWeight: int32(v.JumpWeight),
  94. JumpDelay: v.JumpDelay,
  95. ConfirmStart: v.ConfirmStart,
  96. RelayLocations: int32(v.RelayLocations),
  97. Jmp: v.Jmp,
  98. IsShow: v.IsShow,
  99. Backup1: v.Backup1,
  100. Backup2: v.Backup2,
  101. Backup3: v.Backup3,
  102. DataSource: v.PastureName,
  103. CreatedAt: int32(v.CreatedAt),
  104. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  105. }
  106. }
  107. return res
  108. }
  109. func NewForageByPastureFeed(groupPasture *GroupPasture, data *Feed) *Forage {
  110. forageSourceName := data.Source
  111. forageSourceId := operationPb.ForageSource_SYSTEM_BUILT_IN
  112. if forageSourceName == "用户自定义" {
  113. forageSourceId = operationPb.ForageSource_USER_DEFINED
  114. }
  115. confirmStart := operationPb.IsShow_INVALID
  116. if data.ConfirmStart == 0 {
  117. confirmStart = operationPb.IsShow_NO
  118. }
  119. if data.ConfirmStart == 1 {
  120. confirmStart = operationPb.IsShow_OK
  121. }
  122. return &Forage{
  123. Name: data.FName,
  124. CategoryId: data.FClassId,
  125. CategoryName: data.FClass,
  126. MaterialTypeKey: 0, // 部分牧场有该字段
  127. MaterialTypeName: "", //
  128. UniqueEncode: data.FeedCode,
  129. ForageSourceId: forageSourceId,
  130. ForageSourceName: forageSourceName,
  131. PlanTypeId: operationPb.ForagePlanType_Kind(data.PrintGroupId),
  132. PlanTypeName: data.PrintGroup,
  133. SmallMaterialScale: data.SmtMrName,
  134. AllowError: data.AllowRatio,
  135. PackageWeight: data.UnitWeight,
  136. Price: int64(data.UPrice * 100),
  137. JumpWeight: data.AutoZone,
  138. JumpDelay: operationPb.JumpDelaType_Kind(data.AutoSecond),
  139. ConfirmStart: confirmStart,
  140. RelayLocations: int64(data.TrgAddress),
  141. Jmp: operationPb.IsShow_Kind(data.Jmp),
  142. DataSource: operationPb.DataSource_FROM_PASTURE,
  143. Sort: int64(data.Sort),
  144. PastureId: groupPasture.PastureId,
  145. PastureName: groupPasture.Name,
  146. PastureDataId: data.Id,
  147. IsShow: operationPb.IsShow_Kind(data.Enable),
  148. IsDelete: operationPb.IsShow_OK,
  149. }
  150. }