Bladeren bron

crontab: healthWarning update

Yi 1 maand geleden
bovenliggende
commit
1d298823e5

+ 2 - 2
dep/di_crontab.go

@@ -107,10 +107,10 @@ func EntryCrontab(dependency CrontabDependency) *cron.Crontab {
 		panic(err)
 	}
 
-	/*if err := newCrontab.Bind("NeckRingHealthWarning", cs.NeckRingHealthWarning, dependency.CrontabHub.NeckRingHealthWarning); err != nil {
+	if err := newCrontab.Bind("NeckRingHealthWarning", cs.NeckRingHealthWarning, dependency.CrontabHub.NeckRingHealthWarning); err != nil {
 		zaplog.Error("EntryCrontab", zap.Any("NeckRingHealthWarning", err))
 		panic(err)
-	}*/
+	}
 
 	if err := newCrontab.Bind("UpdatePenBehavior", cs.UpdatePenBehavior, dependency.CrontabHub.UpdatePenBehavior); err != nil {
 		zaplog.Error("EntryCrontab", zap.Any("UpdatePenBehavior", err))

+ 1 - 0
model/neck_ring_health_warning.go

@@ -17,6 +17,7 @@ type NeckRingHealthWarning struct {
 	BeforeThreeSumChew int32                             `json:"beforeThreeSumChew"`
 	Score              int32                             `json:"score"`
 	Level              pasturePb.WarningHealthLevel_Kind `json:"level"`
+	IsShow             pasturePb.IsShow_Kind             `json:"is_show"`
 	CreatedAt          int64                             `json:"created"`
 	UpdatedAt          int64                             `json:"updated"`
 }

+ 2 - 2
module/backend/analysis_cow.go

@@ -214,10 +214,10 @@ func (s *StoreEntry) TwentyOnePregnantDetail(ctx context.Context, req *pasturePb
 		shouldBreedCowList, _ := s.TwentyOnePregnantShouldBreedList(pastureId, req.CowType, stopBreedingDay, middleDay)
 		list = model.CowCalvingSlice(shouldBreedCowList).ToPB()
 	case pasturePb.TwentyOnePregnantType_RealityBreed:
-		realityBreedCowList, _ := s.TwentyOnePregnantRealityBreedList(userModel.AppPasture.Id, req.CowType, req.StartDate, req.EndDate)
+		realityBreedCowList, _ := s.TwentyOnePregnantRealityBreedList(pastureId, req.CowType, req.StartDate, req.EndDate)
 		list = model.EventMatingSlice(realityBreedCowList).ToPB3(false, cowTypeMap)
 	case pasturePb.TwentyOnePregnantType_ShouldPregnant:
-		realityBreedCowList, _ := s.TwentyOnePregnantRealityBreedList(userModel.AppPasture.Id, req.CowType, req.StartDate, req.EndDate)
+		realityBreedCowList, _ := s.TwentyOnePregnantRealityBreedList(pastureId, req.CowType, req.StartDate, req.EndDate)
 		newShouldBreedCowList := make([]*model.EventMating, 0)
 		for _, v := range realityBreedCowList {
 			if s.IsDeparture(ctx, v.PastureId, v.CowId, stopBreedingDay) {

+ 1 - 0
module/backend/dashboard.go

@@ -85,6 +85,7 @@ func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckR
 	healthWarningNumber := int64(0)
 	if err = s.DB.Model(new(model.NeckRingHealthWarning)).
 		Where("pasture_id = ?", userModel.AppPasture.Id).
+		Where("is_show = ?", pasturePb.IsShow_Ok).
 		Group("cow_id").
 		Count(&healthWarningNumber).Error; err != nil {
 		zaplog.Error("NeckRingWarning", zap.Any("estrusWarningNumber", err))

+ 26 - 1
module/crontab/health_warning.go

@@ -14,6 +14,7 @@ import (
 	"go.uber.org/zap"
 )
 
+// HealthWarning 健康预警 create_jbq_update_2024
 func (e *Entry) HealthWarning(pastureId int64, processIds []int64) {
 	newNeckActiveHabitList := make([]*model.NeckActiveHabit, 0)
 	if err := e.DB.Model(new(model.NeckActiveHabit)).
@@ -236,7 +237,18 @@ func (e *Entry) FindNewNeckRingHealthWarning(pastureId int64, healthValue int32)
 			continue
 		}
 
+		if e.FindNeckRingError(pastureId, cowInfo.NeckRingNumber) {
+			continue
+		}
+
 		newNeckRingHealthWarning := model.NewNeckRingHealthWarning(pastureId, v, cowInfo, newScore)
+		zaplog.Info("newNeckRingHealthWarning",
+			zap.Any("newNeckRingHealthWarning", newNeckRingHealthWarning),
+			zap.Any("pastureId", pastureId),
+			zap.Any("neckRingHealth", v),
+			zap.Any("cowInfo", cowInfo),
+			zap.Any("newScore", newScore),
+		)
 		newNeckRingHealthWarningList = append(newNeckRingHealthWarningList, newNeckRingHealthWarning)
 	}
 	return newNeckRingHealthWarningList, nil
@@ -248,7 +260,20 @@ func (e *Entry) HistoryNeckRingHealthWarning(pastureId int64, neckRingNumber str
 		Where("pasture_id = ?", pastureId).
 		Where("neck_ring_number = ?", neckRingNumber).
 		Where("heat_date = ?", heatDate).
-		Where("is_show = ?", pasturePb.IsShow_No).
+		Where("is_show = ?", pasturePb.IsShow_Ok).
+		Count(&count).Error; err != nil {
+		return false
+	}
+	return count > 0
+}
+
+func (e *Entry) FindNeckRingError(pastureId int64, neckRingNumber string) bool {
+	var count int64
+	if err := e.DB.Model(new(model.NeckRing)).
+		Where("pasture_id = ?", pastureId).
+		Where("neck_ring_number = ?", neckRingNumber).
+		Where("status = ?", pasturePb.IsShow_No).
+		Where("error_kind = ?", pasturePb.NeckRingNumberError_Suspected_Fall_Off).
 		Count(&count).Error; err != nil {
 		return false
 	}