执行GrowBy后,需要将类似的客户添加到阵列中



我正在从salesforce获取客户联系人,这些联系人以对象数组的形式出现,如下所示

[
{
"customerID": 1,
"customerName": "Jonhn1"
},
{
"customerID": 1,
"customerName": "Jonhn2"
},
{
"customerID": 1,
"customerName": "Jonhn3"
},
{
"customerID": 1,
"customerName": "Jonhn4"
},
{
"customerID": 1,
"customerName": "Jonhn5"
},
{
"customerID": 2,
"customerName": "Jonhn6"
},
{
"customerID": 2,
"customerName": "Jonhn7"
},
{
"customerID": 2,
"customerName": "Jonhn8"
},
{
"customerID": 3,
"customerName": "Jonhn9"
},
{
"customerID": 3,
"customerName": "Jonhn10"
},
{
"customerID": 3,
"customerName": "Jonhn11"
},
{
"customerID": 4,
"customerName": "Jonhn12"
},
{
"customerID": 4,
"customerName": "Jonhn13"
},
{
"customerID": 5,
"customerName": "Jonhn14"
},
{
"customerID": 5,
"customerName": "Jonhn15"
},
{
"customerID": 5,
"customerName": "Jonhn16"
},
{
"customerID": 6,
"customerName": "Jonhn17"
},
{
"customerID": 7,
"customerName": "Jonhn17"
}
]

我需要输出数组,每个子数组都应该有atmost三个不同客户的所有客户详细信息。

重复输出:

[
[
{
"customerID": 1,
"customerName": "Jonhn1"
},
{
"customerID": 1,
"customerName": "Jonhn2"
},
{
"customerID": 1,
"customerName": "Jonhn3"
},
{
"customerID": 1,
"customerName": "Jonhn4"
},
{
"customerID": 1,
"customerName": "Jonhn5"
},
{
"customerID": 2,
"customerName": "Jonhn6"
},
{
"customerID": 2,
"customerName": "Jonhn7"
},
{
"customerID": 2,
"customerName": "Jonhn8"
},
{
"customerID": 3,
"customerName": "Jonhn9"
},
{
"customerID": 3,
"customerName": "Jonhn10"
},
{
"customerID": 3,
"customerName": "Jonhn11"
}
],
[
{
"customerID": 4,
"customerName": "Jonhn12"
},
{
"customerID": 4,
"customerName": "Jonhn13"
},
{
"customerID": 5,
"customerName": "Jonhn14"
},
{
"customerID": 5,
"customerName": "Jonhn15"
},
{
"customerID": 5,
"customerName": "Jonhn16"
},
{
"customerID": 6,
"customerName": "Jonhn17"
}
],
[
{
"customerID": 7,
"customerName": "Jonhn18"
}
]
]

需要将此数组发送到并行,以便对每个数组进行并行处理。

GroupBy,用于根据customerID进行分组。

CCD_ 2,用于将键为数字的对象转换为数组。

用于划分为数字组的divideBy 3,例如[[1]、[2]、[3]、[[4]、[5]、[6]、[[7]]

用于迭代嵌套数组[array of objects]的map

用于将嵌套数组[[]]]转换为单个数组[[]]的flatten

%dw 2.0
output application/json
import * from dw::core::Arrays
---
payload groupBy $.customerID pluck $ divideBy 3 map((flatten($)))

输出

[
[
{
"customerID": 1,
"customerName": "Jonhn1"
},
{
"customerID": 1,
"customerName": "Jonhn2"
},
{
"customerID": 1,
"customerName": "Jonhn3"
},
{
"customerID": 1,
"customerName": "Jonhn4"
},
{
"customerID": 1,
"customerName": "Jonhn5"
},
{
"customerID": 2,
"customerName": "Jonhn6"
},
{
"customerID": 2,
"customerName": "Jonhn7"
},
{
"customerID": 2,
"customerName": "Jonhn8"
},
{
"customerID": 3,
"customerName": "Jonhn9"
},
{
"customerID": 3,
"customerName": "Jonhn10"
},
{
"customerID": 3,
"customerName": "Jonhn11"
}
],
[
{
"customerID": 4,
"customerName": "Jonhn12"
},
{
"customerID": 4,
"customerName": "Jonhn13"
},
{
"customerID": 5,
"customerName": "Jonhn14"
},
{
"customerID": 5,
"customerName": "Jonhn15"
},
{
"customerID": 5,
"customerName": "Jonhn16"
},
{
"customerID": 6,
"customerName": "Jonhn17"
}
],
[
{
"customerID": 7,
"customerName": "Jonhn17"
}
]
]

最新更新