123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package model
- import (
- "strconv"
- "strings"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventSale struct {
- Id int64 `json:"id"`
- PastureId int64 `json:"pastureId"`
- DealerId int32 `json:"dealerId"`
- DealerName string `json:"dealerName"`
- SalePrice float64 `json:"salePrice"`
- SaleAllWeight int32 `json:"saleAllWeight"`
- SaleAllAmount float64 `json:"saleAllAmount"`
- SaleCowCount int32 `json:"saleCowCount"`
- CowIds string `json:"cowIds"`
- SaleAt int64 `json:"saleAt"`
- SaleTicker string `json:"saleTicker"`
- QuarantineReport string `json:"quarantineReport"`
- Remarks string `json:"remarks"`
- OperationId int64 `json:"operationId"`
- OperationName string `json:"operationName"`
- MessageId int64 `json:"messageId"`
- MessageName string `json:"messageName"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (e *EventSale) TableName() string {
- return "event_sale"
- }
- func NewEventSale(pastureId int64, dealerInfo *SaleDealer, cowIds string, req *pasturePb.EventCowSale, operationUser, currUser *SystemUser) *EventSale {
- return &EventSale{
- PastureId: pastureId,
- DealerId: dealerInfo.Id,
- DealerName: dealerInfo.Name,
- SalePrice: float64(req.SalePrice),
- SaleAllWeight: int32(req.SaleAllWeight * 1000),
- SaleAllAmount: float64(req.SaleAllPrice),
- SaleCowCount: int32(len(req.CowIds)),
- CowIds: cowIds,
- SaleAt: int64(req.SaleAt),
- SaleTicker: strings.Join(req.SaleTicket, ","),
- QuarantineReport: strings.Join(req.QuarantineReport, ","),
- Remarks: req.Remarks,
- OperationId: operationUser.Id,
- OperationName: operationUser.Name,
- MessageId: currUser.Id,
- MessageName: currUser.Name,
- }
- }
- type EventSaleSlice []*EventSale
- func (e EventSaleSlice) ToPB(eventSaleCarMap map[int64][]*EventSaleCar) []*pasturePb.EventCowSale {
- res := make([]*pasturePb.EventCowSale, len(e))
- for i, v := range e {
- cowIds := make([]int32, 0)
- if len(v.CowIds) > 0 {
- for _, cowIdStr := range strings.Split(v.CowIds, ",") {
- cowId, _ := strconv.Atoi(cowIdStr)
- cowIds = append(cowIds, int32(cowId))
- }
- }
- saleVehicleItems := make([]*pasturePb.SaleVehicleItem, 0)
- eventSaleCarItems, ok := eventSaleCarMap[v.Id]
- if ok {
- for _, item := range eventSaleCarItems {
- carCowIds := make([]int32, 0)
- if len(item.CowIds) > 0 {
- for _, cowIdStr := range strings.Split(item.CowIds, ",") {
- carCowId, _ := strconv.Atoi(cowIdStr)
- carCowIds = append(carCowIds, int32(carCowId))
- }
- }
- saleVehicleItems = append(saleVehicleItems, &pasturePb.SaleVehicleItem{
- CarNumber: item.CarNumber,
- CowCount: item.CowCount,
- CowWeight: float32(item.CowWeight) / 1000,
- OutboundTicket: item.OutboundTicket,
- WeighbridgePhotos: strings.Split(item.WeighbridgePhotos, ","),
- VehiclePhotos: strings.Split(item.CarPhotos, ","),
- CowIds: carCowIds,
- })
- }
- }
- res[i] = &pasturePb.EventCowSale{
- DealerId: v.DealerId,
- DealerName: v.DealerName,
- SaleAt: int32(v.SaleAt),
- CowIds: cowIds,
- SaleAllWeight: float32(v.SaleAllWeight) / 1000,
- SaleAllPrice: float32(v.SaleAllAmount),
- SalePrice: float32(v.SalePrice),
- OperationId: int32(v.OperationId),
- OperationName: v.OperationName,
- Remarks: v.Remarks,
- SaleTicket: strings.Split(v.SaleTicker, ","),
- QuarantineReport: strings.Split(v.QuarantineReport, ","),
- SaleVehicleItems: nil,
- }
- }
- return res
- }
|