|  | @@ -13,6 +13,7 @@ import (
 | 
	
		
			
				|  |  |  	operationPb "kpt-tmr-group/proto/go/backend/operation"
 | 
	
		
			
				|  |  |  	"net/http"
 | 
	
		
			
				|  |  |  	"strconv"
 | 
	
		
			
				|  |  | +	"sync"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	"go.uber.org/zap"
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -61,7 +62,6 @@ func (s *StoreEntry) PastureAccountDistribution(ctx context.Context, groupPastur
 | 
	
		
			
				|  |  |  			return xerr.Customf("%s", res.Msg)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -210,6 +210,19 @@ func (s *StoreEntry) AddCattleCategory(ctx context.Context, req *operationPb.Add
 | 
	
		
			
				|  |  |  	if err := s.DB.Create(cattleCategory).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		body := &model.CategoryRequest{
 | 
	
		
			
				|  |  | +			ParentId:   int32(req.ParentId),
 | 
	
		
			
				|  |  | +			ParentName: req.ParentName,
 | 
	
		
			
				|  |  | +			Name:       req.Name,
 | 
	
		
			
				|  |  | +			Id:         int32(req.Id),
 | 
	
		
			
				|  |  | +			Number:     req.Number,
 | 
	
		
			
				|  |  | +			IsShow:     int32(req.IsShow),
 | 
	
		
			
				|  |  | +			GroupId:    int32(cattleCategory.Id),
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		s.CategoryDistribution(ctx, model.CattleCategoryDistributionURl, body)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -234,6 +247,19 @@ func (s *StoreEntry) EditCattleCategory(ctx context.Context, req *operationPb.Ad
 | 
	
		
			
				|  |  |  		Updates(updateData).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		body := &model.CategoryRequest{
 | 
	
		
			
				|  |  | +			ParentId:   int32(req.ParentId),
 | 
	
		
			
				|  |  | +			ParentName: req.ParentName,
 | 
	
		
			
				|  |  | +			Name:       req.Name,
 | 
	
		
			
				|  |  | +			Id:         int32(req.Id),
 | 
	
		
			
				|  |  | +			Number:     req.Number,
 | 
	
		
			
				|  |  | +			IsShow:     int32(req.IsShow),
 | 
	
		
			
				|  |  | +			GroupId:    int32(req.Id),
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		s.CategoryDistribution(ctx, model.CattleCategoryDistributionURl, body)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -250,6 +276,18 @@ func (s *StoreEntry) IsShowCattleCategory(ctx context.Context, req *operationPb.
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.CattleCategory)).Where("id = ?", req.CattleCategoryId).Update("is_show", req.IsShow).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		body := &model.CategoryRequest{
 | 
	
		
			
				|  |  | +			ParentId:   int32(cattleCategory.ParentId),
 | 
	
		
			
				|  |  | +			ParentName: cattleCategory.ParentName,
 | 
	
		
			
				|  |  | +			Name:       cattleCategory.Name,
 | 
	
		
			
				|  |  | +			Id:         int32(req.CattleCategoryId),
 | 
	
		
			
				|  |  | +			Number:     cattleCategory.Number,
 | 
	
		
			
				|  |  | +			IsShow:     int32(req.IsShow),
 | 
	
		
			
				|  |  | +			GroupId:    int32(cattleCategory.Id),
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		s.CategoryDistribution(ctx, model.CattleCategoryDistributionURl, body)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -310,6 +348,18 @@ func (s *StoreEntry) AddForageCategory(ctx context.Context, req *operationPb.Add
 | 
	
		
			
				|  |  |  	if err := s.DB.Create(forageCategory).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		body := &model.CategoryRequest{
 | 
	
		
			
				|  |  | +			ParentId:   int32(req.ParentId),
 | 
	
		
			
				|  |  | +			ParentName: req.ParentName,
 | 
	
		
			
				|  |  | +			Name:       req.Name,
 | 
	
		
			
				|  |  | +			Id:         int32(req.Id),
 | 
	
		
			
				|  |  | +			Number:     req.Number,
 | 
	
		
			
				|  |  | +			IsShow:     int32(req.IsShow),
 | 
	
		
			
				|  |  | +			GroupId:    int32(forageCategory.Id),
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		s.CategoryDistribution(ctx, model.ForageCategoryDistributionURl, body)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -328,12 +378,24 @@ func (s *StoreEntry) EditForageCategory(ctx context.Context, req *operationPb.Ad
 | 
	
		
			
				|  |  |  		Number:     req.Number,
 | 
	
		
			
				|  |  |  		ParentId:   req.ParentId,
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.ForageCategory)).Omit("is_show", "is_delete").
 | 
	
		
			
				|  |  |  		Where("id = ?", req.Id).
 | 
	
		
			
				|  |  |  		Updates(updateData).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		body := &model.CategoryRequest{
 | 
	
		
			
				|  |  | +			ParentId:   int32(req.ParentId),
 | 
	
		
			
				|  |  | +			ParentName: req.ParentName,
 | 
	
		
			
				|  |  | +			Name:       req.Name,
 | 
	
		
			
				|  |  | +			Id:         int32(req.Id),
 | 
	
		
			
				|  |  | +			Number:     req.Number,
 | 
	
		
			
				|  |  | +			IsShow:     int32(req.IsShow),
 | 
	
		
			
				|  |  | +			GroupId:    int32(req.Id),
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		s.CategoryDistribution(ctx, model.ForageCategoryDistributionURl, body)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -350,6 +412,18 @@ func (s *StoreEntry) IsShowForageCategory(ctx context.Context, req *operationPb.
 | 
	
		
			
				|  |  |  	if err := s.DB.Model(new(model.ForageCategory)).Where("id = ?", req.ForageCategoryId).Update("is_show", req.IsShow).Error; err != nil {
 | 
	
		
			
				|  |  |  		return xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		body := &model.CategoryRequest{
 | 
	
		
			
				|  |  | +			ParentId:   int32(forageCategory.ParentId),
 | 
	
		
			
				|  |  | +			ParentName: forageCategory.ParentName,
 | 
	
		
			
				|  |  | +			Name:       forageCategory.Name,
 | 
	
		
			
				|  |  | +			Id:         req.ForageCategoryId,
 | 
	
		
			
				|  |  | +			Number:     forageCategory.Number,
 | 
	
		
			
				|  |  | +			IsShow:     int32(req.IsShow),
 | 
	
		
			
				|  |  | +			GroupId:    int32(forageCategory.Id),
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		s.CategoryDistribution(ctx, model.ForageCategoryDistributionURl, body)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  |  	return nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -408,6 +482,41 @@ func (s *StoreEntry) SearchForageCategoryList(ctx context.Context, req *operatio
 | 
	
		
			
				|  |  |  	}, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// CategoryDistribution 饲料分类和畜牧分类下发
 | 
	
		
			
				|  |  | +func (s *StoreEntry) CategoryDistribution(ctx context.Context, url string, req *model.CategoryRequest) error {
 | 
	
		
			
				|  |  | +	groupList, err := s.SearchGroupPastureList(ctx, &operationPb.SearchPastureRequest{})
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return xerr.WithStack(err)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	wg := sync.WaitGroup{}
 | 
	
		
			
				|  |  | +	wg.Add(len(groupList.Data.List))
 | 
	
		
			
				|  |  | +	for _, v := range groupList.Data.List {
 | 
	
		
			
				|  |  | +		go func(data *operationPb.AddPastureRequest) {
 | 
	
		
			
				|  |  | +			res := &model.PastureCommonResponse{}
 | 
	
		
			
				|  |  | +			req.Id = data.Id
 | 
	
		
			
				|  |  | +			if err = s.PastureHttpClient(ctx, url, int64(data.Id), req, res); err != nil {
 | 
	
		
			
				|  |  | +				zaplog.Error("CategoryDistribution",
 | 
	
		
			
				|  |  | +					zap.Any("url", url),
 | 
	
		
			
				|  |  | +					zap.Any("err", err),
 | 
	
		
			
				|  |  | +					zap.Any("body", req),
 | 
	
		
			
				|  |  | +					zap.Any("res", res),
 | 
	
		
			
				|  |  | +				)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			if res.Code != http.StatusOK {
 | 
	
		
			
				|  |  | +				zaplog.Error("CategoryDistribution-http",
 | 
	
		
			
				|  |  | +					zap.Any("url", url),
 | 
	
		
			
				|  |  | +					zap.Any("body", req),
 | 
	
		
			
				|  |  | +					zap.Any("res", res),
 | 
	
		
			
				|  |  | +				)
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			wg.Done()
 | 
	
		
			
				|  |  | +		}(v)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	wg.Wait()
 | 
	
		
			
				|  |  | +	return nil
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  // CreateForage 创建饲料
 | 
	
		
			
				|  |  |  func (s *StoreEntry) CreateForage(ctx context.Context, req *operationPb.AddForageRequest) error {
 | 
	
		
			
				|  |  |  	forage := model.NewForage(req)
 |