diff --git a/business/src/main/java/com/kevinguanchedarias/owgejava/business/ActiveTimeSpecialBo.java b/business/src/main/java/com/kevinguanchedarias/owgejava/business/ActiveTimeSpecialBo.java index 91168af0..896b7ffc 100644 --- a/business/src/main/java/com/kevinguanchedarias/owgejava/business/ActiveTimeSpecialBo.java +++ b/business/src/main/java/com/kevinguanchedarias/owgejava/business/ActiveTimeSpecialBo.java @@ -165,7 +165,6 @@ public ActiveTimeSpecial activate(Integer timeSpecialId) { newActive.setActivationDate(new Date()); newActive.setExpiringDate(computeExpiringDate(timeSpecial.getDuration())); newActive.setState(TimeSpecialStateEnum.ACTIVE); - definePendingTime(newActive); newActive.setTimeSpecial(timeSpecial); var user = userSessionService.findLoggedInWithDetails(); newActive.setUser(user); @@ -218,7 +217,6 @@ public Class getDtoClass() { @Override public ActiveTimeSpecial onFind(ActiveTimeSpecial activeTimeSpecial) { - definePendingTime(activeTimeSpecial); return activeTimeSpecial; } @@ -293,16 +291,6 @@ private Date computeExpiringDate(Long time) { return new Date(difference); } - private void definePendingTime(ActiveTimeSpecial activeTimeSpecial) { - if (activeTimeSpecial != null) { - if (activeTimeSpecial.getState() == TimeSpecialStateEnum.ACTIVE) { - activeTimeSpecial.setPendingTime(activeTimeSpecial.getExpiringDate().getTime() - new Date().getTime()); - } else { - activeTimeSpecial.setPendingTime(activeTimeSpecial.getReadyDate().getTime() - new Date().getTime()); - } - } - } - private Long resolveTaskId(ScheduledTask task) { if (task.getContent() instanceof Double doubleValue) { return doubleValue.longValue(); diff --git a/business/src/main/java/com/kevinguanchedarias/owgejava/dto/ActiveTimeSpecialDto.java b/business/src/main/java/com/kevinguanchedarias/owgejava/dto/ActiveTimeSpecialDto.java index b0fda630..4a3a0a95 100644 --- a/business/src/main/java/com/kevinguanchedarias/owgejava/dto/ActiveTimeSpecialDto.java +++ b/business/src/main/java/com/kevinguanchedarias/owgejava/dto/ActiveTimeSpecialDto.java @@ -24,7 +24,7 @@ public class ActiveTimeSpecialDto implements DtoFromEntity { private TimeSpecialStateEnum state; private Date activationDate; private Date expiringDate; - private Long pendingTime; + private Long pendingMillis; private Date readyDate; @Override @@ -33,8 +33,20 @@ public void dtoFromEntity(ActiveTimeSpecial entity) { state = entity.getState(); activationDate = entity.getActivationDate(); expiringDate = entity.getExpiringDate(); - pendingTime = entity.getPendingTime(); readyDate = entity.getReadyDate(); + calculatePendingMillis(); timeSpecial = entity.getTimeSpecial().getId(); } + + /** + * Calculates the pending millis, is a public method because maybe it has to be recalculated + * on cache results by @{@link com.kevinguanchedarias.taggablecache.aspect.TaggableCacheable} + */ + public void calculatePendingMillis() { + if (state == TimeSpecialStateEnum.ACTIVE) { + pendingMillis = (expiringDate.getTime() - new Date().getTime()); + } else { + pendingMillis = (readyDate.getTime() - new Date().getTime()); + } + } } diff --git a/game-frontend/CHANGELOG.md b/game-frontend/CHANGELOG.md index 1ca84131..920e7c35 100644 --- a/game-frontend/CHANGELOG.md +++ b/game-frontend/CHANGELOG.md @@ -7,7 +7,8 @@ v0.11.5 (latest) * __Improvememnt:__ [Allow to know that a mission is invisible to the mission sender user #532](https://github.com/KevinGuancheDarias/owge/issues/532) * __Fix:__ [In Neon the gather reports don't show properly the resources, they have free width and height #523](https://github.com/KevinGuancheDarias/owge/issues/523) * __Improvememnt:__ [Add button to mark all messages as read #514](https://github.com/KevinGuancheDarias/owge/issues/514) -* __Fix:__ [Deployment to non owned planet, and then EB mission to other planet, and them from that planet deploy to other non owned planet, would bug the deploy mission #541](https://github.com/KevinGuancheDarias/owge/issues/541) +* __Fix:__ [Deployment to non owned planet, and then EB mission to other planet, and them from that planet deploy to other non owned planet, would bug the deploy mission #541](https://github.com/KevinGuancheDarias/owge/issues/541) +* __Fix:__ [When you force sync the time special's countdown gets weird #530](https://github.com/KevinGuancheDarias/owge/issues/530) v0.11.4 (2024-02-08 05:39) ================== diff --git a/game-rest/src/main/java/com/kevinguanchedarias/owgejava/rest/game/TimeSpecialRestService.java b/game-rest/src/main/java/com/kevinguanchedarias/owgejava/rest/game/TimeSpecialRestService.java index 1e025a3a..1dc8736a 100644 --- a/game-rest/src/main/java/com/kevinguanchedarias/owgejava/rest/game/TimeSpecialRestService.java +++ b/game-rest/src/main/java/com/kevinguanchedarias/owgejava/rest/game/TimeSpecialRestService.java @@ -22,7 +22,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.annotation.ApplicationScope; +import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; @@ -70,8 +72,19 @@ public RestCrudConfigBuilder> findSyncHandlers() { return SyncHandlerBuilder.create() - .withHandler("time_special_change", activeTimeSpecialBo::findByUserWithCurrentStatus) + .withHandler("time_special_change", user -> { + var retVal = activeTimeSpecialBo.findByUserWithCurrentStatus(user); + recomputeDates(retVal); + return retVal; + }) .build(); } + private void recomputeDates(List timeSpecialDtoList) { + timeSpecialDtoList.stream() + .map(TimeSpecialDto::getActiveTimeSpecialDto) + .filter(Objects::nonNull) + .forEach(ActiveTimeSpecialDto::calculatePendingMillis); + } + }