From 24e11794bc2660d6baaf7ba498278358c6cc3e07 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Thu, 21 May 2026 18:08:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(update):=20=E7=A7=BB=E9=99=A4=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E9=87=8D=E5=A4=8D=E6=A3=80=E6=9F=A5=E5=B9=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8F=91=E5=B8=83=E7=8A=B6=E6=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了应用包名和版本号的重复上传检查逻辑 - 修改了发布立即生效时的状态变更机制,改为将其他已发布版本标记为废弃状态 - 新增了按应用键、平台和发布状态查询的方法 - 简化了版本上传时的验证流程,移除了APK文件MD5比较相关代码 --- .../controller/AppVersionController.java | 29 +++++-------------- .../repository/AppVersionRepository.java | 5 +++- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/update-service/src/main/java/com/xuqm/update/controller/AppVersionController.java b/update-service/src/main/java/com/xuqm/update/controller/AppVersionController.java index c4b5bef..ff5219d 100644 --- a/update-service/src/main/java/com/xuqm/update/controller/AppVersionController.java +++ b/update-service/src/main/java/com/xuqm/update/controller/AppVersionController.java @@ -148,28 +148,6 @@ public class AppVersionController { if (platform == AppVersionEntity.Platform.ANDROID && !hasText(apkUrl) && (apkFile == null || apkFile.isEmpty())) { throw new IllegalArgumentException("apkUrl or apkFile is required for ANDROID releases"); } - // Duplicate version check - if (hasText(resolvedPackageName)) { - java.util.Optional existing = versionRepository - .findByAppKeyAndPlatformAndPackageNameAndVersionCode( - appKey, platform, resolvedPackageName, resolvedVersionCode); - if (existing.isPresent()) { - throw new IllegalArgumentException( - "版本已存在,不能重复上传:" + resolvedVersionName + " · " + resolvedVersionCode); - } - // Check if same versionCode exists with any store already live - java.util.List sameCodeVersions = versionRepository - .findByAppKeyAndPlatformAndPackageNameAndVersionCodeAndPublishStatus( - appKey, platform, resolvedPackageName, resolvedVersionCode, - AppVersionEntity.PublishStatus.PUBLISHED); - if (!sameCodeVersions.isEmpty() && inspected != null) { - // If a published version with same code exists, compare APK md5 - // This is a conservative check; we can't easily compare md5 here without downloading, - // so we just block if same versionCode was ever published - throw new IllegalArgumentException( - "应用商店已上线相同版本号,不允许重复上传:" + resolvedVersionName + " · " + resolvedVersionCode); - } - } AppVersionEntity entity = new AppVersionEntity(); entity.setId(UUID.randomUUID().toString()); entity.setAppKey(appKey); @@ -254,6 +232,13 @@ public class AppVersionController { AppVersionEntity.PublishStatus previousStatus = entity.getPublishStatus(); entity.setForceUpdate(forceUpdate); if (publishImmediately && (scheduledPublishAt == null || scheduledPublishAt.isBlank())) { + for (AppVersionEntity live : versionRepository.findByAppKeyAndPlatformAndPublishStatus( + entity.getAppKey(), entity.getPlatform(), AppVersionEntity.PublishStatus.PUBLISHED)) { + if (!live.getId().equals(entity.getId())) { + live.setPublishStatus(AppVersionEntity.PublishStatus.DEPRECATED); + versionRepository.save(live); + } + } entity.setPublishStatus(AppVersionEntity.PublishStatus.PUBLISHED); entity.setScheduledPublishAt(null); } else { diff --git a/update-service/src/main/java/com/xuqm/update/repository/AppVersionRepository.java b/update-service/src/main/java/com/xuqm/update/repository/AppVersionRepository.java index 8cb3a78..c9dfe57 100644 --- a/update-service/src/main/java/com/xuqm/update/repository/AppVersionRepository.java +++ b/update-service/src/main/java/com/xuqm/update/repository/AppVersionRepository.java @@ -43,7 +43,10 @@ public interface AppVersionRepository extends JpaRepository findByAppKeyAndPlatformAndVersionCodeAndIdNot( String appKey, AppVersionEntity.Platform platform, int versionCode, String id); - Optional findByAppKeyAndPlatformAndPackageNameAndVersionCode( + List findByAppKeyAndPlatformAndPublishStatus( + String appKey, AppVersionEntity.Platform platform, AppVersionEntity.PublishStatus status); + + List findByAppKeyAndPlatformAndPackageNameAndVersionCode( String appKey, AppVersionEntity.Platform platform, String packageName, int versionCode); List findByAppKeyAndPlatformAndPackageNameAndVersionCodeAndPublishStatus(