From 3c1f2ca37bffb1ef7bc285c439ad32bb0f8e10c3 Mon Sep 17 00:00:00 2001 From: wanghao Date: Tue, 2 Jun 2026 16:55:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-druid.yml | 10 +- .../controller/PdaApkVersionController.java | 95 +++++++++++-------- 2 files changed, 61 insertions(+), 44 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index 98659f7..f599fcb 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -6,12 +6,12 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://1.13.177.47:3306/bgs_wms_2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root - password: Haiwei123456 -# url: jdbc:mysql://localhost:3306/bgs_wms_2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 +# url: jdbc:mysql://1.13.177.47:3306/bgs_wms_2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # username: root -# password: haiwei@123 +# password: Haiwei123456 + url: jdbc:mysql://localhost:3306/bgs_wms_2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: haiwei@123 # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-webapi/src/main/java/com/ruoyi/webapi/controller/PdaApkVersionController.java b/ruoyi-webapi/src/main/java/com/ruoyi/webapi/controller/PdaApkVersionController.java index a3d35af..8f64ad7 100644 --- a/ruoyi-webapi/src/main/java/com/ruoyi/webapi/controller/PdaApkVersionController.java +++ b/ruoyi-webapi/src/main/java/com/ruoyi/webapi/controller/PdaApkVersionController.java @@ -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; } }