|
@@ -46,12 +46,12 @@ func (e *Entry) ProcessMilkDaily(pastureId int64, maxDate time.Time) {
|
|
// 处理每一天的数据
|
|
// 处理每一天的数据
|
|
for maxDate.Before(nowTime) {
|
|
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))
|
|
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))
|
|
zaplog.Error("ProcessMilkDaily", zap.Any("processCowsWithoutFetal", err))
|
|
}
|
|
}
|
|
// 日期加1天
|
|
// 日期加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)
|
|
cowList := make([]*model.Cow, 0)
|
|
if err := e.DB.Model(new(model.Cow)).
|
|
if err := e.DB.Model(new(model.Cow)).
|
|
|
|
+ Where("pasture_id = ?", pastureId).
|
|
Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
Where("lact > ?", 0).
|
|
Where("lact > ?", 0).
|
|
Where("last_calving_at <= ?", recordDate.Local().Unix()).
|
|
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的奶牛
|
|
// 查询无胎次且EID1>0的奶牛
|
|
cowList := make([]*model.Cow, 0)
|
|
cowList := make([]*model.Cow, 0)
|
|
err := e.DB.Model(new(model.Cow)).
|
|
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").
|
|
//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("(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("admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
Where("lact = ?", 0).
|
|
Where("lact = ?", 0).
|
|
Where("neck_ring_number != ?", "").
|
|
Where("neck_ring_number != ?", "").
|
|
@@ -159,7 +161,8 @@ func (e *Entry) processCowsWithNoLact(recordDate time.Time) error {
|
|
}
|
|
}
|
|
|
|
|
|
if len(milkDailyList) > 0 {
|
|
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
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|