开发者社区 问答 正文

宜搭跨根据条件搜索表单实例 ID 列表接口,如何获取超过100条数据?

宜搭跨应用数据源API根据条件搜索表单实例 ID 列表 /v1/form/searchFormDataIds.json,参数pagesize最大只支持100,现在数据超过100,需要获取所有数据,请问各位大佬该如何解决

展开
收起
游客e6haq6ovt6jdc 2024-10-30 19:20:22 577 分享 版权
4 条回答
写回答
取消 提交回答
  • 自己封了个普通表单的批量查询方法,可以按照需求自己改下

    /**
     * @author kittlent
     * 宜搭普通表单批量查询
     * 不传dataSourceRequestName,则代表的是本appType内的调用,可无需配置,如果跨应用调用,需要借助数据源
     * 配置 dataSourceRequestName数据源请求地址为: "/dingtalk/web/APP_xxxxxxxx/v1/form/searchFormDatas.json" ${APP_xxxxxxxx}替换成对应的应用appType
     * @param param0 {
     * searchFieldJson:查询参数,
     * formUuid:"页面UUID",
     * orderInfo:"排序字段",
     * dataSourceRequestName:"通过数据源来进行查询的数据源名:{需要提前配置好数据源}",
     * maxBatchSearch:"最大查询批次,-1时代表没限制",
     * defDelay:默认请求间隔时长,最小为200(单位毫秒)
     * }
     * @returns {code:"处理结果编码->200:成功,400:参数异常,500:请求异常",msg:"异常描述",result:"请求结果"}
     */
    async function _yidaBatchSearch({
        searchFieldJson = {},
        formUuid = "",
        maxBatchSearch = -1,
        orderInfo = {},
        dataSourceRequestName = "",
        defDelay = 200,
    } = {
            searchFieldJson: {},
            formUuid: "",
            orderInfo: {},
            maxBatchSearch: -1,
            dataSourceRequestName: "",
            defDelay: 200,
        }) {
        if (!formUuid) {
            return { code: 400, msg: "formUuid为空" }
        }
        if (defDelay < 200) {
            defDelay = 200;
        }
        let _searchJsonStr;
        ///是否使用数据源请求
        let canUseDataSourceReq = false;
        try {
            if (!!dataSourceRequestName) {
                if (this.dataSourceMap && this.dataSourceMap[dataSourceRequestName] && this.dataSourceMap[dataSourceRequestName].load) {
                    canUseDataSourceReq = true;
                } else {
                    return { code: 400, msg: "该查询数据源不存在" }
                }
            }
            _searchJsonStr = JSON.stringify(searchFieldJson)
        } catch (e) {
            console.error(`转换查询数据${searchFieldJson}时出现异常,异常为:${e}`)
            return { code: 400, msg: "查询数据异常" }
        }
        const batchSearchLoading = this.utils.toast({
            title: "数据查询中,请稍后...",
            type: "loading"
        })
        const result = { totalCount: 1, nowCount: 0, data: [] }
        let nowCurrentPage = 1;
        let maxSearchCount;
        for (; ;) {
            const delay = nowCurrentPage == 1 ? 0 : defDelay;
            const oneSearchInfo = await new Promise((resolve) => {
                setTimeout(async () => {
                    const requestParams = {
                        formUuid: formUuid,
                        searchFieldJson: JSON.stringify(searchFieldJson),// 根据表单内组件值查询
                        currentPage: nowCurrentPage,
                        pageSize: 100,
                        dynamicOrder: JSON.stringify(orderInfo),// 排序
                    }
                    try {
                        const _req = canUseDataSourceReq ? this.dataSourceMap[dataSourceRequestName].load(requestParams) : this.utils.yida.searchFormDatas(requestParams)
                        // 根据条件搜索表单示例详情列表
                        const _r = await _req.then((res) => {
                            console.log('请求结果', res);
                            return { code: 200, result: res }
                        }).catch(({ message }) => {
                            console.error(`查询数据时出现异常,异常为:${message}`)
                            return { code: 500, msg: `查询数据异常${message}` }
                        });
                        resolve(_r)
                    } catch (e) {
                        console.error(`查询数据时出现异常,异常为:${e}`)
                        resolve({ code: 500, msg: "查询数据异常" })
                    }
                }, delay);
            })
            if (oneSearchInfo.code != 200) {
                batchSearchLoading()
                this.utils.toast({ type: "error", title: `数据查询失败:${oneSearchInfo.msg}`, duration: 3000 })
                return oneSearchInfo;
            }
            if (nowCurrentPage == 1) {
                result.totalCount = oneSearchInfo.result.totalCount
                maxSearchCount = Math.ceil(result.totalCount / 100);
            }
            const data = oneSearchInfo.result.data ? oneSearchInfo.result.data : []
            result.data.push(...data)
            if (maxSearchCount <= nowCurrentPage || (maxBatchSearch != -1 && nowCurrentPage >= maxBatchSearch)) {
                batchSearchLoading()
                result.nowCount = result.data.length;
                return { code: 200, result: result };
            }
            nowCurrentPage++;
        }
    
    }
    

    image.png

    image.png

    2025-08-11 18:53:10
    赞同 展开评论
  • 您可以使用分页参数来获取超过100条数据,每次请求最多可获取500条记录。具体请参阅阿里云宜搭API文档:https://help.aliyun.com/document_detail/147638.html。如果对您有帮助的话,可以帮忙采纳一下。谢谢。

    2025-02-10 16:48:53
    赞同 38 展开评论
  • 资深 C++与人工智能程序员。精通 C++,善用其特性构建稳健架构。在人工智能领域,深入研习机器学习算法,借 C++与 OpenCV 等实现计算机视觉应用,于自然语言处理构建文本处理引擎。以敏锐洞察探索技术融合边界,用代码塑造智能未来。

    宜搭根据条件搜索表单实例 ID 列表接口一般是通过添加分页参数来获取超过100条数据的,具体如下:

    请求参数设置

    在调用接口时,除了传入常规的 formUuid 、 searchFieldJson 等参数外,还需传入 currentPage (当前页)和 pageSize (每页记录数)两个参数 。比如,若要获取第2页且每页显示50条数据的实例 ID 列表, currentPage 的值应为2, pageSize 的值应为50.

    循环调用接口

    确定总数据量和需要获取的页数范围。通过多次循环调用接口,每次传入不同的 currentPage 值,来获取多页数据,从而达到获取超过100条数据的目的。循环过程中,可将每次获取到的数据进行合并或其他处理,以满足具体的业务需求。

    注意事项

    要注意接口的调用频率限制,避免因频繁调用导致接口被限流或封禁。同时,需合理设置 pageSize 的值,若该值过大,可能会导致单次查询数据量过多,影响查询性能和接口响应时间。

    2024-12-09 20:13:35
    赞同 213 展开评论
  • 若问题得到了解决,辛苦点下采纳回答哦~

    您好,如果需要获取超过100条的数据,建议通过JS循环节流调用查询接口,以下类似案例可以供您参考下:https://docs.aliwork.com/docs/yida_subject/_1/ggk8lg9ay1i3oxxb#TIw0L
    image.png

    2024-10-31 09:28:44
    赞同 437 展开评论