Merge pull request #331 from Kitzanos/feature/GEPAFINBE-226
GEPAFINBE-226 (Amendment: Suspended Days Calculation Bug)
This commit is contained in:
@@ -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<ApplicationAmendmentRequestEntity> amendments) {
|
||||
List<Pair<LocalDateTime, LocalDateTime>> 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<LocalDateTime, LocalDateTime> 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<ApplicationAmendmentRequestEntity> amendments) {
|
||||
// List<Pair<LocalDateTime, LocalDateTime>> 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<LocalDateTime, LocalDateTime> 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<ApplicationAmendmentRequestEntity> amendments) {
|
||||
List<Pair<LocalDateTime, LocalDateTime>> periods = amendments.stream()
|
||||
.filter(amendmentRequest -> amendmentRequest.getStartDate() != null)
|
||||
.flatMap(amendmentRequest -> {
|
||||
List<Pair<LocalDateTime, LocalDateTime>> 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<LocalDateTime, LocalDateTime> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,4 +61,11 @@ public class ApplicationAmendmentRequestEntity extends BaseEntity {
|
||||
@Convert(converter = EmailSendResponseConverter.class)
|
||||
@Column(name = "EMAIL_SEND_RESPONSE", columnDefinition = "TEXT")
|
||||
private List<EmailSendResponse> emailSendResponse;
|
||||
|
||||
@Column(name = "EXTENDED_DAYS")
|
||||
private Long extendedDays;
|
||||
|
||||
@Column(name = "EXTENSION_DATE")
|
||||
private LocalDateTime extensionDate;
|
||||
|
||||
}
|
||||
|
||||
@@ -2955,6 +2955,13 @@
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="03-06-2025_RK_182045" author="Rajesh Khore">
|
||||
<addColumn tableName="application_amendment_request">
|
||||
<column name="extended_days" type="INTEGER"></column>
|
||||
<column name="extension_date" type="TIMESTAMP WITHOUT TIME ZONE"></column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="05-06-2025_RK_191738" author="Rajesh Khore">
|
||||
<sqlFile dbms="postgresql"
|
||||
path="db/dump/updated_form_field_05_06_2025.sql"/>
|
||||
|
||||
Reference in New Issue
Block a user