我有这个输入:
[
{
"building": 222,
"default": {
"price": 0.22,
"perHour": null
},
"appPricing": [
{
"pricing": {
"price": 1.25,
"perHour": null
},
"schedules": [
{
"daysOfWeek": [
"FRIDAY",
"MONDAY"
],
"endTime": "21:59:00",
"startTime": "08:00:00"
},
{
"daysOfWeek": [
"TUESDAY",
"WEDNESDAY",
"THURSDAY"
],
"endTime": "19:59:00",
"startTime": "11:00:00"
}
]
},
{
"pricing": {
"price": 0.34,
"perHour": null
},
"schedules": [
{
"daysOfWeek": [
"MONDAY",
"FRIDAY"
],
"endTime": "23:59:00",
"startTime": "22:00:00"
},
{
"daysOfWeek": [
"TUESDAY",
"WEDNESDAY",
"THURSDAY"
],
"endTime": "23:59:00",
"startTime": "20:00:00"
}
]
},
{
"pricing": {
"price": 0.8,
"perHour": null
},
"schedules": [
{
"daysOfWeek": [
"MONDAY",
"FRIDAY"
],
"endTime": "07:59:00",
"startTime": "00:00:00"
},
{
"daysOfWeek": [
"TUESDAY",
"WEDNESDAY",
"THURSDAY"
],
"endTime": "10:59:00",
"startTime": "00:00:00"
}
]
}
]
}
]
我想在一周中的特定日期、特定结束时间和开始时间之后进行过滤。
这是一个例子:
星期几:星期四
结束时间:18:59:00
开始时间:11:00:00
这是输出:
{
"price": 0.22,
"perMinute": null,
"perSession": null
}
我假设您正在尝试根据时间表过滤定价,并在找不到定价的情况下返回默认定价。关键是内部过滤器返回布尔条件,我使用
isEmpty
和 !
运算符来实现相同的效果。
但是,我发现输出与输入存在差异。例如,输出中的 perMinute 和 perSession 字段。因此,请使用以下脚本作为起点,并根据您的要求扩展/修改脚本。
希望这有帮助!
%dw 2.0
output application/json
var inp = {
day: "THURSDAY",
endTime: "16:59:00",
startTime: "11:00:00"
}
fun matchSchedules (schedules) =
!isEmpty (schedules filter (($.daysOfWeek contains inp.day)
and $.endTime == inp.endTime
and $.startTime == inp.startTime))
---
((payload[0].appPricing filter ((price) -> matchSchedules(price.schedules)))[0].pricing) default payload[0]."default"