|
@@ -720,20 +720,26 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 过滤掉已经下发过配方
|
|
|
+ putDistributeFeedRequest := make([]*operationPb.DistributeFeedRequest, 0)
|
|
|
+ for _, v := range newDistributeFeedRequest {
|
|
|
+ if !s.CheckFeedFormulaDistribute(ctx, int64(p.Id), int64(v.Id)) {
|
|
|
+ putDistributeFeedRequest = append(putDistributeFeedRequest, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 请求参数
|
|
|
request, response := &operationPb.DistributeDataRequest{
|
|
|
PastureId: p.Id,
|
|
|
FeedFormulaList: newDistributeFeedRequest,
|
|
|
- }, &model.PastureResponse{}
|
|
|
+ }, &model.PastureSuccessResponse{}
|
|
|
|
|
|
defer func() {
|
|
|
- if response.Code == http.StatusOK {
|
|
|
+ if response.Success == true {
|
|
|
feedFormulaDistributeLog := model.NewFeedFormulaDistributeLogList(distributeData.FeedFormulaList, int64(p.Id), p.Name, operationPb.IsShow_OK)
|
|
|
if err = s.DB.Create(feedFormulaDistributeLog).Error; err != nil {
|
|
|
zaplog.Error("DistributeFeedFormula", zap.Any("feedFormulaDistributeLog", feedFormulaDistributeLog), zap.Any("err", err))
|
|
|
}
|
|
|
- } else {
|
|
|
- muError = multierr.Append(muError, xerr.Custom(response.Msg))
|
|
|
}
|
|
|
}()
|
|
|
|
|
@@ -756,7 +762,7 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
|
}(pasture)
|
|
|
}
|
|
|
wg.Wait()
|
|
|
- return muError
|
|
|
+ return xerr.WithStack(muError)
|
|
|
}
|
|
|
|
|
|
// CancelDistributeFeedFormula 取消配方下发牧场
|
|
@@ -1144,3 +1150,16 @@ func (s *StoreEntry) UpdatePastureFeedDetailVersionLog(ctx context.Context, dist
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// CheckFeedFormulaDistribute 检查该配方是否下发牧场端
|
|
|
+func (s *StoreEntry) CheckFeedFormulaDistribute(ctx context.Context, pastureId, feedFormulaId int64) bool {
|
|
|
+ res := &model.FeedFormulaDistributeLog{}
|
|
|
+ if err := s.DB.Where("feed_formula_id = ?", feedFormulaId).Where("pasture_id = ?", pastureId).First(res).Error; err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if res.IsShow == operationPb.IsShow_OK {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+}
|