您能否帮忙将以下输入数据转换为给定的输出:
输入:[ { “ID_TYPE”:“4”, “日期”:“20230529”, "ADM_TIME": "17:00", "PAYLOAD_NUMBER": "597418", "PAYLOAD_COMMENT": "你好" }, { “ID_TYPE”:“4”, “日期”:“20230531”, "ADM_TIME": "17:00", "PAYLOAD_NUMBER": "597418", "PAYLOAD_COMMENT": "你好" }, { “ID_TYPE”:“4”, “日期”:“20230602”, "ADM_TIME": "17:00", "PAYLOAD_NUMBER": "597418", "PAYLOAD_COMMENT": "你好" }, { “ID_TYPE”:“4”, “日期”:“20230628”, "ADM_TIME": "8:00", "PAYLOAD_NUMBER": "597500", "PAYLOAD_COMMENT": "评论" }, { “ID_TYPE”:“4”, “日期”:“20230628”, "ADM_TIME": "17:00", "PAYLOAD_NUMBER": "597500", "PAYLOAD_COMMENT": "评论" }, { “ID_TYPE”:“4”, “日期”:“20230629”, "ADM_TIME": "12:00", "PAYLOAD_NUMBER": "597500", "PAYLOAD_COMMENT": "评论" }, { “ID_TYPE”:“4”, “日期”:“20230630”, "ADM_TIME": "17:00", "PAYLOAD_NUMBER": "597500", "PAYLOAD_COMMENT": "评论" }, { “ID_TYPE”:“4”, “日期”:“20230702”, "ADM_TIME": "12:00", "PAYLOAD_NUMBER": "597500", "PAYLOAD_COMMENT": "评论" } ]
输出:[
{
"TIMES": "17:00",
"MORNING": "0",
"NOON": "0",
"EVENING": "3",
"TOTAL_QUANTITY": "3",
"DATES": "2023/05/29, 2023/06/02, 2023/05/31",
"PAYLOAD_NUMBER": "597418",
"PAYLOAD_COMMENT": "HELLO"
},
{
"TIMES": "8:00, 12:00, 17:00",
"MORNING": "1",
"NOON": "2",
"EVENING": "2",
"TOTAL_QUANTITY": "5",
"DATES": "2023/06/28, 2023/06/29, 2023/06/30, 2023/07/02",
"PAYLAOD_NUMBER": "597500",
"PAYLOAD_COMMENT": "Comments"
}
]
如果输入是 groupby PAYLOAD_NUMBER,则,
TIMES 是输入数据中的 ADM_TIME 列表,
早上,00:01 到 09:59 之间的时间计数,
中午,10:00 到 14:59 之间的次数,
晚上,计算 15:00PM 至 23:59 之间的次数,
TOTAL_QUANTITY 是 MORNING、NOON 和 Evening 之间的总和,
DATES 是 DATE 的列表。
谢谢你。
您需要使用 groupBy() 然后 mapObject() 根据需要对每个组进行汇总、排序和格式化,然后获取结果列表。
%dw 2.0
output application/json
fun normalizeTime(t: String)= t as LocalTime {format: "H:mm"} as String {format: "HH:mm"}
fun normalizeDate(d: String)= d as Date {format: "yyyyMMdd"} as String {format: "yyyy/MM/dd"}
---
payload
groupBy ($.PAYLOAD_NUMBER)
mapObject ((value, key, index) -> (key): {
TIMES: value.*ADM_TIME distinctBy $ orderBy normalizeTime($) joinBy " ",
MORNING: sizeOf(value.ADM_TIME filter (normalizeTime($) >= "00:00" and normalizeTime($) <= "09:59" )),
NOON: sizeOf(value.ADM_TIME filter (normalizeTime($) >= "10:00" and normalizeTime($) <= "14:59" )),
EVENING: sizeOf(value.ADM_TIME filter (normalizeTime($) >= "15:00" and normalizeTime($) <= "23:59" )),
TOTAL_QUANTITY: sizeOf(value),
DATES: value.*DATE distinctBy $ orderBy $ map normalizeDate($) joinBy " ",
PAYLAOD_NUMBER: key as String,
PAYLOAD_COMMENT: value[0].PAYLOAD_COMMENT
})
pluck ($)
输出:
[
{
"TIMES": "17:00",
"MORNING": 0,
"NOON": 0,
"EVENING": 3,
"TOTAL_QUANTITY": 3,
"DATES": "2023/05/29 2023/05/31 2023/06/02",
"PAYLAOD_NUMBER": "597418",
"PAYLOAD_COMMENT": "HELLO"
},
{
"TIMES": "8:00 12:00 17:00",
"MORNING": 1,
"NOON": 2,
"EVENING": 2,
"TOTAL_QUANTITY": 5,
"DATES": "2023/06/28 2023/06/29 2023/06/30 2023/07/02",
"PAYLAOD_NUMBER": "597500",
"PAYLOAD_COMMENT": "Comments"
}
]
我添加了缺失的“00:00”时间。随意改变。它