图纸下载修改

This commit is contained in:
lihao 2025-08-05 16:17:11 +08:00
parent 51b9d9367e
commit 6ff1a33621
1 changed files with 40 additions and 30 deletions

View File

@ -17,6 +17,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import javax.xml.bind.DatatypeConverter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -86,7 +87,10 @@ public class GetPlmFileUtil {
JSONObject plmFileJson = this.getPlmFile(materialCode); JSONObject plmFileJson = this.getPlmFile(materialCode);
String objId = plmFileJson.getString("objId"); String objId = plmFileJson.getString("objId");
String fname = plmFileJson.getString("fname"); String fname = plmFileJson.getString("fname");
InputStream ins = this.doDownloadPlmFile(objId);
byte[] pdfBytes = this.doDownloadPlmFile(objId);
InputStream ins = new ByteArrayInputStream(pdfBytes);
file = new WebFile(fname, ins); file = new WebFile(fname, ins);
} else { } else {
// 多个物料合并成zip文件输出文件流 // 多个物料合并成zip文件输出文件流
@ -94,14 +98,18 @@ public class GetPlmFileUtil {
ByteArrayOutputStream zipOut = new ByteArrayOutputStream(); ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
ZipOutputStream zipStream = new ZipOutputStream(zipOut); ZipOutputStream zipStream = new ZipOutputStream(zipOut);
try { try {
// int i=0;
for (String materialCode : materialCodeArr) { for (String materialCode : materialCodeArr) {
JSONObject plmFileJson = this.getPlmFile(materialCode); JSONObject plmFileJson = this.getPlmFile(materialCode);
String objId = plmFileJson.getString("objId"); String objId = plmFileJson.getString("objId");
String fname = plmFileJson.getString("fname"); String fname = plmFileJson.getString("fname");
InputStream ins = this.doDownloadPlmFile(objId); byte[] pdfBytes =this.doDownloadPlmFile(objId);
InputStream ins = new ByteArrayInputStream(pdfBytes);
// InputStream ins = this.doDownloadPlmFile(objId);
try { try {
byte[] bytes = parseFileStream(ins); byte[] bytes = parseFileStream(ins);
zipStream.putNextEntry(new ZipEntry(fname)); zipStream.putNextEntry(new ZipEntry(fname+""));
// i++;
zipStream.write(bytes); zipStream.write(bytes);
zipStream.closeEntry(); zipStream.closeEntry();
} finally { } finally {
@ -212,7 +220,7 @@ public class GetPlmFileUtil {
/** /**
* 调用PLM的下载文件接口 * 调用PLM的下载文件接口
*/ */
private InputStream doDownloadPlmFile(String fileId) throws IOException { private byte[] doDownloadPlmFile(String fileId) throws IOException {
String fileUrl = plmBaseUrl + downlownUrl; String fileUrl = plmBaseUrl + downlownUrl;
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("rid", token); map.put("rid", token);
@ -265,7 +273,7 @@ public class GetPlmFileUtil {
* @param requestUrl 文件接口URL * @param requestUrl 文件接口URL
* @return 文件流 * @return 文件流
*/ */
private InputStream getFileFromPlm(String requestUrl, Map<String, String> paramMap) throws IOException { private byte[] getFileFromPlm(String requestUrl, Map<String, String> paramMap) throws IOException {
StringBuilder param = new StringBuilder("?"); StringBuilder param = new StringBuilder("?");
if (paramMap != null) { if (paramMap != null) {
for (Map.Entry<String, String> entry : paramMap.entrySet()) { for (Map.Entry<String, String> entry : paramMap.entrySet()) {
@ -277,18 +285,20 @@ public class GetPlmFileUtil {
param.deleteCharAt(param.length() - 1); param.deleteCharAt(param.length() - 1);
} }
String url = requestUrl + param; String url = requestUrl + param;
HttpGet httpGet = new HttpGet(url); HttpGet get = new HttpGet(url);
byte[] responseString = httpClient.execute(get, response -> EntityUtils.toByteArray(response.getEntity()));
// 执行请求并返回文件流 get.releaseConnection();
return httpClient.execute(httpGet, response -> { return responseString;
// 检查响应状态 // // 执行请求并返回文件流
int statusCode = response.getStatusLine().getStatusCode(); // return httpClient.execute(httpGet, response -> {
if (statusCode >= 200 && statusCode < 300) { // // 检查响应状态
return response.getEntity().getContent(); // int statusCode = response.getStatusLine().getStatusCode();
} else { // if (statusCode >= 200 && statusCode < 300) {
throw new IOException("HTTP request failed with status code: " + statusCode); // return response.getEntity().getContent();
} // } else {
}); // throw new IOException("HTTP request failed with status code: " + statusCode);
// }
// });
} }
/** /**