| 
					
				 | 
			
			
				@@ -3,7 +3,6 @@ package com.doc.biz.controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.biz.domain.DocDir; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.biz.domain.DocInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.biz.domain.DocSpace; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.doc.biz.domain.EsDocInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.biz.service.IDocDirService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.biz.service.IDocInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.biz.service.IEsDocInfoService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -16,7 +15,6 @@ import com.doc.common.core.controller.BaseController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.common.core.domain.AjaxResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.common.core.page.TableDataInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.common.enums.BusinessType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.doc.common.utils.FileContentUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.common.utils.SecurityUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.common.utils.bean.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.doc.common.utils.file.FileUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -36,7 +34,6 @@ import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.function.Function; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 文件基本信息表Controller 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -54,11 +51,11 @@ public class DocInfoController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private IMongoService mongoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private IEsDocInfoService esDocInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IDocDirService dirService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private EsConfig esConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private IDocDirService dirService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IEsDocInfoService esDocInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 文件上传 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -115,9 +112,6 @@ public class DocInfoController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         docInfo.setFileType(vo.getSuffix()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         docInfo.setCreateBy(SecurityUtils.getUsername()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         docInfoService.insertDocInfo(docInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        DocumentVO documentVO = mongoService.downloadFile(vo.getFileId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        insertEs(documentVO.getData(), docInfo.getFileType(), docInfo.getDocId(), spaceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -126,7 +120,7 @@ public class DocInfoController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApiOperation("新建文件") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @GetMapping("/create") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApiImplicitParams({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            @ApiImplicitParam(name = "type", value = "文件类型 \"word\":word文档 \"excel\":excel文件 \"ppt\".ppt文件", required = true), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiImplicitParam(name = "type", value = "文件类型 \"word\":word文档 \"excel\":excel文件 \"ppt\":ppt文件  \"txt\":文本文件", required = true), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @ApiImplicitParam(name = "spaceId", value = "空间ID", required = true), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @ApiImplicitParam(name = "dirId", value = "目录ID", required = true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -147,6 +141,10 @@ public class DocInfoController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     file = ResourceUtils.getFile("classpath:file/new.pptx"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     fileName = "新建ppt文档.pptx"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                case "txt": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    file = ResourceUtils.getFile("classpath:file/new.txt"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    fileName = "新建文本文档.txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             FileInputStream is = new FileInputStream(file); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -320,7 +318,6 @@ public class DocInfoController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Log(title = "文件基本信息表", businessType = BusinessType.UPDATE) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @PutMapping 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public AjaxResult edit(@RequestBody DocInfo docInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //TODO 文件内容修改的ES处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         docInfo.setUpdateBy(SecurityUtils.getUsername()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return toAjax(docInfoService.updateDocInfo(docInfo)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -351,31 +348,4 @@ public class DocInfoController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 文件内容入es库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param data    二进制文件内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param ext     扩展名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param docId   文档ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param spaceId 空间ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void insertEs(byte[] data, String ext, Long docId, Long spaceId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //组装ES索引名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String indexName = "docs_" + spaceId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<String, Function<byte[], String>> handlerMap = new HashMap<>(16); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        handlerMap.put(".docx", FileContentUtils::getContentDocx); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        handlerMap.put(".doc", FileContentUtils::getContentDoc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        handlerMap.put(".wps", FileContentUtils::getContentWps); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        handlerMap.put(".txt", FileContentUtils::getContentTxt); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Function<byte[], String> handler = handlerMap.get(ext); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (handler != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            String content = handler.apply(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            System.err.println(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            EsDocInfo esDocInfo = new EsDocInfo(docId, content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            esConfig.setIndexName(indexName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            esDocInfoService.save(esDocInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |