如何从包含 SQL 和 NoSQL 信息的表中构建聚合 Stream API?

How to build aggregates from a table containing SQL and NoSQL information on stream api?

提问人:Mikhail 提问时间:11/17/2023 最后编辑:Mikhail 更新时间:11/17/2023 访问量:29

问:

我以下表为例。它包含 5 个请求 ,每个请求由一定数量的操作组成,其中显示请求的进度:orderIdactionId

|ordr| data                                                                                      |
| -- | ----------------------------------------------------------------------------------------- |
| 1  | {"actionId":1,"curNum":1,"maxNum":3,"status":"READY","templateId":4,"errMsg":null}        |
| 1  | {"actionId":1,"curNum":1,"maxNum":3,"status":"SUCCESS","templateId":4,"errMsg":null}      |
| 1  | {"actionId":2,"curNum":2,"maxNum":3,"status":"READY","templateId":4,"errMsg":null}        |
| 1  | {"actionId":2,"curNum":2,"maxNum":3,"status":"SUCCESS","templateId":4,"errMsg":null}      |
| 1  | {"actionId":3,"curNum":3,"maxNum":3,"status":"READY","templateId":4,"errMsg":null}        |
| 1  | {"actionId":3,"curNum":3,"maxNum":3,"status":"SUCCESS","templateId":4,"errMsg":null}      |
| 2  | {"actionId":4,"curNum":1,"maxNum":3,"status":"READY","templateId":5,"errMsg":null}        |
| 2  | {"actionId":4,"curNum":1,"maxNum":3,"status":"SUCCESS","templateId":5,"errMsg":null}      |
| 2  | {"actionId":5,"curNum":2,"maxNum":3,"status":"READY","templateId":5,"errMsg":null}        |
| 2  | {"actionId":5,"curNum":2,"maxNum":3,"status":"SUCCESS","templateId":5,"errMsg":null}      |
| 2  | {"actionId":6,"curNum":3,"maxNum":3,"status":"READY","templateId":5,"errMsg":null}        |
| 2  | {"actionId":6,"curNum":3,"maxNum":3,"status":"SUCCESS","templateId":5,"errMsg":null}      |
| 3  | {"actionId":7,"curNum":1,"maxNum":2,"status":"READY","templateId":6,"errMsg":null}        |
| 3  | {"actionId":7,"curNum":1,"maxNum":2,"status":"FAIL","templateId":6,"errMsg":"BAD REQUEST"}|
| 4  | {"actionId":8,"curNum":1,"maxNum":2,"status":"UNKNOWN","templateId":7,"errMsg":null}      |
| 4  | {"actionId":8,"curNum":1,"maxNum":2,"status":"UNKNOWN","templateId":7,"errMsg":null}      |
| 5  | {"actionId":7,"curNum":1,"maxNum":2,"status":"READY","templateId":6,"errMsg":null}        |
| 5  | {"actionId":7,"curNum":1,"maxNum":2,"status":"FAIL","templateId":6,"errMsg":"BAD REQUEST"}|
       |        |

如何使用 Stream Api 获取如下所示的报告(为清楚起见,显示在表中):

| TemplateId | TotalRunOrder  |SuccessRunOrder | FailRunOrder  |FailOrdersInfo  |
| ---------- | -------------- | -------------- | --------------|----------------|
| 4          | 1              | 1              | 0             | null           |
| 5          | 1              | 1              | 0             | null           |
| 6          | 2              | 0              | 2             | [{"OrderId":3,"ErrMsg":"BAD REQUEST"},{"OrderId":5,"ErrMsg":"BAD REQUEST"}]|
| 7          | 0              | 0              | 0             | null           |

如何计算报告字段的说明:

TemplateId- 取自现场的初始表格data

TotalRunOrder- 如果在一个状态中至少有一个状态OrderId"READY"

SuccessRunOrder- 我们在一行中寻找一行,其中,如果它具有状态,则我们认为应用程序成功OrderIdcurNum=maxNum"SUCCESS"

FailRunOrder- 如果在一个状态中至少有一个状态,则我们认为申请失败OrderId"FAIL"

FailOrdersInfo- 以数组的形式显示信息,其中我们显示哪些失败并显示错误文本OrderIdErrMsg

java spring-boot spring-mvc java-stream

评论

1赞 experiment unit 1998X 11/17/2023
您想举一个最小的可重复示例吗?
0赞 Mikhail 11/17/2023
@experimentunit1998X如果我有它,我就不会来这里了

答: 暂无答案