图纸下载修改
This commit is contained in:
parent
51b9d9367e
commit
6ff1a33621
|
@ -17,6 +17,7 @@ import org.apache.http.impl.client.HttpClients;
|
|||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -86,7 +87,10 @@ public class GetPlmFileUtil {
|
|||
JSONObject plmFileJson = this.getPlmFile(materialCode);
|
||||
String objId = plmFileJson.getString("objId");
|
||||
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);
|
||||
} else {
|
||||
// 多个物料合并成zip文件输出文件流
|
||||
|
@ -94,29 +98,33 @@ public class GetPlmFileUtil {
|
|||
ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
|
||||
ZipOutputStream zipStream = new ZipOutputStream(zipOut);
|
||||
try {
|
||||
for (String materialCode : materialCodeArr) {
|
||||
JSONObject plmFileJson = this.getPlmFile(materialCode);
|
||||
String objId = plmFileJson.getString("objId");
|
||||
String fname = plmFileJson.getString("fname");
|
||||
InputStream ins = this.doDownloadPlmFile(objId);
|
||||
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));
|
||||
zipStream.write(bytes);
|
||||
zipStream.closeEntry();
|
||||
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());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to close input stream: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
zipStream.finish();
|
||||
zipStream.finish();
|
||||
} finally {
|
||||
zipStream.close();
|
||||
zipStream.close();
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||
String zipName = "物料图纸下载_" + sdf.format(new Date());
|
||||
|
@ -212,7 +220,7 @@ public class GetPlmFileUtil {
|
|||
/**
|
||||
* 调用PLM的下载文件接口
|
||||
*/
|
||||
private InputStream doDownloadPlmFile(String fileId) throws IOException {
|
||||
private byte[] doDownloadPlmFile(String fileId) throws IOException {
|
||||
String fileUrl = plmBaseUrl + downlownUrl;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("rid", token);
|
||||
|
@ -265,7 +273,7 @@ public class GetPlmFileUtil {
|
|||
* @param requestUrl 文件接口URL
|
||||
* @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("?");
|
||||
if (paramMap != null) {
|
||||
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
|
||||
|
@ -277,18 +285,20 @@ public class GetPlmFileUtil {
|
|||
param.deleteCharAt(param.length() - 1);
|
||||
}
|
||||
String url = requestUrl + param;
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
|
||||
// 执行请求并返回文件流
|
||||
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);
|
||||
}
|
||||
});
|
||||
HttpGet get = new HttpGet(url);
|
||||
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);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue