|
@@ -63,7 +63,6 @@ func (n *NeckRingEstrusWarning) CalculatePzHour(lact int32) time.Time {
|
|
|
} else {
|
|
|
pzHour = firstTime.Add(16 * time.Hour) // v.firsttime + INTERVAL 16 HOUR
|
|
|
}
|
|
|
-
|
|
|
// 胎次调整
|
|
|
if lact >= 3 {
|
|
|
pzHour = pzHour.Add(-1 * time.Hour) // 减去 1 小时
|
|
@@ -73,7 +72,12 @@ func (n *NeckRingEstrusWarning) CalculatePzHour(lact int32) time.Time {
|
|
|
|
|
|
type NeckRingEstrusWarningSlice []*NeckRingEstrusWarning
|
|
|
|
|
|
-func (n NeckRingEstrusWarningSlice) ToPB(cowMap map[int64]*Cow, eventLogMap map[int64]string, matingWindowPeriodKind pasturePb.MatingWindowPeriod_Kind) []*pasturePb.EstrusItem {
|
|
|
+func (n NeckRingEstrusWarningSlice) ToPB(
|
|
|
+ cowMap map[int64]*Cow,
|
|
|
+ eventLogMap map[int64]string,
|
|
|
+ matingWindowPeriodKind pasturePb.MatingWindowPeriod_Kind,
|
|
|
+ matingWindowPeriodKindList []pasturePb.MatingWindowPeriod_Kind,
|
|
|
+) []*pasturePb.EstrusItem {
|
|
|
res := make([]*pasturePb.EstrusItem, 0)
|
|
|
nowTime := time.Now().Local()
|
|
|
for _, v := range n {
|
|
@@ -98,19 +102,20 @@ func (n NeckRingEstrusWarningSlice) ToPB(cowMap map[int64]*Cow, eventLogMap map[
|
|
|
optimumMatingStartTime := pzHour.Add(-4 * time.Hour)
|
|
|
optimumMatingEndTime := pzHour.Add(4 * time.Hour)
|
|
|
|
|
|
- switch matingWindowPeriodKind {
|
|
|
- case pasturePb.MatingWindowPeriod_Front:
|
|
|
- if !nowTime.Before(optimumMatingStartTime) {
|
|
|
- continue
|
|
|
- }
|
|
|
- case pasturePb.MatingWindowPeriod_Middle:
|
|
|
- if !(nowTime.After(optimumMatingStartTime) && nowTime.Before(optimumMatingEndTime)) {
|
|
|
- continue
|
|
|
- }
|
|
|
- case pasturePb.MatingWindowPeriod_Behind:
|
|
|
- if !nowTime.After(optimumMatingEndTime) {
|
|
|
- continue
|
|
|
+ found := false
|
|
|
+ if len(matingWindowPeriodKindList) > 0 && len(matingWindowPeriodKindList) <= 2 {
|
|
|
+ for _, periodKind := range matingWindowPeriodKindList {
|
|
|
+ if isIPeriod(periodKind, nowTime, optimumMatingStartTime, optimumMatingEndTime) {
|
|
|
+ found = true
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ found = isIPeriod(matingWindowPeriodKind, nowTime, optimumMatingStartTime, optimumMatingEndTime)
|
|
|
+ }
|
|
|
+
|
|
|
+ if !found {
|
|
|
+ continue
|
|
|
}
|
|
|
|
|
|
firstTimeParseLocal, _ := util.TimeParseLocal(LayoutTime, v.FirstTime)
|
|
@@ -147,6 +152,19 @@ func (n NeckRingEstrusWarningSlice) ToPB(cowMap map[int64]*Cow, eventLogMap map[
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
+func isIPeriod(periodKind pasturePb.MatingWindowPeriod_Kind, nowTime, optimumMatingStartTime, optimumMatingEndTime time.Time) bool {
|
|
|
+ switch periodKind {
|
|
|
+ case pasturePb.MatingWindowPeriod_Front:
|
|
|
+ return nowTime.Before(optimumMatingStartTime)
|
|
|
+ case pasturePb.MatingWindowPeriod_Middle:
|
|
|
+ return nowTime.After(optimumMatingStartTime) && nowTime.Before(optimumMatingEndTime)
|
|
|
+ case pasturePb.MatingWindowPeriod_Behind:
|
|
|
+ return nowTime.After(optimumMatingEndTime)
|
|
|
+ default:
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const (
|
|
|
Nb1 = 12
|
|
|
Nb2 = 8
|