|
@@ -1,10 +1,8 @@
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
|
import com.qmth.boot.tools.io.ZipReader;
|
|
import com.qmth.boot.tools.io.ZipReader;
|
|
-import com.qmth.boot.tools.io.ZipWriter;
|
|
|
|
import com.qmth.distributed.print.business.bean.upgrade.Mainfest;
|
|
import com.qmth.distributed.print.business.bean.upgrade.Mainfest;
|
|
import com.qmth.distributed.print.business.bean.upgrade.MainfestApp;
|
|
import com.qmth.distributed.print.business.bean.upgrade.MainfestApp;
|
|
import com.qmth.distributed.print.business.bean.upgrade.MainfestScript;
|
|
import com.qmth.distributed.print.business.bean.upgrade.MainfestScript;
|
|
@@ -16,13 +14,12 @@ import com.qmth.distributed.print.business.mapper.ClientUpgradeMapper;
|
|
import com.qmth.distributed.print.business.service.ClientUpgradeService;
|
|
import com.qmth.distributed.print.business.service.ClientUpgradeService;
|
|
import com.qmth.teachcloud.common.bean.vo.FilePathVo;
|
|
import com.qmth.teachcloud.common.bean.vo.FilePathVo;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.teachcloud.common.enums.ClientUpgradeToolTypeEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.enums.clientpackage.ClientPackageEnum;
|
|
import com.qmth.teachcloud.common.enums.clientpackage.ClientPackageEnum;
|
|
import com.qmth.teachcloud.common.service.FileUploadService;
|
|
import com.qmth.teachcloud.common.service.FileUploadService;
|
|
import com.qmth.teachcloud.common.util.FileUtil;
|
|
import com.qmth.teachcloud.common.util.FileUtil;
|
|
-import com.qmth.teachcloud.common.util.Zip4jUtil;
|
|
|
|
-import okio.Buffer;
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FilenameUtils;
|
|
import org.apache.commons.io.FilenameUtils;
|
|
@@ -34,8 +31,6 @@ import javax.annotation.Resource;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.StringJoiner;
|
|
import java.util.StringJoiner;
|
|
-import java.util.zip.ZipEntry;
|
|
|
|
-import java.util.zip.ZipInputStream;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -46,16 +41,14 @@ import java.util.zip.ZipInputStream;
|
|
* @since 2024-03-20
|
|
* @since 2024-03-20
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
-public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, ClientUpgrade> implements ClientUpgradeService {
|
|
|
|
|
|
+public class ClientUpgradeServiceImpl extends MppServiceImpl<ClientUpgradeMapper, ClientUpgrade> implements ClientUpgradeService {
|
|
|
|
|
|
- private static String platform = "WINDOWS";
|
|
|
|
- private static String MAIN_FEST_JSON = "mainfest.json";
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private FileUploadService fileUploadService;
|
|
private FileUploadService fileUploadService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void upload(MultipartFile file, String md5, ClientPackageEnum type) {
|
|
|
|
|
|
+ public void upload(MultipartFile file, String md5, ClientPackageEnum type, String platform, ClientUpgradeToolTypeEnum toolType) {
|
|
File parentDirVar = null;
|
|
File parentDirVar = null;
|
|
try {
|
|
try {
|
|
String fileName = FilenameUtils.getName(file.getOriginalFilename());
|
|
String fileName = FilenameUtils.getName(file.getOriginalFilename());
|
|
@@ -72,18 +65,17 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
}
|
|
}
|
|
|
|
|
|
- ClientUpgrade clientUpgrade = this.getByPlatform(platform);
|
|
|
|
|
|
+ ClientUpgrade clientUpgrade = this.getByPlatformAndToolType(platform, toolType);
|
|
//安装包
|
|
//安装包
|
|
if (ClientPackageEnum.INSTALL.equals(type)) {
|
|
if (ClientPackageEnum.INSTALL.equals(type)) {
|
|
// 上传
|
|
// 上传
|
|
- String filePathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), "release", platform) + fileName;
|
|
|
|
|
|
+ String filePathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), toolType.getType(), "release", platform) + fileName;
|
|
FilePathVo filePathVo = fileUploadService.uploadFile(file, UploadFileEnum.UPGRADE, filePathName, fileMd5);
|
|
FilePathVo filePathVo = fileUploadService.uploadFile(file, UploadFileEnum.UPGRADE, filePathName, fileMd5);
|
|
clientUpgrade.setInstallPath(JSON.toJSONString(filePathVo));
|
|
clientUpgrade.setInstallPath(JSON.toJSONString(filePathVo));
|
|
clientUpgrade.setInstallUploadTime(System.currentTimeMillis());
|
|
clientUpgrade.setInstallUploadTime(System.currentTimeMillis());
|
|
} else if (ClientPackageEnum.UPGRADE.equals(type)) {
|
|
} else if (ClientPackageEnum.UPGRADE.equals(type)) {
|
|
// 升级包文件上传
|
|
// 升级包文件上传
|
|
parentDirVar = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
|
|
parentDirVar = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
|
|
-// file.transferTo(parentDirVar);
|
|
|
|
FileUtils.copyToFile(file.getInputStream(), parentDirVar);
|
|
FileUtils.copyToFile(file.getInputStream(), parentDirVar);
|
|
ZipReader zipReader = new ZipReader(parentDirVar);
|
|
ZipReader zipReader = new ZipReader(parentDirVar);
|
|
String mainfestJson = "mainfest.json";
|
|
String mainfestJson = "mainfest.json";
|
|
@@ -107,8 +99,17 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
if (supportMin == null) {
|
|
if (supportMin == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("supportMin值必填");
|
|
throw ExceptionResultEnum.ERROR.exception("supportMin值必填");
|
|
}
|
|
}
|
|
|
|
+ String serverMin = mainfest.getServerMin();
|
|
|
|
+ if (StringUtils.isBlank(serverMin)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("serverMin值必填");
|
|
|
|
+ }
|
|
|
|
+ // 校验版本号是否支持
|
|
|
|
+ if (!compareVersion(SystemConstant.VERSION_VALUE, serverMin)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("服务端版本号为[" + SystemConstant.VERSION_VALUE + "],升级程序支持的最低版本号为[" + serverMin + "]");
|
|
|
|
+ }
|
|
|
|
+
|
|
// 上传
|
|
// 上传
|
|
- String filePathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), "update", platform, version, String.valueOf(build)) + fileName;
|
|
|
|
|
|
+ String filePathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), toolType.getType(), "update", platform, version, String.valueOf(build)) + fileName;
|
|
FilePathVo filePathVo = fileUploadService.uploadFile(file, UploadFileEnum.UPGRADE, filePathName, fileMd5);
|
|
FilePathVo filePathVo = fileUploadService.uploadFile(file, UploadFileEnum.UPGRADE, filePathName, fileMd5);
|
|
clientUpgrade.setVersion(version);
|
|
clientUpgrade.setVersion(version);
|
|
clientUpgrade.setBuild(build);
|
|
clientUpgrade.setBuild(build);
|
|
@@ -116,34 +117,34 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
clientUpgrade.setUpgradePath(JSON.toJSONString(filePathVo));
|
|
clientUpgrade.setUpgradePath(JSON.toJSONString(filePathVo));
|
|
|
|
|
|
// 上传mainfest.json文件
|
|
// 上传mainfest.json文件
|
|
- String mainfestPathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), "update", platform, version, String.valueOf(build)) + mainfestJson;
|
|
|
|
|
|
+ String mainfestPathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), toolType.getType(), "update", platform, version, String.valueOf(build)) + mainfestJson;
|
|
FilePathVo mainfestPathVo = fileUploadService.uploadFile(zipReader.read(mainfestJson), UploadFileEnum.UPGRADE, mainfestPathName, DigestUtils.md5Hex(zipReader.read(mainfestJson)));
|
|
FilePathVo mainfestPathVo = fileUploadService.uploadFile(zipReader.read(mainfestJson), UploadFileEnum.UPGRADE, mainfestPathName, DigestUtils.md5Hex(zipReader.read(mainfestJson)));
|
|
clientUpgrade.setMainfestPath(JSON.toJSONString(mainfestPathVo));
|
|
clientUpgrade.setMainfestPath(JSON.toJSONString(mainfestPathVo));
|
|
// 上传app目录下文件
|
|
// 上传app目录下文件
|
|
String app = "app";
|
|
String app = "app";
|
|
for (MainfestApp mainfestApp : mainfest.getApp()) {
|
|
for (MainfestApp mainfestApp : mainfest.getApp()) {
|
|
// 上传
|
|
// 上传
|
|
- uploadUpgradeZipFiles(version, build, zipReader, app, mainfestApp.getName());
|
|
|
|
|
|
+ uploadUpgradeZipFiles(version, build, zipReader, app, mainfestApp.getName(), toolType, platform);
|
|
}
|
|
}
|
|
// 上传script目录下文件
|
|
// 上传script目录下文件
|
|
String script = "script";
|
|
String script = "script";
|
|
MainfestScript mainfestScript = mainfest.getScript();
|
|
MainfestScript mainfestScript = mainfest.getScript();
|
|
- uploadUpgradeZipFiles(version, build, zipReader, script, mainfestScript.getBefore());
|
|
|
|
- uploadUpgradeZipFiles(version, build, zipReader, script, mainfestScript.getAfter());
|
|
|
|
|
|
+ uploadUpgradeZipFiles(version, build, zipReader, script, mainfestScript.getBefore(), toolType, platform);
|
|
|
|
+ uploadUpgradeZipFiles(version, build, zipReader, script, mainfestScript.getAfter(), toolType, platform);
|
|
for (String includeFileName : mainfestScript.getIncludes()) {
|
|
for (String includeFileName : mainfestScript.getIncludes()) {
|
|
- uploadUpgradeZipFiles(version, build, zipReader, script, includeFileName);
|
|
|
|
|
|
+ uploadUpgradeZipFiles(version, build, zipReader, script, includeFileName, toolType, platform);
|
|
}
|
|
}
|
|
// 上传data目录下文件
|
|
// 上传data目录下文件
|
|
String data = "data";
|
|
String data = "data";
|
|
for (String dataFileName : mainfest.getData()) {
|
|
for (String dataFileName : mainfest.getData()) {
|
|
- uploadUpgradeZipFiles(version, build, zipReader, data, dataFileName);
|
|
|
|
|
|
+ uploadUpgradeZipFiles(version, build, zipReader, data, dataFileName, toolType, platform);
|
|
}
|
|
}
|
|
clientUpgrade.setUpgradeUploadTime(System.currentTimeMillis());
|
|
clientUpgrade.setUpgradeUploadTime(System.currentTimeMillis());
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("请选择正确的包类型");
|
|
throw ExceptionResultEnum.ERROR.exception("请选择正确的包类型");
|
|
}
|
|
}
|
|
// 保存或更新
|
|
// 保存或更新
|
|
- this.saveOrUpdate(clientUpgrade);
|
|
|
|
|
|
+ this.saveOrUpdateByMultiId(clientUpgrade);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw ExceptionResultEnum.ERROR.exception(type.getName() + "上传失败:" + e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception(type.getName() + "上传失败:" + e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
@@ -153,13 +154,13 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void uploadUpgradeZipFiles(String version, int build, ZipReader zipReader, String pathType, String fileName) {
|
|
|
|
|
|
+ private void uploadUpgradeZipFiles(String version, int build, ZipReader zipReader, String pathType, String fileName, ClientUpgradeToolTypeEnum toolType, String platform) {
|
|
if (StringUtils.isBlank(fileName)) {
|
|
if (StringUtils.isBlank(fileName)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// 上传
|
|
// 上传
|
|
String filePath = FileUtil.replaceSplit(pathType + File.separator + fileName);
|
|
String filePath = FileUtil.replaceSplit(pathType + File.separator + fileName);
|
|
- String dataPathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), "update", platform, version, String.valueOf(build), pathType) + fileName;
|
|
|
|
|
|
+ String dataPathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), toolType.getType(), "update", platform, version, String.valueOf(build), pathType) + fileName;
|
|
try {
|
|
try {
|
|
fileUploadService.uploadFile(zipReader.read(filePath), UploadFileEnum.UPGRADE, dataPathName, DigestUtils.md5Hex(zipReader.read(filePath)));
|
|
fileUploadService.uploadFile(zipReader.read(filePath), UploadFileEnum.UPGRADE, dataPathName, DigestUtils.md5Hex(zipReader.read(filePath)));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -171,21 +172,20 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
* 升级数据查询
|
|
* 升级数据查询
|
|
*
|
|
*
|
|
* @param platform 平台类型
|
|
* @param platform 平台类型
|
|
|
|
+ * @param toolType 文件类型
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ClientUpgrade getByPlatform(String platform) {
|
|
|
|
- QueryWrapper<ClientUpgrade> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.lambda().eq(ClientUpgrade::getPlatform, platform);
|
|
|
|
- ClientUpgrade clientUpgrade = this.getOne(queryWrapper);
|
|
|
|
|
|
+ public ClientUpgrade getByPlatformAndToolType(String platform, ClientUpgradeToolTypeEnum toolType) {
|
|
|
|
+ ClientUpgrade clientUpgrade = this.selectByMultiId(new ClientUpgrade(platform, toolType));
|
|
if (clientUpgrade == null) {
|
|
if (clientUpgrade == null) {
|
|
- clientUpgrade = new ClientUpgrade(platform);
|
|
|
|
|
|
+ clientUpgrade = new ClientUpgrade(platform, toolType);
|
|
}
|
|
}
|
|
return clientUpgrade;
|
|
return clientUpgrade;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ClientResult getExternalByPlatform(String platform) {
|
|
|
|
- ClientUpgrade clientUpgrade = this.getByPlatform(platform);
|
|
|
|
|
|
+ public ClientResult getExternalByPlatform(String platform, ClientUpgradeToolTypeEnum toolType) {
|
|
|
|
+ ClientUpgrade clientUpgrade = this.getByPlatformAndToolType(platform, toolType);
|
|
ClientResult clientResult = new ClientResult();
|
|
ClientResult clientResult = new ClientResult();
|
|
ClientInstallResult clientInstallResult = new ClientInstallResult();
|
|
ClientInstallResult clientInstallResult = new ClientInstallResult();
|
|
ClientUpgradeResult clientUpgradeResult = new ClientUpgradeResult();
|
|
ClientUpgradeResult clientUpgradeResult = new ClientUpgradeResult();
|
|
@@ -211,6 +211,7 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
}
|
|
}
|
|
clientResult.setUpgrade(clientUpgradeResult);
|
|
clientResult.setUpgrade(clientUpgradeResult);
|
|
clientResult.setPrefix(prefix);
|
|
clientResult.setPrefix(prefix);
|
|
|
|
+ clientResult.setServerVersion(SystemConstant.VERSION_VALUE);
|
|
return clientResult;
|
|
return clientResult;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -253,4 +254,32 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
return path;
|
|
return path;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 比较version1>=version2
|
|
|
|
+ *
|
|
|
|
+ * @param version1
|
|
|
|
+ * @param version2
|
|
|
|
+ */
|
|
|
|
+ public static Boolean compareVersion(String version1, String version2) {
|
|
|
|
+ String[] appVersion1 = version1.split("\\.");
|
|
|
|
+ String[] appVersion2 = version2.split("\\.");
|
|
|
|
+ //根据位数最短的判断
|
|
|
|
+ int lim = appVersion1.length > appVersion2.length ? appVersion1.length : appVersion2.length;
|
|
|
|
+ boolean flag = true;
|
|
|
|
+ //根据位数循环判断各个版本
|
|
|
|
+ for (int i = 0; i < lim; i++) {
|
|
|
|
+ String appVersion1Str = appVersion1.length - 1 >= i ? appVersion1[i] : "0";
|
|
|
|
+ String appVersion2Str = appVersion2.length - 1 >= i ? appVersion2[i] : "0";
|
|
|
|
+ if (Integer.parseInt(appVersion1Str) > Integer.parseInt(appVersion2Str)) {
|
|
|
|
+ flag = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (Integer.parseInt(appVersion1Str) < Integer.parseInt(appVersion2Str)) {
|
|
|
|
+ flag = false;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return flag;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|