|  | @@ -230,21 +230,32 @@ func (s *StoreEntry) FeedSyncData(ctx context.Context, req *operationPb.FeedForm
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// FeedInsert 饲料数据同步 todo 后面优化成有就更新,没有则新增
 | 
	
		
			
				|  |  |  func (s *StoreEntry) FeedInsert(ctx context.Context, groupPasture *model.GroupPasture, list []*model.Feed) error {
 | 
	
		
			
				|  |  |  	res := make([]*model.Forage, 0)
 | 
	
		
			
				|  |  |  	for _, data := range list {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  		forageSourceName := data.Source
 | 
	
		
			
				|  |  |  		forageSourceId := operationPb.ForageSource_SYSTEM_BUILT_IN
 | 
	
		
			
				|  |  |  		if forageSourceName == "用户自定义" {
 | 
	
		
			
				|  |  |  			forageSourceId = operationPb.ForageSource_USER_DEFINED
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +		confirmStart := operationPb.IsShow_INVALID
 | 
	
		
			
				|  |  | +		if data.ConfirmStart == 0 {
 | 
	
		
			
				|  |  | +			confirmStart = operationPb.IsShow_NO
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if data.ConfirmStart == 1 {
 | 
	
		
			
				|  |  | +			confirmStart = operationPb.IsShow_OK
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if data.Id <= 0 {
 | 
	
		
			
				|  |  | +			continue
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  		res = append(res, &model.Forage{
 | 
	
		
			
				|  |  |  			Name:               data.FName,
 | 
	
		
			
				|  |  |  			CategoryId:         data.FClassId,
 | 
	
		
			
				|  |  |  			CategoryName:       data.FClass,
 | 
	
		
			
				|  |  | -			MaterialType:       0,
 | 
	
		
			
				|  |  | +			MaterialType:       0, // 牧场端找不到这个字段
 | 
	
		
			
				|  |  |  			UniqueEncode:       data.FeedCode,
 | 
	
		
			
				|  |  |  			ForageSourceId:     forageSourceId,
 | 
	
		
			
				|  |  |  			ForageSourceName:   forageSourceName,
 | 
	
	
		
			
				|  | @@ -256,17 +267,95 @@ func (s *StoreEntry) FeedInsert(ctx context.Context, groupPasture *model.GroupPa
 | 
	
		
			
				|  |  |  			Price:              int64(data.UPrice * 100),
 | 
	
		
			
				|  |  |  			JumpWeight:         data.AutoZone,
 | 
	
		
			
				|  |  |  			JumpDelay:          operationPb.JumpDelaType_Kind(data.AutoSecond),
 | 
	
		
			
				|  |  | -			ConfirmStart:       operationPb.IsShow_Kind(data.ConfirmStart),
 | 
	
		
			
				|  |  | +			ConfirmStart:       confirmStart,
 | 
	
		
			
				|  |  |  			RelayLocations:     int64(data.TrgAddress),
 | 
	
		
			
				|  |  |  			Jmp:                operationPb.IsShow_Kind(data.Jmp),
 | 
	
		
			
				|  |  |  			DataSource:         operationPb.DataSource_FROM_PASTURE,
 | 
	
		
			
				|  |  |  			Sort:               int64(data.Sort),
 | 
	
		
			
				|  |  | +			PastureId:          groupPasture.PastureId,
 | 
	
		
			
				|  |  |  			PastureName:        groupPasture.Name,
 | 
	
		
			
				|  |  |  			PastureDataId:      data.Id,
 | 
	
		
			
				|  |  |  			IsShow:             operationPb.IsShow_Kind(data.Enable),
 | 
	
		
			
				|  |  |  			IsDelete:           operationPb.IsShow_OK,
 | 
	
		
			
				|  |  |  		})
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if err := s.DB.Model(new(model.Forage)).Create(res).Error; err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return nil
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +// FeedFormulaDetailListSyncData 饲料配方详情同步
 | 
	
		
			
				|  |  | +func (s *StoreEntry) FeedFormulaDetailListSyncData(ctx context.Context, req *operationPb.FeedFormulaSyncRequest) error {
 | 
	
		
			
				|  |  | +	groupPastureList, err := s.DataSyncGroupPastureList(ctx)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	var (
 | 
	
		
			
				|  |  | +		ok           bool
 | 
	
		
			
				|  |  | +		groupPasture *model.GroupPasture
 | 
	
		
			
				|  |  | +	)
 | 
	
		
			
				|  |  | +	for _, pastureDetail := range groupPastureList {
 | 
	
		
			
				|  |  | +		if pastureDetail.Id != int64(req.PastureId) {
 | 
	
		
			
				|  |  | +			continue
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		groupPasture = pastureDetail
 | 
	
		
			
				|  |  | +		ok = true
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if ok {
 | 
	
		
			
				|  |  | +		total := 0
 | 
	
		
			
				|  |  | +		page := 1
 | 
	
		
			
				|  |  | +		pageSize := 100
 | 
	
		
			
				|  |  | +		for i := 0; i <= total; i++ {
 | 
	
		
			
				|  |  | +			body := &model.FeedFormulaListRequest{
 | 
	
		
			
				|  |  | +				PastureId: int32(groupPasture.PastureId),
 | 
	
		
			
				|  |  | +				Page:      int32(page),
 | 
	
		
			
				|  |  | +				PageSize:  int32(pageSize),
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			response := &model.FeedFormulaDetailListResponse{}
 | 
	
		
			
				|  |  | +			if _, err = s.PastureHttpClient(ctx, model.FeedFormulaDetailListAsyncUrl, int64(req.PastureId), body, response); err != nil {
 | 
	
		
			
				|  |  | +				return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			if response.Code != http.StatusOK {
 | 
	
		
			
				|  |  | +				return xerr.Customf("%s", response.Msg)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if response.Data.Total > 0 && response.Data.List != nil {
 | 
	
		
			
				|  |  | +				total = int(math.Ceil(float64(response.Data.Total) / float64(pageSize)))
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if err = s.FeedFormulaDetailInsert(ctx, groupPasture, response.Data.List); err != nil {
 | 
	
		
			
				|  |  | +				return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return nil
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func (s *StoreEntry) FeedFormulaDetailInsert(ctx context.Context, groupPasture *model.GroupPasture, list []*model.FeedTemplateDetail) error {
 | 
	
		
			
				|  |  | +	res := make([]*model.FeedFormulaDetail, 0)
 | 
	
		
			
				|  |  | +	for _, data := range list {
 | 
	
		
			
				|  |  | +		if data.Id <= 0 {
 | 
	
		
			
				|  |  | +			continue
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		res = append(res, &model.FeedFormulaDetail{
 | 
	
		
			
				|  |  | +			PastureId:       groupPasture.PastureId,
 | 
	
		
			
				|  |  | +			PastureName:     groupPasture.Name,
 | 
	
		
			
				|  |  | +			PastureDataId:   data.Id,
 | 
	
		
			
				|  |  | +			ForgeId:         data.FId,
 | 
	
		
			
				|  |  | +			FeedFormulaId:   data.FtId,
 | 
	
		
			
				|  |  | +			Weight:          int32(data.FWeight * 100),
 | 
	
		
			
				|  |  | +			ForageGroupName: data.FeedGroup,
 | 
	
		
			
				|  |  | +			StirDelay:       data.AutoSecond,
 | 
	
		
			
				|  |  | +			AllowError:      data.Deviation,
 | 
	
		
			
				|  |  | +			IsShow:          operationPb.IsShow_OK,
 | 
	
		
			
				|  |  | +			Sort:            data.Sort,
 | 
	
		
			
				|  |  | +		})
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.Forage)).Create(res).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 |