-4
我试图创建一个对象,需要按BatchCode进行分组,并在某些字段上进行汇总。我正在尝试使用Groupby函数来完成此操作,但是我遇到了困难,我将不胜感激。如何创建具有正确总计和分组的对象
输入记录:
记录1:
BatchCode 1234
BatchType Scanned
Amount 10.00
RecType Adc
记录2:
BatchCode 1234
BatchType Scanned
Amount 5.00
RecType NotAdc
记录3:
BatchCode 2222
BatchType NonScanned
Amount 25.00
RecType Adc
记录4:
BatchCode 2222
BatchType NonScanned
Amount 30.01
RecType NotAdc
预期的输出对象:
"Batches": [
{
"BatchCode": "1234",
"BatchType": "Scanned",
"DetailRecordCountAdc": 1,
"DetailRecordCountNotAdc": 1,
"DetailRecordCountTotal": 2,
"AmountAdc": 10.00,
"AmountNotAdc": 5.00,
"AmountTotal": 15.00
},
{
"BatchCode": "2222",
"BatchType": "Nonscanned",
"DetailRecordCountAdc": 1,
"DetailRecordCountNotAdc": 1,
"DetailRecordCountTotal": 2,
"AmountAdc": 25.00,
"AmountNotAdc": 30.01,
"AmountTotal": 55.01
}
]
你能分享你的代码和安排(一些实体)吗? – kat1330