|
@@ -1,6 +1,8 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
+ "time"
|
|
|
+
|
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
)
|
|
|
|
|
@@ -12,6 +14,7 @@ type EventCowSameTime struct {
|
|
|
PenName string `json:"penName"`
|
|
|
Lact int32 `json:"lact"`
|
|
|
SameTimeId int64 `json:"sameTimeId"`
|
|
|
+ SameTimeName string `json:"sameTimeName"`
|
|
|
SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"`
|
|
|
PlanDay int64 `json:"planDay"`
|
|
|
EndDay int64 `json:"endDay"`
|
|
@@ -30,13 +33,14 @@ func (s *EventCowSameTime) TableName() string {
|
|
|
return "event_cow_same_time"
|
|
|
}
|
|
|
|
|
|
-func NewEventCowSameTime(cow *Cow, planTime int64, sameTimeId int64, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {
|
|
|
+func NewEventCowSameTime(cow *Cow, planTime int64, sameTime *SameTime, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {
|
|
|
return &EventCowSameTime{
|
|
|
CowId: cow.Id,
|
|
|
Lact: cow.Lact,
|
|
|
CowType: cow.CowType,
|
|
|
PenId: cow.PenId,
|
|
|
- SameTimeId: sameTimeId,
|
|
|
+ SameTimeId: sameTime.Id,
|
|
|
+ SameTimeName: sameTime.Name,
|
|
|
SameTimeType: sameTimeType,
|
|
|
Status: pasturePb.IsShow_No,
|
|
|
PlanDay: planTime,
|
|
@@ -44,54 +48,74 @@ func NewEventCowSameTime(cow *Cow, planTime int64, sameTimeId int64, sameTimeTyp
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func NewEventCowSameTimeList(cowList []*Cow, sameTimeId int64, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {
|
|
|
+func NewEventCowSameTimeList(cowList []*Cow, sameTime *SameTime, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {
|
|
|
res := make([]*EventCowSameTime, len(cowList))
|
|
|
for i, cow := range cowList {
|
|
|
- res[i] = NewEventCowSameTime(cow, planTime, sameTimeId, sameTimeType)
|
|
|
+ res[i] = NewEventCowSameTime(cow, planTime, sameTime, sameTimeType)
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
-type SameTimeBody struct {
|
|
|
- Id int64 `json:"id"`
|
|
|
- CowId int64 `json:"cowId"`
|
|
|
- BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
|
|
|
- BreedStatusName string `json:"breedStatusName"`
|
|
|
- CowType pasturePb.CowType_Kind `json:"cowType"`
|
|
|
- CowTypeName string `json:"cowTypeName"`
|
|
|
- PenId int32 `json:"penId"`
|
|
|
- PenName string `json:"penName"`
|
|
|
- Lact int32 `json:"lact"`
|
|
|
- CalvingAge int32 `json:"calvingAge"`
|
|
|
- AbortionAge int32 `json:"abortionAge"`
|
|
|
- DayAge int32 `json:"dayAge"`
|
|
|
- Status pasturePb.IsShow_Kind `json:"status"`
|
|
|
+type SameTimeItemBody struct {
|
|
|
+ Id int64 `json:"id"`
|
|
|
+ CowId int64 `json:"cowId"`
|
|
|
+ BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
|
|
|
+ BreedStatusName string `json:"breedStatusName"`
|
|
|
+ CowType pasturePb.CowType_Kind `json:"cowType"`
|
|
|
+ CowTypeName string `json:"cowTypeName"`
|
|
|
+ PenId int32 `json:"penId"`
|
|
|
+ PenName string `json:"penName"`
|
|
|
+ Lact int32 `json:"lact"`
|
|
|
+ CalvingAge int32 `json:"calvingAge"`
|
|
|
+ AbortionAge int32 `json:"abortionAge"`
|
|
|
+ DayAge int32 `json:"dayAge"`
|
|
|
+ Status pasturePb.IsShow_Kind `json:"status"`
|
|
|
+ SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"`
|
|
|
+ LastCalvingAt int64 `json:"lastCalvingAt"`
|
|
|
+ LastAbortionAt int64 `json:"lastAbortionAt"`
|
|
|
+ MatingTimes int32 `json:"matingTimes"`
|
|
|
+ SameTimeName string `json:"sameTimeName"`
|
|
|
}
|
|
|
|
|
|
-type SameTimeBodySlice []*SameTimeBody
|
|
|
+type SameTimeBodySlice []*SameTimeItemBody
|
|
|
|
|
|
func (s SameTimeBodySlice) ToPB(
|
|
|
breedStatusMap map[pasturePb.BreedStatus_Kind]string,
|
|
|
penMap map[int32]*Pen,
|
|
|
+ sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string,
|
|
|
) []*pasturePb.SameTimeItems {
|
|
|
res := make([]*pasturePb.SameTimeItems, len(s))
|
|
|
for i, v := range s {
|
|
|
- penName := ""
|
|
|
+ penName, calvingAtFormat, abortionAtFormat := "", "", ""
|
|
|
if pen, ok := penMap[v.PenId]; ok {
|
|
|
penName = pen.Name
|
|
|
}
|
|
|
+
|
|
|
+ if v.LastCalvingAt > 0 {
|
|
|
+ calvingAtFormat = time.Unix(v.LastCalvingAt, 0).Format(LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
+ if v.LastAbortionAt > 0 {
|
|
|
+ abortionAtFormat = time.Unix(v.LastAbortionAt, 0).Format(LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
res[i] = &pasturePb.SameTimeItems{
|
|
|
- Id: int32(v.Id),
|
|
|
- CowId: int32(v.CowId),
|
|
|
- BreedStatus: v.BreedStatus,
|
|
|
- BreedStatusName: breedStatusMap[v.BreedStatus],
|
|
|
- PenName: penName,
|
|
|
- PenId: v.PenId,
|
|
|
- Lact: v.Lact,
|
|
|
- CalvingAge: v.CalvingAge,
|
|
|
- AbortionAge: v.AbortionAge,
|
|
|
- DayAge: v.DayAge,
|
|
|
- Status: v.Status,
|
|
|
+ Id: int32(v.Id),
|
|
|
+ CowId: int32(v.CowId),
|
|
|
+ BreedStatus: v.BreedStatus,
|
|
|
+ BreedStatusName: breedStatusMap[v.BreedStatus],
|
|
|
+ PenName: penName,
|
|
|
+ PenId: v.PenId,
|
|
|
+ Lact: v.Lact,
|
|
|
+ CalvingAge: v.CalvingAge,
|
|
|
+ AbortionAge: v.AbortionAge,
|
|
|
+ DayAge: v.DayAge,
|
|
|
+ Status: v.Status,
|
|
|
+ SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
|
|
|
+ CalvingAtFormat: calvingAtFormat,
|
|
|
+ AbortionAtFormat: abortionAtFormat,
|
|
|
+ MatingTimes: v.MatingTimes,
|
|
|
+ SameTimeName: v.SameTimeName,
|
|
|
}
|
|
|
}
|
|
|
return res
|
|
@@ -99,7 +123,7 @@ func (s SameTimeBodySlice) ToPB(
|
|
|
|
|
|
type EventCowSameTimeSlice []*EventCowSameTime
|
|
|
|
|
|
-func (s EventCowSameTimeSlice) ToPB() []*pasturePb.EventSameTime {
|
|
|
+func (s EventCowSameTimeSlice) ToPB(sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string) []*pasturePb.EventSameTime {
|
|
|
res := make([]*pasturePb.EventSameTime, len(s))
|
|
|
for i, v := range s {
|
|
|
res[i] = &pasturePb.EventSameTime{
|
|
@@ -110,7 +134,7 @@ func (s EventCowSameTimeSlice) ToPB() []*pasturePb.EventSameTime {
|
|
|
Lact: v.Lact,
|
|
|
SameTimeId: int32(v.SameTimeId),
|
|
|
SameTimeType: v.SameTimeType,
|
|
|
- SameTimeTypeName: "",
|
|
|
+ SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
|
|
|
}
|
|
|
}
|
|
|
return res
|