我想扣除库存中与商品代码匹配的可用数量
json数据来自 Postman
[billamount:1000,
disocunt:500,
billcart[{itemcode:1001, quantity:4 }, {itemcode:1002, quantity:7 }]]
方法
@Autowired
private StockRepository stockRepository;
public Bill createBill(Bill bill) {
for (Billcart data : bill.getBillcart()) {
Stock entity = stockRepository.findByItemcode(data.getItemcode());
if(entity.getItemcode() ==data.getItemcode()){
entity.setAvailableQuantity(entity.getAvailableQuantity()- data.getQuantity())
stockRepository.save(entity)
}
}
扣除前
[{itemcode:1001, availableQuantity:20 }, {itemcode:1002, availableQuantity:40 }]]
结果应该是这样的:
[{itemcode:1001, availableQuantity:16 }, {itemcode:1002, availableQuantity:33 }]]
1条答案
按热度按时间wqsoz72f1#
您还必须更新账单的价值: