diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/AppVersionController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/AppVersionController.java new file mode 100644 index 0000000..3de0168 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/pc/AppVersionController.java @@ -0,0 +1,31 @@ +package com.ruoyi.web.controller.pc; + +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.system.domain.AppVersionsInfo; +import com.ruoyi.system.service.IAppVersionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 版本管理 + * + * @author gongzhenkun + * @date 2022/10/8 14:27 + */ +@RestController +@RequestMapping("/version") +public class AppVersionController { + @Autowired + private IAppVersionService appVersionService; + + @GetMapping("/queryAll") + public AjaxResult queryAllVersions() { + AppVersionsInfo allVersions = appVersionService.selectAllVersions(RuoYiConfig.getAppVersionPath()); + return AjaxResult.success(allVersions); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java index 935b8eb..853a9d7 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java @@ -141,6 +141,14 @@ public class RuoYiConfig return getProfile() + "/appInfo"; } + /** + * 获取应用信息路径 + */ + public static String getAppVersionPath() + { + return getProfile() + "appVersions"; + } + /** * 获取二维码路径 */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index a4b9eba..3a0cc8b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -3,7 +3,9 @@ package com.ruoyi.common.utils.file; import java.io.*; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Base64; +import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -365,4 +367,28 @@ public class FileUtils throw new ServiceException(e.getMessage()); } } + + /** + * 扫描文件路径 + * + * @param folderPath 文件夹路径 + * @return {@code List} + */ + public static List scanFilesWithPath(String folderPath) { + ArrayList scanFiles = new ArrayList<>(); + File directory = new File(folderPath); + if (!directory.isDirectory()) { + throw new ServiceException(folderPath + "is not directory."); + } + if (directory.isDirectory()) { + File[] fileList = directory.listFiles(); + assert fileList != null; + for (File file : fileList) { + if (!file.isDirectory()) { + scanFiles.add(file.getAbsolutePath()); + } + } + } + return scanFiles; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppVersionsInfo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppVersionsInfo.java new file mode 100644 index 0000000..4a2af24 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppVersionsInfo.java @@ -0,0 +1,31 @@ +package com.ruoyi.system.domain; + +import java.util.List; + +/** + * app版本信息实体 + * + * @author gongzhenkun + * @date 2022/10/8 15:45 + */ +public class AppVersionsInfo { + private String baseURL; + + private List versions; + + public String getBaseURL() { + return baseURL; + } + + public void setBaseURL(String baseURL) { + this.baseURL = baseURL; + } + + public List getVersions() { + return versions; + } + + public void setVersions(List versions) { + this.versions = versions; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IAppVersionService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IAppVersionService.java new file mode 100644 index 0000000..96c7c5a --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IAppVersionService.java @@ -0,0 +1,23 @@ +package com.ruoyi.system.service; + +import com.ruoyi.system.domain.AppVersionsInfo; +import com.ruoyi.system.domain.SysConfig; + +import java.util.List; + +/** + * app版服务 + * + * @author gongzhenkun + * @date 2022/10/08 + */ +public interface IAppVersionService { + + /** + * 查询app所有版本 + * + * @param folderPath 文件夹路径 + * @return {@code List} + */ + public AppVersionsInfo selectAllVersions(String folderPath); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AppVersionServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AppVersionServiceImpl.java new file mode 100644 index 0000000..a2387f6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AppVersionServiceImpl.java @@ -0,0 +1,41 @@ +package com.ruoyi.system.service.impl; + +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.utils.file.FileUtils; +import com.ruoyi.system.domain.AppVersionsInfo; +import com.ruoyi.system.service.IAppVersionService; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * app版本服务impl + * + * @author gongzhenkun + * @date 2022/10/08 + */ +@Service +public class AppVersionServiceImpl implements IAppVersionService { + /** + * 查询所有版本 + * + * @param folderPath 文件夹路径 + * @return {@code List} + */ + @Override + public AppVersionsInfo selectAllVersions(String folderPath) { + AppVersionsInfo appVersionsInfo = new AppVersionsInfo(); + List files = FileUtils.scanFilesWithPath(folderPath); + files = files.stream() + .filter(s -> s.contains(".apk")) + .map(s -> s.replaceAll("\\\\", "/")) + .map(s -> s.replace(RuoYiConfig.getProfile(), "/profile/")) + .collect(Collectors.toList()); + String relativePath = files.get(0); + String baseURL = relativePath.substring(0, relativePath.lastIndexOf("/") + 1); + appVersionsInfo.setBaseURL(baseURL); + appVersionsInfo.setVersions(files.stream().map(s -> s.replace(baseURL, "")).collect(Collectors.toList())); + return appVersionsInfo; + } +}