Skip to content
This repository was archived by the owner on Apr 10, 2022. It is now read-only.

用户当前版本版本与最新版本之间存在强制更新版本,则该次升级即为强制更新 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Created by hzlizx on 2018/6/21 0021
Expand Down Expand Up @@ -70,6 +71,8 @@ public ServiceResult findNewestVersion(String tenantAppId, String version, Strin
}
// 将查询结果再次进行筛选,选出大于传入version的安卓版本,然后再找出最新版本
List<AndroidVersion> androidVersionsResult = new LinkedList<>();
//是否强制更新
AtomicBoolean forceUpdate = new AtomicBoolean(false);
androidVersionsResult.addAll(androidVersions);
if (VersionCompareUtils.compareVersion(version, androidVersions.get(androidVersions.size() - 1).getAppVersion()) > 0) {
Collections.reverse(androidVersions);
Expand All @@ -86,7 +89,11 @@ public ServiceResult findNewestVersion(String tenantAppId, String version, Strin
}
logger.debug("查询到的筛选过的版本:");
androidVersionsResult.forEach(androidVersion -> logger.debug(androidVersion.getAppVersion()));

androidVersionsResult.forEach(androidVersion -> {
if (androidVersion.getUpdateType().equals(0)) {
forceUpdate.set(true);
}
});
//查找指定渠道
logger.debug("查询channelCode为{}的渠道...", channelCode);
Channel channel = new Channel();
Expand Down Expand Up @@ -117,15 +124,15 @@ public ServiceResult findNewestVersion(String tenantAppId, String version, Strin
for (AndroidVersion androidVersion : androidVersionsResult) {
if (channelSelected != null) {
if (channelSelected.getChannelStatus() == 1) {
HashMap<String, Object> apk = this.findApk(androidVersion, appSelected.getId(), channelSelected.getId());
HashMap<String, Object> apk = this.findApk(androidVersion, appSelected.getId(), channelSelected.getId(), forceUpdate.get());
if (apk != null) {
logger.debug("结果:{}", $.json.toJsonString(apk));
return ServiceResult.ok(apk);
}
}
}
if (officialChannel != null) {
HashMap<String, Object> apk = this.findApk(androidVersion, appSelected.getId(), officialChannel.getId());
HashMap<String, Object> apk = this.findApk(androidVersion, appSelected.getId(), officialChannel.getId(), forceUpdate.get());
if (apk != null) {
logger.debug("结果:{}", $.json.toJsonString(apk));
return ServiceResult.ok(apk);
Expand Down Expand Up @@ -234,7 +241,7 @@ private ServiceResult loopSelectAndroidVersions(List<AndroidVersion> list, int a
return null;
}

private HashMap<String, Object> findApk(AndroidVersion androidVersion, int appId, int channelId) {
private HashMap<String, Object> findApk(AndroidVersion androidVersion, int appId, int channelId, boolean forceUpdate) {
int versionId = androidVersion.getId();
Apk apk = new Apk();
apk.setAppId(appId);
Expand All @@ -250,7 +257,7 @@ private HashMap<String, Object> findApk(AndroidVersion androidVersion, int appId
map.put("allowLowestVersion", androidVersion.getAllowLowestVersion());
map.put("downloadUrl", "/v/download/" + apkSelected.getId());
map.put("description", androidVersion.getVersionDescription());
map.put("forceUpdate", androidVersion.getUpdateType());
map.put("forceUpdate", forceUpdate ? 0 : androidVersion.getUpdateType());
map.put("version", androidVersion.getAppVersion());
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Created by hzlizx on 2018/6/21 0021
Expand Down Expand Up @@ -54,6 +55,8 @@ public ServiceResult findNewestVersion(String tenantAppId, String version) {
}
// 将查询结果再次进行筛选,选出大于传入version的版本,然后再找出最新版本
List<IosVersion> iosVersionsResult = new LinkedList<>();
//是否强制更新
AtomicBoolean forceUpdate = new AtomicBoolean(false);
iosVersionsResult.addAll(iosVersions);
iosVersions.forEach(iosVersion -> logger.debug(iosVersion.getAppVersion()));
if (VersionCompareUtils.compareVersion(version, iosVersions.get(iosVersions.size() - 1).getAppVersion()) > 0) {
Expand All @@ -71,7 +74,11 @@ public ServiceResult findNewestVersion(String tenantAppId, String version) {
}
logger.debug("查询到的版本:");
iosVersionsResult.forEach(iosVersion -> logger.debug(iosVersion.getAppVersion()));

iosVersionsResult.forEach(iosVersion -> {
if(iosVersion.getUpdateType().equals(0)) {
forceUpdate.set(true);
}
});
IosVersion iosVersion = iosVersionsResult.get(0);
logger.debug("当前最新版本为:{}", iosVersion.getAppVersion());

Expand All @@ -80,7 +87,7 @@ public ServiceResult findNewestVersion(String tenantAppId, String version) {
map.put("allowLowestVersion", iosVersion.getAllowLowestVersion());
map.put("appStoreUrl", iosVersion.getAppStoreUrl());
map.put("description", iosVersion.getVersionDescription());
map.put("forceUpdate", iosVersion.getUpdateType());
map.put("forceUpdate", forceUpdate.get() ? 0 : iosVersion.getUpdateType());
map.put("version", iosVersion.getAppVersion());
ServiceResult ok = ServiceResult.ok(map);
logger.debug("结果:{}", $.json.toJsonString(ok));
Expand Down