修改物资逻辑

This commit is contained in:
lcj
2025-08-22 19:56:52 +08:00
parent f06d46469e
commit dc02c5dfae

View File

@ -104,7 +104,7 @@ public class MatMaterialsUseRecordServiceImpl extends ServiceImpl<MatMaterialsUs
);
BigDecimal residueNumber;
if (lastRecord == null) {
residueNumber = BigDecimal.valueOf(inventory.getNumber());
residueNumber = BigDecimal.valueOf(inventory.getResidue());
} else {
residueNumber = lastRecord.getResidueNumber();
}
@ -113,7 +113,18 @@ public class MatMaterialsUseRecordServiceImpl extends ServiceImpl<MatMaterialsUs
throw new ServiceException("使用数量不能大于库存数量", HttpStatus.BAD_REQUEST);
}
materialsUseRecord.setResidueNumber(subtract);
return this.save(materialsUseRecord);
boolean save = this.save(materialsUseRecord);
if (!save) {
throw new ServiceException("保存材料使用登记失败", HttpStatus.ERROR);
}
MatMaterialsInventory updateInventory = new MatMaterialsInventory();
updateInventory.setId(inventoryId);
updateInventory.setResidue(subtract.longValue());
boolean update = materialsInventoryService.updateById(updateInventory);
if (!update) {
throw new ServiceException("更新库存信息失败", HttpStatus.ERROR);
}
return true;
}
/**
@ -140,14 +151,26 @@ public class MatMaterialsUseRecordServiceImpl extends ServiceImpl<MatMaterialsUs
throw new ServiceException("只能修改最新数据", HttpStatus.CONFLICT);
}
BigDecimal useNumber = req.getUseNumber();
BigDecimal subtract = BigDecimal.ZERO;
if (useNumber != null && useNumber.compareTo(oldMaterialsUseRecord.getUseNumber()) != 0) {
BigDecimal subtract = oldMaterialsUseRecord.getResidueNumber().add(oldMaterialsUseRecord.getUseNumber()).subtract(useNumber);
subtract = oldMaterialsUseRecord.getResidueNumber().add(oldMaterialsUseRecord.getUseNumber()).subtract(useNumber);
if (subtract.compareTo(BigDecimal.ZERO) < 0) {
throw new ServiceException("使用数量不能大于库存数量", HttpStatus.BAD_REQUEST);
}
materialsUseRecord.setResidueNumber(subtract);
}
return this.updateById(materialsUseRecord);
boolean update = this.updateById(materialsUseRecord);
if (!update) {
throw new ServiceException("修改材料使用登记信息失败", HttpStatus.ERROR);
}
MatMaterialsInventory updateInventory = new MatMaterialsInventory();
updateInventory.setId(oldMaterialsUseRecord.getInventoryId());
updateInventory.setResidue(subtract.longValue());
boolean updated = materialsInventoryService.updateById(updateInventory);
if (!updated) {
throw new ServiceException("更新库存信息失败", HttpStatus.ERROR);
}
return true;
}
/**