| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | private final Cache cache; |
| | | |
| | | private final PrizeActivityService prizeActivityService; |
| | | |
| | | @GetMapping("/hideActivityPopupToday") |
| | | public Result hideActivityPopupToday(){ |
| | | String id = UserContext.getCurrentUser().getId(); |
| | | Object o = cache.get(id); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59); |
| | | long remainingSeconds = ChronoUnit.SECONDS.between(now, endOfDay); |
| | | |
| | | // 确保剩余秒数不为负(极端情况:当前时间正好是23:59:59) |
| | | if (remainingSeconds <= 0) { |
| | | remainingSeconds = 1; // 至少保留1秒,避免缓存立即失效 |
| | | } |
| | | if (o == null){ |
| | | cache.put(id,id,remainingSeconds, TimeUnit.SECONDS); |
| | | |
| | | return Result.ok(); |
| | | }else { |
| | | cache.remove(id); |
| | | cache.put(id,id,remainingSeconds, TimeUnit.SECONDS); |
| | | |
| | | return Result.ok(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @GetMapping("/setPopupRedisTime") |
| | | public Result setPopupRedisTime(){ |
| | | String id = UserContext.getCurrentUser().getId(); |
| | | |
| | | Object o = cache.get(id); |
| | | if (o == null){ |
| | | cache.put(id,id,10L, TimeUnit.SECONDS); |