新增版本管理

master
gongzhenkun 2 years ago
parent 2086b90ce7
commit 1b31218d57

@ -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);
}
}

@ -141,6 +141,14 @@ public class RuoYiConfig
return getProfile() + "/appInfo";
}
/**
*
*/
public static String getAppVersionPath()
{
return getProfile() + "appVersions";
}
/**
*
*/

@ -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<String>}
*/
public static List<String> scanFilesWithPath(String folderPath) {
ArrayList<String> 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;
}
}

@ -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<String> versions;
public String getBaseURL() {
return baseURL;
}
public void setBaseURL(String baseURL) {
this.baseURL = baseURL;
}
public List<String> getVersions() {
return versions;
}
public void setVersions(List<String> versions) {
this.versions = versions;
}
}

@ -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<String>}
*/
public AppVersionsInfo selectAllVersions(String folderPath);
}

@ -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;
/**
* appimpl
*
* @author gongzhenkun
* @date 2022/10/08
*/
@Service
public class AppVersionServiceImpl implements IAppVersionService {
/**
*
*
* @param folderPath
* @return {@code List<String>}
*/
@Override
public AppVersionsInfo selectAllVersions(String folderPath) {
AppVersionsInfo appVersionsInfo = new AppVersionsInfo();
List<String> 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;
}
}
Loading…
Cancel
Save