get_agent_collection_list_logic.go 1.9 KB

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