【发布时间】:2019-12-06 08:04:28
【问题描述】:
我有点像 DataWeave 新手。我正在尝试获取用户的最新扣除记录,但也按数组中的类型进行分组。这是我必须处理的数据:
"users": [
{
"employeeId": "123456",
"lastName": "smith",
"firstName": "joe ",
"deductions": [
{
"deductionType": "ABC",
"Amt": 1000,
"StartDate": "2001-01-02T00:00:00"
},
{
"deductionType": "ABC",
"Amt": 1000,
"StartDate": "2019-01-02T00:00:00"
},
{
"deductionType": "ABC",
"Amt": 1000,
"StartDate": "2016-01-02T00:00:00"
},
{
"deductionType": "DCA",
"Amt": 4000,
"StartDate": "2019-11-02T00:00:00",
}
]
}
我尝试使用发布在以下位置的类似解决方案:Dataweave 2.0 maxBy and filter 但这似乎不起作用,因为我得到了一个空有效负载。
最终结果应该是这样的:
"users": [
{
"employeeId": "123456",
"lastName": "smith",
"firstName": "joe ",
"deductions": [
{
"deductionType": "ABC",
"Amt": 1000,
"StartDate": "2019-01-02T00:00:00"
},
{
"deductionType": "DCA",
"Amt": 4000,
"StartDate": "2019-11-02T00:00:00",
}
]
我目前尝试的解决方案是:
payload.users map {($),
deductions: (($.deductions groupBy $.deductionType) mapObject (value, key) ->
{(key) : (value maxBy $.benefitStartDate)}) pluck (value) -> value
}
但这也不起作用。
【问题讨论】:
-
我试图了解取消扣除的标准是什么——看来你只是保留最新的(按日期计算);我说的对吗?
-
我正在尝试获取该用户的用户和扣除记录,该用户按 deductionType 分组,开始日期最晚