Browse Source

pasture: 牧场数据同步

Yi 1 year ago
parent
commit
7e602cf9c4
2 changed files with 8 additions and 5 deletions
  1. 7 4
      module/backend/pasture_service.go
  2. 1 1
      module/backend/statistic_service.go

+ 7 - 4
module/backend/pasture_service.go

@@ -32,8 +32,6 @@ func (s *StoreEntry) CreateGroupPasture(ctx context.Context, req *operationPb.Ad
 	if err := s.PastureAccountDistribution(ctx, groupPasture); err != nil {
 		s.DB.Model(new(model.GroupPasture)).Where("id = ?", groupPasture.Id).Update("is_delete", operationPb.IsShow_NO)
 		return xerr.WithStack(err)
-	} else {
-		s.DB.Model(new(model.GroupPasture)).Where("id = ?", groupPasture.Id).Update("is_distribution", operationPb.IsShow_OK)
 	}
 	return nil
 }
@@ -43,17 +41,22 @@ func (s *StoreEntry) PastureAccountDistribution(ctx context.Context, groupPastur
 	if groupPasture.Domain == "" {
 		return nil
 	}
+
+	pastureId := groupPasture.Id
+	if groupPasture.PastureId > 0 {
+		pastureId = groupPasture.PastureId
+	}
 	body := &model.AccountDistribution{
 		Account:     groupPasture.Account,
 		UserName:    groupPasture.ManagerUser,
 		Password:    groupPasture.Password,
 		Phone:       groupPasture.ManagerPhone,
-		PastureId:   int32(groupPasture.Id),
+		PastureId:   int32(pastureId),
 		PastureName: groupPasture.Name,
 		Address:     groupPasture.Address,
 	}
 	res := &model.PastureCommonResponse{}
-	if _, err := s.PastureHttpClient(ctx, model.PastureAccountDistributionURl, groupPasture.GetPastureId(), body, res); err != nil {
+	if _, err := s.PastureHttpClient(ctx, model.PastureAccountDistributionURl, groupPasture.Id, body, res); err != nil {
 		zaplog.Error("AccountDistribution", zap.Any("url", model.PastureAccountDistributionURl), zap.Any("err", err), zap.Any("body", body), zap.Any("res", res))
 		return xerr.WithStack(err)
 	}

+ 1 - 1
module/backend/statistic_service.go

@@ -81,7 +81,7 @@ func (s *StoreEntry) SearchFormulaEstimateList(ctx context.Context, req *operati
 		},
 	}
 	response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
-	if _, err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
+	if _, err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
 		return nil, xerr.WithStack(err)
 	}
 	return response, nil