|
@@ -322,14 +322,17 @@ func (s *StoreEntry) deleteFeedFormulaDetailAddRecode(ctx context.Context, req *
|
|
|
// SearchFeedFormulaDetail 查询配方饲料详情
|
|
|
func (s *StoreEntry) SearchFeedFormulaDetail(ctx context.Context, req *operationPb.AddFeedFormulaDetail) (*operationPb.FeedFormulaDetailResponse, error) {
|
|
|
feedFormulaData := &model.FeedFormula{Id: int64(req.FeedFormulaId)}
|
|
|
- if err := s.DB.Model(new(model.FeedFormula)).First(feedFormulaData).Error; err != nil {
|
|
|
+ if err := s.DB.Model(new(model.FeedFormula)).First(feedFormulaData).Debug().Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
var count int64
|
|
|
- feedFormulaDetail := make([]*model.FeedFormulaDetail, 0)
|
|
|
+ feedFormulaDetailList := make([]*model.FeedFormulaDetail, 0)
|
|
|
+
|
|
|
+ pref := s.DB.Model(new(model.FeedFormulaDetail)).
|
|
|
+ Where("is_show = ?", operationPb.IsShow_OK).
|
|
|
+ Where("feed_formula_id = ?", req.FeedFormulaId)
|
|
|
|
|
|
- pref := s.DB.Model(new(model.FeedFormulaDetail)).Where("is_show = ?", operationPb.IsShow_OK).Where("feed_formula_id = ?", req.FeedFormulaId)
|
|
|
if req.ForageName != "" {
|
|
|
pref.Where("forage_name = ?", req.ForageName)
|
|
|
}
|
|
@@ -346,19 +349,23 @@ func (s *StoreEntry) SearchFeedFormulaDetail(ctx context.Context, req *operation
|
|
|
pref.Where("is_lock_cow_count_ratio = ?", req.IsLockCowCountRatio)
|
|
|
}
|
|
|
|
|
|
+ if req.StirDelay > 0 {
|
|
|
+ pref.Where("stir_delay = ?", req.StirDelay)
|
|
|
+ }
|
|
|
+
|
|
|
if req.Sort > 0 {
|
|
|
pref.Where("sort = ?", req.Sort)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("sort").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
|
|
|
- Find(&feedFormulaDetail).Error; err != nil {
|
|
|
+ if err := pref.Order("sort").Count(&count).Limit(int(req.Pagination.PageSize)).
|
|
|
+ Offset(int(req.Pagination.PageOffset)).Find(&feedFormulaDetailList).Debug().Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
return &operationPb.FeedFormulaDetailResponse{
|
|
|
Code: http.StatusOK,
|
|
|
Msg: "ok",
|
|
|
- Data: model.FeedFormulaDetailSlice(feedFormulaDetail).ToPB(),
|
|
|
+ Data: model.FeedFormulaDetailSlice(feedFormulaDetailList).ToPB(),
|
|
|
}, nil
|
|
|
|
|
|
}
|
|
@@ -698,20 +705,11 @@ func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb
|
|
|
for _, pasture := range distributeData.PastureList {
|
|
|
go func(p *model.GroupPasture) {
|
|
|
defer wg.Done()
|
|
|
- // 过滤已下发的
|
|
|
- body := make([]*model.FeedFormula, 0)
|
|
|
- for _, v := range distributeData.FeedFormulaList {
|
|
|
- if ok := s.checkoutDistributeLog(ctx, p.Id, v.Id); !ok {
|
|
|
- body = append(body, v)
|
|
|
- }
|
|
|
- }
|
|
|
- if len(body) <= 0 {
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
request := &model.DistributeFeedFormulaRequest{
|
|
|
- PastureId: p.Id,
|
|
|
- Body: body,
|
|
|
+ PastureId: p.Id,
|
|
|
+ FeedFormula: distributeData.FeedFormulaList,
|
|
|
+ FeedFormulaDetail: distributeData.FeedFormulaDetail,
|
|
|
}
|
|
|
response := &model.PastureResponse{}
|
|
|
defer func() {
|
|
@@ -971,8 +969,9 @@ func (s *StoreEntry) PastureFeedFormulaIsModify(ctx context.Context, feedFormula
|
|
|
|
|
|
func (s *StoreEntry) checkoutDistributeData(ctx context.Context, req *operationPb.DistributeFeedFormulaRequest) (*model.DistributeData, error) {
|
|
|
result := &model.DistributeData{
|
|
|
- PastureList: make([]*model.GroupPasture, 0),
|
|
|
- FeedFormulaList: make([]*model.FeedFormula, 0),
|
|
|
+ PastureList: make([]*model.GroupPasture, 0),
|
|
|
+ FeedFormulaList: make([]*model.FeedFormula, 0),
|
|
|
+ FeedFormulaDetail: make([]*model.FeedFormulaDetail, 0),
|
|
|
}
|
|
|
|
|
|
if err := s.DB.Where("id IN ?", req.PastureIds).Where("is_delete = ?", operationPb.IsShow_OK).Find(&result.PastureList).Error; err != nil {
|
|
@@ -983,6 +982,20 @@ func (s *StoreEntry) checkoutDistributeData(ctx context.Context, req *operationP
|
|
|
return result, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
+ feedFormulaDetailList := make([]*model.FeedFormulaDetail, 0)
|
|
|
+ for _, v := range req.FeedFormulaIds {
|
|
|
+ feedFormulaDetail := make([]*model.FeedFormulaDetail, 0)
|
|
|
+ if err := s.DB.Model(new(model.FeedFormulaDetail)).Where("feed_formula_id = ?", v).Find(&feedFormulaDetail).Error; err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return result, xerr.Customf("该配方没有添加相关饲料:%d", v)
|
|
|
+ }
|
|
|
+ return result, xerr.WithStack(err)
|
|
|
+ } else {
|
|
|
+ feedFormulaDetailList = append(feedFormulaDetailList, feedFormulaDetail...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result.FeedFormulaDetail = feedFormulaDetailList
|
|
|
if len(result.PastureList) <= 0 || len(result.FeedFormulaList) <= 0 {
|
|
|
return result, xerr.Customf("数据错误")
|
|
|
}
|