|
@@ -73,8 +73,7 @@ public abstract class AsyncPushTaskTemplate {
|
|
|
* @param tbSyncTask
|
|
|
*/
|
|
|
public void createTxt(TBSyncTask tbSyncTask) {
|
|
|
-// OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
|
|
|
- TBTaskService tbTaskService = SpringContextHolder.getBean(TBTaskService.class);
|
|
|
+ FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
|
|
|
ByteArrayOutputStream out = null;
|
|
|
InputStream inputStream = null;
|
|
|
try {
|
|
@@ -82,21 +81,29 @@ public abstract class AsyncPushTaskTemplate {
|
|
|
out.write(tbSyncTask.getSummary().getBytes(StandardCharsets.UTF_8));
|
|
|
byte[] bookByteAry = out.toByteArray();
|
|
|
inputStream = new ByteArrayInputStream(bookByteAry);
|
|
|
- LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+
|
|
|
+ DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
|
|
|
StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ if (Objects.nonNull(dictionaryConfig) && dictionaryConfig.sysDomain().isOss()) {
|
|
|
+ json.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ } else {
|
|
|
+ stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
+ json.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ }
|
|
|
stringJoiner.add(UploadFileEnum.FILE.getTitle()).add(File.separator);
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
stringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
.add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
.add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
.add(File.separator).add(SystemConstant.getUuid()).add(TXT_PREFIX);
|
|
|
+
|
|
|
String path = stringJoiner.toString().replaceAll("\\\\","/");
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+ String type = (String) json.get(SystemConstant.TYPE);
|
|
|
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- if (oss) {//上传至oss
|
|
|
- FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
|
|
|
+ //上传至oss
|
|
|
+ if (Objects.equals(type, SystemConstant.OSS)) {
|
|
|
fileStoreUtil.ossUpload(path, inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), fileStoreUtil.getUploadEnumByPath(stringJoiner.toString()).getFssType());
|
|
|
- json.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
} else {//上传至服务器
|
|
|
File finalFile = new File(stringJoiner.toString());
|
|
|
if (!finalFile.exists()) {
|
|
@@ -104,7 +111,6 @@ public abstract class AsyncPushTaskTemplate {
|
|
|
finalFile.createNewFile();
|
|
|
}
|
|
|
FileUtils.copyInputStreamToFile(inputStream, finalFile);
|
|
|
- json.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
}
|
|
|
json.put(SystemConstant.PATH, path);
|
|
|
json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|