Browse Source

group: 集团配方下发牧场端

Yi 1 year ago
parent
commit
08e7383950
2 changed files with 34 additions and 4 deletions
  1. 26 0
      model/feed_formula.go
  2. 8 4
      module/backend/feed_service.go

+ 26 - 0
model/feed_formula.go

@@ -82,6 +82,32 @@ func (f FeedFormulaSlice) ToPB() []*operationPb.AddFeedFormulaRequest {
 	return res
 }
 
+func (f FeedFormulaSlice) ToDistributePB() []*operationPb.DistributeFeedRequest {
+	res := make([]*operationPb.DistributeFeedRequest, len(f))
+	for i, v := range f {
+		res[i] = &operationPb.DistributeFeedRequest{
+			Id:                 int32(v.Id),
+			Name:               v.Name,
+			Colour:             v.Colour,
+			EncodeNumber:       v.EncodeNumber,
+			CattleCategoryId:   v.CattleCategoryId,
+			CattleCategoryName: v.CattleCategoryName,
+			FormulaTypeId:      v.FormulaTypeId,
+			FormulaTypeName:    v.FormulaTypeName,
+			DataSourceName:     v.DataSourceName,
+			DataSourceId:       v.DataSourceId,
+			Remarks:            v.Remarks,
+			Version:            int32(v.Version),
+			PastureName:        v.PastureName,
+			IsShow:             v.IsShow,
+			IsModify:           v.IsModify,
+			CreatedAt:          int32(v.CreatedAt),
+			CreatedAtFormat:    time.Unix(v.CreatedAt, 0).Format(LayoutTime),
+		}
+	}
+	return res
+}
+
 func NewNewFeedFormulaByMixed(req *operationPb.MixedFeedFormulaRequest) *FeedFormula {
 	return &FeedFormula{
 		Name:               req.Name,

+ 8 - 4
module/backend/feed_service.go

@@ -748,7 +748,9 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
 				b, _ := json.Marshal(request)
 				res, _ := json.Marshal(response)
 				pastureDataLog := model.NewPastureDataLog(int64(p.Id), PastureDataLogType["FeedFormula_Distribute"], model.FeedFormulaDistributeUrl, string(b), string(res))
-				s.DB.Create(pastureDataLog)
+				if err = s.DB.Create(pastureDataLog).Error; err != nil {
+					zaplog.Error("DistributeFeedFormula", zap.Any("pastureDataLog", pastureDataLog), zap.Any("err", err))
+				}
 			}
 
 		}(pasture)
@@ -999,12 +1001,14 @@ func (s *StoreEntry) checkoutDistributeData(ctx context.Context, req *operationP
 		PastureList:     make([]*operationPb.AddPastureRequest, 0),
 		FeedFormulaList: make([]*operationPb.DistributeFeedRequest, 0),
 	}
-
-	if err := s.DB.Where("id IN ?", req.PastureIds).Where("is_delete = ?", operationPb.IsShow_OK).Find(&result.PastureList).Error; err != nil {
+	newGroupPastureList := make([]*model.GroupPasture, 0)
+	if err := s.DB.Model(new(model.GroupPasture)).Where("id IN ?", req.PastureIds).Where("is_delete = ?", operationPb.IsShow_OK).Find(&newGroupPastureList).Error; err != nil {
 		return result, xerr.WithStack(err)
 	}
+	result.PastureList = model.GroupPastureSlice(newGroupPastureList).ToPB()
 
-	if err := s.DB.Where("id IN ?", req.FeedFormulaIds).Find(&result.FeedFormulaList).Error; err != nil {
+	newFeedFormulaList := make([]*model.FeedFormula, 0)
+	if err := s.DB.Model(new(model.FeedFormula)).Where("id IN ?", req.FeedFormulaIds).Find(&newFeedFormulaList).Error; err != nil {
 		return result, xerr.WithStack(err)
 	}