diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index 68d67983..ee165f63 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -1152,6 +1152,8 @@ public class ApplicationAmendmentRequestDao { ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(applicationAmendmentRequestEntity); Long currentResponseDays = applicationAmendmentRequestEntity.getResponseDays() != null ? applicationAmendmentRequestEntity.getResponseDays() : 0L; applicationAmendmentRequestEntity.setResponseDays(currentResponseDays + newResponseDays); + applicationAmendmentRequestEntity.setExtendedDays(newResponseDays); + applicationAmendmentRequestEntity.setExtensionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); applicationAmendmentRequestEntity.setEndDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now().plusDays(newResponseDays))); applicationAmendmentRequestEntity.setStatus(ApplicationAmendmentRequestEnum.AWAITING.getValue()); applicationAmendmentRequestEntity.getApplicationEvaluationEntity().setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue()); @@ -1640,53 +1642,53 @@ public class ApplicationAmendmentRequestDao { return updated; } - public long calculateSuspendedDays(List amendments) { - List> periods = amendments.stream() - .filter(amendmentRequest -> amendmentRequest.getStartDate() != null) - .map(amendmentRequest -> { - LocalDateTime start = amendmentRequest.getStartDate(); - LocalDateTime end; - - String status = amendmentRequest.getStatus(); - if (Boolean.TRUE.equals(ApplicationAmendmentRequestEnum.CLOSE.getValue().equals(status)) && amendmentRequest.getClosingDate() != null) { - end = amendmentRequest.getClosingDate(); - } else if (Boolean.TRUE.equals(ApplicationAmendmentRequestEnum.EXPIRED.getValue().equals(status)) && amendmentRequest.getEndDate() != null) { - end = amendmentRequest.getStartDate().plusDays(amendmentRequest.getResponseDays()); - }else { - end= amendmentRequest.getEndDate(); - } - - return Pair.of(start, end); - }) - .filter(Objects::nonNull) - .sorted(Comparator.comparing(Pair::getLeft)) - .collect(Collectors.toList()); - - long totalDays = 0; - LocalDateTime currentStart = null; - LocalDateTime currentEnd = null; - - for (Pair period : periods) { - if (currentStart == null) { - currentStart = period.getLeft(); - currentEnd = period.getRight(); - } else if (!period.getLeft().isAfter(currentEnd)) { - // Merge overlapping/touching periods - currentEnd = currentEnd.isAfter(period.getRight()) ? currentEnd : period.getRight(); - } else { - // Non-overlapping: count previous period - totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate()); - currentStart = period.getLeft(); - currentEnd = period.getRight(); - } - } - - if (currentStart != null && currentEnd != null) { - totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate()); - } - - return totalDays; - } +// public long calculateSuspendedDays(List amendments) { +// List> periods = amendments.stream() +// .filter(amendmentRequest -> amendmentRequest.getStartDate() != null) +// .map(amendmentRequest -> { +// LocalDateTime start = amendmentRequest.getStartDate(); +// LocalDateTime end; +// +// String status = amendmentRequest.getStatus(); +// if (Boolean.TRUE.equals(ApplicationAmendmentRequestEnum.CLOSE.getValue().equals(status)) && amendmentRequest.getClosingDate() != null) { +// end = amendmentRequest.getClosingDate(); +// } else if (Boolean.TRUE.equals(ApplicationAmendmentRequestEnum.EXPIRED.getValue().equals(status)) && amendmentRequest.getEndDate() != null) { +// end = amendmentRequest.getStartDate().plusDays(amendmentRequest.getResponseDays()); +// }else { +// end= amendmentRequest.getEndDate(); +// } +// +// return Pair.of(start, end); +// }) +// .filter(Objects::nonNull) +// .sorted(Comparator.comparing(Pair::getLeft)) +// .collect(Collectors.toList()); +// +// long totalDays = 0; +// LocalDateTime currentStart = null; +// LocalDateTime currentEnd = null; +// +// for (Pair period : periods) { +// if (currentStart == null) { +// currentStart = period.getLeft(); +// currentEnd = period.getRight(); +// } else if (!period.getLeft().isAfter(currentEnd)) { +// // Merge overlapping/touching periods +// currentEnd = currentEnd.isAfter(period.getRight()) ? currentEnd : period.getRight(); +// } else { +// // Non-overlapping: count previous period +// totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate()); +// currentStart = period.getLeft(); +// currentEnd = period.getRight(); +// } +// } +// +// if (currentStart != null && currentEnd != null) { +// totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate()); +// } +// +// return totalDays; +// } @@ -1712,4 +1714,65 @@ public class ApplicationAmendmentRequestDao { } return applicationAmendmentRequestEntity; } + public long calculateSuspendedDays(List amendments) { + List> periods = amendments.stream() + .filter(amendmentRequest -> amendmentRequest.getStartDate() != null) + .flatMap(amendmentRequest -> { + List> result = new ArrayList<>(); + + LocalDateTime start = amendmentRequest.getStartDate(); + String status = amendmentRequest.getStatus(); + Long responseDays = amendmentRequest.getResponseDays() != null ? amendmentRequest.getResponseDays() : 0L; + LocalDateTime extensionDate = amendmentRequest.getExtensionDate(); + Long extendedDays = amendmentRequest.getExtendedDays() != null ? amendmentRequest.getExtendedDays() : 0L; + + if (ApplicationAmendmentRequestEnum.CLOSE.getValue().equals(status) && amendmentRequest.getClosingDate() != null) { + if (extensionDate != null && amendmentRequest.getClosingDate().isAfter(extensionDate)) { + long overlappingExtensionDays = ChronoUnit.DAYS.between(extensionDate.toLocalDate(), amendmentRequest.getClosingDate().toLocalDate()); + long adjustedInitialPeriod = responseDays - overlappingExtensionDays; + + result.add(Pair.of(start, start.plusDays(adjustedInitialPeriod))); + } else { + result.add(Pair.of(start, amendmentRequest.getClosingDate())); + } + } else if (ApplicationAmendmentRequestEnum.EXPIRED.getValue().equals(status)) { + result.add(Pair.of(start, start.plusDays(responseDays))); + } else { + if (amendmentRequest.getEndDate() != null) { + result.add(Pair.of(start, amendmentRequest.getEndDate())); + } else { + result.add(Pair.of(start, start.plusDays(responseDays))); + } + } + + return result.stream(); + }) + .filter(Objects::nonNull) + .sorted(Comparator.comparing(Pair::getLeft)) + .collect(Collectors.toList()); + + long totalDays = 0; + LocalDateTime currentStart = null; + LocalDateTime currentEnd = null; + + for (Pair period : periods) { + if (currentStart == null) { + currentStart = period.getLeft(); + currentEnd = period.getRight(); + } else if (!period.getLeft().isAfter(currentEnd)) { + currentEnd = currentEnd.isAfter(period.getRight()) ? currentEnd : period.getRight(); + } else { + totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate()); + currentStart = period.getLeft(); + currentEnd = period.getRight(); + } + } + + if (currentStart != null && currentEnd != null) { + totalDays += ChronoUnit.DAYS.between(currentStart.toLocalDate(), currentEnd.toLocalDate()); + } + + return totalDays; + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java index c0112618..b9af1ca8 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java @@ -61,4 +61,11 @@ public class ApplicationAmendmentRequestEntity extends BaseEntity { @Convert(converter = EmailSendResponseConverter.class) @Column(name = "EMAIL_SEND_RESPONSE", columnDefinition = "TEXT") private List emailSendResponse; + + @Column(name = "EXTENDED_DAYS") + private Long extendedDays; + + @Column(name = "EXTENSION_DATE") + private LocalDateTime extensionDate; + } diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index 3debb704..61de71f6 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -3008,4 +3008,11 @@ + + + + + + +