提交 059f9060 作者: obcy

Merge remote-tracking branch 'origin/master'

...@@ -108,21 +108,25 @@ public class KnowledgeController { ...@@ -108,21 +108,25 @@ public class KnowledgeController {
public Result<?> uploadKnowledge(HttpServletRequest request, Knowledge knowledge) { public Result<?> uploadKnowledge(HttpServletRequest request, Knowledge knowledge) {
MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class); MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
List<Result<KnowFile>> resultList = localFileService.upload(fileMap); Result<List<KnowFile>> result = localFileService.upload(fileMap);
if(!Integer.valueOf("200").equals(result.getCode())){
return Result.error(result.getMessage());
}
List<KnowFile> resultList = result.getResult();
KbAuthorizedUser userInfo = SpringContextUtils.getUserInfo(); KbAuthorizedUser userInfo = SpringContextUtils.getUserInfo();
knowledge.setImportData(0); knowledge.setImportData(0);
CompletableFuture.runAsync(()-> this.add(resultList,knowledge,userInfo)); CompletableFuture.runAsync(()-> this.add(resultList,knowledge,userInfo));
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
private void add(List<Result<KnowFile>> resultList, Knowledge knowledge,KbAuthorizedUser userInfo){ private void add( List<KnowFile> resultList, Knowledge knowledge,KbAuthorizedUser userInfo){
if (null == resultList || resultList.isEmpty()) { if (null == resultList || resultList.isEmpty()) {
return ; return ;
} }
for (Result<KnowFile> knowFileResult : resultList) { for ( KnowFile knowFileResult : resultList) {
knowledge.setId(null); knowledge.setId(null);
knowledge.setTitle(null); knowledge.setTitle(null);
knowledgeService.addKnowledge(knowFileResult.getResult(), knowledge,userInfo); knowledgeService.addKnowledge(knowFileResult, knowledge,userInfo);
} }
} }
......
...@@ -34,7 +34,7 @@ public interface ILocalFileService { ...@@ -34,7 +34,7 @@ public interface ILocalFileService {
* @param fileMap * @param fileMap
* @return * @return
*/ */
List<Result<KnowFile>> upload(Map<String,MultipartFile> fileMap); Result<List<KnowFile>> upload(Map<String,MultipartFile> fileMap);
/** /**
* 文件下载 * 文件下载
......
...@@ -45,8 +45,8 @@ public class DocumentServiceImpl implements DocumentService { ...@@ -45,8 +45,8 @@ public class DocumentServiceImpl implements DocumentService {
/** /**
* 大小限制,默认10M * 大小限制,默认10M
*/ */
@Value("${document.file-size.limit:10485760}") @Value("${filesize-max}")
private Long docFileSizeLimit; private String filesizeMax;
@Value("${files.docservice.url.site}") @Value("${files.docservice.url.site}")
private String documentServerHost; private String documentServerHost;
@Value("${files.docservice.url.api}") @Value("${files.docservice.url.api}")
...@@ -293,8 +293,8 @@ public class DocumentServiceImpl implements DocumentService { ...@@ -293,8 +293,8 @@ public class DocumentServiceImpl implements DocumentService {
log.error("$$$ 目标文档[{}]不可读,无法打开!", docFile.getAbsolutePath()); log.error("$$$ 目标文档[{}]不可读,无法打开!", docFile.getAbsolutePath());
throw new DocumentException(ErrorCodeEnum.DOC_FILE_UNREADABLE); throw new DocumentException(ErrorCodeEnum.DOC_FILE_UNREADABLE);
} }
if (docFile.length() > docFileSizeLimit) { if (docFile.length() > Long.parseLong(filesizeMax)) {
log.error("$$$ 目标文档大小超过限制({}B > {}B),无法打开!", docFile.length(), docFileSizeLimit); log.error("$$$ 目标文档大小超过限制({}B > {}B),无法打开!", docFile.length(), Long.parseLong(filesizeMax));
throw new DocumentException(ErrorCodeEnum.DOC_FILE_OVERSIZE); throw new DocumentException(ErrorCodeEnum.DOC_FILE_OVERSIZE);
} }
String ext = StringUtils.lowerCase(FilenameUtils.getExtension(docFile.getName())); String ext = StringUtils.lowerCase(FilenameUtils.getExtension(docFile.getName()));
......
...@@ -174,9 +174,13 @@ class KnowledgeServiceImpl implements IKnowledgeService { ...@@ -174,9 +174,13 @@ class KnowledgeServiceImpl implements IKnowledgeService {
for (String id : split) { for (String id : split) {
esOpUtil.docDeleteById(Constants.ES_DATA_FOR_KNOWLEDGE, id); esOpUtil.docDeleteById(Constants.ES_DATA_FOR_KNOWLEDGE, id);
} }
CompletableFuture.runAsync(() ->{
for (String id : split) { for (String id : split) {
CompletableFuture.runAsync(() -> deleteForPython(id)); deleteForPython(id);
} }
});
} }
......
...@@ -80,15 +80,18 @@ public class LocalFileServiceImpl implements ILocalFileService { ...@@ -80,15 +80,18 @@ public class LocalFileServiceImpl implements ILocalFileService {
String fileExtension = fileUtility.getFileExtension(fileName); // 获取文件扩展名 String fileExtension = fileUtility.getFileExtension(fileName); // 获取文件扩展名
String fileType = fileUtility.getFileType(fileName); //获取文件类型 String fileType = fileUtility.getFileType(fileName); //获取文件类型
long fileSize = file.getSize(); // get file size long fileSize = file.getSize(); // get file size
log.info("文件上传:"+ fileName);
// check if the file size exceeds the maximum file size or is less than 0 // check if the file size exceeds the maximum file size or is less than 0
if (fileUtility.getMaxFileSize() < fileSize || fileSize <= 0) { if (fileUtility.getMaxFileSize() < fileSize || fileSize <= 0) {
Result result = Result.error("文件大小不正确!"); Result result = Result.error("文件大小不正确!");
log.info("文件大小不正确!");
return result; return result;
} }
// check if file extension is supported by the editor // check if file extension is supported by the editor
if (!fileUtility.getFileExts().contains(fileExtension)) { if (!fileUtility.getFileExts().contains(fileExtension)) {
Result result = Result.error("不支持的文件类型!"); Result result = Result.error("不支持的文件类型!");
log.info("不支持的文件类型!");
return result; return result;
} }
...@@ -105,24 +108,33 @@ public class LocalFileServiceImpl implements ILocalFileService { ...@@ -105,24 +108,33 @@ public class LocalFileServiceImpl implements ILocalFileService {
knowFile.setFileType(fileType); knowFile.setFileType(fileType);
knowFile.setFileSize(fileSize); knowFile.setFileSize(fileSize);
Result result = Result.OK(knowFile); Result result = Result.OK(knowFile);
log.info("文件上传成功:" + fileName + "---" + filePath);
return result; // create user metadata and return it return result; // create user metadata and return it
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// if the operation of file uploading is unsuccessful, an error occurs // if the operation of file uploading is unsuccessful, an error occurs
Result result = Result.error("上传文件时出现问题!"); Result result = Result.error("上传文件时出现问题!");
log.info("上传文件时出现问题!");
return result; return result;
} }
@Override @Override
public List<Result<KnowFile>> upload(Map<String, MultipartFile> fileMap) { public Result<List<KnowFile>> upload(Map<String, MultipartFile> fileMap) {
List<Result<KnowFile>> list = new ArrayList<>(); List<KnowFile> list = new ArrayList<>();
Result<List<KnowFile>> res = Result.OK(list);
for (Map.Entry<String,MultipartFile> entity : fileMap.entrySet()) { for (Map.Entry<String,MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象 MultipartFile file = entity.getValue();// 获取上传文件对象
Result<KnowFile> result = upload(file); Result<KnowFile> result = upload(file);
list.add(result); if(result.getCode() == 200){
res.getResult().add(result.getResult());
} else {
return res.error500(result.getMessage());
}
} }
return list; return res;
} }
@Override @Override
...@@ -186,15 +198,15 @@ public class LocalFileServiceImpl implements ILocalFileService { ...@@ -186,15 +198,15 @@ public class LocalFileServiceImpl implements ILocalFileService {
public void callBack(HttpServletRequest request, HttpServletResponse response) throws IOException{ public void callBack(HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter writer = null; PrintWriter writer = null;
JSONObject jsonObj = null; JSONObject jsonObj = null;
System.out.println("===saveeditedfile------------"); log.info("===saveeditedfile------------");
try { try {
writer = response.getWriter(); writer = response.getWriter();
Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A"); Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
String body = scanner.hasNext() ? scanner.next() : ""; String body = scanner.hasNext() ? scanner.next() : "";
jsonObj = (JSONObject) new JSONParser().parse(body); jsonObj = (JSONObject) new JSONParser().parse(body);
System.out.println(jsonObj); log.info(jsonObj.toJSONString());
System.out.println("===saveeditedfile:" + jsonObj.get("status")); log.info("===saveeditedfile:" + jsonObj.get("status"));
/* /*
0-找不到具有密钥标识符的文档, 0-找不到具有密钥标识符的文档,
1-文档正在编辑, 1-文档正在编辑,
...@@ -250,11 +262,11 @@ public class LocalFileServiceImpl implements ILocalFileService { ...@@ -250,11 +262,11 @@ public class LocalFileServiceImpl implements ILocalFileService {
* 定义要与文档存储服务保存的编辑文档的链接。当状态值仅等于2或3时,存在链路。 * 定义要与文档存储服务保存的编辑文档的链接。当状态值仅等于2或3时,存在链路。
* */ * */
String downloadUri = (String) jsonObj.get("url"); String downloadUri = (String) jsonObj.get("url");
System.out.println("====文档编辑完成,现在开始保存编辑后的文档,其下载地址为:" + downloadUri); log.info("====文档编辑完成,现在开始保存编辑后的文档,其下载地址为:" + downloadUri);
//解析得出文件名 //解析得出文件名
//String fileName = downloadUri.substring(downloadUri.lastIndexOf('/')+1); //String fileName = downloadUri.substring(downloadUri.lastIndexOf('/')+1);
String fileName = request.getParameter("fileName"); String fileName = request.getParameter("fileName");
System.out.println("====下载的文件名:" + fileName); log.info("====下载的文件名:" + fileName);
URL url = new URL(downloadUri); URL url = new URL(downloadUri);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection(); java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
......
...@@ -72,4 +72,4 @@ files: ...@@ -72,4 +72,4 @@ files:
timeout: 120000 timeout: 120000
history: history:
postfix: -hist postfix: -hist
filesize-max: 5242880 filesize-max: 52428800
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论