Add workflow bpmn file preview support (#441)

This commit is contained in:
kl
2023-03-09 21:00:03 +08:00
committed by GitHub
parent eb12ced77f
commit 09a3fd2db8
26 changed files with 64911 additions and 41 deletions

View File

@ -29,7 +29,8 @@ public enum FileType {
Online3D("online3DFilePreviewImpl"),
XMIND("xmindFilePreviewImpl"),
SVG("svgFilePreviewImpl"),
Epub("epubFilePreviewImpl");
Epub("epubFilePreviewImpl"),
BPMN("bpmnFilePreviewImpl");
private static final String[] OFFICE_TYPES = {"docx", "wps", "doc", "docm", "xls", "xlsx", "csv" ,"xlsm", "ppt", "pptx", "vsd", "rtf", "odt", "wmf", "emf", "dps", "et", "ods", "ots", "tsv", "odp", "otp", "sxi", "ott", "vsdx", "fodt", "fods", "xltx","tga","psd","dotm","ett","xlt","xltm","wpt","dot","xlam","xla"};
private static final String[] PICTURE_TYPES = {"jpg", "jpeg", "png", "gif", "bmp", "ico", "jfif", "webp"};
@ -98,6 +99,7 @@ public enum FileType {
FILE_TYPE_MAPPER.put("xml", FileType.XML);
FILE_TYPE_MAPPER.put("pdf", FileType.PDF);
FILE_TYPE_MAPPER.put("flv", FileType.FLV);
FILE_TYPE_MAPPER.put("bpmn", FileType.BPMN);
}
private static FileType to(String fileType) {

View File

@ -28,6 +28,7 @@ public interface FilePreview {
String EXEL_FILE_PREVIEW_PAGE = "html";
String XML_FILE_PREVIEW_PAGE = "xml";
String MARKDOWN_FILE_PREVIEW_PAGE = "markdown";
String BPMN_FILE_PREVIEW_PAGE = "bpmn";
String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported";
String filePreviewHandle(String url, Model model, FileAttribute fileAttribute);

View File

@ -0,0 +1,27 @@
package cn.keking.service.impl;
import cn.keking.model.FileAttribute;
import cn.keking.service.FilePreview;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
/**
* @author kl (http://kailing.pub)
* @since 2023/3/9
*/
@Component
public class BpmnFilePreviewImpl implements FilePreview {
private final CommonPreviewImpl commonPreview;
public BpmnFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
commonPreview.filePreviewHandle(url,model,fileAttribute);
model.addAttribute("fileName", fileAttribute.getName());
return FilePreview.BPMN_FILE_PREVIEW_PAGE;
}
}

View File

@ -0,0 +1,48 @@
package cn.keking.service.impl;
import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse;
import cn.keking.service.FileHandlerService;
import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils;
import cn.keking.utils.KkFileUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kl on 2018/1/17.
* Content :图片文件处理
*/
@Component("commonPreview")
public class CommonPreviewImpl implements FilePreview {
private final FileHandlerService fileHandlerService;
private final OtherFilePreviewImpl otherFilePreview;
public CommonPreviewImpl(FileHandlerService fileHandlerService, OtherFilePreviewImpl otherFilePreview) {
this.fileHandlerService = fileHandlerService;
this.otherFilePreview = otherFilePreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
// 不是http开头浏览器不能直接访问需下载到本地
if (url != null && !url.toLowerCase().startsWith("http")) {
ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, null);
if (response.isFailure()) {
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
} else {
String file = fileHandlerService.getRelativePath(response.getContent());
model.addAttribute("currentUrl", file);
}
} else {
model.addAttribute("currentUrl", url);
}
return null;
}
}

View File

@ -11,15 +11,15 @@ import org.springframework.ui.Model;
@Service
public class EmlFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
private final CommonPreviewImpl commonPreview;
public EmlFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
public EmlFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
commonPreview.filePreviewHandle(url,model,fileAttribute);
return EML_FILE_PREVIEW_PAGE;
}
}

View File

@ -13,15 +13,15 @@ import org.springframework.ui.Model;
@Service
public class EpubFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
private final CommonPreviewImpl commonPreview;
public EpubFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
public EpubFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
commonPreview.filePreviewHandle(url,model,fileAttribute);
return EpubFilePreviewImpl;
}
}

View File

@ -13,15 +13,15 @@ import org.springframework.ui.Model;
@Service
public class OfdFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
private final CommonPreviewImpl commonPreview;
public OfdFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
public OfdFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
commonPreview.filePreviewHandle(url,model,fileAttribute);
return OFD_FILE_PREVIEW_PAGE;
}
}

View File

@ -12,15 +12,15 @@ import org.springframework.ui.Model;
@Service
public class Online3DFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
private final CommonPreviewImpl commonPreview;
public Online3DFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
public Online3DFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
commonPreview.filePreviewHandle(url,model,fileAttribute);
return Online3D_FILE_PAGE;
}
}

View File

@ -18,12 +18,13 @@ import java.util.List;
* Content :图片文件处理
*/
@Service
public class PictureFilePreviewImpl implements FilePreview {
public class PictureFilePreviewImpl extends CommonPreviewImpl {
private final FileHandlerService fileHandlerService;
private final OtherFilePreviewImpl otherFilePreview;
public PictureFilePreviewImpl(FileHandlerService fileHandlerService, OtherFilePreviewImpl otherFilePreview) {
super(fileHandlerService, otherFilePreview);
this.fileHandlerService = fileHandlerService;
this.otherFilePreview = otherFilePreview;
}
@ -39,21 +40,8 @@ public class PictureFilePreviewImpl implements FilePreview {
imgUrls.addAll(zipImgUrls);
}
// 不是http开头浏览器不能直接访问需下载到本地
if (url != null && !url.toLowerCase().startsWith("http")) {
ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, null);
if (response.isFailure()) {
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
} else {
String file = fileHandlerService.getRelativePath(response.getContent());
imgUrls.clear();
imgUrls.add(file);
model.addAttribute("imgUrls", imgUrls);
model.addAttribute("currentUrl", file);
}
} else {
model.addAttribute("imgUrls", imgUrls);
model.addAttribute("currentUrl", url);
}
super.filePreviewHandle(url, model, fileAttribute);
model.addAttribute("imgUrls", imgUrls);
return PICTURE_FILE_PREVIEW_PAGE;
}
}

View File

@ -13,15 +13,15 @@ import org.springframework.ui.Model;
@Service
public class SvgFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
private final CommonPreviewImpl commonPreview;
public SvgFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
public SvgFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
commonPreview.filePreviewHandle(url,model,fileAttribute);
return SVG_FILE_PREVIEW_PAGE;
}
}

View File

@ -13,15 +13,15 @@ import org.springframework.ui.Model;
@Service
public class XmindFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
private final CommonPreviewImpl commonPreview;
public XmindFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
public XmindFilePreviewImpl(CommonPreviewImpl commonPreview) {
this.commonPreview = commonPreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
commonPreview.filePreviewHandle(url,model,fileAttribute);
return XMIND_FILE_PREVIEW_PAGE;
}
}