|
@@ -308,6 +308,13 @@ func (e *Entry) EntryUpdateActiveHabit(pastureId int64) (err error) {
|
|
|
if err = e.UpdateChangeAdJust(pastureId, xToday); err != nil {
|
|
|
zaplog.Error("EntryUpdateActiveHabit", zap.Any("UpdateChangeAdJust", err), zap.Any("xToday", xToday))
|
|
|
}
|
|
|
+
|
|
|
+ // 健康预警
|
|
|
+ if len(processIds) > 0 {
|
|
|
+ if err = e.HealthWarning(pastureId, processIds); err != nil {
|
|
|
+ zaplog.Error("EntryUpdateActiveHabit", zap.Any("HealthWarning", err))
|
|
|
+ }
|
|
|
+ }
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -643,6 +650,21 @@ func (e *Entry) FilterCorrectAndScoreUpdate(pastureId int64, xToday *XToday) err
|
|
|
|
|
|
// UpdateChangeAdJust 更新群体校正数据
|
|
|
func (e *Entry) UpdateChangeAdJust(pastureId int64, xToday *XToday) error {
|
|
|
+ /*-- 插入群体校正表
|
|
|
+ INSERT INTO data_bar_change(heatdate, frameid, intCurBar, intCurBarName, nb, highchange, changefilter)
|
|
|
+ SELECT h.heatdate, h.frameid, c.intCurBar, c.intCurBarName, COUNT(*) nb, ROUND(AVG(h.highchange)) highchange, ROUND(AVG(h.changefilter) ) changefilter
|
|
|
+ FROM h_activehabit h JOIN cow c ON h.intCowId=c.intCowId
|
|
|
+ WHERE h.heatdate>=(CURDATE() -INTERVAL 1 DAY )
|
|
|
+ GROUP BY h.heatdate, h.frameid, c.intCurBar
|
|
|
+ ORDER BY h.heatdate, h.frameid, c.intCurBarName
|
|
|
+ ON DUPLICATE KEY UPDATE nb = VALUES(nb), highchange = VALUES(highchange), changefilter = VALUES(changefilter);
|
|
|
+
|
|
|
+ UPDATE h_activehabit h
|
|
|
+ JOIN cow c ON h.intCowId=c.intCowId
|
|
|
+ JOIN data_bar_change cg ON h.heatdate=cg.heatdate AND h.frameid=cg.frameid AND c.intCurBar=cg.intCurBar
|
|
|
+ SET h.changeadjust=cg.changefilter
|
|
|
+ WHERE h.id>xBeg_update_act_Id AND h.heatdate>=CURRENT_DATE() - INTERVAL 1 DAY AND ABS(cg.changefilter)>=10;
|
|
|
+ */
|
|
|
res := make([]*model.NeckRingBarChange, 0)
|
|
|
oneDayAgo := time.Now().AddDate(0, 0, -1).Format(model.LayoutDate2)
|
|
|
if err := e.DB.Table(fmt.Sprintf("%s as h", new(model.NeckActiveHabit).TableName())).
|
|
@@ -651,12 +673,14 @@ func (e *Entry) UpdateChangeAdJust(pastureId int64, xToday *XToday) error {
|
|
|
Where("h.pasture_id = ?", pastureId).
|
|
|
Where("h.heat_date >= ?", oneDayAgo).
|
|
|
Where("h.cow_id >= ?", 0).
|
|
|
+ Where("h.cow_id >= ?", 0).
|
|
|
Group("h.heat_date, h.frameid, c.pen_id").
|
|
|
Order("h.heat_date, h.frameid, c.pen_name").
|
|
|
Find(&res).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
+ // todo ABS(cg.changefilter)>=10;
|
|
|
for _, v := range res {
|
|
|
if err := e.DB.Model(new(model.NeckActiveHabit)).
|
|
|
Where("id > ?", xToday.LastMaxHabitId).
|