Commit 1e7012def8fc7392ce79247359b7cea3cc3f440d
1 parent
a4ab06ac
fix(config): 更新配置文件和修复分页计算问题
- 在.gitignore中添加.mcp.json文件忽略 - 更新application-dev.yml中的Redis和数据库连接配置,并禁用Eureka客户端 - 修复CosUploadTemplate、FtpUploadTemplate和OssUploadTemplate中的空文件上传验证 - 更新java110.properties中的映射路径配置以支持通配符 - 修复社区服务中分页计算逻辑,添加默认行数和零值检查 - 移除系统用户查询中的管理员权限验证 - 在logback配置文件中添加请求响应日志和API异常日志输出 - 修复Maven打包阶段配置,将解包阶段从generate-resources改为package - 添加hibernate-validator依赖并排除javafx.base冲突 - 扩展文件上传组件以支持multipart文件上传和IP地址获取功能
Showing
1 changed file
with
19 additions
and
8 deletions
service-api/src/main/java/com/java110/api/smo/file/impl/AddFileSMOImpl.java
| @@ -78,17 +78,28 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | @@ -78,17 +78,28 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | ||
| 78 | String apkFileName = UUID.randomUUID().toString() + ".apk"; | 78 | String apkFileName = UUID.randomUUID().toString() + ".apk"; |
| 79 | String apkDir = "/park/apk/"; | 79 | String apkDir = "/park/apk/"; |
| 80 | File dir = new File(apkDir); | 80 | File dir = new File(apkDir); |
| 81 | - if (!dir.exists()) dir.mkdirs(); | 81 | + if (!dir.exists()) { |
| 82 | + boolean created = dir.mkdirs(); | ||
| 83 | + if (!created) { | ||
| 84 | + throw new IOException("无法创建APK存储目录: " + apkDir); | ||
| 85 | + } | ||
| 86 | + } | ||
| 82 | File apkFile = new File(apkDir + apkFileName); | 87 | File apkFile = new File(apkDir + apkFileName); |
| 83 | is = uploadFile.getInputStream(); | 88 | is = uploadFile.getInputStream(); |
| 84 | - FileOutputStream fos = new FileOutputStream(apkFile); | ||
| 85 | - byte[] buf = new byte[8192]; | ||
| 86 | - int len; | ||
| 87 | - while ((len = is.read(buf)) != -1) { | ||
| 88 | - fos.write(buf, 0, len); | 89 | + FileOutputStream fos = null; |
| 90 | + try { | ||
| 91 | + fos = new FileOutputStream(apkFile); | ||
| 92 | + byte[] buf = new byte[8192]; | ||
| 93 | + int len; | ||
| 94 | + while ((len = is.read(buf)) != -1) { | ||
| 95 | + fos.write(buf, 0, len); | ||
| 96 | + } | ||
| 97 | + fos.flush(); | ||
| 98 | + } finally { | ||
| 99 | + if (fos != null) { try { fos.close(); } catch (Exception ignored) {} } | ||
| 100 | + if (is != null) { try { is.close(); } catch (Exception ignored) {} } | ||
| 101 | + is = null; // 防止外层 finally 重复关闭 | ||
| 89 | } | 102 | } |
| 90 | - fos.close(); | ||
| 91 | - is.close(); | ||
| 92 | 103 | ||
| 93 | JSONObject outParam = new JSONObject(); | 104 | JSONObject outParam = new JSONObject(); |
| 94 | outParam.put("fileId", "apk/" + apkFileName); | 105 | outParam.put("fileId", "apk/" + apkFileName); |