Updated code for call exipration
This commit is contained in:
@@ -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,41 +1163,23 @@ 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());
|
|
||||||
|
|
||||||
// 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
|
LocalDate currentDate = DateTimeUtil.DateServerToUTC(LocalDateTime.now()).toLocalDate();
|
||||||
Expression<LocalDateTime> endDateTime = criteriaBuilder.function(
|
LocalTime currentTime = DateTimeUtil.LocalTimeServerToEurope(LocalTime.now());
|
||||||
"to_timestamp",
|
|
||||||
LocalDateTime.class,
|
|
||||||
fullDateTimeString,
|
|
||||||
criteriaBuilder.literal("YYYY-MM-DD HH24:MI:SS")
|
|
||||||
);
|
|
||||||
|
|
||||||
Predicate isExpired = criteriaBuilder.lessThan(endDateTime, LocalDateTime.now());
|
List<CallEntity> expirdedCallList = callRepository.findExpiredCallsWhichIsPublished(CallStatusEnum.PUBLISH.getValue(), currentDate, currentTime);
|
||||||
|
|
||||||
return criteriaBuilder.and(isPublished, isExpired);
|
if (!expirdedCallList.isEmpty()) {
|
||||||
});
|
|
||||||
|
|
||||||
if (!expiredCalls.isEmpty()) {
|
|
||||||
for (CallEntity call : expiredCalls) {
|
|
||||||
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()
|
loggingUtil.logUserAction(UserActionRequest.builder()
|
||||||
.request(request)
|
.request(request)
|
||||||
.actionType(UserActionLogsEnum.UPDATE)
|
.actionType(UserActionLogsEnum.UPDATE)
|
||||||
.actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
|
.actionContext(UserActionContextEnum.UPDATE_EXPIRED_CALL)
|
||||||
.build());
|
.build());
|
||||||
|
for (CallEntity call : expirdedCallList) {
|
||||||
|
CallEntity oldCallEntity = Utils.getClonedEntityForData(call); // Clone before modification
|
||||||
|
call.setStatus(CallStatusEnum.EXPIRED.getValue());
|
||||||
|
|
||||||
// Add version history log
|
// Add version history log
|
||||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
|
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
|
||||||
@@ -1206,8 +1189,7 @@ public class CallDao {
|
|||||||
.newData(call)
|
.newData(call)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
callRepository.saveAll(expirdedCallList); // Save all modified calls at once
|
||||||
callRepository.saveAll(expiredCalls); // 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) {
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -59,4 +61,7 @@ public interface CallRepository extends JpaRepository<CallEntity, Long>, JpaSpec
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ public class DateTimeUtil {
|
|||||||
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());
|
||||||
return zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalTime();
|
return zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Rome")).toLocalTime();
|
||||||
|
|||||||
Reference in New Issue
Block a user