-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