这是我的第一批春季用户。我想每小时获取通过引用和id设计为List
@Override
public Long getStockByRef(String ref, Long id) {
Iterable<Produit> MyProducts = storeService.getAllProductOfStore(id);
Long stock = 0L;
for (Produit produit : MyProducts) {
if(produit.getReference().equals(ref)) {
stock = produit.getStock();
}
}
return stock;
}
这是我的RestController
@GetMapping("products/{id}/stock/{ref}")
public Long getStockByRef(@PathVariable Long id, @PathVariable String ref) {
Long stock = produitService.getStockByRef(ref, id);
return stock;
}
我的Spring批处理类配置
@Configuration
@EnableBatchProcessing
public class SpringBatchConfig {
@Autowired private ProduitService produitService;
@Autowired private JobBuilderFactory jobBuilderFactory;
@Autowired private StepBuilderFactory stepBuilderFactory;
@Autowired private ItemReader<Long> itemStockReader;
@Autowired private ItemWriter<List<Map<Date,Long>>> itemStockWriter;
@Autowired private ItemProcessor<Long, List<Map<Date,Long>> > itemStockProcessor;
@Bean
public Job myJob() {
Step step1 = stepBuilderFactory.get("step-get-stock")
.<Long,List<Map<Date,Long>>>chunk(1)
.reader(itemStockReader)
.processor(itemStockProcessor)
.writer(itemStockWriter)
.build();
return jobBuilderFactory.get("data").start(step1).build();
}
}
如何编写我的ItemReader ItemProcessor和我的Itemwrite以返回List