Explorar o código

group: 增加校验配方是否已下发

Yi hai 1 ano
pai
achega
c6e3ed07ad
Modificáronse 2 ficheiros con 28 adicións e 5 borrados
  1. 4 0
      model/pasture_data.go
  2. 24 5
      module/backend/feed_service.go

+ 4 - 0
model/pasture_data.go

@@ -13,6 +13,10 @@ type PastureResponse struct {
 	Data interface{} `json:"data"`
 }
 
+type PastureSuccessResponse struct {
+	Success bool `json:"success"`
+}
+
 type DashboardAccuracyRequest struct {
 	CattleParentCategoryId int32  `json:"cattle_parent_category_id,omitempty"`
 	FeedFormulaId          int32  `json:"feed_formula_id"`

+ 24 - 5
module/backend/feed_service.go

@@ -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
+}