|
@@ -134,7 +134,7 @@ func (s *StoreEntry) FeedFormulaSyncData(ctx context.Context, req *operationPb.F
|
|
|
PageSize: int32(pageSize),
|
|
|
}
|
|
|
response := &model.FeedFormulaListResponse{}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.FeedFormulaListAsyncUrl, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if _, err = s.PastureHttpClient(ctx, model.FeedFormulaAsyncUrl, int64(req.PastureId), body, response); err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
@@ -181,3 +181,94 @@ func (s *StoreEntry) FeedFormulaInsert(ctx context.Context, groupPasture *model.
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *StoreEntry) FeedSyncData(ctx context.Context, req *operationPb.FeedFormulaSyncRequest) error {
|
|
|
+ groupPastureList, err := s.DataSyncGroupPastureList(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var (
|
|
|
+ ok bool
|
|
|
+ groupPasture *model.GroupPasture
|
|
|
+ )
|
|
|
+ for _, pastureDetail := range groupPastureList {
|
|
|
+ if pastureDetail.Id != int64(req.PastureId) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ groupPasture = pastureDetail
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ total := 0
|
|
|
+ page := 1
|
|
|
+ pageSize := 100
|
|
|
+ for i := 0; i <= total; i++ {
|
|
|
+ body := &model.FeedFormulaListRequest{
|
|
|
+ PastureId: int32(groupPasture.PastureId),
|
|
|
+ Page: int32(page),
|
|
|
+ PageSize: int32(pageSize),
|
|
|
+ }
|
|
|
+ response := &model.FeedListResponse{}
|
|
|
+ if _, err = s.PastureHttpClient(ctx, model.FeedAsyncUrl, int64(req.PastureId), body, response); err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if response.Code != http.StatusOK {
|
|
|
+ return xerr.Customf("%s", response.Msg)
|
|
|
+ }
|
|
|
+ if response.Data.Total > 0 && response.Data.List != nil {
|
|
|
+ total = int(math.Ceil(float64(response.Data.Total) / float64(pageSize)))
|
|
|
+ }
|
|
|
+ if err = s.FeedInsert(ctx, groupPasture, response.Data.List); err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *StoreEntry) FeedInsert(ctx context.Context, groupPasture *model.GroupPasture, list []*model.Feed) error {
|
|
|
+ res := make([]*model.Forage, 0)
|
|
|
+ for _, data := range list {
|
|
|
+
|
|
|
+ forageSourceName := data.Source
|
|
|
+ forageSourceId := operationPb.ForageSource_SYSTEM_BUILT_IN
|
|
|
+ if forageSourceName == "用户自定义" {
|
|
|
+ forageSourceId = operationPb.ForageSource_USER_DEFINED
|
|
|
+ }
|
|
|
+
|
|
|
+ res = append(res, &model.Forage{
|
|
|
+ Name: data.FName,
|
|
|
+ CategoryId: data.FClassId,
|
|
|
+ CategoryName: data.FClass,
|
|
|
+ MaterialType: 0,
|
|
|
+ UniqueEncode: data.FeedCode,
|
|
|
+ ForageSourceId: forageSourceId,
|
|
|
+ ForageSourceName: forageSourceName,
|
|
|
+ PlanTypeId: operationPb.ForagePlanType_Kind(data.PrintGroupId),
|
|
|
+ PlanTypeName: data.PrintGroup,
|
|
|
+ SmallMaterialScale: data.SmtMrName,
|
|
|
+ AllowError: data.AllowRatio,
|
|
|
+ PackageWeight: data.UnitWeight,
|
|
|
+ Price: int64(data.UPrice * 100),
|
|
|
+ JumpWeight: data.AutoZone,
|
|
|
+ JumpDelay: operationPb.JumpDelaType_Kind(data.AutoSecond),
|
|
|
+ ConfirmStart: operationPb.IsShow_Kind(data.ConfirmStart),
|
|
|
+ RelayLocations: int64(data.TrgAddress),
|
|
|
+ Jmp: operationPb.IsShow_Kind(data.Jmp),
|
|
|
+ DataSource: operationPb.DataSource_FROM_PASTURE,
|
|
|
+ Sort: int64(data.Sort),
|
|
|
+ PastureName: groupPasture.Name,
|
|
|
+ PastureDataId: data.Id,
|
|
|
+ IsShow: operationPb.IsShow_Kind(data.Enable),
|
|
|
+ IsDelete: operationPb.IsShow_OK,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if err := s.DB.Model(new(model.FeedFormula)).Create(res).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|