Script1723182361473.groovy 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import java.io.File
  2. import java.io.FileWriter
  3. import java.io.BufferedWriter
  4. import java.text.SimpleDateFormat
  5. import java.util.Date
  6. import java.util.Random
  7. // Definisikan nama file dan path
  8. String fileName = 'Data Files/Data Upload/03 Switching/upload_switching_transaction.txt'
  9. File file = new File(fileName)
  10. // Cek apakah file sudah ada, jika ada hapus file tersebut
  11. if (file.exists()) {
  12. file.delete()
  13. println("File lama telah dihapus: " + fileName)
  14. }
  15. // Buat writer untuk menulis ke file
  16. BufferedWriter writer = new BufferedWriter(new FileWriter(file))
  17. // Tulis header CSV dengan format baru
  18. writer.write("TransactionDate|TransactionType|SACode|InvestorFundUnitACNo|SwitchOutFundCode|SwitchOutAmount(Nominal)|SwitchOutAmount(Unit)|SwitchOutAmount(AllUnits)|SwitchingFeeChargeFund|Fee(Nominal)|Fee(Unit)|Fee|SwitchinFundCode|PaymentDate|TransferType|SAReferenceNo")
  19. writer.newLine()
  20. // Inisialisasi format tanggal dan generator nomor acak
  21. //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd")
  22. //String currentDate = dateFormat.format(new Date()) // Menghasilkan tanggal saat ini
  23. // Inisialisasi format tanggal dengan format yyyyMMdd
  24. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd")
  25. String currentDate = dateFormat.format(new Date()) // Menghasilkan tanggal saat ini dalam format yyyyMMdd
  26. // Data dummy yang ingin ditulis
  27. List<Map<String, String>> data = [
  28. [transactionType: "3", saCode: "BPTPR", investorFundUnitACNo: "BPTPR0CZGMHF0129", switchOutFundCode: "BPTPRDTCPMPKON01", switchOutAmountNominal: "", switchOutAmountUnit: "10000", switchOutAmountAllUnits: "", switchingFeeChargeFund: "2", feeNominal: "", feeUnit: "1000", fee: "", switchinFundCode: "BPTPRDTSTPRSYR01", paymentDate: "", transferType: "2", saReferenceNo: "REF005"],
  29. [transactionType: "3", saCode: "BPTPR", investorFundUnitACNo: "BPTPR0CZGMHF0129", switchOutFundCode: "BPTPRDTCPMFKON01", switchOutAmountNominal: "", switchOutAmountUnit: "10000", switchOutAmountAllUnits: "", switchingFeeChargeFund: "2", feeNominal: "", feeUnit: "1000", fee: "", switchinFundCode: "BPTPRDFCBPTPRX01", paymentDate: "", transferType: "2", saReferenceNo: "REF006"]
  30. ]
  31. // Tulis data ke file CSV dengan menambahkan tanggal dan nomor acak untuk UnitBalanceComparison
  32. data.each { record ->
  33. writer.write("${currentDate}|${record.transactionType}|${record.saCode}|${record.investorFundUnitACNo}|${record.switchOutFundCode}|${record.switchOutAmountNominal}|${record.switchOutAmountUnit}|${record.switchOutAmountAllUnits}|${record.switchingFeeChargeFund}|${record.feeNominal}|${record.feeUnit}|${record.fee}|${record.switchinFundCode}|${record.paymentDate}|${record.transferType}|${record.saReferenceNo}")
  34. writer.newLine()
  35. }
  36. // Tutup writer
  37. writer.close()
  38. println("File CSV telah dibuat di: " + fileName)