|
|
@@ -1,6 +1,10 @@
|
|
|
package com.doc.scanner.controller;
|
|
|
|
|
|
+import com.doc.biz.domain.DocDir;
|
|
|
+import com.doc.biz.domain.DocInfo;
|
|
|
+import com.doc.biz.service.IDocDirService;
|
|
|
import com.doc.biz.service.IDocInfoService;
|
|
|
+import com.doc.biz.service.IDocSpaceService;
|
|
|
import com.doc.biz.service.IMongoService;
|
|
|
import com.doc.biz.vo.DocumentVO;
|
|
|
import com.doc.common.annotation.Log;
|
|
|
@@ -55,6 +59,10 @@ public class ScannerInfoController extends BaseController {
|
|
|
private IDocInfoService docInfoService;
|
|
|
@Resource
|
|
|
private IMongoService mongoService;
|
|
|
+ @Resource
|
|
|
+ private IDocSpaceService spaceService;
|
|
|
+ @Resource
|
|
|
+ private IDocDirService dirService;
|
|
|
@Value("${ftp.port}")
|
|
|
private int port;
|
|
|
|
|
|
@@ -139,12 +147,16 @@ public class ScannerInfoController extends BaseController {
|
|
|
@PostMapping(value = "/claim")
|
|
|
@Log(title = "扫描仪管理", businessType = BusinessType.INSERT, eventLevel = EventLevel.MIDDLE)
|
|
|
public AjaxResult claim(@RequestBody ScannerVO obj) {
|
|
|
+ DocDir dir = dirService.selectDocDirByDirId(obj.getDirId());
|
|
|
+ Long spaceId = dir.getSpaceId();
|
|
|
+ List<String> fileIds = new ArrayList<>();
|
|
|
if (obj.getMerge()) {
|
|
|
//是否合并为PDF
|
|
|
File f = PdfUtils.imageToPdf(obj.getQ());
|
|
|
if (f != null && f.exists()) {
|
|
|
String name = obj.getName() + ".pdf";
|
|
|
- claimUpload(f, name, obj.getSpaceId(), obj.getDirId());
|
|
|
+ DocInfo info = claimUpload(f, name, spaceId, obj.getDirId());
|
|
|
+ fileIds.add(info.getFileId());
|
|
|
} else {
|
|
|
return error("文件已被人认领!");
|
|
|
}
|
|
|
@@ -156,10 +168,11 @@ public class ScannerInfoController extends BaseController {
|
|
|
String name = index.get() == 1 ? obj.getName() : obj.getName() + index;
|
|
|
index.getAndIncrement();
|
|
|
name += path.substring(path.lastIndexOf("."));
|
|
|
- claimUpload(f, name, obj.getSpaceId(), obj.getDirId());
|
|
|
+ DocInfo info = claimUpload(f, name, spaceId, obj.getDirId());
|
|
|
+ fileIds.add(info.getFileId());
|
|
|
});
|
|
|
}
|
|
|
- return success(1);
|
|
|
+ return success(fileIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -170,16 +183,18 @@ public class ScannerInfoController extends BaseController {
|
|
|
* @param spaceId 空间ID
|
|
|
* @param dirId 目录ID
|
|
|
*/
|
|
|
- private void claimUpload(File f, String name, Long spaceId, Long dirId) {
|
|
|
+ private DocInfo claimUpload(File f, String name, Long spaceId, Long dirId) {
|
|
|
try (FileInputStream input = new FileInputStream(f)) {
|
|
|
MultipartFile file = FileUtils.getMultipartFile(input, name);
|
|
|
|
|
|
DocumentVO vo = mongoService.uploadFile(file);
|
|
|
- docInfoService.upload(vo, spaceId, dirId);
|
|
|
+ DocInfo info = docInfoService.upload(vo, spaceId, dirId);
|
|
|
|
|
|
FileUtils.deleteFile(f.getPath());
|
|
|
+ return info;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("认领出错啦:{}", e.getMessage());
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|