我需要创建3个单独的文件。
我的批处理作业应从Mongo中读取,然后解析信息并找到“业务”列(3种业务类型:RETAIL,HPP,SAX),然后为其各自的业务创建文件。该文件应创建RETAIL + formattedDate; HPP + formattedDate; SAX + formattedDate作为文件名,以及在txt文件中的数据库中找到的信息。另外,我需要将.resource(new FileSystemResource(“ C:\ filewriter \ index.txt))设置为将信息发送到正确位置的位置,现在硬编码可以工作,但只能创建一个.txt文件。 / p>
示例:
@Bean
public FlatFileItemWriter<PaymentAudit> writer() {
LOG.debug("Mongo-writer");
FlatFileItemWriter<PaymentAudit> flatFile = new
FlatFileItemWriterBuilder<PaymentAudit>()
.name("flatFileItemWriter")
.resource(new FileSystemResource("C:\\filewriter\\index.txt))
//trying to create a path instead of hard coding it
.lineAggregator(createPaymentPortalLineAggregator())
.build();
String exportFileHeader =
"CREATE_DTTM";
StringHeaderWriter headerWriter = new
StringHeaderWriter(exportFileHeader);
flatFile.setHeaderCallback(headerWriter);
return flatFile;
}
我的想法是,但不确定要去哪里
public Map<String, List<PaymentAudit>> getPaymentPortalRecords() {
List<PaymentAudit> recentlyCreated =
PaymentPortalRepository.findByCreateDttmBetween(yesterdayMidnight,
yesterdayEndOfDay);
List<PaymentAudit> retailList = new ArrayList<>();
List<PaymentAudit> saxList = new ArrayList<>();
List<PaymentAudit> hppList = new ArrayList<>();
//String exportFilePath = "C://filewriter/";??????
recentlyCreated.parallelStream().forEach(paymentAudit -> {
if (paymentAudit.getBusiness().equalsIgnoreCase(RETAIL)) {
retailList.add(paymentAudit);
} else if
(paymentAudit.getBusiness().equalsIgnoreCase(SAX)) {
saxList.add(paymentAudit);
} else if
(paymentAudit.getBusiness().equalsIgnoreCase(HPP)) {
hppList.add(paymentAudit);
}
});
答案 0 :(得分:0)
要为每种业务对象类型创建文件,可以使用ClassifierCompositeItemWriter
。对于您的情况,您可以为每种类型创建一个writer,并将它们作为委托添加到复合项目writer中。
根据动态创建文件名,您需要使用步进作用域写入器。参考文档的Step Scope部分中有一个示例。
希望这会有所帮助。