Untitled

mail@pastecode.io avatar
unknown
java
a year ago
791 B
1
Indexable
Never
private String generateSupplyCode(Long idSuppliesGroup) {
        String supplyGroupCode = suppliesGroupRepository.findActiveCode(idSuppliesGroup);
        Optional<String> lastCodeOfSpecificGroup = suppliesRepository.findLastCodeByStartWithSuppliesGroupCode(supplyGroupCode);

        if (!lastCodeOfSpecificGroup.isPresent()) {
            String startNumber = "0001";
            return supplyGroupCode + Constants.UNDERLINED + startNumber;
        }

        String[] parts = lastCodeOfSpecificGroup.get().split(Constants.UNDERLINED);
        int currentNumber = Integer.parseInt(parts[parts.length - 1]);
        String formattedNumber = String.format("%0" + NUM_DIGITS + "d", ++currentNumber);
        return supplyGroupCode + Constants.UNDERLINED + formattedNumber;
    }