拆分中图片内容处理
This commit is contained in:
+1
@@ -93,6 +93,7 @@ public class ShiroConfig {
|
||||
filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token
|
||||
filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览
|
||||
filterChainDefinitionMap.put("/sys/common/download/**", "anon");//文件预览
|
||||
filterChainDefinitionMap.put("/sys/split/file/**", "anon");//图片预览
|
||||
filterChainDefinitionMap.put("/generic/**", "anon");//pdf预览需要文件
|
||||
filterChainDefinitionMap.put("/", "anon");
|
||||
filterChainDefinitionMap.put("/doc.html", "anon");
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.jero.modules.oss;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
@Slf4j
|
||||
public class SplitFileUtils {
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: encodeFileName
|
||||
* @Description: 导出文件转换文件名称编码
|
||||
* @param @param fileNames
|
||||
* @param @param request
|
||||
* @param @return 设定文件
|
||||
* @return String 返回类型
|
||||
* @throws
|
||||
*/
|
||||
public static String encodeFileName(String fileNames , HttpServletRequest request) {
|
||||
try {
|
||||
String agent = request.getHeader("User-Agent");
|
||||
if (agent.contains("Firefox")) {
|
||||
fileNames = new String(fileNames.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器
|
||||
} else {
|
||||
fileNames = URLEncoder.encode(fileNames, "utf-8");
|
||||
//谷歌中空格变为+问题
|
||||
fileNames = fileNames.replaceAll("\\+","%20");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return fileNames ;
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.jero.modules.oss.controller;
|
||||
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.oss.SplitFileUtils;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import sun.misc.BASE64Decoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/sys/split/file")
|
||||
public class SplitFileController {
|
||||
|
||||
@Autowired
|
||||
private IOSSFileService ossFileService;
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/getImage")
|
||||
public void queryPageList(@RequestParam("fileUrl") String fileUrl, HttpServletResponse response, HttpServletRequest request) {
|
||||
|
||||
//base64解码
|
||||
BASE64Decoder base64Decoder = new BASE64Decoder();
|
||||
try {
|
||||
byte[] bytes = base64Decoder.decodeBuffer(fileUrl);
|
||||
fileUrl = new String(bytes, "utf-8");
|
||||
} catch (IOException e) {
|
||||
throw new JeroBootException("文件不存在");
|
||||
}
|
||||
int splitIndex = fileUrl.lastIndexOf(File.separator);
|
||||
String fileName = fileUrl.substring(splitIndex);
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=\""+fileName+"\"");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=\""+ SplitFileUtils.encodeFileName(fileName, request) +"\"");
|
||||
response.setContentType("application/force-download");
|
||||
try(OutputStream os = response.getOutputStream();
|
||||
FileInputStream fis = new FileInputStream(fileUrl);) {
|
||||
|
||||
int len = 0;
|
||||
while ((len = fis.read()) != -1) {
|
||||
os.write(len);
|
||||
}
|
||||
os.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new JeroBootException("文件不存在");
|
||||
} catch (IOException e) {
|
||||
throw new JeroBootException("文件不存在");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+11
-12
@@ -33,8 +33,11 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -1220,19 +1223,12 @@ public class FileSpiltService {
|
||||
|
||||
// 处理段落生成编号不识别问题
|
||||
String paragraphString = p.getText();
|
||||
if (StringUtils.isNotBlank(paragraphString)) {
|
||||
if (!StringUtils.isEmpty(paragraphString)) {
|
||||
paragraphString = paragraphString.replace((char) 12288, ' ');
|
||||
paragraphString = paragraphString.replaceAll("\r\n","");
|
||||
paragraphString = paragraphString.replaceAll("\n","");
|
||||
paragraphString = paragraphString.trim();
|
||||
}
|
||||
if(StringUtils.isEmpty(paragraphString)){
|
||||
continue;
|
||||
}
|
||||
paragraphString = paragraphString.replaceAll("\r\n","");
|
||||
paragraphString = paragraphString.replaceAll("\n","");
|
||||
paragraphString = paragraphString.trim();
|
||||
if(StringUtils.isEmpty(paragraphString)){
|
||||
continue;
|
||||
}
|
||||
// if (StringUtils.isNotEmpty(p.getNumLevelText())&& p.getNumLevelText().indexOf(".")>0) {
|
||||
// String numberParent = p.getNumLevelText().substring(0,p.getNumLevelText().lastIndexOf("."));
|
||||
// if (numberMap.containsKey(numberParent)){
|
||||
@@ -2570,13 +2566,16 @@ public class FileSpiltService {
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filepathandname);
|
||||
fos.write(bytev);
|
||||
String path = splitUrl + "/" + imageName;
|
||||
// String fileUrl = splitUrl + "/" + filepathandname;
|
||||
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||
String encode = base64Encoder.encode(filepathandname.getBytes(StandardCharsets.UTF_8));
|
||||
String path = splitUrl+"/jero-boot/sys/split/file/getImage?fileUrl="+encode;
|
||||
String imgCon = path;
|
||||
String imgConVal = "<img class=\'wordImg\' src=\'" + path + "\'>";
|
||||
message.getItemsCondi().add(imgConVal);
|
||||
message.setItermsConditions(message.getItermsConditions() + imgConVal);
|
||||
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.IMG.getValue(), imgCon, message.getItemsCondi().size(), null));
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +191,8 @@ jero :
|
||||
# 本地:local\Minio:minio\阿里云:alioss
|
||||
uploadType: local
|
||||
backUrl: http://localhost:3000
|
||||
splitUrl: http://39.98.140.126:8888
|
||||
#拆分图片展示地址
|
||||
splitUrl: http://localhost:8080
|
||||
path :
|
||||
#文件上传根目录 设置
|
||||
upload: D://opt//upFiles
|
||||
|
||||
Reference in New Issue
Block a user