Untitled
unknown
java
a year ago
932 B
2
Indexable
Never
private String generateSupplyCode(Long idSuppliesGroup) { String supplyGroupCode = suppliesGroupRepository.findActiveCode(idSuppliesGroup); Optional<String> optionalLastCodeOfSpecificGroup = suppliesRepository.findLastCodeByStartWithSuppliesGroupCode(supplyGroupCode); if (!optionalLastCodeOfSpecificGroup.isPresent()) { String startNumber = "0001"; return supplyGroupCode + Constants.UNDERLINED + startNumber; } String lastCodeOfSpecificGroup = optionalLastCodeOfSpecificGroup.get(); int lastUnderlinedIndex = lastCodeOfSpecificGroup.lastIndexOf(Constants.UNDERLINED); int currentNumber = Integer.parseInt(lastCodeOfSpecificGroup.substring(lastUnderlinedIndex + 1)); String formattedNumber = String.format("%0" + NUM_DIGITS + "d", ++currentNumber); return supplyGroupCode + Constants.UNDERLINED + formattedNumber; }