Updated code for call exipration
This commit is contained in:
@@ -796,6 +796,7 @@ public class CallDao {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
|
||||
}
|
||||
expirePublishedCalls(request);
|
||||
Specification<CallEntity> spec = buildCallSpecification(request, user, companyId, onlyPreferredCall, onlyConfidiCall, callStatusList);
|
||||
|
||||
List<CallEntity> calls = callRepository.findAll(spec);
|
||||
@@ -959,7 +960,7 @@ public class CallDao {
|
||||
Status.NOT_FOUND,
|
||||
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());
|
||||
|
||||
if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) ||
|
||||
@@ -1000,6 +1001,7 @@ public class CallDao {
|
||||
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL)
|
||||
);
|
||||
}
|
||||
expirePublishedCalls(request);
|
||||
Specification<CallEntity> spec = search(request,user, callPageableRequestBean);
|
||||
Page<CallEntity> entityPage;
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
||||
@@ -1078,7 +1080,6 @@ public class CallDao {
|
||||
|
||||
private List<Predicate> getPredicates(HttpServletRequest request,CallPageableRequestBean callPageableRequestBean,
|
||||
CriteriaBuilder criteriaBuilder, Root<CallEntity> root, UserEntity userEntity) {
|
||||
expirePublishedCalls(request);
|
||||
Integer year = null;
|
||||
String search = null;
|
||||
Map<String, FilterCriteria> filters = new HashMap<>();
|
||||
@@ -1162,42 +1163,24 @@ public class CallDao {
|
||||
}
|
||||
|
||||
public void expirePublishedCalls(HttpServletRequest request) {
|
||||
List<CallEntity> expiredCalls = callRepository.findAll((root, query, criteriaBuilder) -> {
|
||||
Predicate isPublished = criteriaBuilder.equal(root.get(GepafinConstant.STATUS), CallStatusEnum.PUBLISH.name());
|
||||
|
||||
// Concatenate date and time as a single string
|
||||
Expression<String> dateTimeString = criteriaBuilder.concat(
|
||||
root.get(GepafinConstant.END_DATE),
|
||||
criteriaBuilder.literal(" ") // Space between date and time
|
||||
);
|
||||
Expression<String> fullDateTimeString = criteriaBuilder.concat(dateTimeString, root.get(GepafinConstant.END_TIME));
|
||||
|
||||
// Convert the concatenated string into TIMESTAMP
|
||||
Expression<LocalDateTime> endDateTime = criteriaBuilder.function(
|
||||
"to_timestamp",
|
||||
LocalDateTime.class,
|
||||
fullDateTimeString,
|
||||
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) {
|
||||
|
||||
|
||||
LocalDate currentDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now()).toLocalDate();
|
||||
LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now());
|
||||
|
||||
List<CallEntity> expirdedCallList = callRepository.findExpiredCallsWhichIsPublished(CallStatusEnum.PUBLISH.getValue(), currentDate, currentTime);
|
||||
|
||||
if (!expirdedCallList.isEmpty()) {
|
||||
|
||||
loggingUtil.logUserAction(UserActionRequest.builder()
|
||||
.request(request)
|
||||
.actionType(UserActionLogsEnum.UPDATE)
|
||||
.actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
|
||||
.build());
|
||||
for (CallEntity call : expirdedCallList) {
|
||||
CallEntity oldCallEntity = Utils.getClonedEntityForData(call); // Clone before modification
|
||||
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
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
|
||||
.request(request)
|
||||
@@ -1205,9 +1188,8 @@ public class CallDao {
|
||||
.oldData(oldCallEntity)
|
||||
.newData(call)
|
||||
.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) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
@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);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@@ -28,11 +28,6 @@ public class DateTimeUtil {
|
||||
LocalDateTime localDatetime = ldtZoned.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalDateTime();
|
||||
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) {
|
||||
ZonedDateTime zonedDateTime = systemTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault());
|
||||
|
||||
Reference in New Issue
Block a user