get_agent_collection_list_logic.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package agent
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/errorx"
  5. "wechat-api/hook/fastgpt"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type GetAgentCollectionListLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewGetAgentCollectionListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentCollectionListLogic {
  16. return &GetAgentCollectionListLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx}
  20. }
  21. func (l *GetAgentCollectionListLogic) GetAgentCollectionList(req *types.CollectionListReq) (*types.CollectionListResp, error) {
  22. collectionResp := types.CollectionListResp{}
  23. collectionResp.PageNum = req.PageNum
  24. collectionResp.PageSize = req.PageSize
  25. var total int
  26. params := fastgpt.GetCollectionListReq{}
  27. params.DatasetId = *req.DatasetId
  28. params.PageNum = *req.PageNum
  29. params.PageSize = *req.PageSize
  30. resp, err := fastgpt.GetCollectionList(&params)
  31. if err != nil {
  32. return nil, errorx.NewInvalidArgumentError("fastgpt error" + err.Error())
  33. }
  34. collectionResp.Data = make([]types.CollectionSimpleInfo, 0, 1)
  35. collectionResp.Total = &total
  36. if resp.Code == 200 && resp.Data.Total > 0 {
  37. for _, val := range resp.Data.Data {
  38. collectionResp.Data = append(collectionResp.Data, types.CollectionSimpleInfo{
  39. ID: &val.ID,
  40. ParentID: &val.ParentID,
  41. TmbId: &val.TmbID,
  42. Type: &val.Type,
  43. Name: &val.Name,
  44. DataAmount: &val.DataAmount,
  45. TrainingAmount: &val.TrainingAmount,
  46. })
  47. }
  48. collectionResp.Total = &resp.Data.Total
  49. }
  50. return &collectionResp, nil
  51. }