|
@@ -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)
|
|
|
|