|
@@ -281,6 +281,11 @@ func (s *StoreEntry) WeightBatch(ctx context.Context, req *pasturePb.EventWeight
|
|
|
return xerr.Customf("获取当前登录用户失败: %s", err.Error())
|
|
|
}
|
|
|
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ req.OperationName = operationUser.Name
|
|
|
weightEvent := make([]*model.EventWeight, 0)
|
|
|
for _, item := range req.WeightItems {
|
|
|
cow, err := s.GetCowInfoByCowId(ctx, int64(item.CowId))
|
|
@@ -288,24 +293,23 @@ func (s *StoreEntry) WeightBatch(ctx context.Context, req *pasturePb.EventWeight
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
var weight = int32(item.Weight * 100)
|
|
|
-
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
- if err != nil {
|
|
|
- return xerr.WithStack(err)
|
|
|
- }
|
|
|
- req.OperationName = operationUser.Name
|
|
|
- weightEvent = append(weightEvent, model.NewEventWeight(cow, currentUser, weight, req))
|
|
|
+ weightEvent = append(weightEvent, model.NewEventWeight(cow, currentUser, weight, int32(item.Height), req))
|
|
|
}
|
|
|
+
|
|
|
if len(weightEvent) <= 0 {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
for _, item := range weightEvent {
|
|
|
- if err = tx.Model(new(model.Cow)).Where("id = ?", item.CowId).
|
|
|
+ if err = tx.Model(new(model.Cow)).
|
|
|
+ Where("id = ?", item.CowId).
|
|
|
+ Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
Updates(map[string]interface{}{
|
|
|
- "last_weight_at": item.WeightAt,
|
|
|
- "current_weight": item.Weight,
|
|
|
+ "last_second_weight_at": gorm.Expr("last_weight_at"),
|
|
|
+ "last_second_weight": gorm.Expr("current_weight"),
|
|
|
+ "last_weight_at": item.WeightAt,
|
|
|
+ "current_weight": item.Weight,
|
|
|
}).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|