2026-04-21 22:07:29 +08:00
|
|
|
package com.xuqm.update.controller;
|
|
|
|
|
|
|
|
|
|
import com.xuqm.common.model.ApiResponse;
|
|
|
|
|
import com.xuqm.update.entity.AppVersionEntity;
|
|
|
|
|
import com.xuqm.update.repository.AppVersionRepository;
|
2026-04-29 12:33:25 +08:00
|
|
|
import com.xuqm.update.model.AppPackageInspectResult;
|
2026-04-30 09:49:05 +08:00
|
|
|
import com.xuqm.update.service.UpdateOperationLogService;
|
2026-04-29 17:35:52 +08:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2026-04-21 22:07:29 +08:00
|
|
|
import org.springframework.http.ResponseEntity;
|
2026-04-24 16:16:33 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2026-04-21 22:07:29 +08:00
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.UUID;
|
2026-04-28 21:05:06 +08:00
|
|
|
import com.xuqm.update.service.UpdateAssetService;
|
2026-04-29 19:08:13 +08:00
|
|
|
import com.xuqm.update.service.PublishConfigService;
|
|
|
|
|
import com.xuqm.update.service.AppStoreService;
|
2026-04-21 22:07:29 +08:00
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/v1/updates")
|
|
|
|
|
public class AppVersionController {
|
|
|
|
|
|
2026-04-29 17:35:52 +08:00
|
|
|
private static final Logger log = LoggerFactory.getLogger(AppVersionController.class);
|
|
|
|
|
|
2026-04-21 22:07:29 +08:00
|
|
|
private final AppVersionRepository versionRepository;
|
2026-04-28 21:05:06 +08:00
|
|
|
private final UpdateAssetService updateAssetService;
|
2026-04-29 19:08:13 +08:00
|
|
|
private final PublishConfigService publishConfigService;
|
|
|
|
|
private final AppStoreService appStoreService;
|
2026-04-30 09:49:05 +08:00
|
|
|
private final UpdateOperationLogService operationLogService;
|
2026-04-21 22:07:29 +08:00
|
|
|
|
2026-04-29 19:08:13 +08:00
|
|
|
public AppVersionController(AppVersionRepository versionRepository,
|
|
|
|
|
UpdateAssetService updateAssetService,
|
|
|
|
|
PublishConfigService publishConfigService,
|
2026-04-30 09:49:05 +08:00
|
|
|
AppStoreService appStoreService,
|
|
|
|
|
UpdateOperationLogService operationLogService) {
|
2026-04-21 22:07:29 +08:00
|
|
|
this.versionRepository = versionRepository;
|
2026-04-28 21:05:06 +08:00
|
|
|
this.updateAssetService = updateAssetService;
|
2026-04-29 19:08:13 +08:00
|
|
|
this.publishConfigService = publishConfigService;
|
|
|
|
|
this.appStoreService = appStoreService;
|
2026-04-30 09:49:05 +08:00
|
|
|
this.operationLogService = operationLogService;
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/app/check")
|
|
|
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> checkUpdate(
|
|
|
|
|
@RequestParam String appId,
|
|
|
|
|
@RequestParam AppVersionEntity.Platform platform,
|
|
|
|
|
@RequestParam int currentVersionCode) {
|
|
|
|
|
|
|
|
|
|
Optional<AppVersionEntity> latest = versionRepository
|
2026-04-30 09:49:05 +08:00
|
|
|
.findTopByAppIdAndPlatformAndPublishStatusAndVersionCodeGreaterThanOrderByVersionCodeDesc(
|
|
|
|
|
appId, platform, AppVersionEntity.PublishStatus.PUBLISHED, currentVersionCode);
|
|
|
|
|
Optional<AppVersionEntity> forcedHigher = versionRepository
|
|
|
|
|
.findTopByAppIdAndPlatformAndPublishStatusAndVersionCodeGreaterThanAndForceUpdateTrueOrderByVersionCodeDesc(
|
|
|
|
|
appId, platform, AppVersionEntity.PublishStatus.PUBLISHED, currentVersionCode);
|
2026-04-21 22:07:29 +08:00
|
|
|
|
2026-04-30 09:49:05 +08:00
|
|
|
if (latest.isEmpty()) {
|
2026-04-21 22:07:29 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(Map.of("needsUpdate", false)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppVersionEntity v = latest.get();
|
2026-04-29 19:08:13 +08:00
|
|
|
String appStoreJumpUrl = hasText(v.getAppStoreUrl())
|
|
|
|
|
? v.getAppStoreUrl()
|
|
|
|
|
: appStoreService.getStoreJumpUrl(appId, com.xuqm.update.entity.AppStoreConfigEntity.StoreType.APP_STORE);
|
|
|
|
|
String harmonyJumpUrl = hasText(v.getMarketUrl())
|
|
|
|
|
? v.getMarketUrl()
|
|
|
|
|
: appStoreService.getStoreJumpUrl(appId, com.xuqm.update.entity.AppStoreConfigEntity.StoreType.HARMONY_APP);
|
2026-04-21 22:07:29 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(Map.of(
|
|
|
|
|
"needsUpdate", true,
|
|
|
|
|
"versionName", v.getVersionName(),
|
|
|
|
|
"versionCode", v.getVersionCode(),
|
|
|
|
|
"downloadUrl", v.getDownloadUrl() != null ? v.getDownloadUrl() : "",
|
|
|
|
|
"changeLog", v.getChangeLog() != null ? v.getChangeLog() : "",
|
2026-04-30 09:49:05 +08:00
|
|
|
"forceUpdate", forcedHigher.isPresent(),
|
2026-04-29 19:08:13 +08:00
|
|
|
"appStoreUrl", appStoreJumpUrl,
|
|
|
|
|
"marketUrl", harmonyJumpUrl
|
2026-04-21 22:07:29 +08:00
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/app/upload")
|
|
|
|
|
public ResponseEntity<ApiResponse<AppVersionEntity>> upload(
|
|
|
|
|
@RequestParam String appId,
|
|
|
|
|
@RequestParam AppVersionEntity.Platform platform,
|
2026-04-29 12:33:25 +08:00
|
|
|
@RequestParam(required = false) String versionName,
|
|
|
|
|
@RequestParam(required = false) Integer versionCode,
|
2026-04-21 22:07:29 +08:00
|
|
|
@RequestParam(required = false) String changeLog,
|
|
|
|
|
@RequestParam(defaultValue = "false") boolean forceUpdate,
|
2026-04-29 17:35:52 +08:00
|
|
|
@RequestParam(required = false) String apkUrl,
|
2026-04-29 00:34:17 +08:00
|
|
|
@RequestParam(required = false) MultipartFile apkFile,
|
|
|
|
|
@RequestParam(required = false) String scheduledPublishAt,
|
|
|
|
|
@RequestParam(required = false) String webhookUrl,
|
|
|
|
|
@RequestParam(required = false) String storeSubmitTargets,
|
|
|
|
|
@RequestParam(defaultValue = "false") boolean autoPublishAfterReview,
|
2026-04-29 15:46:40 +08:00
|
|
|
@RequestParam(defaultValue = "false") boolean publishImmediately,
|
|
|
|
|
@RequestParam(required = false) String packageName,
|
2026-04-29 19:08:13 +08:00
|
|
|
@RequestParam(required = false) String expectedPackageName,
|
2026-04-29 15:46:40 +08:00
|
|
|
@RequestParam(required = false) String appStoreUrl,
|
|
|
|
|
@RequestParam(required = false) String marketUrl) throws Exception {
|
2026-04-21 22:07:29 +08:00
|
|
|
|
2026-04-29 17:35:52 +08:00
|
|
|
AppPackageInspectResult inspected = null;
|
|
|
|
|
try {
|
|
|
|
|
inspected = hasText(apkUrl)
|
|
|
|
|
? updateAssetService.inspectAppPackage(apkUrl)
|
|
|
|
|
: (apkFile != null && !apkFile.isEmpty() ? updateAssetService.inspectAppPackage(apkFile) : null);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.warn("Unable to inspect upload package for appId={}, platform={}, source={}, fallback to manual version fields: {}",
|
|
|
|
|
appId, platform, hasText(apkUrl) ? apkUrl : (apkFile != null ? apkFile.getOriginalFilename() : null), ex.getMessage());
|
|
|
|
|
}
|
2026-04-29 15:46:40 +08:00
|
|
|
String resolvedVersionName = hasText(versionName) ? versionName : (inspected != null ? inspected.versionName() : null);
|
|
|
|
|
Integer resolvedVersionCode = versionCode != null ? versionCode : (inspected != null ? inspected.versionCode() : null);
|
|
|
|
|
String resolvedPackageName = hasText(packageName) ? packageName : (inspected != null ? inspected.packageName() : null);
|
2026-04-29 12:33:25 +08:00
|
|
|
if (!hasText(resolvedVersionName) || resolvedVersionCode == null) {
|
|
|
|
|
throw new IllegalArgumentException("versionName and versionCode are required or must be readable from the uploaded package");
|
|
|
|
|
}
|
2026-04-29 19:08:13 +08:00
|
|
|
if (hasText(expectedPackageName) && hasText(resolvedPackageName) && !expectedPackageName.equals(resolvedPackageName)) {
|
|
|
|
|
throw new IllegalArgumentException("packageName does not match current app packageName");
|
2026-04-29 15:46:40 +08:00
|
|
|
}
|
2026-04-29 19:08:13 +08:00
|
|
|
if (platform == AppVersionEntity.Platform.ANDROID && !hasText(apkUrl) && (apkFile == null || apkFile.isEmpty())) {
|
|
|
|
|
throw new IllegalArgumentException("apkUrl or apkFile is required for ANDROID releases");
|
2026-04-29 15:46:40 +08:00
|
|
|
}
|
2026-04-21 22:07:29 +08:00
|
|
|
AppVersionEntity entity = new AppVersionEntity();
|
|
|
|
|
entity.setId(UUID.randomUUID().toString());
|
|
|
|
|
entity.setAppId(appId);
|
|
|
|
|
entity.setPlatform(platform);
|
2026-04-29 12:33:25 +08:00
|
|
|
entity.setVersionName(resolvedVersionName);
|
|
|
|
|
entity.setVersionCode(resolvedVersionCode);
|
2026-04-29 19:08:13 +08:00
|
|
|
entity.setDownloadUrl(platform == AppVersionEntity.Platform.ANDROID
|
|
|
|
|
? (hasText(apkUrl) ? apkUrl : updateAssetService.storeAppPackage(apkFile))
|
|
|
|
|
: null);
|
2026-04-21 22:07:29 +08:00
|
|
|
entity.setChangeLog(changeLog);
|
|
|
|
|
entity.setForceUpdate(forceUpdate);
|
|
|
|
|
entity.setPublishStatus(AppVersionEntity.PublishStatus.DRAFT);
|
|
|
|
|
entity.setCreatedAt(LocalDateTime.now());
|
2026-04-29 19:08:13 +08:00
|
|
|
entity.setStoreSubmitMode("MANUAL");
|
|
|
|
|
entity.setStoreSubmitScheduledAt(null);
|
|
|
|
|
entity.setGrayMode("PERCENT");
|
|
|
|
|
entity.setGrayMemberIds(null);
|
2026-04-29 00:34:17 +08:00
|
|
|
if (scheduledPublishAt != null && !scheduledPublishAt.isBlank()) {
|
|
|
|
|
entity.setScheduledPublishAt(LocalDateTime.parse(scheduledPublishAt));
|
|
|
|
|
}
|
|
|
|
|
entity.setWebhookUrl(webhookUrl);
|
|
|
|
|
entity.setStoreSubmitTargets(storeSubmitTargets);
|
|
|
|
|
entity.setAutoPublishAfterReview(autoPublishAfterReview);
|
2026-04-29 12:33:25 +08:00
|
|
|
entity.setPackageName(resolvedPackageName);
|
2026-04-29 19:08:13 +08:00
|
|
|
entity.setAppStoreUrl(hasText(appStoreUrl)
|
|
|
|
|
? appStoreUrl
|
|
|
|
|
: (platform == AppVersionEntity.Platform.IOS
|
|
|
|
|
? appStoreService.getStoreJumpUrl(appId, com.xuqm.update.entity.AppStoreConfigEntity.StoreType.APP_STORE)
|
|
|
|
|
: null));
|
|
|
|
|
entity.setMarketUrl(hasText(marketUrl)
|
|
|
|
|
? marketUrl
|
|
|
|
|
: (platform == AppVersionEntity.Platform.HARMONY
|
|
|
|
|
? appStoreService.getStoreJumpUrl(appId, com.xuqm.update.entity.AppStoreConfigEntity.StoreType.HARMONY_APP)
|
|
|
|
|
: null));
|
2026-04-29 15:46:40 +08:00
|
|
|
if (publishImmediately) {
|
|
|
|
|
entity.setPublishStatus(AppVersionEntity.PublishStatus.PUBLISHED);
|
|
|
|
|
entity.setGrayEnabled(false);
|
|
|
|
|
entity.setGrayPercent(0);
|
|
|
|
|
}
|
2026-04-30 09:49:05 +08:00
|
|
|
AppVersionEntity saved = versionRepository.save(entity);
|
|
|
|
|
operationLogService.record(
|
|
|
|
|
saved.getAppId(),
|
|
|
|
|
"APP_VERSION",
|
|
|
|
|
saved.getId(),
|
|
|
|
|
"UPLOAD",
|
|
|
|
|
null,
|
|
|
|
|
Map.of(
|
|
|
|
|
"platform", saved.getPlatform().name(),
|
|
|
|
|
"versionName", saved.getVersionName(),
|
|
|
|
|
"versionCode", saved.getVersionCode(),
|
|
|
|
|
"publishImmediately", publishImmediately,
|
|
|
|
|
"forceUpdate", saved.isForceUpdate(),
|
|
|
|
|
"packageName", saved.getPackageName() == null ? "" : saved.getPackageName()
|
|
|
|
|
));
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(saved));
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-29 17:35:52 +08:00
|
|
|
@RequestMapping(value = "/app/inspect", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
|
|
public ResponseEntity<ApiResponse<AppPackageInspectResult>> inspect(
|
|
|
|
|
@RequestParam(required = false) String apkUrl,
|
|
|
|
|
@RequestParam(required = false) MultipartFile apkFile) throws Exception {
|
|
|
|
|
if (hasText(apkUrl)) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(updateAssetService.inspectAppPackage(apkUrl)));
|
|
|
|
|
}
|
2026-04-29 12:33:25 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(updateAssetService.inspectAppPackage(apkFile)));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 22:07:29 +08:00
|
|
|
@PostMapping("/app/{id}/publish")
|
2026-04-29 19:08:13 +08:00
|
|
|
public ResponseEntity<ApiResponse<AppVersionEntity>> publish(
|
|
|
|
|
@PathVariable String id,
|
|
|
|
|
@RequestBody(required = false) Map<String, Object> body) {
|
2026-04-21 22:07:29 +08:00
|
|
|
AppVersionEntity entity = versionRepository.findById(id).orElseThrow();
|
2026-04-29 19:08:13 +08:00
|
|
|
boolean publishImmediately = body == null || !Boolean.FALSE.equals(body.get("publishImmediately"));
|
|
|
|
|
String scheduledPublishAt = body != null && body.get("scheduledPublishAt") != null
|
|
|
|
|
? body.get("scheduledPublishAt").toString() : null;
|
|
|
|
|
boolean forceUpdate = body != null && body.get("forceUpdate") != null
|
|
|
|
|
? Boolean.parseBoolean(body.get("forceUpdate").toString()) : entity.isForceUpdate();
|
2026-04-30 09:49:05 +08:00
|
|
|
AppVersionEntity.PublishStatus previousStatus = entity.getPublishStatus();
|
2026-04-29 19:08:13 +08:00
|
|
|
entity.setForceUpdate(forceUpdate);
|
|
|
|
|
if (publishImmediately && (scheduledPublishAt == null || scheduledPublishAt.isBlank())) {
|
|
|
|
|
entity.setPublishStatus(AppVersionEntity.PublishStatus.PUBLISHED);
|
|
|
|
|
entity.setScheduledPublishAt(null);
|
|
|
|
|
} else {
|
|
|
|
|
entity.setPublishStatus(AppVersionEntity.PublishStatus.DRAFT);
|
|
|
|
|
if (scheduledPublishAt != null && !scheduledPublishAt.isBlank()) {
|
|
|
|
|
entity.setScheduledPublishAt(LocalDateTime.parse(scheduledPublishAt));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-24 16:16:33 +08:00
|
|
|
entity.setGrayEnabled(false);
|
|
|
|
|
entity.setGrayPercent(0);
|
2026-04-29 19:08:13 +08:00
|
|
|
entity.setGrayMode("PERCENT");
|
|
|
|
|
entity.setGrayMemberIds(null);
|
2026-04-30 09:49:05 +08:00
|
|
|
AppVersionEntity saved = versionRepository.save(entity);
|
|
|
|
|
operationLogService.record(
|
|
|
|
|
saved.getAppId(),
|
|
|
|
|
"APP_VERSION",
|
|
|
|
|
saved.getId(),
|
|
|
|
|
publishAction(previousStatus, saved.getPublishStatus(), publishImmediately),
|
|
|
|
|
null,
|
|
|
|
|
Map.of(
|
|
|
|
|
"versionName", saved.getVersionName(),
|
|
|
|
|
"versionCode", saved.getVersionCode(),
|
|
|
|
|
"publishImmediately", publishImmediately,
|
|
|
|
|
"scheduledPublishAt", saved.getScheduledPublishAt() == null ? "" : saved.getScheduledPublishAt().toString(),
|
|
|
|
|
"forceUpdate", saved.isForceUpdate()
|
|
|
|
|
));
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(saved));
|
2026-04-24 16:16:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/app/{id}/unpublish")
|
2026-04-30 09:49:05 +08:00
|
|
|
public ResponseEntity<ApiResponse<AppVersionEntity>> unpublish(
|
|
|
|
|
@PathVariable String id,
|
|
|
|
|
@RequestBody(required = false) Map<String, Object> body) {
|
2026-04-24 16:16:33 +08:00
|
|
|
AppVersionEntity entity = versionRepository.findById(id).orElseThrow();
|
2026-04-30 09:49:05 +08:00
|
|
|
String reason = body != null && body.get("reason") != null ? body.get("reason").toString().trim() : "";
|
|
|
|
|
if (reason.isBlank()) {
|
|
|
|
|
throw new IllegalArgumentException("unpublish reason is required");
|
|
|
|
|
}
|
2026-04-24 16:16:33 +08:00
|
|
|
entity.setPublishStatus(AppVersionEntity.PublishStatus.DEPRECATED);
|
2026-04-30 09:49:05 +08:00
|
|
|
AppVersionEntity saved = versionRepository.save(entity);
|
|
|
|
|
operationLogService.record(
|
|
|
|
|
saved.getAppId(),
|
|
|
|
|
"APP_VERSION",
|
|
|
|
|
saved.getId(),
|
|
|
|
|
"UNPUBLISH",
|
|
|
|
|
reason,
|
|
|
|
|
Map.of(
|
|
|
|
|
"versionName", saved.getVersionName(),
|
|
|
|
|
"versionCode", saved.getVersionCode()
|
|
|
|
|
));
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(saved));
|
2026-04-24 16:16:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/app/{id}/gray")
|
|
|
|
|
public ResponseEntity<ApiResponse<AppVersionEntity>> gray(
|
|
|
|
|
@PathVariable String id,
|
2026-04-29 19:08:13 +08:00
|
|
|
@RequestBody Map<String, Object> body) throws Exception {
|
2026-04-24 16:16:33 +08:00
|
|
|
AppVersionEntity entity = versionRepository.findById(id).orElseThrow();
|
2026-04-29 19:08:13 +08:00
|
|
|
boolean enabled = Boolean.TRUE.equals(body.get("enabled"));
|
|
|
|
|
String grayMode = body.get("grayMode") == null ? "PERCENT" : body.get("grayMode").toString().trim().toUpperCase();
|
|
|
|
|
entity.setGrayEnabled(enabled);
|
|
|
|
|
if (!enabled) {
|
|
|
|
|
entity.setGrayPercent(0);
|
|
|
|
|
entity.setGrayMode("PERCENT");
|
|
|
|
|
entity.setGrayMemberIds(null);
|
|
|
|
|
} else if ("MEMBERS".equals(grayMode)) {
|
|
|
|
|
List<String> memberIds = extractMemberIds(body.get("memberIds"));
|
|
|
|
|
String selectionSource = body.get("selectionSource") == null ? "LOCAL"
|
|
|
|
|
: body.get("selectionSource").toString().trim().toUpperCase();
|
|
|
|
|
if (memberIds.isEmpty() && "CALLBACK".equals(selectionSource)) {
|
|
|
|
|
memberIds = publishConfigService.resolveGrayMembers(entity.getAppId(), body);
|
|
|
|
|
}
|
|
|
|
|
entity.setGrayMode("MEMBERS");
|
|
|
|
|
entity.setGrayMemberIds(toJson(memberIds));
|
|
|
|
|
entity.setGrayPercent(0);
|
|
|
|
|
} else {
|
|
|
|
|
entity.setGrayMode("PERCENT");
|
|
|
|
|
entity.setGrayPercent(body.get("percent") instanceof Number n ? n.intValue() : 0);
|
|
|
|
|
entity.setGrayMemberIds(null);
|
|
|
|
|
}
|
2026-04-24 16:16:33 +08:00
|
|
|
entity.setPublishStatus(AppVersionEntity.PublishStatus.PUBLISHED);
|
2026-04-30 09:49:05 +08:00
|
|
|
AppVersionEntity saved = versionRepository.save(entity);
|
|
|
|
|
operationLogService.record(
|
|
|
|
|
saved.getAppId(),
|
|
|
|
|
"APP_VERSION",
|
|
|
|
|
saved.getId(),
|
|
|
|
|
"GRAY_UPDATE",
|
|
|
|
|
null,
|
|
|
|
|
Map.of(
|
|
|
|
|
"enabled", enabled,
|
|
|
|
|
"grayMode", saved.getGrayMode(),
|
|
|
|
|
"grayPercent", saved.getGrayPercent(),
|
|
|
|
|
"memberCount", saved.getGrayMemberIds() == null ? 0 : extractMemberIds(saved.getGrayMemberIds()).size()
|
|
|
|
|
));
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(saved));
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/app/list")
|
|
|
|
|
public ResponseEntity<ApiResponse<List<AppVersionEntity>>> list(
|
|
|
|
|
@RequestParam String appId, @RequestParam AppVersionEntity.Platform platform) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(
|
|
|
|
|
versionRepository.findByAppIdAndPlatformOrderByVersionCodeDesc(appId, platform)));
|
|
|
|
|
}
|
2026-04-29 12:33:25 +08:00
|
|
|
|
2026-04-30 09:49:05 +08:00
|
|
|
private String publishAction(AppVersionEntity.PublishStatus previousStatus,
|
|
|
|
|
AppVersionEntity.PublishStatus currentStatus,
|
|
|
|
|
boolean publishImmediately) {
|
|
|
|
|
if (!publishImmediately) {
|
|
|
|
|
return "SCHEDULE_PUBLISH";
|
|
|
|
|
}
|
|
|
|
|
if (previousStatus == AppVersionEntity.PublishStatus.PUBLISHED) {
|
|
|
|
|
return "UPDATE_FORCE";
|
|
|
|
|
}
|
|
|
|
|
if (previousStatus == AppVersionEntity.PublishStatus.DEPRECATED) {
|
|
|
|
|
return "REPUBLISH";
|
|
|
|
|
}
|
|
|
|
|
return currentStatus == AppVersionEntity.PublishStatus.PUBLISHED ? "PUBLISH" : "SAVE_DRAFT";
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 12:33:25 +08:00
|
|
|
private boolean hasText(String value) {
|
|
|
|
|
return value != null && !value.isBlank();
|
|
|
|
|
}
|
2026-04-29 19:08:13 +08:00
|
|
|
|
|
|
|
|
private List<String> extractMemberIds(Object raw) {
|
|
|
|
|
if (raw == null) {
|
|
|
|
|
return List.of();
|
|
|
|
|
}
|
|
|
|
|
if (raw instanceof List<?> list) {
|
|
|
|
|
return list.stream()
|
|
|
|
|
.map(String::valueOf)
|
|
|
|
|
.filter(this::hasText)
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
if (raw instanceof String s) {
|
|
|
|
|
if (!hasText(s)) {
|
|
|
|
|
return List.of();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
return java.util.Arrays.stream(s.split(","))
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.filter(this::hasText)
|
|
|
|
|
.toList();
|
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
return List.of();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return List.of();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String toJson(List<String> values) {
|
|
|
|
|
try {
|
|
|
|
|
return new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(values == null ? List.of() : values);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return "[]";
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|