|
@@ -1,14 +1,22 @@
|
|
package model
|
|
package model
|
|
|
|
|
|
-import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
|
|
|
+import (
|
|
|
|
+ "time"
|
|
|
|
+
|
|
|
|
+ pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
|
+)
|
|
|
|
|
|
type EventSaleCow struct {
|
|
type EventSaleCow struct {
|
|
Id int64 `json:"id"`
|
|
Id int64 `json:"id"`
|
|
|
|
+ BatchNumber string `json:"batchNumber"`
|
|
PastureId int64 `json:"pastureId"`
|
|
PastureId int64 `json:"pastureId"`
|
|
SaleId int64 `json:"saleId"`
|
|
SaleId int64 `json:"saleId"`
|
|
CowId int64 `json:"cowId"`
|
|
CowId int64 `json:"cowId"`
|
|
CowType pasturePb.CowType_Kind `json:"cowType"`
|
|
CowType pasturePb.CowType_Kind `json:"cowType"`
|
|
|
|
+ CowKind pasturePb.CowKind_Kind `json:"cowKind"`
|
|
EarNumber string `json:"earNumber"`
|
|
EarNumber string `json:"earNumber"`
|
|
|
|
+ PenId int32 `json:"penId"`
|
|
|
|
+ PenName string `json:"penName"`
|
|
DayAge int32 `json:"dayAge"`
|
|
DayAge int32 `json:"dayAge"`
|
|
Lact int32 `json:"lact"`
|
|
Lact int32 `json:"lact"`
|
|
PregnancyAge int32 `json:"pregnancyAge"`
|
|
PregnancyAge int32 `json:"pregnancyAge"`
|
|
@@ -27,16 +35,20 @@ func (e *EventSaleCow) TableName() string {
|
|
func NewEventSaleCow(pastureId int64, saleId, saleAt int64, cowInfo *Cow) *EventSaleCow {
|
|
func NewEventSaleCow(pastureId int64, saleId, saleAt int64, cowInfo *Cow) *EventSaleCow {
|
|
return &EventSaleCow{
|
|
return &EventSaleCow{
|
|
PastureId: pastureId,
|
|
PastureId: pastureId,
|
|
|
|
+ BatchNumber: cowInfo.BatchNumber,
|
|
SaleId: saleId,
|
|
SaleId: saleId,
|
|
CowId: cowInfo.Id,
|
|
CowId: cowInfo.Id,
|
|
Lact: cowInfo.Lact,
|
|
Lact: cowInfo.Lact,
|
|
EarNumber: cowInfo.EarNumber,
|
|
EarNumber: cowInfo.EarNumber,
|
|
|
|
+ PenId: cowInfo.PenId,
|
|
|
|
+ PenName: cowInfo.PenName,
|
|
PregnancyAge: cowInfo.PregnancyAge,
|
|
PregnancyAge: cowInfo.PregnancyAge,
|
|
BreedStatus: cowInfo.BreedStatus,
|
|
BreedStatus: cowInfo.BreedStatus,
|
|
LactationAge: cowInfo.LactationAge,
|
|
LactationAge: cowInfo.LactationAge,
|
|
AdmissionAge: cowInfo.AdmissionAge,
|
|
AdmissionAge: cowInfo.AdmissionAge,
|
|
DayAge: cowInfo.GetEventDayAge(saleAt),
|
|
DayAge: cowInfo.GetEventDayAge(saleAt),
|
|
CowType: cowInfo.CowType,
|
|
CowType: cowInfo.CowType,
|
|
|
|
+ CowKind: cowInfo.CowKind,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -47,3 +59,49 @@ func NewEventSaleCowList(pastureId int64, eventSale *EventSale, cowList []*Cow)
|
|
}
|
|
}
|
|
return res
|
|
return res
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+type EventSaleCowSlice []*EventSaleCow
|
|
|
|
+
|
|
|
|
+func (e EventSaleCowSlice) ToPB(eventSaleMap map[int64]*EventSale, cowKindMap map[pasturePb.CowKind_Kind]string) []*pasturePb.AlreadySalesReport {
|
|
|
|
+ res := make([]*pasturePb.AlreadySalesReport, 0)
|
|
|
|
+ for _, v := range e {
|
|
|
|
+ cowKindName, saleAtFormat, dealerName := "", "", ""
|
|
|
|
+ if name, ok := cowKindMap[v.CowKind]; ok {
|
|
|
|
+ cowKindName = name
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ salePrice, saleTotalAmount, saleAllWeight, saleAvgWeight := float32(0), float32(0), float32(0), float32(0)
|
|
|
|
+ if eventSale, ok := eventSaleMap[v.SaleId]; ok {
|
|
|
|
+ if eventSale.SaleAt > 0 {
|
|
|
|
+ saleAtFormat = time.Unix(eventSale.SaleAt, 0).Local().Format(LayoutDate2)
|
|
|
|
+ }
|
|
|
|
+ saleTotalAmount = float32(eventSale.SaleAllAmount)
|
|
|
|
+ dealerName = eventSale.DealerName
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ res = append(res, &pasturePb.AlreadySalesReport{
|
|
|
|
+ CowId: int32(v.CowId),
|
|
|
|
+ EarNumber: v.EarNumber,
|
|
|
|
+ BatchNumber: v.BatchNumber,
|
|
|
|
+ CowKindName: cowKindName,
|
|
|
|
+ PenName: v.PenName,
|
|
|
|
+ SaleAtFormat: saleAtFormat,
|
|
|
|
+ SalePrice: salePrice,
|
|
|
|
+ SaleTotalAmount: saleTotalAmount,
|
|
|
|
+ SaleAvgWeight: saleAvgWeight,
|
|
|
|
+ SaleAllWeight: saleAllWeight,
|
|
|
|
+ AdmissionAge: v.AdmissionAge,
|
|
|
|
+ CowSourceName: "",
|
|
|
|
+ EnterWeight: 0,
|
|
|
|
+ EnterPrice: 0,
|
|
|
|
+ GrowthWeight: 0,
|
|
|
|
+ AllFeedCost: 0,
|
|
|
|
+ DayAvgFeedCost: 0,
|
|
|
|
+ AllMedicalCharge: 0,
|
|
|
|
+ OtherCost: 0,
|
|
|
|
+ DealerName: dealerName,
|
|
|
|
+ ProfitAndLoss: 0,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ return res
|
|
|
|
+}
|