修改物资逻辑
This commit is contained in:
@ -104,7 +104,7 @@ public class MatMaterialsUseRecordServiceImpl extends ServiceImpl<MatMaterialsUs
|
|||||||
);
|
);
|
||||||
BigDecimal residueNumber;
|
BigDecimal residueNumber;
|
||||||
if (lastRecord == null) {
|
if (lastRecord == null) {
|
||||||
residueNumber = BigDecimal.valueOf(inventory.getNumber());
|
residueNumber = BigDecimal.valueOf(inventory.getResidue());
|
||||||
} else {
|
} else {
|
||||||
residueNumber = lastRecord.getResidueNumber();
|
residueNumber = lastRecord.getResidueNumber();
|
||||||
}
|
}
|
||||||
@ -113,7 +113,18 @@ public class MatMaterialsUseRecordServiceImpl extends ServiceImpl<MatMaterialsUs
|
|||||||
throw new ServiceException("使用数量不能大于库存数量", HttpStatus.BAD_REQUEST);
|
throw new ServiceException("使用数量不能大于库存数量", HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
materialsUseRecord.setResidueNumber(subtract);
|
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);
|
throw new ServiceException("只能修改最新数据", HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
BigDecimal useNumber = req.getUseNumber();
|
BigDecimal useNumber = req.getUseNumber();
|
||||||
|
BigDecimal subtract = BigDecimal.ZERO;
|
||||||
if (useNumber != null && useNumber.compareTo(oldMaterialsUseRecord.getUseNumber()) != 0) {
|
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) {
|
if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
throw new ServiceException("使用数量不能大于库存数量", HttpStatus.BAD_REQUEST);
|
throw new ServiceException("使用数量不能大于库存数量", HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
materialsUseRecord.setResidueNumber(subtract);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user