From 5f372d36332b48c4cdc354d0c7c0de0dfa76ef2d Mon Sep 17 00:00:00 2001 From: lixuhuilll <676824363@qq.com> Date: Tue, 12 Dec 2023 17:35:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=AE=A4=E4=B8=BA?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E9=97=AD=E6=97=B6=E9=97=B4=E3=80=82=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E7=83=AD=E5=BA=A6=E6=83=A9=E7=BD=9A=E4=BB=85=E9=99=90?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E4=B8=8A=E4=BC=A0=E6=97=B6=E9=97=B4=E4=BA=8E?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E5=85=B3=E9=97=AD=E5=89=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/copilot/ArkLevelInfo.java | 9 ++++++++- .../backend/repository/entity/ArkLevel.java | 7 ++++++- .../maa/backend/service/ArkLevelService.java | 18 ++++++++++++++++++ .../backend/task/CopilotScoreRefreshTask.java | 8 +++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java b/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java index 27e19731..10579bc3 100644 --- a/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java +++ b/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java @@ -1,5 +1,6 @@ package plus.maa.backend.controller.response.copilot; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Data; @@ -8,6 +9,7 @@ import org.jetbrains.annotations.Nullable; import java.io.Serializable; +import java.time.LocalDateTime; /** * @author john180 @@ -26,7 +28,12 @@ public class ArkLevelInfo implements Serializable { private String name; private int width; private int height; - // 当前版本地图是否开放 + // 只是服务器认为的当前版本地图是否开放 @Nullable + @JsonIgnore private Boolean isOpen; + // 非实际意义上的活动地图关闭时间,只是服务器认为的关闭时间 + @Nullable + @JsonIgnore + private LocalDateTime closeTime; } diff --git a/src/main/java/plus/maa/backend/repository/entity/ArkLevel.java b/src/main/java/plus/maa/backend/repository/entity/ArkLevel.java index fd5d9238..beca9be4 100644 --- a/src/main/java/plus/maa/backend/repository/entity/ArkLevel.java +++ b/src/main/java/plus/maa/backend/repository/entity/ArkLevel.java @@ -9,6 +9,8 @@ import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.mapping.Document; +import java.time.LocalDateTime; + /** * 地图数据 * @@ -39,7 +41,10 @@ public class ArkLevel { private String name; private int width; private int height; - // 当前版本地图是否开放 + // 只是服务器认为的当前版本地图是否开放 @Nullable private Boolean isOpen; + // 非实际意义上的活动地图关闭时间,只是服务器认为的关闭时间 + @Nullable + private LocalDateTime closeTime; } diff --git a/src/main/java/plus/maa/backend/service/ArkLevelService.java b/src/main/java/plus/maa/backend/service/ArkLevelService.java index f8c62ccf..4749bb49 100644 --- a/src/main/java/plus/maa/backend/service/ArkLevelService.java +++ b/src/main/java/plus/maa/backend/service/ArkLevelService.java @@ -34,6 +34,8 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -220,6 +222,10 @@ public void updateActivitiesOpenStatus() { // 分页修改 Pageable pageable = Pageable.ofSize(1000); Page arkLevelPage = arkLevelRepo.findAllByCatOne(catOne, pageable); + + // 获取当前时间 + LocalDateTime nowTime = LocalDateTime.now(); + while (arkLevelPage.hasContent()) { arkLevelPage.forEach(arkLevel -> { @@ -227,9 +233,15 @@ public void updateActivitiesOpenStatus() { if (keyInfos.contains(ArkLevelUtil.getKeyInfoById(arkLevel.getStageId()))) { arkLevel.setIsOpen(true); + // 如果一个旧地图重新开放,关闭时间也需要另算 + arkLevel.setCloseTime(null); } else if (arkLevel.getIsOpen() != null) { // 数据可能存在部分缺失,因此地图此前必须被匹配过,才会认为其关闭 arkLevel.setIsOpen(false); + // 不能每天都变更关闭时间 + if (arkLevel.getCloseTime() == null) { + arkLevel.setCloseTime(nowTime); + } } }); @@ -265,6 +277,7 @@ public void updateCrisisV2OpenStatus() { // 获取当前时间 Instant nowInstant = Instant.now(); + LocalDateTime nowTime = LocalDateTime.ofInstant(nowInstant, ZoneId.systemDefault()); while (arkCrisisV2Page.hasContent()) { @@ -275,6 +288,11 @@ public void updateCrisisV2OpenStatus() { .map(crisisV2Info -> Instant.ofEpochSecond(crisisV2Info.getEndTs())) .ifPresent(endInstant -> arkCrisisV2.setIsOpen(endInstant.isAfter(nowInstant))); + if (arkCrisisV2.getCloseTime() == null && + Boolean.FALSE.equals(arkCrisisV2.getIsOpen())) { + // 危机合约应该不存在赛季重新开放的问题,只要不每天变动关闭时间即可 + arkCrisisV2.setCloseTime(nowTime); + } }); arkLevelRepo.saveAll(arkCrisisV2Page); diff --git a/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java b/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java index 08f115cd..7a61731d 100644 --- a/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java +++ b/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java @@ -110,7 +110,13 @@ private void refresh(Collection copilotIdSTRs, Iterable copilot double hotScore = CopilotService.getHotScore(copilot, likeCount, dislikeCount); // 判断关卡是否开放 ArkLevelInfo arkLevelInfo = arkLevelService.findByLevelIdFuzzy(copilot.getStageName()); - if (arkLevelInfo != null && Boolean.FALSE.equals(arkLevelInfo.getIsOpen())) { + // 关卡已关闭,且作业在关闭前上传 + if (arkLevelInfo != null && + arkLevelInfo.getCloseTime() != null && + copilot.getFirstUploadTime() != null && + Boolean.FALSE.equals(arkLevelInfo.getIsOpen()) && + copilot.getFirstUploadTime().isBefore(arkLevelInfo.getCloseTime())) { + // 非开放关卡打入冷宫 hotScore /= 3; } From aba876173247203a50d11c476d8d8b9b73130290 Mon Sep 17 00:00:00 2001 From: lixuhuilll <676824363@qq.com> Date: Tue, 12 Dec 2023 21:15:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20findByLevelIdFuzzy=20?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E8=AF=A5=E6=96=B9=E6=B3=95=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E4=BB=8E=E6=9C=AA=E7=94=A8=E4=BA=8E=E5=93=8D=E5=BA=94=E7=BB=99?= =?UTF-8?q?=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/response/copilot/ArkLevelInfo.java | 11 ----------- .../plus/maa/backend/service/ArkLevelService.java | 9 ++++----- .../plus/maa/backend/service/CopilotService.java | 9 +++------ .../plus/maa/backend/task/CopilotBackupTask.java | 4 ++-- .../maa/backend/task/CopilotScoreRefreshTask.java | 12 ++++++------ src/main/resources/application.yml | 2 +- 6 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java b/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java index 10579bc3..7df5976d 100644 --- a/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java +++ b/src/main/java/plus/maa/backend/controller/response/copilot/ArkLevelInfo.java @@ -1,15 +1,12 @@ package plus.maa.backend.controller.response.copilot; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import org.jetbrains.annotations.Nullable; import java.io.Serializable; -import java.time.LocalDateTime; /** * @author john180 @@ -28,12 +25,4 @@ public class ArkLevelInfo implements Serializable { private String name; private int width; private int height; - // 只是服务器认为的当前版本地图是否开放 - @Nullable - @JsonIgnore - private Boolean isOpen; - // 非实际意义上的活动地图关闭时间,只是服务器认为的关闭时间 - @Nullable - @JsonIgnore - private LocalDateTime closeTime; } diff --git a/src/main/java/plus/maa/backend/service/ArkLevelService.java b/src/main/java/plus/maa/backend/service/ArkLevelService.java index 4749bb49..833c7c09 100644 --- a/src/main/java/plus/maa/backend/service/ArkLevelService.java +++ b/src/main/java/plus/maa/backend/service/ArkLevelService.java @@ -79,7 +79,7 @@ public class ArkLevelService { private final List bypassFileNames = List.of("overview.json"); - @Cacheable("arkLevels") + @Cacheable("arkLevelInfos") public List getArkLevelInfos() { return arkLevelRepo.findAll() .stream() @@ -88,13 +88,12 @@ public List getArkLevelInfos() { } @Cacheable("arkLevel") - public ArkLevelInfo findByLevelIdFuzzy(String levelId) { - ArkLevel level = arkLevelRepo.findByLevelIdFuzzy(levelId).findAny().orElse(null); - return arkLevelConverter.convert(level); + public ArkLevel findByLevelIdFuzzy(String levelId) { + return arkLevelRepo.findByLevelIdFuzzy(levelId).findAny().orElse(null); } - public List queryLevelByKeyword(String keyword) { + public List queryLevelInfosByKeyword(String keyword) { List levels = arkLevelRepo.queryLevelByKeyword(keyword).collect(Collectors.toList()); return arkLevelConverter.convert(levels); } diff --git a/src/main/java/plus/maa/backend/service/CopilotService.java b/src/main/java/plus/maa/backend/service/CopilotService.java index ee088492..ba5d8839 100644 --- a/src/main/java/plus/maa/backend/service/CopilotService.java +++ b/src/main/java/plus/maa/backend/service/CopilotService.java @@ -29,10 +29,7 @@ import plus.maa.backend.controller.response.copilot.CopilotInfo; import plus.maa.backend.controller.response.copilot.CopilotPageInfo; import plus.maa.backend.repository.*; -import plus.maa.backend.repository.entity.CommentsArea; -import plus.maa.backend.repository.entity.Copilot; -import plus.maa.backend.repository.entity.MaaUser; -import plus.maa.backend.repository.entity.Rating; +import plus.maa.backend.repository.entity.*; import plus.maa.backend.service.model.RatingCache; import plus.maa.backend.service.model.RatingType; @@ -119,7 +116,7 @@ private CopilotDTO correctCopilot(CopilotDTO copilotDTO) { .setName(action.getName() == null ? null : action.getName().replaceAll("[\"“”]", ""))); } // 使用stageId存储作业关卡信息 - ArkLevelInfo level = levelService.findByLevelIdFuzzy(copilotDTO.getStageName()); + ArkLevel level = levelService.findByLevelIdFuzzy(copilotDTO.getStageName()); if (level != null) { copilotDTO.setStageName(level.getStageId()); } @@ -286,7 +283,7 @@ public CopilotPageInfo queriesCopilot(@Nullable String userId, CopilotQueriesReq //关卡名、关卡类型、关卡编号 if (StringUtils.isNotBlank(request.getLevelKeyword())) { - List levelInfo = levelService.queryLevelByKeyword(request.getLevelKeyword()); + List levelInfo = levelService.queryLevelInfosByKeyword(request.getLevelKeyword()); if (levelInfo.isEmpty()) { andQueries.add(Criteria.where("stageName").regex(caseInsensitive(request.getLevelKeyword()))); } else { diff --git a/src/main/java/plus/maa/backend/task/CopilotBackupTask.java b/src/main/java/plus/maa/backend/task/CopilotBackupTask.java index 19da3794..dd56f9c1 100644 --- a/src/main/java/plus/maa/backend/task/CopilotBackupTask.java +++ b/src/main/java/plus/maa/backend/task/CopilotBackupTask.java @@ -15,8 +15,8 @@ import org.springframework.stereotype.Component; import plus.maa.backend.config.external.CopilotBackup; import plus.maa.backend.config.external.MaaCopilotProperties; -import plus.maa.backend.controller.response.copilot.ArkLevelInfo; import plus.maa.backend.repository.CopilotRepository; +import plus.maa.backend.repository.entity.ArkLevel; import plus.maa.backend.repository.entity.Copilot; import plus.maa.backend.service.ArkLevelService; @@ -107,7 +107,7 @@ public void backupCopilots() { File baseDirectory = git.getRepository().getWorkTree(); List copilots = copilotRepository.findAll(); copilots.forEach(copilot -> { - ArkLevelInfo level = levelService.findByLevelIdFuzzy(copilot.getStageName()); + ArkLevel level = levelService.findByLevelIdFuzzy(copilot.getStageName()); if (Objects.isNull(level)) { return; } diff --git a/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java b/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java index 7a61731d..bc9a4aa4 100644 --- a/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java +++ b/src/main/java/plus/maa/backend/task/CopilotScoreRefreshTask.java @@ -10,9 +10,9 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import plus.maa.backend.controller.response.copilot.ArkLevelInfo; import plus.maa.backend.repository.CopilotRepository; import plus.maa.backend.repository.RedisCache; +import plus.maa.backend.repository.entity.ArkLevel; import plus.maa.backend.repository.entity.Copilot; import plus.maa.backend.repository.entity.Rating; import plus.maa.backend.service.ArkLevelService; @@ -109,13 +109,13 @@ private void refresh(Collection copilotIdSTRs, Iterable copilot long dislikeCount = dislikeCountMap.getOrDefault(Long.toString(copilot.getCopilotId()), 0L); double hotScore = CopilotService.getHotScore(copilot, likeCount, dislikeCount); // 判断关卡是否开放 - ArkLevelInfo arkLevelInfo = arkLevelService.findByLevelIdFuzzy(copilot.getStageName()); + ArkLevel level = arkLevelService.findByLevelIdFuzzy(copilot.getStageName()); // 关卡已关闭,且作业在关闭前上传 - if (arkLevelInfo != null && - arkLevelInfo.getCloseTime() != null && + if (level != null && + level.getCloseTime() != null && copilot.getFirstUploadTime() != null && - Boolean.FALSE.equals(arkLevelInfo.getIsOpen()) && - copilot.getFirstUploadTime().isBefore(arkLevelInfo.getCloseTime())) { + Boolean.FALSE.equals(level.getIsOpen()) && + copilot.getFirstUploadTime().isBefore(level.getCloseTime())) { // 非开放关卡打入冷宫 hotScore /= 3; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4ced4110..40a4be83 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,7 +21,7 @@ spring: check-template-location: false # 缓存配置,使用caffeine缓存框架,缓存时长为5分钟,最大缓存数量500 cache: - cache-names: arkLevel, arkLevels, copilotPage + cache-names: arkLevel, arkLevelInfos, copilotPage type: caffeine caffeine: spec: maximumSize=500,expireAfterWrite=300s