public class CheckVersionUtil {
private static final int versionLength = 3;
/** 判断当前客户端版本号是否大于某个版本 */
public static boolean checkVersion(Map<String, Object> deviceInfo, int versionOne, int versionTwo, int versionThree) {
if(deviceInfo == null || deviceInfo.get("appVersion") == null){
throw new CommonException(CommonErrorEnum.VERSION_CHECK_ERROR.getCode(), CommonErrorEnum.VERSION_CHECK_ERROR.getDescription());
}
String appVersion = deviceInfo.get("appVersion").toString();
appVersion = appVersion.trim();
// 防止版本号里面有空格,将空格去掉
appVersion = appVersion.replaceAll("[\\s]","");
String[] versions = appVersion.split("\\.");
if(versions.length < versionLength){
throw new CommonException(CommonErrorEnum.VERSION_CHECK_ERROR.getCode(), CommonErrorEnum.VERSION_CHECK_ERROR.getDescription());
}
if(Integer.parseInt(versions[0]) > versionOne){
return true;
}
if(Integer.parseInt(versions[0]) >= versionOne && Integer.parseInt(versions[1]) > versionTwo){
return true;
}
if(Integer.parseInt(versions[0]) >= versionOne && Integer.parseInt(versions[1]) >= versionTwo && Integer.parseInt(versions[2]) >= versionThree){
return true;
}
return false;
}
}