event_sale.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package model
  2. import (
  3. "strconv"
  4. "strings"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type EventSale struct {
  8. Id int64 `json:"id"`
  9. PastureId int64 `json:"pastureId"`
  10. DealerId int32 `json:"dealerId"`
  11. DealerName string `json:"dealerName"`
  12. SalePrice float64 `json:"salePrice"`
  13. SaleAllWeight int32 `json:"saleAllWeight"`
  14. SaleAllAmount float64 `json:"saleAllAmount"`
  15. SaleCowCount int32 `json:"saleCowCount"`
  16. CowIds string `json:"cowIds"`
  17. SaleAt int64 `json:"saleAt"`
  18. SaleTicker string `json:"saleTicker"`
  19. QuarantineReport string `json:"quarantineReport"`
  20. Remarks string `json:"remarks"`
  21. OperationId int64 `json:"operationId"`
  22. OperationName string `json:"operationName"`
  23. MessageId int64 `json:"messageId"`
  24. MessageName string `json:"messageName"`
  25. CreatedAt int64 `json:"createdAt"`
  26. UpdatedAt int64 `json:"updatedAt"`
  27. }
  28. func (e *EventSale) TableName() string {
  29. return "event_sale"
  30. }
  31. func NewEventSale(pastureId int64, dealerInfo *SaleDealer, cowIds string, req *pasturePb.EventCowSale, operationUser, currUser *SystemUser) *EventSale {
  32. return &EventSale{
  33. PastureId: pastureId,
  34. DealerId: dealerInfo.Id,
  35. DealerName: dealerInfo.Name,
  36. SalePrice: float64(req.SalePrice),
  37. SaleAllWeight: int32(req.SaleAllWeight * 1000),
  38. SaleAllAmount: float64(req.SaleAllPrice),
  39. SaleCowCount: int32(len(req.CowIds)),
  40. CowIds: cowIds,
  41. SaleAt: int64(req.SaleAt),
  42. SaleTicker: strings.Join(req.SaleTicket, ","),
  43. QuarantineReport: strings.Join(req.QuarantineReport, ","),
  44. Remarks: req.Remarks,
  45. OperationId: operationUser.Id,
  46. OperationName: operationUser.Name,
  47. MessageId: currUser.Id,
  48. MessageName: currUser.Name,
  49. }
  50. }
  51. type EventSaleSlice []*EventSale
  52. func (e EventSaleSlice) ToPB(eventSaleCarMap map[int64][]*EventSaleCar) []*pasturePb.EventCowSale {
  53. res := make([]*pasturePb.EventCowSale, len(e))
  54. for i, v := range e {
  55. cowIds := make([]int32, 0)
  56. if len(v.CowIds) > 0 {
  57. for _, cowIdStr := range strings.Split(v.CowIds, ",") {
  58. cowId, _ := strconv.Atoi(cowIdStr)
  59. cowIds = append(cowIds, int32(cowId))
  60. }
  61. }
  62. saleVehicleItems := make([]*pasturePb.SaleVehicleItem, 0)
  63. eventSaleCarItems, ok := eventSaleCarMap[v.Id]
  64. if ok {
  65. for _, item := range eventSaleCarItems {
  66. carCowIds := make([]int32, 0)
  67. if len(item.CowIds) > 0 {
  68. for _, cowIdStr := range strings.Split(item.CowIds, ",") {
  69. carCowId, _ := strconv.Atoi(cowIdStr)
  70. carCowIds = append(carCowIds, int32(carCowId))
  71. }
  72. }
  73. saleVehicleItems = append(saleVehicleItems, &pasturePb.SaleVehicleItem{
  74. CarNumber: item.CarNumber,
  75. CowCount: item.CowCount,
  76. CowWeight: float32(item.CowWeight) / 1000,
  77. OutboundTicket: item.OutboundTicket,
  78. WeighbridgePhotos: strings.Split(item.WeighbridgePhotos, ","),
  79. VehiclePhotos: strings.Split(item.CarPhotos, ","),
  80. CowIds: carCowIds,
  81. })
  82. }
  83. }
  84. res[i] = &pasturePb.EventCowSale{
  85. DealerId: v.DealerId,
  86. DealerName: v.DealerName,
  87. SaleAt: int32(v.SaleAt),
  88. CowIds: cowIds,
  89. SaleAllWeight: float32(v.SaleAllWeight) / 1000,
  90. SaleAllPrice: float32(v.SaleAllAmount),
  91. SalePrice: float32(v.SalePrice),
  92. OperationId: int32(v.OperationId),
  93. OperationName: v.OperationName,
  94. Remarks: v.Remarks,
  95. SaleTicket: strings.Split(v.SaleTicker, ","),
  96. QuarantineReport: strings.Split(v.QuarantineReport, ","),
  97. SaleVehicleItems: nil,
  98. }
  99. }
  100. return res
  101. }