Commit 5a51fcff authored by sherlock's avatar sherlock

unchange

parent d22b8055
......@@ -26,7 +26,8 @@ import pwc.taxtech.atms.common.config.FileServiceConfig;
import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.exception.ServiceException;
import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
......@@ -42,32 +43,24 @@ public class HttpFileService extends BaseService {
* 上传模板
*
* @param fileName 文件名
* @param fileBytes 文件字节
* @param file MultipartFile
* @return Boolean
*/
public String uploadTemplateWithBytes(String fileName, byte[] fileBytes) throws ServiceException {
if (StringUtils.isBlank(fileName) || null == fileBytes) {
public String uploadTemplate(String fileName, MultipartFile file) throws ServiceException {
if (StringUtils.isBlank(fileName) || null == file) {
throw new IllegalArgumentException("上传参数为空");
}
CloseableHttpClient httpClient = null;
String fullPath = USER_TEMPLATE_PATH + fileName;
try {
httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(config.getServerUrl() + config.getUploadUrl());
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();
param.put("path", fullPath);
param.put("file", byt);
fis.close();
out.close();
param.put("file", file.getBytes());
HttpEntity httpEntity = new StringEntity(param.toJSONString(), ContentType.APPLICATION_JSON);
httpPost.setEntity(httpEntity);
......@@ -90,25 +83,6 @@ public class HttpFileService extends BaseService {
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;
import pwc.taxtech.atms.vat.entity.PeriodCellData;
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.util.*;
import java.util.stream.Collectors;
......@@ -221,7 +223,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
optional.get().write(bos);
String tmpPath = httpFileService.uploadTemplateWithBytes(newName, bos.toByteArray());
String tmpPath = httpFileService.uploadTemplate(newName, file);
String[] arr = sheetName.split("_");
String name = arr.length >= 2 ? arr[1] : arr[0];
Template template = new Template();
......@@ -368,7 +370,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
}
}
wtemp.write(bos);
String tmpPath = httpFileService.uploadTemplateWithBytes(newName, bos.toByteArray());
String tmpPath = httpFileService.uploadTemplate(newName, file);
String[] arr = sheetName.split("_");
String name = arr.length >= 2 ? arr[1] : arr[0];
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