|
@@ -26,8 +26,9 @@ import (
|
|
const EncodeNumberPrefix = "encode_number"
|
|
const EncodeNumberPrefix = "encode_number"
|
|
|
|
|
|
var PastureDataLogType = map[string]int32{
|
|
var PastureDataLogType = map[string]int32{
|
|
- "FeedFormula_Distribute": 1,
|
|
|
|
- "FeedFormula_IsModify": 2,
|
|
|
|
|
|
+ "FeedFormula_Distribute": 1,
|
|
|
|
+ "FeedFormula_IsModify": 2,
|
|
|
|
+ "FeedFormula_Cancel_Distribute": 3,
|
|
}
|
|
}
|
|
|
|
|
|
// CreateFeedFormula 添加数据
|
|
// CreateFeedFormula 添加数据
|
|
@@ -342,9 +343,6 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
if err != nil {
|
|
if err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
- if len(distributeData.PastureList) <= 0 {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(len(distributeData.PastureList))
|
|
wg.Add(len(distributeData.PastureList))
|
|
@@ -352,6 +350,7 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
|
|
|
|
for _, pasture := range distributeData.PastureList {
|
|
for _, pasture := range distributeData.PastureList {
|
|
go func(p *model.GroupPasture) {
|
|
go func(p *model.GroupPasture) {
|
|
|
|
+ defer wg.Done()
|
|
// 过滤已下发的
|
|
// 过滤已下发的
|
|
body := make([]*model.FeedFormula, 0)
|
|
body := make([]*model.FeedFormula, 0)
|
|
for _, v := range distributeData.FeedFormulaList {
|
|
for _, v := range distributeData.FeedFormulaList {
|
|
@@ -374,7 +373,6 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
} else {
|
|
} else {
|
|
muError = multierr.Append(muError, xerr.Custom(response.Msg))
|
|
muError = multierr.Append(muError, xerr.Custom(response.Msg))
|
|
}
|
|
}
|
|
- wg.Done()
|
|
|
|
}()
|
|
}()
|
|
|
|
|
|
if _, err = s.PastureHttpClient(ctx, model.FeedFormulaDistributeUrl, p.Id, request, response); err != nil {
|
|
if _, err = s.PastureHttpClient(ctx, model.FeedFormulaDistributeUrl, p.Id, request, response); err != nil {
|
|
@@ -392,6 +390,51 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
return muError
|
|
return muError
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// CancelDistributeFeedFormula 取消配方下发牧场
|
|
|
|
+func (s *StoreEntry) CancelDistributeFeedFormula(ctx context.Context, req *operationPb.DistributeFeedFormulaRequest) error {
|
|
|
|
+ distributeData, err := s.checkoutDistributeData(ctx, req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ wg := sync.WaitGroup{}
|
|
|
|
+ wg.Add(len(distributeData.PastureList))
|
|
|
|
+ var muError error
|
|
|
|
+
|
|
|
|
+ for _, pasture := range distributeData.PastureList {
|
|
|
|
+ go func(p *model.GroupPasture) {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+
|
|
|
|
+ pastureDataId := make([]int64, 0)
|
|
|
|
+ for _, v := range distributeData.FeedFormulaList {
|
|
|
|
+ if v.PastureId == p.Id {
|
|
|
|
+ pastureDataId = append(pastureDataId, v.PastureDataId)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(pastureDataId) <= 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ request := &model.CancelDistributeFeedFormulaRequest{
|
|
|
|
+ PastureId: p.Id,
|
|
|
|
+ PastureDataId: pastureDataId,
|
|
|
|
+ }
|
|
|
|
+ response := &model.PastureResponse{}
|
|
|
|
+
|
|
|
|
+ if _, err = s.PastureHttpClient(ctx, model.FeedFormulaCancelDistributeUrl, p.Id, request, response); err != nil {
|
|
|
|
+ zaplog.Error("DistributeFeedFormula", zap.Any("pasture", p), zap.Any("body", distributeData.FeedFormulaList), zap.Any("err", err), zap.Any("response", response))
|
|
|
|
+ b, _ := json.Marshal(request)
|
|
|
|
+ res, _ := json.Marshal(response)
|
|
|
|
+ pastureDataLog := model.NewPastureDataLog(p.Id, PastureDataLogType["FeedFormula_Cancel_Distribute"], model.FeedFormulaCancelDistributeUrl, string(b), string(res))
|
|
|
|
+ s.DB.Create(pastureDataLog)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }(pasture)
|
|
|
|
+ }
|
|
|
|
+ wg.Wait()
|
|
|
|
+ return muError
|
|
|
|
+}
|
|
|
|
+
|
|
// FeedFormulaUsage 配方使用概况
|
|
// FeedFormulaUsage 配方使用概况
|
|
func (s *StoreEntry) FeedFormulaUsage(ctx context.Context, req *operationPb.FeedFormulaUsageRequest) (*operationPb.FeedFormulaUsageResponse, error) {
|
|
func (s *StoreEntry) FeedFormulaUsage(ctx context.Context, req *operationPb.FeedFormulaUsageRequest) (*operationPb.FeedFormulaUsageResponse, error) {
|
|
feedFormulaDistributeLogList := make([]*model.FeedFormulaDistributeLog, 0)
|
|
feedFormulaDistributeLogList := make([]*model.FeedFormulaDistributeLog, 0)
|