|
@@ -1,16 +1,13 @@
|
|
|
package com.caimei.modules.archive.service;
|
|
|
|
|
|
-import java.awt.*;
|
|
|
-import java.awt.geom.Rectangle2D;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
-import java.net.URI;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
|
|
|
|
import com.caimei.dfs.image.beens.ImageUploadInfo;
|
|
|
-import com.caimei.modules.archive.entity.CmOrderArchiveFile;
|
|
|
+import com.thinkgem.jeesite.common.utils.HtmlGenerateUtils;
|
|
|
import com.caimei.modules.archive.entity.CmProductArchiveFile;
|
|
|
import com.caimei.modules.archive.utils.OssArchiveUtil;
|
|
|
import com.caimei.modules.common.utils.UploadUtils;
|
|
@@ -18,15 +15,6 @@ import com.caimei.modules.sys.utils.UploadImageUtils;
|
|
|
import com.thinkgem.jeesite.common.config.Global;
|
|
|
import com.thinkgem.jeesite.common.utils.Encodes;
|
|
|
import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.poi.hslf.model.TextRun;
|
|
|
-import org.apache.poi.hslf.usermodel.RichTextRun;
|
|
|
-import org.apache.poi.hslf.usermodel.SlideShow;
|
|
|
-import org.apache.poi.hwpf.HWPFDocument;
|
|
|
-import org.apache.poi.hwpf.converter.PicturesManager;
|
|
|
-import org.apache.poi.hwpf.converter.WordToHtmlConverter;
|
|
|
-import org.apache.poi.hwpf.usermodel.Picture;
|
|
|
-import org.apache.poi.hwpf.usermodel.PictureType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -35,16 +23,9 @@ import com.thinkgem.jeesite.common.service.CrudService;
|
|
|
import com.caimei.modules.archive.entity.CmProductArchiveContent;
|
|
|
import com.caimei.modules.archive.dao.CmProductArchiveContentDao;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import org.w3c.dom.Document;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.imageio.ImageIO;
|
|
|
-import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
-import javax.xml.transform.OutputKeys;
|
|
|
-import javax.xml.transform.Transformer;
|
|
|
-import javax.xml.transform.TransformerFactory;
|
|
|
-import javax.xml.transform.dom.DOMSource;
|
|
|
-import javax.xml.transform.stream.StreamResult;
|
|
|
|
|
|
/**
|
|
|
* 商品资料内容Service
|
|
@@ -153,18 +134,9 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
//保存本地
|
|
|
File file = OssArchiveUtil.ossUpload(multipartFile);
|
|
|
logger.info("默认路径>>>" + file.getAbsolutePath());
|
|
|
- //上传oss
|
|
|
- String url = OssArchiveUtil.ossUpload(filePath, "archiveFile/", file, contentType);
|
|
|
- String htmlUrl = null;
|
|
|
- //doc和ppt文件生成html文件
|
|
|
- /*if (fileType.contains("doc") || fileType.contains("ppt")) {
|
|
|
- String htmluuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
- String htmlFilePath = htmluuid + ".html";
|
|
|
- String htmlPath = generateHtml(file, fileShortName, fileType);
|
|
|
- File htmlFile = new File(htmlPath);
|
|
|
- htmlUrl = OssArchiveUtil.ossUpload(htmlFilePath, "archiveFile/", htmlFile, "text/html");
|
|
|
- htmlFile.delete();
|
|
|
- }*/
|
|
|
+ String contentDispositon = "pdf".equals(fileType) ? "inline" : "attachment";
|
|
|
+ //上传oss
|
|
|
+ String url = OssArchiveUtil.ossUpload(filePath, "archiveFile/", file, contentType, contentDispositon);
|
|
|
//删除本地文件
|
|
|
OssArchiveUtil.deleteFile(file);
|
|
|
//保存关联关系
|
|
@@ -172,7 +144,6 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
archiveFile.setFileName(fileName);
|
|
|
archiveFile.setOssName(filePath);
|
|
|
archiveFile.setOssUrl(url);
|
|
|
-// archiveFile.setHtmlUrl(htmlUrl);
|
|
|
archiveFile.setUploadTime(new Date());
|
|
|
cmProductArchiveContentDao.insertFile(archiveFile);
|
|
|
map.put("success", true);
|
|
@@ -186,110 +157,4 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
-
|
|
|
- private String generateHtml(File file, String fileShortName, String fileType) throws Exception {
|
|
|
-// String filePath = "/mnt/newdatadrive/data/runtime/tomcat-instance/manager/temp/tempHtml/";
|
|
|
-// String filePath = "D:\\poi-test\\wordToHtml\\";
|
|
|
- if (fileType.contains("doc")) {
|
|
|
- InputStream input = new FileInputStream(file);
|
|
|
- HWPFDocument wordDocument = new HWPFDocument(input);
|
|
|
- WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
|
|
- DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
|
|
- .newDocument());
|
|
|
- wordToHtmlConverter.setPicturesManager((content, pictureType, suggestedName, widthInches, heightInches) -> suggestedName);
|
|
|
- wordToHtmlConverter.processDocument(wordDocument);
|
|
|
- List<Picture> pics = wordDocument.getPicturesTable().getAllPictures();
|
|
|
- for (Picture pic : pics) {
|
|
|
- try {
|
|
|
- pic.writeImageContent(new FileOutputStream(htmlTempPath
|
|
|
- + pic.suggestFullFileName()));
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- Document htmlDocument = wordToHtmlConverter.getDocument();
|
|
|
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
|
- DOMSource domSource = new DOMSource(htmlDocument);
|
|
|
- StreamResult streamResult = new StreamResult(outStream);
|
|
|
- TransformerFactory tf = TransformerFactory.newInstance();
|
|
|
- Transformer serializer = tf.newTransformer();
|
|
|
- serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
|
|
|
- serializer.setOutputProperty(OutputKeys.INDENT, "yes");
|
|
|
- serializer.setOutputProperty(OutputKeys.METHOD, "html");
|
|
|
- serializer.transform(domSource, streamResult);
|
|
|
- outStream.close();
|
|
|
- String content = new String(outStream.toByteArray());
|
|
|
- FileUtils.writeStringToFile(new File(htmlTempPath, fileShortName + ".html"), content, "utf-8");
|
|
|
- return htmlTempPath + fileShortName + ".html";
|
|
|
- } else {
|
|
|
- boolean isppt = checkFile(file);
|
|
|
- if (!isppt) {
|
|
|
- System.out.println("The image you specify don't exit!");
|
|
|
- return null;
|
|
|
- }
|
|
|
- try {
|
|
|
- FileInputStream is = new FileInputStream(file);
|
|
|
- SlideShow ppt = new SlideShow(is);
|
|
|
- is.close();
|
|
|
- Dimension pgsize = ppt.getPageSize();
|
|
|
- org.apache.poi.hslf.model.Slide[] slide = ppt.getSlides();
|
|
|
- for (int i = 0; i < slide.length; i++) {
|
|
|
- System.out.print("第" + i + "页。");
|
|
|
- TextRun[] truns = slide[i].getTextRuns();
|
|
|
- for ( int k=0;k<truns.length;k++){
|
|
|
- RichTextRun[] rtruns = truns[k].getRichTextRuns();
|
|
|
- for(int l=0;l<rtruns.length;l++){
|
|
|
- int index = rtruns[l].getFontIndex();
|
|
|
- String name = rtruns[l].getFontName();
|
|
|
- rtruns[l].setFontIndex(1);
|
|
|
- rtruns[l].setFontName("宋体");
|
|
|
-// System.out.println(rtruns[l].getText());
|
|
|
- }
|
|
|
- }
|
|
|
- BufferedImage img = new BufferedImage(pgsize.width,pgsize.height, BufferedImage.TYPE_INT_RGB);
|
|
|
- Graphics2D graphics = img.createGraphics();
|
|
|
- graphics.setPaint(Color.BLUE);
|
|
|
- graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
|
|
|
- slide[i].draw(graphics);
|
|
|
- // 这里设置图片的存放路径和图片的格式(jpeg,png,bmp等等),注意生成文件路径
|
|
|
- FileOutputStream out = new FileOutputStream("D:/poi-test/pptToImg/pict_"+ (i + 1) + ".jpeg");
|
|
|
- javax.imageio.ImageIO.write(img, "jpeg", out);
|
|
|
- out.close();
|
|
|
- }
|
|
|
- System.out.println("success!!");
|
|
|
- return null;
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- System.out.println(e);
|
|
|
- // System.out.println("Can't find the image!");
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // function 检查文件是否为PPT
|
|
|
- public static boolean checkFile(File file) {
|
|
|
- boolean isppt = false;
|
|
|
- String filename = file.getName();
|
|
|
- String suffixname = null;
|
|
|
- if (filename != null && filename.indexOf(".") != -1) {
|
|
|
- suffixname = filename.substring(filename.indexOf("."));
|
|
|
- if (suffixname.equals(".ppt")) {
|
|
|
- isppt = true;
|
|
|
- }
|
|
|
- return isppt;
|
|
|
- } else {
|
|
|
- return isppt;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*@Transactional(readOnly = false)
|
|
|
- public void deleteFile(Integer fileId) {
|
|
|
- CmOrderArchiveFile archiveFile = cmOrderArchiveDao.getArchiveFileById(fileId);
|
|
|
- if (archiveFile != null) {
|
|
|
- //删除oss服务器上的文件
|
|
|
- OssArchiveUtil.deleteSingleFile("archiveFile/", archiveFile.getOssName());
|
|
|
- cmOrderArchiveDao.deleteArchiveFile(fileId);
|
|
|
- }
|
|
|
- }*/
|
|
|
}
|