123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package model
- import (
- "fmt"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventSaleCow struct {
- Id int64 `json:"id"`
- BatchNumber string `json:"batchNumber"`
- PastureId int64 `json:"pastureId"`
- SaleId int64 `json:"saleId"`
- CowId int64 `json:"cowId"`
- CowType pasturePb.CowType_Kind `json:"cowType"`
- CowKind pasturePb.CowKind_Kind `json:"cowKind"`
- EarNumber string `json:"earNumber"`
- PenId int32 `json:"penId"`
- PenName string `json:"penName"`
- DayAge int32 `json:"dayAge"`
- Lact int32 `json:"lact"`
- PregnancyAge int32 `json:"pregnancyAge"`
- BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
- LactationAge int32 `json:"lactationAge"`
- CalvingAge int32 `json:"calvingAge"`
- AdmissionAge int32 `json:"admissionAge"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (e *EventSaleCow) TableName() string {
- return "event_sale_cow"
- }
- func NewEventSaleCow(pastureId int64, saleId, saleAt int64, cowInfo *Cow) *EventSaleCow {
- return &EventSaleCow{
- PastureId: pastureId,
- BatchNumber: cowInfo.BatchNumber,
- SaleId: saleId,
- CowId: cowInfo.Id,
- Lact: cowInfo.Lact,
- EarNumber: cowInfo.EarNumber,
- PenId: cowInfo.PenId,
- PenName: cowInfo.PenName,
- PregnancyAge: cowInfo.PregnancyAge,
- BreedStatus: cowInfo.BreedStatus,
- LactationAge: cowInfo.LactationAge,
- AdmissionAge: cowInfo.AdmissionAge,
- DayAge: cowInfo.GetEventDayAge(saleAt),
- CowType: cowInfo.CowType,
- CowKind: cowInfo.CowKind,
- }
- }
- func NewEventSaleCowList(pastureId int64, eventSale *EventSale, cowList []*Cow) []*EventSaleCow {
- res := make([]*EventSaleCow, 0)
- for _, cow := range cowList {
- res = append(res, NewEventSaleCow(pastureId, eventSale.Id, eventSale.SaleAt, cow))
- }
- return res
- }
- type EventSaleCowSlice []*EventSaleCow
- func (e EventSaleCowSlice) ToPB(
- eventSaleMap map[int64]*EventSale,
- cowKindMap map[pasturePb.CowKind_Kind]string,
- cowMap map[int64]*Cow,
- sourceMap map[pasturePb.CowSource_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
- }
- feedCycle, cowSourceName := "", ""
- if cowInfo, ok := cowMap[v.CowId]; ok {
- admissionAtFormat := ""
- if cowInfo.AdmissionAt > 0 {
- feedCycle = time.Unix(cowInfo.AdmissionAt, 0).Local().Format(LayoutDate2)
- }
- feedCycle = fmt.Sprintf("%s-%s", admissionAtFormat, saleAtFormat)
- if name, ok := sourceMap[cowInfo.SourceKind]; ok {
- cowSourceName = name
- }
- }
- 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: cowSourceName,
- EnterWeight: 0,
- EnterPrice: 0,
- GrowthWeight: 0,
- AllFeedCost: 0,
- DayAvgFeedCost: 0,
- AllMedicalCharge: 0,
- OtherCost: 0,
- DealerName: dealerName,
- ProfitAndLoss: 0,
- FeedCycle: feedCycle,
- })
- }
- return res
- }
|