假设系统里已经有许多的Lead历史数据,而我们正在进行的微信小程序和C4C集成的项目里,又创建了许多新的Lead数据。如何将这些新的在微信小程序里调用OData服务创建的Lead数据同老的历史数据做区分呢?
(1) 在C4C Sales Lead页面里,通过Source字段来标明Lead的来源。

对于AI Card项目来说,所有的Lead经由微信小程序创建,因此调用OData API时,SourceCode指定为“Wechat Social Channel”的代号:Z01

这样,在读取操作时,使用inlinecount=allpages,能一并返回SourceCode为Z01的Lead一共有多少个。
最后的url如下:
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?inlinecount=allpages
结果如下:

截至2020年3月20日12:23PM为止,在系统上经由微信小程序创建,Source Code字段为Z01的Lead总共有6个。

如果系统里满足这个条件的Lead越来越多,调用OData服务后,会造成规模巨大的数据量从服务器发送往消费端,所以建议使用客户端分页方式读取数据。
首先获取满足SourceCode为Z01的lead个数:
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection/filter=SourceCode eq 'Z01'

假设返回结果数为1000, 我们可以在客户端进行分页读取,每页读取的个数可以客户端自行决定,比如每次读取20个。
第一页的读取请求:
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?orderby=CreatedOn desc&$top=20
20个Lead返回:

第二页:即第21到第40个:
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?orderby=CreatedOn desc&
top=20
第三页:即第41个到第60个
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?orderby=CreatedOn desc&
top=20
要获取更多Jerry的原创文章,请关注公众号"汪子熙":

网友评论