|
@@ -1,13 +1,16 @@
|
|
|
package com.caimei.service.async;
|
|
|
|
|
|
import com.caimei.config.FastDfsClient;
|
|
|
+import com.caimei.mapper.cmMapper.ArticleMapper;
|
|
|
import com.caimei.mapper.cmMapper.FileMapper;
|
|
|
import com.caimei.model.po.ArticlePo;
|
|
|
+import com.caimei.model.vo.ArticleFormVo;
|
|
|
import com.caimei.model.vo.FileTreeVo;
|
|
|
import com.caimei.utils.FileZipUtils;
|
|
|
import com.caimei.utils.OSSUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -44,44 +47,69 @@ public class AsyncService {
|
|
|
@Resource
|
|
|
private FastDfsClient client;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ArticleMapper articleMapper;
|
|
|
+
|
|
|
@Async("taskExecutor")
|
|
|
public void saveArticleImage(boolean insertFlag, ArticlePo article, Integer parentId) {
|
|
|
+ //保存文章相关属性
|
|
|
+ FileTreeVo fileTreeVo = new FileTreeVo();
|
|
|
+ fileTreeVo.setPackageType(1);
|
|
|
+ fileTreeVo.setMime("text/plain");
|
|
|
+ fileTreeVo.setFileName(article.getTitle() + ".txt");
|
|
|
+ fileTreeVo.setFileType("article");
|
|
|
+ fileTreeVo.setParentId(parentId);
|
|
|
+ fileTreeVo.setAuthUserId(article.getAuthUserId());
|
|
|
+ fileTreeVo.setArticleId(article.getId());
|
|
|
+ UUID uuid = UUID.randomUUID();
|
|
|
+ fileTreeVo.setOssName(uuid + ".txt");
|
|
|
+ //http://192.168.2.92:8888/:authUserId/:prefix/docs/article-detail?fileId=fileId
|
|
|
+ String prefix = fileMapper.findShopPrefix(article.getAuthUserId());
|
|
|
+ prefix = null == prefix ? "app" : prefix;
|
|
|
+ String path = "";
|
|
|
+ path = "/" + article.getAuthUserId() + "/" + prefix + "/docs/article-detail?articleId=" + article.getId();
|
|
|
+ if ("dev".equals(active)) {
|
|
|
+ path = "http://192.168.2.92:8888" + path;
|
|
|
+ } else {
|
|
|
+ path = zpapi + path;
|
|
|
+ }
|
|
|
+ if (2 == article.getArticleType()) {
|
|
|
+ path = article.getArticleLink();
|
|
|
+ }
|
|
|
+ fileTreeVo.setOssUrl(path);
|
|
|
+ //创建txt文件保存链接上传到阿里云
|
|
|
+ String delPath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/" + uuid;
|
|
|
+ String filePath = delPath + "/";
|
|
|
+ if ("dev".equals(active)) {
|
|
|
+ delPath = "D:\\caimei-workSpace\\file\\" + uuid;
|
|
|
+ filePath = delPath + "\\";
|
|
|
+ }
|
|
|
+ File file = writeTxt(filePath, path);
|
|
|
+ OSSUtils.ossUpload(fileTreeVo.getOssName(), file, "text/plain", null);
|
|
|
+ try {
|
|
|
+ client.downloadFile(article.getImage(), filePath + "myShotImage.jpg");
|
|
|
+ log.info("下载成功???");
|
|
|
+ Thumbnails.of(filePath + "myShotImage.jpg").size(64, 64).toFile(filePath + "NewMyShotImage.jpg");
|
|
|
+ String imgUrl = imageDomain + "/" + client.uploadFile(filePath + "NewMyShotImage.jpg");
|
|
|
+ fileTreeVo.setScreenshot(imgUrl);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
if (insertFlag) {
|
|
|
- //保存文章相关属性
|
|
|
- FileTreeVo fileTreeVo = new FileTreeVo();
|
|
|
- fileTreeVo.setPackageType(1);
|
|
|
- fileTreeVo.setMime("text/plain");
|
|
|
- fileTreeVo.setFileName(article.getTitle());
|
|
|
- fileTreeVo.setFileType("article");
|
|
|
- fileTreeVo.setParentId(parentId);
|
|
|
- fileTreeVo.setAuthUserId(article.getAuthUserId());
|
|
|
- fileTreeVo.setArticleId(article.getId());
|
|
|
- UUID uuid = UUID.randomUUID();
|
|
|
- fileTreeVo.setOssName(uuid + ".txt");
|
|
|
- //http://192.168.2.92:8888/:authUserId/:prefix/docs/article-detail?fileId=fileId
|
|
|
- String prefix = fileMapper.findShopPrefix(article.getAuthUserId());
|
|
|
- prefix = null == prefix ? "app" : prefix;
|
|
|
- String path = "/" + article.getAuthUserId() + "/" + prefix + "/docs/article-detail?articleId=" + article.getId();
|
|
|
- if ("dev".equals(active)) {
|
|
|
- path = "http://192.168.2.92:8888" + path;
|
|
|
- } else {
|
|
|
- path = zpapi + path;
|
|
|
- }
|
|
|
- fileTreeVo.setOssUrl(path);
|
|
|
fileMapper.insertNewFile(fileTreeVo);
|
|
|
- //创建txt文件保存链接上传到阿里云
|
|
|
- String delPath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/" + uuid;
|
|
|
- String filePath = delPath + "/";
|
|
|
- if ("dev".equals(active)) {
|
|
|
- delPath = "D:\\caimei-workSpace\\file\\" + uuid;
|
|
|
- filePath = delPath + "\\";
|
|
|
+ } else {
|
|
|
+ FileTreeVo fil = fileMapper.findFileByArticleId(article.getId());
|
|
|
+ if (StringUtils.isNotBlank(fil.getScreenshot())) {
|
|
|
+ client.deleteFile(fil.getScreenshot());
|
|
|
}
|
|
|
- File file = writeTxt(filePath, path);
|
|
|
- OSSUtils.ossUpload(fileTreeVo.getOssName(), file, "text/plain", null);
|
|
|
- File fileDir = new File(delPath);
|
|
|
- Boolean aBoolean = FileZipUtils.deleteFile(fileDir);
|
|
|
- log.info("临时txt删除------------>" + aBoolean);
|
|
|
+ if (StringUtils.isNotBlank(fil.getOssName())) {
|
|
|
+ OSSUtils.deleteSingleFile(fil.getOssName());
|
|
|
+ }
|
|
|
+ fileMapper.updateFileByArticleId(fileTreeVo);
|
|
|
}
|
|
|
+ File fileDir = new File(delPath);
|
|
|
+ Boolean aBoolean = FileZipUtils.deleteFile(fileDir);
|
|
|
+ log.info("临时txt删除------------>" + aBoolean);
|
|
|
}
|
|
|
|
|
|
private File writeTxt(String filePath, String content) {
|