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(