Updated code for call exipration

This commit is contained in:
rajesh
2025-04-01 18:09:01 +05:30
parent 0d7306cf78
commit 51eb7172d3
3 changed files with 24 additions and 42 deletions

View File

@@ -796,6 +796,7 @@ public class CallDao {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL)); Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
} }
expirePublishedCalls(request);
Specification<CallEntity> spec = buildCallSpecification(request, user, companyId, onlyPreferredCall, onlyConfidiCall, callStatusList); Specification<CallEntity> spec = buildCallSpecification(request, user, companyId, onlyPreferredCall, onlyConfidiCall, callStatusList);
List<CallEntity> calls = callRepository.findAll(spec); List<CallEntity> calls = callRepository.findAll(spec);
@@ -959,7 +960,7 @@ public class CallDao {
Status.NOT_FOUND, Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED)); Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED));
} }
LocalDate currentDate = DateTimeUtil.LocalDateServerToEurope(LocalDate.now()); LocalDate currentDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now()).toLocalDate();
LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now()); LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now());
if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) || if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) ||
@@ -1000,6 +1001,7 @@ public class CallDao {
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL) Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL)
); );
} }
expirePublishedCalls(request);
Specification<CallEntity> spec = search(request,user, callPageableRequestBean); Specification<CallEntity> spec = search(request,user, callPageableRequestBean);
Page<CallEntity> entityPage; Page<CallEntity> entityPage;
if (Boolean.TRUE.equals(onlyPreferredCall)) { if (Boolean.TRUE.equals(onlyPreferredCall)) {
@@ -1078,7 +1080,6 @@ public class CallDao {
private List<Predicate> getPredicates(HttpServletRequest request,CallPageableRequestBean callPageableRequestBean, private List<Predicate> getPredicates(HttpServletRequest request,CallPageableRequestBean callPageableRequestBean,
CriteriaBuilder criteriaBuilder, Root<CallEntity> root, UserEntity userEntity) { CriteriaBuilder criteriaBuilder, Root<CallEntity> root, UserEntity userEntity) {
expirePublishedCalls(request);
Integer year = null; Integer year = null;
String search = null; String search = null;
Map<String, FilterCriteria> filters = new HashMap<>(); Map<String, FilterCriteria> filters = new HashMap<>();
@@ -1162,42 +1163,24 @@ public class CallDao {
} }
public void expirePublishedCalls(HttpServletRequest request) { public void expirePublishedCalls(HttpServletRequest request) {
List<CallEntity> expiredCalls = callRepository.findAll((root, query, criteriaBuilder) -> {
Predicate isPublished = criteriaBuilder.equal(root.get(GepafinConstant.STATUS), CallStatusEnum.PUBLISH.name());
LocalDate currentDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now()).toLocalDate();
// Concatenate date and time as a single string LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now());
Expression<String> dateTimeString = criteriaBuilder.concat(
root.get(GepafinConstant.END_DATE), List<CallEntity> expirdedCallList = callRepository.findExpiredCallsWhichIsPublished(CallStatusEnum.PUBLISH.getValue(), currentDate, currentTime);
criteriaBuilder.literal(" ") // Space between date and time
); if (!expirdedCallList.isEmpty()) {
Expression<String> fullDateTimeString = criteriaBuilder.concat(dateTimeString, root.get(GepafinConstant.END_TIME));
loggingUtil.logUserAction(UserActionRequest.builder()
// Convert the concatenated string into TIMESTAMP .request(request)
Expression<LocalDateTime> endDateTime = criteriaBuilder.function( .actionType(UserActionLogsEnum.UPDATE)
"to_timestamp", .actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
LocalDateTime.class, .build());
fullDateTimeString, for (CallEntity call : expirdedCallList) {
criteriaBuilder.literal("YYYY-MM-DD HH24:MI:SS")
);
Predicate isExpired = criteriaBuilder.lessThan(endDateTime, LocalDateTime.now());
return criteriaBuilder.and(isPublished, isExpired);
});
if (!expiredCalls.isEmpty()) {
for (CallEntity call : expiredCalls) {
CallEntity oldCallEntity = Utils.getClonedEntityForData(call); // Clone before modification CallEntity oldCallEntity = Utils.getClonedEntityForData(call); // Clone before modification
call.setStatus(CallStatusEnum.EXPIRED.getValue()); call.setStatus(CallStatusEnum.EXPIRED.getValue());
if (!oldCallEntity.getStatus().equals(call.getStatus())) {
// Log user action
loggingUtil.logUserAction(UserActionRequest.builder()
.request(request)
.actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
.build());
// Add version history log // Add version history log
loggingUtil.addVersionHistory(VersionHistoryRequest.builder() loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
.request(request) .request(request)
@@ -1205,9 +1188,8 @@ public class CallDao {
.oldData(oldCallEntity) .oldData(oldCallEntity)
.newData(call) .newData(call)
.build()); .build());
}
} }
callRepository.saveAll(expiredCalls); // Save all modified calls at once callRepository.saveAll(expirdedCallList); // Save all modified calls at once
} }
} }
private void applyFilters(Root<?> root, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Map<String, FilterCriteria> filters) { private void applyFilters(Root<?> root, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Map<String, FilterCriteria> filters) {

View File

@@ -7,6 +7,8 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List; import java.util.List;
@Repository @Repository
@@ -58,5 +60,8 @@ public interface CallRepository extends JpaRepository<CallEntity, Long>, JpaSpec
List<CallEntity> findByIdInAndStatusInAndConfidi(@Param("ids") List<Long> ids, @Param("status") List<String> status,Boolean confidi); List<CallEntity> findByIdInAndStatusInAndConfidi(@Param("ids") List<Long> ids, @Param("status") List<String> status,Boolean confidi);
public List<CallEntity> findByStatusInAndHubIdAndConfidi(List<String> callStatus, Long hubId,Boolean onlyConfidiCall); public List<CallEntity> findByStatusInAndHubIdAndConfidi(List<String> callStatus, Long hubId,Boolean onlyConfidiCall);
@Query("SELECT c FROM CallEntity c WHERE c.status = :status AND (FUNCTION('DATE', c.endDate) < :endDate OR (FUNCTION('DATE', c.endDate) = :endDate AND c.endTime <= :endTime))")
List<CallEntity> findExpiredCallsWhichIsPublished(@Param("status") String status, @Param("endDate") LocalDate endDate, @Param("endTime") LocalTime endTime);
} }

View File

@@ -28,11 +28,6 @@ public class DateTimeUtil {
LocalDateTime localDatetime = ldtZoned.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalDateTime(); LocalDateTime localDatetime = ldtZoned.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalDateTime();
return localDatetime; return localDatetime;
} }
public static LocalDate LocalDateServerToEurope(LocalDate systemDate) {
ZonedDateTime zonedDateTime = systemDate.atStartOfDay(ZoneId.systemDefault());
return zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalDate();
}
public static LocalTime LocalTimeServerToEurope(LocalTime systemTime) { public static LocalTime LocalTimeServerToEurope(LocalTime systemTime) {
ZonedDateTime zonedDateTime = systemTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()); ZonedDateTime zonedDateTime = systemTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault());