|
@@ -140,7 +140,6 @@ func (s *StoreEntry) ForbiddenMatingBatch(ctx context.Context, req *pasturePb.Ev
|
|
|
}
|
|
|
|
|
|
eventForbiddenMatingList := make([]*model.EventForbiddenMating, 0)
|
|
|
- cowLogList := make([]*model.EventCowLog, 0)
|
|
|
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
for _, item := range items {
|
|
@@ -149,7 +148,6 @@ func (s *StoreEntry) ForbiddenMatingBatch(ctx context.Context, req *pasturePb.Ev
|
|
|
item.ForbiddenMatingReasonsKind, item.ForbiddenMatingReasonsName, item.Remarks, item.OperationUser, userModel.SystemUser)
|
|
|
|
|
|
eventForbiddenMatingList = append(eventForbiddenMatingList, eventForbiddenMating)
|
|
|
- cowLogList = append(cowLogList, cowLog)
|
|
|
|
|
|
// 更新牛只信息
|
|
|
item.Cow.ForbiddenMatingUpdate(item.ForbiddenMatingAt)
|
|
@@ -158,6 +156,12 @@ func (s *StoreEntry) ForbiddenMatingBatch(ctx context.Context, req *pasturePb.Ev
|
|
|
Updates(item.Cow).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
+
|
|
|
+ // 记录日志
|
|
|
+ if err = tx.Table(cowLog.TableName()).
|
|
|
+ Create(cowLog).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if err = tx.Model(new(model.EventForbiddenMating)).
|
|
@@ -165,11 +169,6 @@ func (s *StoreEntry) ForbiddenMatingBatch(ctx context.Context, req *pasturePb.Ev
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- if err = tx.Model(new(model.EventCowLog)).
|
|
|
- Create(cowLogList).Error; err != nil {
|
|
|
- return xerr.WithStack(err)
|
|
|
- }
|
|
|
-
|
|
|
return nil
|
|
|
}); err != nil {
|
|
|
return xerr.WithStack(err)
|
|
@@ -223,11 +222,11 @@ func (s *StoreEntry) UnForbiddenMating(ctx context.Context, req *pasturePb.Event
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- if len(req.EarNumber) <= 0 {
|
|
|
+ if len(req.EarNumbers) <= 0 {
|
|
|
return xerr.Custom("请选择相关牛只")
|
|
|
}
|
|
|
|
|
|
- if len(req.EarNumber) > 50 {
|
|
|
+ if len(req.EarNumbers) > 50 {
|
|
|
return xerr.Custom("最多只能添加50条数据")
|
|
|
}
|
|
|
|
|
@@ -235,7 +234,7 @@ func (s *StoreEntry) UnForbiddenMating(ctx context.Context, req *pasturePb.Event
|
|
|
if err = s.DB.Model(new(model.EventForbiddenMating)).
|
|
|
Where("pasture_id = ?", userModel.AppPasture.Id).
|
|
|
Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
|
- Where("ear_number IN (?)", req.EarNumber).
|
|
|
+ Where("ear_number IN (?)", req.EarNumbers).
|
|
|
Find(&eventForbiddenMatingList).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -271,7 +270,7 @@ func (s *StoreEntry) UnForbiddenMating(ctx context.Context, req *pasturePb.Event
|
|
|
}
|
|
|
|
|
|
cowLog := s.SubmitEventLog(ctx, userModel.AppPasture.Id, cowInfo, pasturePb.EventType_UnForbiddenMating, item)
|
|
|
- if err = tx.Model(new(model.EventCowLog)).Create(cowLog).Error; err != nil {
|
|
|
+ if err = tx.Table(cowLog.TableName()).Create(cowLog).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
}
|