batch_delete_agent_data_logic.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package agent
  2. import (
  3. "context"
  4. "fmt"
  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 BatchDeleteAgentDataLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewBatchDeleteAgentDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BatchDeleteAgentDataLogic {
  16. return &BatchDeleteAgentDataLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx}
  20. }
  21. func (l *BatchDeleteAgentDataLogic) BatchDeleteAgentData(req *types.BatchDeleteIds) (*types.BaseDataInfo, error) {
  22. var success, fail int
  23. if len(req.Ids) > 0 {
  24. for _, sid := range req.Ids {
  25. response, err := fastgpt.DeleteData(sid)
  26. fmt.Printf("id=%s, response=%+v\n", sid, response)
  27. if err != nil {
  28. fail++
  29. fmt.Printf("delete fastgpt data failed:%v\n", err)
  30. }
  31. if response != nil && response.Code == 200 {
  32. success++
  33. }
  34. }
  35. }
  36. resp := types.BaseDataInfo{}
  37. resp.Msg = fmt.Sprintf("succeed %d rows, fail %d rows", success, fail)
  38. return &resp, nil
  39. }