|
@@ -145,47 +145,41 @@ public class TaskExportCommon {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
public void writeExportResultTxt(String path, String txtStr, String excelFilePath) throws IOException {
|
|
public void writeExportResultTxt(String path, String txtStr, String excelFilePath) throws IOException {
|
|
- FileWriter fileWriter = null;
|
|
|
|
|
|
+ ByteArrayOutputStream out = null;
|
|
|
|
+ InputStream inputStream = null;
|
|
try {
|
|
try {
|
|
- File file = new File(path + File.separator + String.valueOf(UUID.randomUUID()).replaceAll("-", "")
|
|
|
|
- + SystemConstant.TXT_PREFIX);
|
|
|
|
- if (!file.exists()) {
|
|
|
|
- file.getParentFile().mkdirs();
|
|
|
|
- file.createNewFile();
|
|
|
|
- }
|
|
|
|
- fileWriter = new FileWriter(file);
|
|
|
|
- fileWriter.write(txtStr);
|
|
|
|
|
|
+ out = new ByteArrayOutputStream();
|
|
|
|
+ out.write(txtStr.getBytes("UTF-8"));
|
|
|
|
+ byte[] bookByteAry = out.toByteArray();
|
|
|
|
+ inputStream = new ByteArrayInputStream(bookByteAry);
|
|
JSONObject json = new JSONObject();
|
|
JSONObject json = new JSONObject();
|
|
- if (Objects.equals(this.type, SystemConstant.OSS)) {
|
|
|
|
- json.put("path", file.getPath().replaceAll("\\\\", "/"));
|
|
|
|
- } else {
|
|
|
|
- json.put("path", file.getPath());
|
|
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
|
+ if (Objects.equals(this.type, SystemConstant.OSS)) {//上传至oss
|
|
|
|
+ stringJoiner.add(path).add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
|
|
|
|
+ .add(SystemConstant.TXT_PREFIX).toString();
|
|
|
|
+ this.ossUtil.upload(false, stringJoiner.toString(), inputStream, null);
|
|
}
|
|
}
|
|
|
|
+ json.put("path", stringJoiner.toString());
|
|
json.put("type", this.type);
|
|
json.put("type", this.type);
|
|
json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.file.ordinal());
|
|
json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.file.ordinal());
|
|
this.tbTaskHistory.setReportFilePath(json.toJSONString());
|
|
this.tbTaskHistory.setReportFilePath(json.toJSONString());
|
|
if (Objects.nonNull(excelFilePath)) {
|
|
if (Objects.nonNull(excelFilePath)) {
|
|
JSONObject excelJson = new JSONObject();
|
|
JSONObject excelJson = new JSONObject();
|
|
- if (Objects.equals(this.type, SystemConstant.OSS)) {
|
|
|
|
- excelJson.put("path", excelFilePath);
|
|
|
|
- } else {
|
|
|
|
- excelJson.put("path", excelFilePath);
|
|
|
|
- }
|
|
|
|
|
|
+ excelJson.put("path", excelFilePath);
|
|
excelJson.put("type", this.type);
|
|
excelJson.put("type", this.type);
|
|
excelJson.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.file.ordinal());
|
|
excelJson.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.file.ordinal());
|
|
this.tbTaskHistory.setResultFilePath(excelJson.toJSONString());
|
|
this.tbTaskHistory.setResultFilePath(excelJson.toJSONString());
|
|
}
|
|
}
|
|
- if (Objects.equals(this.type, SystemConstant.OSS)) {
|
|
|
|
- this.ossUtil.upload(false, file.getPath().replaceAll("\\\\", "/"), txtStr);
|
|
|
|
- file.delete();
|
|
|
|
- }
|
|
|
|
tbTaskHistoryService.updateById(this.tbTaskHistory);
|
|
tbTaskHistoryService.updateById(this.tbTaskHistory);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("请求出错", e);
|
|
log.error("请求出错", e);
|
|
} finally {
|
|
} finally {
|
|
- if (Objects.nonNull(fileWriter)) {
|
|
|
|
- fileWriter.flush();
|
|
|
|
- fileWriter.close();
|
|
|
|
|
|
+ if (Objects.nonNull(inputStream)) {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(out)) {
|
|
|
|
+ out.flush();
|
|
|
|
+ out.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|