|  | @@ -163,7 +163,21 @@ func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstru
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return xerr.Custom("获取当前登录用户失败")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	if err = s.DB.Create(estrusInfo).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err = s.DB.Transaction(func(tx *gorm.DB) error {
 | 
	
		
			
				|  |  | +		if err = tx.Create(estrusInfo).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if estrusInfo.IsMating == pasturePb.IsShow_Ok {
 | 
	
		
			
				|  |  | +			cow, _ := s.GetCowInfoByCowId(ctx, int64(req.CowId))
 | 
	
		
			
				|  |  | +			newEventMating := model.NewEventMating(cow, estrusInfo.EstrusAt, estrusInfo.ExposeEstrusType)
 | 
	
		
			
				|  |  | +			if err = tx.Create(newEventMating).Error; err != nil {
 | 
	
		
			
				|  |  | +				return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		return nil
 | 
	
		
			
				|  |  | +	}); err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return nil
 | 
	
	
		
			
				|  | @@ -171,14 +185,27 @@ func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstru
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrusBatch) error {
 | 
	
		
			
				|  |  |  	estrusList := make([]*model.EventEstrus, 0)
 | 
	
		
			
				|  |  | +	eventMatingList := make([]*model.EventMating, 0)
 | 
	
		
			
				|  |  |  	for _, v := range req.Item {
 | 
	
		
			
				|  |  |  		estrusInfo, err := s.EventEstrusCheck(ctx, v)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			return xerr.Custom("获取当前登录用户失败")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		estrusList = append(estrusList, estrusInfo)
 | 
	
		
			
				|  |  | +		cow, _ := s.GetCowInfoByCowId(ctx, int64(v.CowId))
 | 
	
		
			
				|  |  | +		eventMatingList = append(eventMatingList, model.NewEventMating(cow, estrusInfo.EstrusAt, estrusInfo.ExposeEstrusType))
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	if err := s.DB.Create(estrusList).Error; err != nil {
 | 
	
		
			
				|  |  | +	if err := s.DB.Transaction(func(tx *gorm.DB) error {
 | 
	
		
			
				|  |  | +		if err := tx.Create(estrusList).Error; err != nil {
 | 
	
		
			
				|  |  | +			return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if len(eventMatingList) > 0 {
 | 
	
		
			
				|  |  | +			if err := tx.Create(eventMatingList).Error; err != nil {
 | 
	
		
			
				|  |  | +				return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		return nil
 | 
	
		
			
				|  |  | +	}); err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return nil
 |