Code for ticket GEPAFINBE-226

This commit is contained in:
rajesh
2025-07-24 12:22:59 +05:30
parent 113c191a0f
commit 39d3d7dce5
3 changed files with 124 additions and 47 deletions

View File

@@ -1151,6 +1151,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());
@@ -1639,53 +1641,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;
// }
@@ -1711,4 +1713,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;
}
}

View File

@@ -62,4 +62,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;
}

View File

@@ -2829,4 +2829,11 @@
</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>
</databaseChangeLog>