1.1. 审核采购入库单
1.1.1. 审核流程(需要事务管理)
- 判断入库单是否存在,是否可以审核等
- 修改状态,审核人,审核时间
- 在循环外面更新仓库总金额、当前数量
- 添加或者更新即时库存表
1.1.2. 代码实现
@Service
public class StockincomebillServiceImpl extends BaseServiceImpl<Stockincomebill, Long>
implements IStockincomebillService {
@Autowired
private IProductStockService productStockService;
@Autowired
private IDepotService depotService;
// 审核入库单功能(需要事务管理)
@Override
@Transactional
public void auding(Long billId, Employee auditor) {
Stockincomebill bill = findOne(billId);
if (bill == null) {
throw new RuntimeException("此入库单不存在...");
}
// 0待审,1已审,-1作废
if (bill.getStatus() == 1) {
throw new RuntimeException("此入库单已经审核完成");
}
if (bill.getStatus() == -1) {
throw new RuntimeException("此入库单已经作废");
}
// 入库单状态,审核人,审核时间
bill.setStatus(1);
bill.setAuditor(auditor);
bill.setAuditorTime(new Date());
// 显示更新一下
save(bill);
Depot depot = bill.getDepot();
// 仓库总数量,总金额(循环的外面写)
depot.setCurrentCapacity(depot.getCurrentCapacity().add(bill.getTotalNum()));
depot.setTotalAmount(depot.getTotalAmount().add(bill.getTotalAmount()));
depotService.save(depot);
// 添加或者更新即时库存ProductStock
String jpql = "select o from ProductStock o where o.depot=? and o.product=?";
List<Stockincomebillitem> items = bill.getItems();
for (Stockincomebillitem billItem : items) {
Product product = billItem.getProduct();
List<ProductStock> list = findByJpql(jpql, depot, product);
if (list.size() == 0) {// 添加
ProductStock productStock = new ProductStock();
// 小计