Jelajahi Sumber

crontab: neckRingHealth update

Yi 3 hari lalu
induk
melakukan
b62dff752e

+ 0 - 1
model/cow.go

@@ -786,7 +786,6 @@ func ExcelEnterCow(pastureId int64, req *pasturePb.EventEnterRequest) *Cow {
 		if req.MatingAt > 0 && req.PregnantCheckResult == pasturePb.PregnantCheckResult_UnPregnant &&
 			req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
 			breedStatus = pasturePb.BreedStatus_Empty
-
 		}
 
 		if req.CalvingAt > 0 && req.CalvingAt >= req.MatingAt && req.CalvingAt >= req.AbortionAt {

+ 1 - 1
module/crontab/neck_ring_estrus.go

@@ -144,7 +144,7 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday, nowTime time.T
 				continue
 			}
 
-			if cowInfo.Sex == pasturePb.Genders_Male {
+			if cowInfo.Sex == pasturePb.Genders_Male || cowInfo.PurposeKind == pasturePb.Purpose_Fatten {
 				continue
 			}
 

+ 21 - 0
module/crontab/neck_ring_health.go

@@ -4,6 +4,7 @@ import (
 	"kpt-pasture/model"
 	"kpt-pasture/util"
 	"math"
+	"time"
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
@@ -46,6 +47,9 @@ func (e *Entry) HealthWarning(pastureId int64, processIds []int64) {
 
 func (e *Entry) updateNeckRingHealth(pastureId int64, healthWarningList []*model.NeckRingHealth) {
 	for _, v := range healthWarningList {
+		if ok := e.CalculateNeckRingData(pastureId, v.CowId); !ok {
+			continue
+		}
 		startAt := util.TimeParseLocalUnix(v.HeatDate)
 		endAt := util.TimeParseLocalEndUnix(v.HeatDate)
 		isMove := e.isEventCowLog(pastureId, v.CowId, startAt, endAt, pasturePb.EventType_Transfer_Ben)
@@ -92,6 +96,23 @@ func (e *Entry) isEventCowLog(pastureId int64, CowId int64, startAt, endAt int64
 	return count > 0
 }
 
+// CalculateNeckRingData 判断牛只脖环数据是否大于3天
+func (e *Entry) CalculateNeckRingData(pastureId, cowId int64) bool {
+	var count int64
+	before3DaysDate := time.Now().AddDate(0, 0, -3).Local().Format(model.LayoutDate2)
+	if err := e.DB.Model(new(model.NeckActiveHabit)).
+		Where("pasture_id = ?", pastureId).
+		Where("cow_id = ?", cowId).
+		Where("heat_date = ?", before3DaysDate).
+		Count(&count).Error; err != nil {
+		return false
+	}
+	if count > 12 {
+		return true
+	}
+	return false
+}
+
 func calculateNewScore(data *model.NeckRingHealth) int32 {
 	otherScore := int32(0)
 

+ 0 - 1
util/util.go

@@ -124,7 +124,6 @@ func TimeParseLocalUnix(DayTime string) int64 {
 	if len(DayTime) <= 11 {
 		value = fmt.Sprintf("%s 00:00:00", DayTime)
 	}
-
 	theTime, _ := TimeParseLocal(LayoutTime, value)
 	return theTime.Unix()
 }

+ 6 - 6
util/util_test.go

@@ -535,10 +535,10 @@ type WeeklyActiveModel struct {
 }
 
 func Test_demo(t *testing.T) {
-	nowTime := time.Now().Local()
-	currentMonth := nowTime.Format(LayoutMonth)
-	startTime := time.Date(nowTime.Year(), nowTime.Month(), 1, 0, 0, 0, 0, nowTime.Location())
-	startMonth := startTime.AddDate(0, -5, 0).Format(LayoutMonth)
-	monthRang, _ := GetMonthsBetween(startMonth, currentMonth)
-	fmt.Println("currentMonth:", currentMonth, "startMonth:", startMonth, "monthRang", monthRang)
+	a := true
+	if !a {
+		fmt.Println("a")
+	} else {
+		fmt.Println("b")
+	}
 }