我有一个场景,员工暂存表中有数百万条记录,我需要丰富该值并将其存储在员工最终表中。现在我正在使用块处理,块大小为 10,000。
在我必须进行丰富的处理器中,我想收集该块的所有员工 ID,并对每个块执行 1 次 API 调用并丰富值。而不是百万要求百万条记录。
我观察到我现在使用的扩展 RepositoryItemReader 的阅读器没有返回列表,因为我正在使用 JPA 我正在使用 RepositoryItemReader。 因此,即使块大小为 10,000,每个项目也会进行 1 次处理。
我们可以从 reader 获取整个 List 并对其进行处理吗? 或者还有其他方法吗,因为我无法真正为每条记录拨打 1 个电话。
public class EmployeeStagingReader extends RepositoryItemReader<EmployeeStaging>{
public EmployeeStagingReader(EmployeeStagingRepository repo){
super();
this.setRepository(repo);
this.setMethodName("findAll");
final Map<String,Sort.Direction> sorts = new HashMap<>();
sorts.put("ID",Sort.Direction.ASC)
this.setSort(sorts);
}
}
public class EmployeeProcessor implements ItemProcessor<List<EmployeeStaging>, List<EmployeeFinal>> {
//Want to Perform transformation of stagingemployee list of records and return employeefinal list of records
}
}
@Bean
public Step step1() {
return this.stepBuilderFactory.get("step1")
.<List<EmployeeStaging>, List<EmployeeFinal>>chunk(1000)
.reader(EmployeeStagingReader())
.processor(EmployeeProcessor())
.writer(EmployeeFinalWriter())
.build();
}
尝试这个方法。