|
|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.ruoyi.webapi.controller;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.IpUtils;
|
|
|
|
|
import com.ruoyi.webapi.doman.PdaApkVersion;
|
|
|
|
|
import com.ruoyi.webapi.service.IPdaApkVersionService;
|
|
|
|
|
import com.ruoyi.webapi.utils.Md5Utils;
|
|
|
|
|
@ -10,17 +9,14 @@ import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -78,33 +74,31 @@ public class PdaApkVersionController extends BaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增保存手持版本升级
|
|
|
|
|
* 前端通过 bootstrap-fileinput 先将 APK 上传到 /common/upload,
|
|
|
|
|
* 上传成功后把 common/upload 返回的完整 url 写入 downloadUrl 字段。
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("pda:pda_version:add")
|
|
|
|
|
@Log(title = "手持版本升级", businessType = BusinessType.INSERT)
|
|
|
|
|
@PostMapping("/add")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult addSave(MultipartFile file, PdaApkVersion pdaApkVersion) {
|
|
|
|
|
// 上传文件路径
|
|
|
|
|
String filePath = RuoYiConfig.getUploadPath() + "/apk";
|
|
|
|
|
// 上传并返回新文件名称
|
|
|
|
|
try {
|
|
|
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
|
String pathname = filePath + fileName;
|
|
|
|
|
System.out.println("地址1" + pathname);
|
|
|
|
|
pathname = pathname.replace("/profile/upload/apk", "");
|
|
|
|
|
System.out.println("地址2:" + pathname);
|
|
|
|
|
File file1 = new File(pathname);
|
|
|
|
|
System.out.println("文件获取:" + file1.exists());
|
|
|
|
|
System.out.println(file1.length() / 1024);
|
|
|
|
|
pdaApkVersion.setApkSize(file1.length() / 1024);
|
|
|
|
|
pdaApkVersion.setApkMd5(Md5Utils.getFileMD5(file1));
|
|
|
|
|
|
|
|
|
|
pdaApkVersion.setDownloadUrl( "http://"+"119.45.202.115"+":8091"+fileName);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
public AjaxResult addSave(PdaApkVersion pdaApkVersion) {
|
|
|
|
|
String downloadUrl = pdaApkVersion.getDownloadUrl();
|
|
|
|
|
if (downloadUrl == null || downloadUrl.isEmpty()) {
|
|
|
|
|
return AjaxResult.error("请先上传APK文件");
|
|
|
|
|
}
|
|
|
|
|
return toAjax(pdaApkVersionService.insertPdaApkVersion(pdaApkVersion));
|
|
|
|
|
|
|
|
|
|
// common/upload 返回的 url 已经是完整地址(含 http://host:port),直接存入
|
|
|
|
|
// 格式:http://host:port/profile/upload/yyyy/MM/dd/xxx.apk
|
|
|
|
|
pdaApkVersion.setDownloadUrl(downloadUrl);
|
|
|
|
|
|
|
|
|
|
// 根据 URL 定位本地文件,计算大小和 MD5
|
|
|
|
|
File file = getLocalFile(downloadUrl);
|
|
|
|
|
if (file != null && file.exists()) {
|
|
|
|
|
pdaApkVersion.setApkSize(file.length() / 1024);
|
|
|
|
|
pdaApkVersion.setApkMd5(Md5Utils.getFileMD5(file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return toAjax(pdaApkVersionService.insertPdaApkVersion(pdaApkVersion));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -115,16 +109,8 @@ public class PdaApkVersionController extends BaseController {
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult edit(@PathVariable("objid") Long objid) {
|
|
|
|
|
PdaApkVersion pdaApkVersion = pdaApkVersionService.selectPdaApkVersionByObjid(objid);
|
|
|
|
|
String downloadUrl = pdaApkVersion.getDownloadUrl();
|
|
|
|
|
String substring = downloadUrl.substring(downloadUrl.indexOf("/apk"));
|
|
|
|
|
try {
|
|
|
|
|
FileUtils.deleteFile(RuoYiConfig.getUploadPath() + substring);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteApkLocalFile(pdaApkVersion.getDownloadUrl());
|
|
|
|
|
return toAjax(pdaApkVersionService.deletePdaApkVersionByObjid(objid));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -146,13 +132,44 @@ public class PdaApkVersionController extends BaseController {
|
|
|
|
|
@PostMapping("/remove")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult remove(String ids) {
|
|
|
|
|
System.out.println(ids);
|
|
|
|
|
PdaApkVersion pdaApkVersion = pdaApkVersionService.selectPdaApkVersionByObjid(Long.valueOf(ids));
|
|
|
|
|
String downloadUrl = pdaApkVersion.getDownloadUrl();
|
|
|
|
|
if (downloadUrl!=null&&!downloadUrl.isEmpty()){
|
|
|
|
|
String substring = downloadUrl.substring(downloadUrl.indexOf("/apk"));
|
|
|
|
|
FileUtils.deleteFile(RuoYiConfig.getUploadPath() + substring);
|
|
|
|
|
}
|
|
|
|
|
deleteApkLocalFile(pdaApkVersion.getDownloadUrl());
|
|
|
|
|
return toAjax(pdaApkVersionService.deletePdaApkVersionByObjids(ids));
|
|
|
|
|
// return AjaxResult.error()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从完整URL中提取本地文件路径
|
|
|
|
|
* URL格式:http://host:port/profile/upload/yyyy/MM/dd/xxx.apk
|
|
|
|
|
* 转换为:RuoYiConfig.getProfile()/upload/yyyy/MM/dd/xxx.apk
|
|
|
|
|
*/
|
|
|
|
|
private String getLocalPath(String downloadUrl) {
|
|
|
|
|
if (downloadUrl == null || downloadUrl.isEmpty()) return null;
|
|
|
|
|
// 取 /profile 之后的部分,如 "/upload/2026/06/02/xxx.apk"
|
|
|
|
|
String subPath = FileUtils.stripPrefix(downloadUrl);
|
|
|
|
|
if (subPath == null || subPath.isEmpty()) {
|
|
|
|
|
System.err.println("[PdaApkVersion] getLocalPath FAIL: 未找到 /profile 前缀, downloadUrl=[" + downloadUrl + "]");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String localPath = RuoYiConfig.getProfile() + subPath;
|
|
|
|
|
System.err.println("[PdaApkVersion] getLocalPath: downloadUrl=[" + downloadUrl + "] -> localPath=[" + localPath + "]");
|
|
|
|
|
return localPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 删除APK本地文件,供 edit/remove 公用 */
|
|
|
|
|
private void deleteApkLocalFile(String downloadUrl) {
|
|
|
|
|
String localPath = getLocalPath(downloadUrl);
|
|
|
|
|
if (localPath == null) {
|
|
|
|
|
System.err.println("[PdaApkVersion] deleteApkLocalFile: getLocalPath null, skip");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
boolean deleted = FileUtils.deleteFile(localPath);
|
|
|
|
|
System.err.println("[PdaApkVersion] deleteApkLocalFile: localPath=[" + localPath + "] deleted=" + deleted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private File getLocalFile(String downloadUrl) {
|
|
|
|
|
String localPath = getLocalPath(downloadUrl);
|
|
|
|
|
return localPath != null ? new File(localPath) : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|