Commit 5a51fcff authored by sherlock's avatar sherlock

unchange

parent d22b8055
...@@ -26,7 +26,8 @@ import pwc.taxtech.atms.common.config.FileServiceConfig; ...@@ -26,7 +26,8 @@ import pwc.taxtech.atms.common.config.FileServiceConfig;
import pwc.taxtech.atms.dto.ApiResultDto; import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.exception.ServiceException; import pwc.taxtech.atms.exception.ServiceException;
import java.io.*; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -42,32 +43,24 @@ public class HttpFileService extends BaseService { ...@@ -42,32 +43,24 @@ public class HttpFileService extends BaseService {
* 上传模板 * 上传模板
* *
* @param fileName 文件名 * @param fileName 文件名
* @param fileBytes 文件字节 * @param file MultipartFile
* @return Boolean * @return Boolean
*/ */
public String uploadTemplateWithBytes(String fileName, byte[] fileBytes) throws ServiceException { public String uploadTemplate(String fileName, MultipartFile file) throws ServiceException {
if (StringUtils.isBlank(fileName) || null == fileBytes) { if (StringUtils.isBlank(fileName) || null == file) {
throw new IllegalArgumentException("上传参数为空"); throw new IllegalArgumentException("上传参数为空");
} }
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
String fullPath = USER_TEMPLATE_PATH + fileName; String fullPath = USER_TEMPLATE_PATH + fileName;
try { try {
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(config.getServerUrl() + config.getUploadUrl()); HttpPost httpPost = new HttpPost(config.getServerUrl() + config.getUploadUrl());
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()); httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
FileOutputStream out = new FileOutputStream(fullPath);
out.write(fileBytes);
FileInputStream fis = new FileInputStream(fullPath);
byte[] byt = new byte[fis.available()];
fis.read(byt);
JSONObject param = new JSONObject(); JSONObject param = new JSONObject();
param.put("path", fullPath); param.put("path", fullPath);
param.put("file", byt); param.put("file", file.getBytes());
fis.close();
out.close();
HttpEntity httpEntity = new StringEntity(param.toJSONString(), ContentType.APPLICATION_JSON); HttpEntity httpEntity = new StringEntity(param.toJSONString(), ContentType.APPLICATION_JSON);
httpPost.setEntity(httpEntity); httpPost.setEntity(httpEntity);
...@@ -90,25 +83,6 @@ public class HttpFileService extends BaseService { ...@@ -90,25 +83,6 @@ public class HttpFileService extends BaseService {
throw new ServiceException("uploadTemplate error."); throw new ServiceException("uploadTemplate error.");
} }
/**
* 上传模板
*
* @param fileName 文件名
* @param file MultipartFile
* @return Boolean
*/
public String uploadTemplate(String fileName, MultipartFile file) throws ServiceException {
if (StringUtils.isBlank(fileName) || null == file) {
throw new IllegalArgumentException("上传参数为空");
}
try {
return uploadTemplateWithBytes(fileName, file.getBytes());
} catch (IOException e) {
logger.error("close httpClient error.", e);
}
throw new ServiceException("uploadTemplate error.");
}
/** /**
* 下载模板 * 下载模板
* *
......
...@@ -41,7 +41,9 @@ import pwc.taxtech.atms.vat.dao.PeriodDataSourceMapper; ...@@ -41,7 +41,9 @@ import pwc.taxtech.atms.vat.dao.PeriodDataSourceMapper;
import pwc.taxtech.atms.vat.entity.PeriodCellData; import pwc.taxtech.atms.vat.entity.PeriodCellData;
import pwc.taxtech.atms.vat.entity.PeriodDataSource; import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import java.io.*; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -221,7 +223,7 @@ public class TemplateGroupServiceImpl extends AbstractService { ...@@ -221,7 +223,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
} }
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
optional.get().write(bos); optional.get().write(bos);
String tmpPath = httpFileService.uploadTemplateWithBytes(newName, bos.toByteArray()); String tmpPath = httpFileService.uploadTemplate(newName, file);
String[] arr = sheetName.split("_"); String[] arr = sheetName.split("_");
String name = arr.length >= 2 ? arr[1] : arr[0]; String name = arr.length >= 2 ? arr[1] : arr[0];
Template template = new Template(); Template template = new Template();
...@@ -368,7 +370,7 @@ public class TemplateGroupServiceImpl extends AbstractService { ...@@ -368,7 +370,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
} }
} }
wtemp.write(bos); wtemp.write(bos);
String tmpPath = httpFileService.uploadTemplateWithBytes(newName, bos.toByteArray()); String tmpPath = httpFileService.uploadTemplate(newName, file);
String[] arr = sheetName.split("_"); String[] arr = sheetName.split("_");
String name = arr.length >= 2 ? arr[1] : arr[0]; String name = arr.length >= 2 ? arr[1] : arr[0];
Template template = new Template(); Template template = new Template();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment