|
@@ -1,10 +1,12 @@
|
|
|
package com.qmth.distributed.print.api;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.boot.api.annotation.Aac;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.boot.core.fss.utils.FssUtils;
|
|
|
import com.qmth.distributed.print.business.bean.params.LoginParam;
|
|
|
import com.qmth.distributed.print.business.bean.result.EditResult;
|
|
|
import com.qmth.distributed.print.business.entity.TBSyncTask;
|
|
@@ -28,7 +30,9 @@ import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
|
|
|
import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import io.swagger.annotations.*;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -42,9 +46,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -103,6 +105,9 @@ public class SysController {
|
|
|
@Resource
|
|
|
BasicTeachClazzService basicTeachClazzService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private FileStoreUtil fileStoreUtil;
|
|
|
+
|
|
|
/**
|
|
|
* 登录
|
|
|
*
|
|
@@ -796,4 +801,89 @@ public class SysController {
|
|
|
public void sysLogDownload(HttpServletResponse response) {
|
|
|
FileUtil.outputFile(response, new File(sysLogPath), "sys.log");
|
|
|
}
|
|
|
+
|
|
|
+// @ApiOperation(value = "读取markdown文件")
|
|
|
+// @RequestMapping(value = "/reader/markdown", method = RequestMethod.POST)
|
|
|
+// @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
|
|
|
+// @Aac(auth = false)
|
|
|
+// public void readerMarkDown(@ApiParam(value = "md文件", required = true) @RequestParam MultipartFile file) throws IOException {
|
|
|
+// File tempFile = null, finalTempFile = null;
|
|
|
+// String yqUrl = "https://cdn.nlark.com", mkdir = "/markDown";//语雀url
|
|
|
+// try {
|
|
|
+// String format = "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+// Objects.requireNonNull(format, "请上传文件");
|
|
|
+//
|
|
|
+// if (!Objects.equals(format, ".md")) {
|
|
|
+// throw ExceptionResultEnum.ERROR.exception("文件格式只能为.md");
|
|
|
+// }
|
|
|
+// String md5 = ServletUtil.getRequestMd5();
|
|
|
+// Objects.requireNonNull(md5, "md5为空");
|
|
|
+//
|
|
|
+// String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
+// if (!Objects.equals(fileMd5, md5)) {
|
|
|
+// throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
+// }
|
|
|
+//// ByteArrayOutputStream ou = new ByteArrayOutputStream();
|
|
|
+//// IOUtils.copy(file.getInputStream(), ou);
|
|
|
+//// String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
|
|
|
+//// log.info("string:{}", string);
|
|
|
+//
|
|
|
+// tempFile = SystemConstant.getFileTempVar(".md");
|
|
|
+// file.transferTo(tempFile);
|
|
|
+// BufferedReader reader = new BufferedReader(new FileReader(tempFile));
|
|
|
+// String line = null;
|
|
|
+// StringJoiner stringJoiner = new StringJoiner("\n");
|
|
|
+// while ((line = reader.readLine()) != null) {
|
|
|
+// // 处理每一行
|
|
|
+// if (Objects.nonNull(line) && line.indexOf(yqUrl) != -1) {
|
|
|
+// String url = StringUtils.substringBetween(line, "(", ")");
|
|
|
+// String imgFormat = StringUtils.substringAfterLast(url, ".");
|
|
|
+// Objects.requireNonNull(imgFormat, "图片格式为空");
|
|
|
+//
|
|
|
+// File imgUrlTempFile = null;
|
|
|
+// imgUrlTempFile = SystemConstant.getFileTempVar("." + imgFormat);
|
|
|
+// try {
|
|
|
+// HttpUtil.downloadImage(url, imgUrlTempFile.getPath(), imgFormat);
|
|
|
+// String imageMd5 = DigestUtils.md5Hex(new FileInputStream(imgUrlTempFile));
|
|
|
+// String path = mkdir + File.separator + FssUtils.buildPath(UploadFileEnum.FILE.getTitle(), SystemConstant.getNanoId() + "." + imgFormat);
|
|
|
+// fileStoreUtil.ossUpload(path, imgUrlTempFile, imageMd5, UploadFileEnum.FILE.getFssType());
|
|
|
+// JSONObject json = new JSONObject();
|
|
|
+// json.put(SystemConstant.PATH, path);
|
|
|
+// json.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+// json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
+// json.put(SystemConstant.MD5, imageMd5);
|
|
|
+// String imgUrl = fileUploadService.filePreview(json.toJSONString());
|
|
|
+// line = line.replaceAll(url, imgUrl);
|
|
|
+// } finally {
|
|
|
+// if (Objects.nonNull(imgUrlTempFile)) {
|
|
|
+// imgUrlTempFile.delete();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// stringJoiner.add(line);
|
|
|
+// }
|
|
|
+// log.info("stringJoiner:{}", stringJoiner);
|
|
|
+// HttpServletResponse response = (HttpServletResponse) ServletUtil.getResponse();
|
|
|
+// finalTempFile = SystemConstant.getFileTempVar(".md");
|
|
|
+// String fileName = FilenameUtils.getName(finalTempFile.getPath());
|
|
|
+// // 使用response对象设置文件名
|
|
|
+// response.setContentType("text/plain");
|
|
|
+// response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
+//
|
|
|
+// // 导出文件
|
|
|
+// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
|
|
|
+// writer.write(stringJoiner.toString());
|
|
|
+// writer.flush();
|
|
|
+// writer.close();
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+// } finally {
|
|
|
+// if (Objects.nonNull(tempFile)) {
|
|
|
+// tempFile.delete();
|
|
|
+// }
|
|
|
+// if (Objects.nonNull(finalTempFile)) {
|
|
|
+// finalTempFile.delete();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|