37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
package com.ruoyi.cai.util;
|
|
|
|
import com.ruoyi.cai.enums.version.VersionPlatformEnum;
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
public class VersionUtil {
|
|
|
|
public static String getAppVersion(){
|
|
HttpServletRequest request = ServletUtils.getRequest();
|
|
return request.getHeader("version");
|
|
}
|
|
|
|
public static VersionPlatformEnum getVersionPlatform(){
|
|
HttpServletRequest request = ServletUtils.getRequest();
|
|
String sourceId = request.getHeader("source_id");
|
|
if("2".equals(sourceId)){
|
|
return VersionPlatformEnum.IOS;
|
|
}
|
|
return VersionPlatformEnum.ANDROID;
|
|
}
|
|
|
|
public static int compareVersion(String v1, String v2) {
|
|
String[] ss1 = v1.split("\\."), ss2 = v2.split("\\.");
|
|
int n = ss1.length, m = ss2.length;
|
|
int i = 0, j = 0;
|
|
while (i < n || j < m) {
|
|
int a = 0, b = 0;
|
|
if (i < n) a = Integer.parseInt(ss1[i++]);
|
|
if (j < m) b = Integer.parseInt(ss2[j++]);
|
|
if (a != b) return a > b ? 1 : -1;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|