From e53a7fa44eb05b2c195afd78fedc59bba6b09790 Mon Sep 17 00:00:00 2001 From: mzr Date: Fri, 8 Aug 2025 18:18:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(uapbd):=20=E4=BC=98=E5=8C=96=E6=9D=90?= =?UTF-8?q?=E6=96=99=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 MaterialPlmDownloadAction 中添加日志记录,便于调试和监控 - 更新 GetPlmFileUtil 类中的文件下载逻辑,提高代码可读性和性能 - 修复 zip压缩包创建过程中的潜在资源泄漏问题 --- .../action/MaterialPlmDownloadAction.java | 7 +++- .../nc/bs/uapbd/util/GetPlmFileUtil.java | 37 +++---------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/uapbd/src/client/nccloud/web/uapbd/material/action/MaterialPlmDownloadAction.java b/uapbd/src/client/nccloud/web/uapbd/material/action/MaterialPlmDownloadAction.java index fe6559d..a6f1010 100644 --- a/uapbd/src/client/nccloud/web/uapbd/material/action/MaterialPlmDownloadAction.java +++ b/uapbd/src/client/nccloud/web/uapbd/material/action/MaterialPlmDownloadAction.java @@ -1,10 +1,13 @@ package nccloud.web.uapbd.material.action; +import nc.bs.logging.Logger; import nc.bs.uapbd.util.GetPlmFileUtil; +import nccloud.baseapp.core.log.NCCForUAPLogger; import nccloud.framework.core.io.WebFile; import nccloud.framework.web.action.itf.ICommonAction; import nccloud.framework.web.container.IRequest; +import java.util.Arrays; import java.util.Map; /** @@ -21,11 +24,13 @@ public class MaterialPlmDownloadAction implements ICommonAction { try { Map params_1 = request.readParameters(); String[] pks = params_1.get("materialCode"); // ȡ pk - String materialCode = "101092250323,101092250323"; + NCCForUAPLogger.debug("ȡ pk:" + Arrays.toString(pks)); + String materialCode = "101092250323,101092250321,101092250322"; String[] materialCodeArr = materialCode.split(",", -1); GetPlmFileUtil fileUtil = new GetPlmFileUtil(); files = fileUtil.getPlmFiles(materialCodeArr); } catch (Exception e) { + Logger.error("MaterialPlmDownloadAction-exp:" + e.getMessage()); throw new RuntimeException(e); } return files; diff --git a/uapbd/src/public/nc/bs/uapbd/util/GetPlmFileUtil.java b/uapbd/src/public/nc/bs/uapbd/util/GetPlmFileUtil.java index 98d520d..7800d14 100644 --- a/uapbd/src/public/nc/bs/uapbd/util/GetPlmFileUtil.java +++ b/uapbd/src/public/nc/bs/uapbd/util/GetPlmFileUtil.java @@ -88,8 +88,8 @@ public class GetPlmFileUtil { String objId = plmFileJson.getString("objId"); String fname = plmFileJson.getString("fname"); - byte[] pdfBytes = this.doDownloadPlmFile(objId); - InputStream ins = new ByteArrayInputStream(pdfBytes); + byte[] fileBytes = this.doDownloadPlmFile(objId); + InputStream ins = new ByteArrayInputStream(fileBytes); file = new WebFile(fname, ins); } else { @@ -98,29 +98,14 @@ public class GetPlmFileUtil { ByteArrayOutputStream zipOut = new ByteArrayOutputStream(); ZipOutputStream zipStream = new ZipOutputStream(zipOut); try { -// int i=0; for (String materialCode : materialCodeArr) { JSONObject plmFileJson = this.getPlmFile(materialCode); String objId = plmFileJson.getString("objId"); String fname = plmFileJson.getString("fname"); - byte[] pdfBytes =this.doDownloadPlmFile(objId); - InputStream ins = new ByteArrayInputStream(pdfBytes); -// InputStream ins = this.doDownloadPlmFile(objId); - try { - byte[] bytes = parseFileStream(ins); - zipStream.putNextEntry(new ZipEntry(fname+"")); -// i++; - zipStream.write(bytes); - zipStream.closeEntry(); - } finally { - if (ins != null) { - try { - ins.close(); - } catch (IOException e) { - logger.error("Failed to close input stream: " + e.getMessage()); - } - } - } + byte[] fileBytes = this.doDownloadPlmFile(objId); + zipStream.putNextEntry(new ZipEntry(fname)); + zipStream.write(fileBytes); + zipStream.closeEntry(); } zipStream.finish(); } finally { @@ -289,16 +274,6 @@ public class GetPlmFileUtil { byte[] responseString = httpClient.execute(get, response -> EntityUtils.toByteArray(response.getEntity())); get.releaseConnection(); return responseString; -// // ִ󲢷ļ -// return httpClient.execute(httpGet, response -> { -// // Ӧ״̬ -// int statusCode = response.getStatusLine().getStatusCode(); -// if (statusCode >= 200 && statusCode < 300) { -// return response.getEntity().getContent(); -// } else { -// throw new IOException("HTTP request failed with status code: " + statusCode); -// } -// }); } /**