String keys ="merchantNo,terminalId,tradeTime,refundCompletionTime,tradeAmount,commissionAmount,refundAmount,balanceAmount,tradeType,payMethod,tradeStatus,tradeNo,refundOriginalOrderNo,terminalSerialNumber,channelOrderNo,liquidationDate,userId,bankCardType";

String[] keysArray = keys.split(",");

final int batchSize =1000;

try (Stream lines = Files.lines(Paths.get("D:\\data\\pay\\20230506.txt"))) {

List<ShopMerchantBill> list =new ArrayList<>(batchSize);

    lines.map(line -> {

String[] values = line.split(",");

        Map map = IntStream.range(0, keysArray.length)

.boxed()

.collect(Collectors.toMap(i -> keysArray[i], i -> values[i]));

        ShopMerchantBill bill = JSON.parseObject(JSON.toJSONString(map), ShopMerchantBill.class);

        bill.setTradeType(bill.getTradeAmount() >0 ?"退款" :"收款");

        return bill;

    }).forEach(bill -> {

list.add(bill);

        if (list.size() >= batchSize) {

shopMerchantBillService.saveBatch(list);

            list.clear();

        }

});

    if (!list.isEmpty()) {

shopMerchantBillService.saveBatch(list);

    }

}catch (IOException e) {

e.printStackTrace();

}