gpt4 book ai didi

java - 在 birt 中创建组并分析数组列表中的数据

转载 作者:行者123 更新时间:2023-11-30 06:23:02 28 4
gpt4 key购买 nike

我在 birt 报告中使用 mongo db。我的数据集包含一个如图所示的对象数组。

enter image description here

deviceStatus 是一个数组,其中包含状态、错误代码、设备名称等子对象。

我想在创建组时在报告中创建 deviceName 的组,它是以这种形式创建的:

[ "CardReader" , "CashAcceptor" , "CashDispenser" , "ChequeAcceptor" , "EmiratesIdScanner" , "PinPad" , "JournalPrinter" , "ReceiptPrinter" , "StatementPrinter" , "SignpadScanner"]

我希望它以 splinter 的形式分组,例如:

CardReader
CashAcceptor
CashDispenser ..

错误代码也以这种形式来自数据集:

[ "97080301" , "97080302,97080303" , "" , "" , "" , "" , "" , "" , "" , ""]

以同样的方式,我想将错误代码和状态代码从数组形式分解到每个 deviceName 的每一行。

CardReader  97080301
CashAcceptor 97080302,97080303
CashDispenser

我是 birt 的新手,请有人帮忙。提前致谢。

应用 Veeram 的答案后,错误代码未显示在报告中,但出现在预览结果中:

1: enter image description here

2:

enter image description here

最佳答案

请按照以下步骤获取所需的回复。

数据:

db.devicestatus.insert([
{
"_id": "0001",
"className":"store",
"deviceStatus": [ {
"deviceName": "CardReader",
"errorCode": "97080301",
"status": "Bad"
},
{
"deviceName": "CashAcceptor",
"errorCode": "97080302,97080303",
"status": "Bad"
},
{
"deviceName": "CashDispenser",
"errorCode": "",
"status": "Good"
}]
}
])

1.数据浏览器-进入数据集-新建数据集-选择数据源-输入数据集名称-点击下一步

enter image description here

2.输入集合名称 - 设备状态 - 列出所有字段 - 从命令类型下拉列表中选择聚合选项 - 单击表达式

enter image description here

3.在表达式生成器提示中添加以下表达式 - 单击“确定”

enter image description here

下面的表达式$unwind展平数组以将 devicestatus 数组分解为文档,后跟 $project 保留必填字段。

[
{"$unwind":"$deviceStatus"},
{"$project":{
"_id":0,
"className":1,
"deviceStatus.deviceName":1,
"deviceStatus.errorCode":1
}
}
]

或者

下面的表达式迭代 devicestatus 数组和 $map$project必填字段,后跟 $unwind展平以将数组分解为文档。

[{
"$project":{
"_id":0,
"className":1,
"deviceStatus":{
"$map":{
"input":"$deviceStatus",
"as":"result",
"in":{
"deviceName":"$$result.deviceName",
"errorCode":"$$result.errorCode"
}
}
}
}
},
{"$unwind":"$deviceStatus"}
]

或者

4.确认刷新-点击yes

enter image description here

5.将所有可用字段移至选定的多选下拉框 - 单击“完成”

enter image description here

6.预览结果

{"className":"store", "deviceStatus":{"deviceName":"CardReader","errorCode":"97080301"}}
{"className":"store", "deviceStatus":{ "deviceName":"CashAcceptor","errorCode":"97080302,97080303"}}
{"className":"store","deviceStatus":{"deviceName":"CashDispenser","errorCode":""}}

关于java - 在 birt 中创建组并分析数组列表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47752325/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com