Ver código fonte

crontab: neck_ring update

Yi 1 mês atrás
pai
commit
c295472261
1 arquivos alterados com 8 adições e 5 exclusões
  1. 8 5
      module/crontab/milk_daily.go

+ 8 - 5
module/crontab/milk_daily.go

@@ -46,12 +46,12 @@ func (e *Entry) ProcessMilkDaily(pastureId int64, maxDate time.Time) {
 	// 处理每一天的数据
 	for maxDate.Before(nowTime) {
 		// 处理有胎次的奶牛
-		if err := e.processCowsWithLact(maxDate); err != nil {
+		if err := e.processCowsWithLact(pastureId, maxDate); err != nil {
 			zaplog.Error("ProcessMilkDaily", zap.Any("processCowsWithFetal", err))
 		}
 
 		// 处理无胎次的奶牛
-		if err := e.processCowsWithNoLact(maxDate); err != nil {
+		if err := e.processCowsWithNoLact(pastureId, maxDate); err != nil {
 			zaplog.Error("ProcessMilkDaily", zap.Any("processCowsWithoutFetal", err))
 		}
 		// 日期加1天
@@ -66,10 +66,11 @@ func (e *Entry) UpdateMilkDaily(pastureId int64, maxDateTime string) error {
 }
 
 // 处理有胎次的奶牛
-func (e *Entry) processCowsWithLact(recordDate time.Time) error {
+func (e *Entry) processCowsWithLact(pastureId int64, recordDate time.Time) error {
 	// 查询有胎次且在记录日期前有记录的奶牛
 	cowList := make([]*model.Cow, 0)
 	if err := e.DB.Model(new(model.Cow)).
+		Where("pasture_id = ?", pastureId).
 		Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
 		Where("lact > ?", 0).
 		Where("last_calving_at <= ?", recordDate.Local().Unix()).
@@ -116,12 +117,13 @@ func (e *Entry) processCowsWithLact(recordDate time.Time) error {
 }
 
 // 处理无胎次的奶牛
-func (e *Entry) processCowsWithNoLact(recordDate time.Time) error {
+func (e *Entry) processCowsWithNoLact(pastureId int64, recordDate time.Time) error {
 	// 查询无胎次且EID1>0的奶牛
 	cowList := make([]*model.Cow, 0)
 	err := e.DB.Model(new(model.Cow)).
 		//Select("c.intCowId as cow_id, c.intPastureId as pasture_id, c.varCowCode as cow_code,c.dateBirthDate as birth_date, c.intCurBar as cur_bar").
 		//Where("(c.dateLeave IS NULL OR c.dateLeave > ?) AND c.intCurFetal = 0 AND c.EID1 > 0", recordDate).
+		Where("pasture_id = ?", pastureId).
 		Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
 		Where("lact = ?", 0).
 		Where("neck_ring_number != ?", "").
@@ -159,7 +161,8 @@ func (e *Entry) processCowsWithNoLact(recordDate time.Time) error {
 	}
 
 	if len(milkDailyList) > 0 {
-		if err = e.DB.Model(new(model.MilkDaily)).Create(&milkDailyList).Error; err != nil {
+		if err = e.DB.Model(new(model.MilkDaily)).
+			Create(&milkDailyList).Error; err != nil {
 			return err
 		}
 	}