|
@@ -116,12 +116,12 @@ func (s *StoreEntry) AddFeedByFeedFormula(ctx context.Context, req *operationPb.
|
|
|
if err := s.DB.Model(new(model.FeedFormulaDetail)).Save(insertData).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
-
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// addFeedFormulaDetailAddRecode 添加配方记录
|
|
|
func (s *StoreEntry) addFeedFormulaDetailAddRecode(ctx context.Context, req *operationPb.GroupAddFeedFormulaDetail) {
|
|
|
+ editRecord, _ := s.GetEditRecordLastGroupId(ctx)
|
|
|
editRecordList := make([]*model.FeedFormulaEditRecord, 0)
|
|
|
for _, v := range req.List {
|
|
|
editRecordList = append(editRecordList, &model.FeedFormulaEditRecord{
|
|
@@ -129,6 +129,7 @@ func (s *StoreEntry) addFeedFormulaDetailAddRecode(ctx context.Context, req *ope
|
|
|
PastureName: "集团",
|
|
|
ForageName: v.ForageName,
|
|
|
Status: operationPb.FeedFormulaEditRecordType_INSERT,
|
|
|
+ GroupId: editRecord.GroupId + 1,
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -390,22 +391,9 @@ func (s *StoreEntry) MixedFeedFormula(ctx context.Context, req *operationPb.Mixe
|
|
|
}
|
|
|
|
|
|
tr := s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
- newFeedFormulaData := &model.FeedFormula{
|
|
|
- Name: req.Name,
|
|
|
- Colour: req.Colour,
|
|
|
- EncodeNumber: s.EncodeNumber(ctx),
|
|
|
- CattleCategoryId: operationPb.CattleCategoryParent_Kind(req.CattleCategoryId),
|
|
|
- CattleCategoryName: req.CattleCategoryName,
|
|
|
- FormulaTypeId: req.FormulaTypeId,
|
|
|
- FormulaTypeName: req.FormulaTypeName,
|
|
|
- DataSourceId: operationPb.DataSource_Kind(req.DataSourceId),
|
|
|
- DataSourceName: operationPb.DataSource_Kind_name[req.DataSourceId],
|
|
|
- Remarks: req.Remarks,
|
|
|
- PastureName: "集团",
|
|
|
- IsShow: operationPb.IsShow_OK,
|
|
|
- IsModify: operationPb.IsShow_OK,
|
|
|
- IsDelete: operationPb.IsShow_OK,
|
|
|
- }
|
|
|
+ newFeedFormulaData := model.NewNewFeedFormulaByMixed(req)
|
|
|
+ newFeedFormulaData.EncodeNumber = s.EncodeNumber(ctx)
|
|
|
+
|
|
|
if err := s.DB.Model(new(model.FeedFormula)).Create(newFeedFormulaData).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -1043,8 +1031,79 @@ func (s *StoreEntry) SearchFeedFormalDetailById(ctx context.Context, feedFormula
|
|
|
return res, nil
|
|
|
}
|
|
|
|
|
|
+// UpdateFeedFormalVersion 更新版本库并通知牧场端
|
|
|
func (s *StoreEntry) UpdateFeedFormalVersion(ctx context.Context, req *model.FeedFormula) {
|
|
|
if err := s.DB.Model(req).UpdateColumn("version", gorm.Expr("version + ?", 1)).Error; err != nil {
|
|
|
- zaplog.Error("UpdateFeedFormalVersion", zap.Any("err", err))
|
|
|
+ zaplog.Error("UpdateFeedFormalVersion-UpdateColumn", zap.Any("err", err))
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取该配方下发记录表
|
|
|
+ feedFormulaDistributeLogList := make([]*model.FeedFormulaDistributeLog, 0)
|
|
|
+ if err := s.DB.Table(new(model.FeedFormulaDistributeLog).TableName()).
|
|
|
+ Where("feed_formula_id = ?", req.Id).
|
|
|
+ Where("is_show = ?", operationPb.IsShow_OK).
|
|
|
+ Group("pasture_id").
|
|
|
+ Find(&feedFormulaDistributeLogList).Debug().Error; err != nil {
|
|
|
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ zaplog.Error("UpdateFeedFormalVersion-feedFormulaDistributeLog", zap.Any("err", err))
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(feedFormulaDistributeLogList) > 0 {
|
|
|
+ wg := sync.WaitGroup{}
|
|
|
+ wg.Add(len(feedFormulaDistributeLogList))
|
|
|
+ for _, v := range feedFormulaDistributeLogList {
|
|
|
+ go func(feedFormulaDistributeLog *model.FeedFormulaDistributeLog) {
|
|
|
+ defer wg.Done()
|
|
|
+ // 更新牧场端配方版本
|
|
|
+ s.UpdatePastureFeedDetailVersionLog(ctx, feedFormulaDistributeLog, req)
|
|
|
+ }(v)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (s *StoreEntry) UpdatePastureFeedDetailVersionLog(ctx context.Context, distributeLog *model.FeedFormulaDistributeLog, req *model.FeedFormula) {
|
|
|
+ pastureId := distributeLog.PastureId
|
|
|
+ groupPasture, err := s.GetGroupPastureById(ctx, pastureId)
|
|
|
+ if err != nil {
|
|
|
+ zaplog.Error("UpdateFeedFormalVersion", zap.Any("GetGroupPastureById", pastureId), zap.Any("err", err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if groupPasture.IsDistribution != operationPb.IsShow_OK {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ belong int32 = 1
|
|
|
+ feedTemplateId = req.Id
|
|
|
+ )
|
|
|
+
|
|
|
+ if req.PastureDataId > 0 {
|
|
|
+ belong = 2
|
|
|
+ feedTemplateId = req.PastureDataId
|
|
|
+ }
|
|
|
+
|
|
|
+ response := &model.FeedFormulaUpdateVersionResponse{}
|
|
|
+ body := &model.FeedFormulaUpdateVersionRequest{
|
|
|
+ FeedTemplateId: feedTemplateId,
|
|
|
+ Version: req.Version,
|
|
|
+ Belong: belong,
|
|
|
+ }
|
|
|
+
|
|
|
+ zaplog.Info("UpdateFeedFormalVersion", zap.Any("body", body))
|
|
|
+ if _, err = s.PastureHttpClient(ctx, model.FeedFormulaVersionUpdateUrl, pastureId, body, response); err != nil {
|
|
|
+ zaplog.Error("UpdateFeedFormalVersion-http",
|
|
|
+ zap.String("url", model.FeedFormulaVersionUpdateUrl),
|
|
|
+ zap.Any("pasture", groupPasture), zap.Any("body", body),
|
|
|
+ zap.Any("err", err), zap.Any("response", response))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if response.Code != http.StatusOK {
|
|
|
+ zaplog.Error("UpdateFeedFormalVersion-response",
|
|
|
+ zap.String("url", model.DashboardExecTimeUrl),
|
|
|
+ zap.Any("pasture", groupPasture), zap.Any("body", body),
|
|
|
+ zap.Any("err", err), zap.Any("response", response))
|
|
|
+ return
|
|
|
}
|
|
|
}
|