parent
7dc090209c
commit
375f0a3882
@ -0,0 +1,66 @@
|
|||||||
|
package au.com.royalpay.payment.manage.process;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.support.abafile.ABAConfig;
|
||||||
|
import au.com.royalpay.payment.manage.support.abafile.ABAFile;
|
||||||
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
||||||
|
import org.apache.commons.csv.CSVFormat;
|
||||||
|
import org.apache.commons.csv.CSVParser;
|
||||||
|
import org.apache.commons.csv.CSVRecord;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create by yixian at 2019-01-17 12:47
|
||||||
|
*/
|
||||||
|
public class ABAGenerator {
|
||||||
|
private ABAConfig.ABABase config;
|
||||||
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
private String csvFile = "C:\\Users\\yixian\\Documents\\royalpay\\2019\\cemtexaba-template-csv.csv";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepareEnv() {
|
||||||
|
PlatformEnvironment env = new PlatformEnvironment();
|
||||||
|
env.afterInitialize();
|
||||||
|
ReflectionTestUtils.setField(env, "foreignCurrency", "AUD");
|
||||||
|
config = new ABAConfig.ABABase()
|
||||||
|
.setBank("CBA")
|
||||||
|
.setApca("301500")
|
||||||
|
.setBsb("063109")
|
||||||
|
.setAccountNo("11505847")
|
||||||
|
.setAccountName("Tunnel Show Pty Ltd");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generate() {
|
||||||
|
ABAFile file = config.initFile(new Date());
|
||||||
|
try (FileReader reader = new FileReader(csvFile)) {
|
||||||
|
CSVParser parser = new CSVParser(reader, CSVFormat.newFormat(','));
|
||||||
|
List<CSVRecord> records = parser.getRecords();
|
||||||
|
for (CSVRecord record : records) {
|
||||||
|
logger.debug("reading record:{}", record.toString());
|
||||||
|
String bsb = record.get(0).replace("-", "");
|
||||||
|
String accountNo = record.get(1);
|
||||||
|
String accountName = record.get(2);
|
||||||
|
BigDecimal amount = new BigDecimal(record.get(3));
|
||||||
|
String remark = record.get(4);
|
||||||
|
file.addSettleMerchant(bsb, accountNo, accountName, amount, remark);
|
||||||
|
}
|
||||||
|
byte[] bytes = file.output(0);
|
||||||
|
FileUtils.writeByteArrayToFile(new File("C:\\Users\\yixian\\Documents\\royalpay\\2019\\cemtexaba-template.aba"), bytes);
|
||||||
|
logger.info("output done");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue