如何使用 BeanWriter 创建分隔文件



>我可以创建文件,但输出文件不包含分隔符,它具有固定长度的分隔符。如何使用 beanio json 中提供的分隔符使其

下面是我尝试编写文件的代码,但它没有给出预期的输出

String qualifiedChannelName = programId + "_" + channel;
BeanWriter out = factory.createWriter(qualifiedChannelName, new File("D:\dataengine\files\40287a35725ae63e0172934c765d0014\tm.txt"));
for (Transaction e : transactions) {
out.write(e);
}
out.flush();
out.close();

这是我的豆io文件格式

[ { "key": "beanio.transaction.sku.streamname", "value": "SKU" }, { "key": "beanio.transaction.payment.streamname", "value": "PAYMENT" }, { "key": "transaction.payment.identifier", "value": "12" }, { "key": "transaction.sku.identifier", "value": "11" }, { "key": "create.ghost.customer.from.card", "value": "true" }, { "key": "beanio.fileHeadercustomer.streamname", "value": "Header" }, { "key": "tenant.useHeader", "value": "false" }, { "key": "beanio.fileHeaderTransaction.streamname", "value": "Header" }, { "key": "transaction.fileheader.identifier", "value": "00" }, { "key": "beanio.card.streamname", "value": "Card" }, { "key": "customer.record.identifier", "value": "10" }, { "key": "beanio.transaction.streamname", "value": "Transaction" }, { "key": "card.fileheader.identifier", "value": "00" }, { "key": "customer.fileheader.identifier", "value": "00" }, { "key": "beanio.account.streamname", "value": "" }, { "key": "beanio.configuration", "value": "\u003C?xml version=\"1.0\"?> <beanio xmlns=\"http://www.beanio.org/2012/03\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd\"> <stream name=\"40287a35725ae63e0172934c765d0014_AJIO_ONLINE\" format=\"delimited\"> <parser class=\"com.loylty.dataacquisition.util.CustomDelimitedBeanIOParserFactory\"> <property name=\"customDelimiter\" value=\"\\\\^\"><\/property> <\/parser> <typeHandler type=\"java.util.Date\" class=\"com.loylty.dataacquisition.util.CustomDateTypeHandler\"> <property name=\"pattern\" value=\"dd-MMM-yyyy\"/> <\/typeHandler> <typeHandler type=\"java.math.BigDecimal\" class=\"com.loylty.dataacquisition.util.BigDecimalHandler\"/> <typeHandler name=\"negativeHandler\" class=\"com.loylty.dataacquisition.util.NegativeBigDecimalHandler\"/> <record name=\"Transaction\" class=\"com.loylty.dataacquisition.entities.Transaction\" maxLength=\"17\" minLength=\"17\" > <field name=\"paymentProcessor\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"merchantName\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"merchantTransactionId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"terminalId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"merchantId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"terminalOwnerName\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"first6DigitCard\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"last4DigitCard\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"cardTypeCode\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"cardIssuer\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"acquirerId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionType\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionAmount\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionDate\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionTime\" regex=\"([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"postDate\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <\/record> <\/stream> <stream name=\"40287a35725ae63e0172934c765d0014_AJIO_ONLINE_REFUND\" format=\"delimited\"> <parser class=\"com.loylty.dataacquisition.util.CustomDelimitedBeanIOParserFactory\"> <property name=\"customDelimiter\" value=\"\\\\^\"><\/property> <\/parser> <typeHandler type=\"java.util.Date\" class=\"com.loylty.dataacquisition.util.CustomDateTypeHandler\"> <property name=\"pattern\" value=\"dd-MMM-yyyy\"/> <\/typeHandler> <typeHandler type=\"java.math.BigDecimal\" class=\"com.loylty.dataacquisition.util.BigDecimalHandler\"/> <typeHandler name=\"negativeHandler\" class=\"com.loylty.dataacquisition.util.NegativeBigDecimalHandler\"/> <record name=\"Transaction\" class=\"com.loylty.dataacquisition.entities.Transaction\" maxLength=\"17\" minLength=\"17\" > <field name=\"paymentProcessor\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"merchantName\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"merchantTransactionId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"terminalId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"merchantId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"terminalOwnerName\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"first6DigitCard\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"last4DigitCard\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"cardTypeCode\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"cardIssuer\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"acquirerId\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionType\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionAmount\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionDate\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"transactionTime\" regex=\"([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <field name=\"postDate\" trim=\"true\" lazy=\"true\" maxLength=\"100\" /> <\/record> <\/stream> <\/beanio>\r\n" }, { "key": "beanio.fileHeaderaccount.streamname", "value": "" }, { "key": "account.fileheader.identifier", "value": "00" }, { "key": "beanio.customer.streamname", "value": "Customer" }, { "key": "account.record.identifier", "value": "11" }, { "key": "card.record.identifier", "value": "12" }, { "key": "camel.routes", "value": "\u003C?xml version=\"1.0\"?> <routes xmlns=\"http://camel.apache.org/schema/spring\"> <route startupOrder=\"1\" id=\"download\" autoStartup=\"false\"> <from uri=\"sftp://lradmin@192.168.250.204:22/../../../../files/40287a35725ae63e0172934c765d0014/sftp?password=Lrp@1234&amp;sendEmptyMessageWhenIdle=true&amp;move=.done&amp;delay=15000&amp;readLock=readLockCheckInterval&amp;disconnectOnBatchComplete=true\" /> <choice> <when> <simple>${header.CamelFileNameOnly} == null<\/simple> <\/when> <otherwise> <to uri =\"file:/dataengine/files/40287a35725ae63e0172934c765d0014\" /> <\/otherwise> <\/choice> <onCompletion> <filter> <log message=\"download thread completed\"><\/log> <simple>${property.CamelBatchComplete} == true<\/simple> <to uri=\"direct:completeddownload\"/> <\/filter> <\/onCompletion> <\/route> <route id=\"handback\" autoStartup=\"false\"> <from uri =\"file:/dataengine/files/40287a35725ae63e0172934c765d0014?include=.*\\.handback&amp;delay=15000&amp;sendEmptyMessageWhenIdle=true\" /> <choice> <when> <simple>${body} == null<\/simple> <\/when> <otherwise> <to uri=\"sftp://lradmin@192.168.250.204:22/../../files/40287a35725ae63e0172934c765d0014/handback?password=Lrp@1234&amp;sendEmptyMessageWhenIdle=true&amp;disconnectOnBatchComplete=true\" /> <\/otherwise> <\/choice> <onCompletion> <filter> <log message=\"HandBack thread completed\"><\/log> <simple>${property.CamelBatchComplete} == true<\/simple> <to uri=\"direct:completedhandback\"/> <\/filter> <\/onCompletion> <\/route> <route> <from uri=\"direct:completeddownload\" /> <to uri=\"controlbus:route?routeId=download&amp;action=stop&amp;async=true\" /> <\/route> <route> <from uri=\"direct:completedhandback\" /> <to uri=\"controlbus:route?routeId=handback&amp;action=stop&amp;async=true\" /> <\/route> <route startupOrder=\"2\" id=\"AJIO_ONLINE\" autoStartup=\"false\"> <from uri=\"file:/dataengine/files/40287a35725ae63e0172934c765d0014/?include=POS.*\\.txt&amp;sendEmptyMessageWhenIdle=true&amp;delay=5000&amp;sortBy=date:file:yyyyMMdd;file:name\"/> <onCompletion> <filter> <simple>${property.CamelBatchComplete} == true<\/simple> <to uri=\"direct:completedAJIO_ONLINE\"/> <\/filter> <\/onCompletion> <setHeader headerName=\"fileType\"> <simple>TRANSACTION<\/simple> <\/setHeader> <setheader headerName=\"channel\"> <simple>AJIO_ONLINE<\/simple> <\/setheader> <setHeader headerName=\"programId\"> <simple>40287a35725ae63e0172934c765d0014<\/simple> <\/setHeader> <to uri=\"bean:genericFileProcessorImpl?method=processOnlinePartner\"/> <\/route> <route> <from uri=\"direct:completedAJIO_ONLINE\" /> <to uri=\"controlbus:route?routeId=AJIO_ONLINE&amp;action=stop&amp;async=true\" /> <\/route> <route startupOrder=\"3\" id=\"AJIO_ONLINE_REFUND\" autoStartup=\"false\"> <from uri=\"file:/dataengine/files/40287a35725ae63e0172934c765d0014/?include=refundpos.*\\.txt&amp;sendEmptyMessageWhenIdle=true&amp;delay=5000&amp;sortBy=date:file:yyyyMMdd;file:name\"/> <onCompletion> <filter> <simple>${property.CamelBatchComplete} == true<\/simple> <to uri=\"direct:completedAJIO_ONLINE_REFUND\"/> <\/filter> <\/onCompletion> <setHeader headerName=\"fileType\"> <simple>REFUND<\/simple> <\/setHeader> <setheader headerName=\"channel\"> <simple>AJIO_ONLINE_REFUND<\/simple> <\/setheader> <setHeader headerName=\"programId\"> <simple>40287a35725ae63e0172934c765d0014<\/simple> <\/setHeader> <to uri=\"bean:genericFileProcessorImpl?method=processOnlinePartner\"/> <\/route> <route> <from uri=\"direct:completedAJIO_ONLINE_REFUND\" /> <to uri=\"controlbus:route?routeId=AJIO_ONLINE_REFUND&amp;action=stop&amp;async=true\" /> <\/route> <\/routes>" }, { "key": "create.ghost.account.from.card", "value": "true" }, { "key": "beanio.fileHeadercard.streamname", "value": "" }, { "key": "transaction.record.identifier", "value": "10" } ]

交易。.JAVA

public class Transaction {
private String header;
private String uniqueCustomerId;
private String debitCardnumber;
private String first4digitAccountnumber;
private String last4digitsAccountnumber;
private String terminalId;
private String merchantId;
private Date transactionDate;
private String transactionTime;
private String postDate;
private String terminalLocation;
private String terminalOwnerName;
private String terminalCity;
private String terminalState;
private String terminalCountry;
private BigDecimal transactionAmount;
private String transactionId;
private String acquirerId;
private String first6DigitCard;
private String last4DigitCard;
private String merchantCategorycode;
private String transactionType;
private boolean isCardValidated = false;
private boolean isAccountValidated = false;
private boolean isCustomerValidated = false;
private boolean isBinValidated = false;
private String accountNumber;
private String storeId;
private String storeCode;
private String cashier;
private String posId;
private String source;
private String isSuccessful;
private String responseCode;
private String currencyCode;
private BigDecimal fee;
private String addressLine1;
private String addressLine2;
private BigDecimal settlementAmount;
private String zip;
private String atmTransactionType;
// BOM
private String cardTypeCode;
// Transaction Meta info
private String fileName;        // supplied by camel in exchange object
private String channel;         // supplied by client during config
private FileType objectType;      // supplied by client during config
// Some random attributes ?
private BigDecimal transactionInitialAmount;
private BigDecimal vatAmount;
private BigDecimal redeemAmount;
private BigDecimal voucherAmount;
public String getCardTypeCode() {
return cardTypeCode;
}
public void setCardTypeCode(String cardTypeCode) {
this.cardTypeCode = cardTypeCode;
}
private BigDecimal netPayable;
private BigDecimal tax;
private BigDecimal discountAmount;
private BigDecimal redeemedAmount;
private String redemptionReferenceId;
private String recordData;
// Refund related attributes
private String originalTransactionId;
private Date originalTransactionDate;
private String originalTransactionTime;
private BigDecimal originalAmount;
// Non-transaction attributes
private String eventName;
private String eventCategory;
private int points;
private List<TransactionPayment> transactionPayments;
private List<TransactionSKU> transactionSKUs;
private Map<String, Float> transactionTax;
private int version;
private BigDecimal adjustmentAmount;
// Yes DC
private String primaryCardIdentifier;
//  PHFL and HDFC Exclusive
private String category;
private String product;
// TMB
private String isOnlineTransaction;
private Long fileId;
// AJIO(ONLINE_PARTNER TXNS field)
private String merchantName;
private String merchantTransactionId;
private String cardIssuer;
private String lrTransactionId;
private String partnerProgramId;
private String paymentProcessor;
}

现有输出

BILLDESK    RUR28350404633  AJIO    pay_sp_4a7caa2b-28bf-11ea-83ae-f1c5f19c7fb3 BDR00001    0000000BDR00001 AJIO    324145  4164    SALE    1401.0  24-Mar-2020 13:58:52    

预期输出

BILLDESK^RUR28350404633^AJIO^pay_sp_4a7caa2b-28bf-11ea-83ae-f1c5f19c7fb3^BDR00001^0000000BDR00001^AJIO^324145^4164^SALE^1401.0^24-Mar-2020^13:58:52^

我不确定为什么你需要一个自定义的 BeanIO 解析器

<parser class="com.loylty.dataacquisition.util.CustomDelimitedBeanIOParserFactory"> 
<property name="customDelimiter" value="^" />
</parser>

尝试使用以下方法配置默认解析器:

<parser>
<property name="delimiter" value="^" />
</parser>

相关内容

  • 没有找到相关文章

最新更新