ocr识别-校核限制不能同时编辑
This commit is contained in:
+123
-36
@@ -1,19 +1,27 @@
|
|||||||
package com.jero.modules.ocr.controller;
|
package com.jero.modules.ocr.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.jero.common.api.vo.Result;
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
import com.jero.common.system.vo.LoginUser;
|
import com.jero.common.system.vo.LoginUser;
|
||||||
|
import com.jero.modules.ocr.entity.OcrRecordEO;
|
||||||
|
import com.jero.modules.ocr.enums.CheckFlagEnum;
|
||||||
import com.jero.modules.ocr.helpers.ConfigManager;
|
import com.jero.modules.ocr.helpers.ConfigManager;
|
||||||
import com.jero.modules.ocr.helpers.DocumentManager;
|
import com.jero.modules.ocr.helpers.DocumentManager;
|
||||||
import com.jero.modules.ocr.helpers.FileUtility;
|
import com.jero.modules.ocr.helpers.FileUtility;
|
||||||
import com.jero.modules.ocr.helpers.ServiceConverter;
|
import com.jero.modules.ocr.helpers.ServiceConverter;
|
||||||
|
import com.jero.modules.ocr.service.IOcrRecordEOService;
|
||||||
|
import com.jero.modules.ocr.service.WebSocketServer;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -40,6 +48,11 @@ import java.util.Scanner;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class OcrCheckController {
|
public class OcrCheckController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOcrRecordEOService ocrRecordService;
|
||||||
|
@Autowired
|
||||||
|
private WebSocketServer webSocketServer;
|
||||||
|
|
||||||
@Value("${OCR.ocrDownPath}")
|
@Value("${OCR.ocrDownPath}")
|
||||||
private String ocrDownPath;
|
private String ocrDownPath;
|
||||||
|
|
||||||
@@ -78,14 +91,37 @@ public class OcrCheckController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "验证文档是否被锁定")
|
||||||
|
@GetMapping("/verifyCheckFlag")
|
||||||
|
public Result<?> verifyCheckFlag(String id) {
|
||||||
|
if(StringUtils.isBlank(id)){
|
||||||
|
return Result.error("参数不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
OcrRecordEO ocrRecordEO = ocrRecordService.getById(id);
|
||||||
|
if (CheckFlagEnum.LOCK.getValue().equals(ocrRecordEO.getCheckFlag())) {
|
||||||
|
return Result.error("该文档当前正在被校核,请稍后重试!");
|
||||||
|
|
||||||
|
} else if (CheckFlagEnum.UNLOCK.getValue().equals(ocrRecordEO.getCheckFlag())) {
|
||||||
|
return Result.OK();
|
||||||
|
}
|
||||||
|
// 文档没被校核过
|
||||||
|
return Result.OK();
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "编辑文件")
|
@ApiOperation(value = "编辑文件")
|
||||||
@RequestMapping("/editorFile")
|
@RequestMapping("/editorFile")
|
||||||
public ModelAndView index(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
|
public ModelAndView index(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
|
||||||
|
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
if (request.getParameterMap().containsKey("fileName")) {
|
String id = "";
|
||||||
fileName = request.getParameter("fileName");
|
try {
|
||||||
}
|
if (request.getParameterMap().containsKey("fileName")) {
|
||||||
|
fileName = request.getParameter("fileName");
|
||||||
|
}
|
||||||
|
if (request.getParameterMap().containsKey("id")) {
|
||||||
|
id = request.getParameter("id");
|
||||||
|
}
|
||||||
// String fileExt = null;
|
// String fileExt = null;
|
||||||
// if (request.getParameterMap().containsKey("fileExt")) {
|
// if (request.getParameterMap().containsKey("fileExt")) {
|
||||||
// fileExt = request.getParameter("fileExt");
|
// fileExt = request.getParameter("fileExt");
|
||||||
@@ -111,37 +147,48 @@ public class OcrCheckController {
|
|||||||
// file.SetTypeDesktop(desktopMode);
|
// file.SetTypeDesktop(desktopMode);
|
||||||
// file.SetFileName(fileName);
|
// file.SetFileName(fileName);
|
||||||
|
|
||||||
log.info("==========EditorFile==========");
|
log.info("==========EditorFile==========");
|
||||||
DocumentManager.Init(request, response);
|
|
||||||
//要编辑的文件名
|
DocumentManager.Init(request, response);
|
||||||
model.addAttribute("fileName", fileName) ;
|
//要编辑的文件名
|
||||||
//要编辑的文件类型
|
model.addAttribute("fileName", fileName);
|
||||||
model.addAttribute("fileType", FileUtility.GetFileExtension(fileName).replace(".", "")) ;
|
//要编辑的文件类型
|
||||||
//要编辑的文档类型
|
model.addAttribute("fileType", FileUtility.GetFileExtension(fileName).replace(".", ""));
|
||||||
model.addAttribute("documentType",FileUtility.GetFileType(fileName).toString().toLowerCase()) ;
|
//要编辑的文档类型
|
||||||
//要编辑的文档访问url
|
model.addAttribute("documentType", FileUtility.GetFileType(fileName).toString().toLowerCase());
|
||||||
|
//要编辑的文档访问url
|
||||||
// model.addAttribute("fileUri",DocumentManager.GetFileUri(fileName, true)) ;
|
// model.addAttribute("fileUri",DocumentManager.GetFileUri(fileName, true)) ;
|
||||||
// model.addAttribute("callbackUrl", DocumentManager.GetCallback(fileName)) ;
|
// model.addAttribute("callbackUrl", DocumentManager.GetCallback(fileName)) ;
|
||||||
// model.addAttribute("serverUrl", DocumentManager.GetServerUrl(true)) ;
|
// model.addAttribute("serverUrl", DocumentManager.GetServerUrl(true)) ;
|
||||||
model.addAttribute("fileUri", ocrDownPath + "?fileName=" + fileName) ;
|
model.addAttribute("fileUri", ocrDownPath + "?fileName=" + fileName);
|
||||||
model.addAttribute("callbackUrl", ocrSavePath + "?fileName=" + fileName) ;
|
model.addAttribute("callbackUrl", ocrSavePath + "?id=" + id);
|
||||||
model.addAttribute("serverUrl", serverUrl) ;
|
model.addAttribute("serverUrl", serverUrl);
|
||||||
model.addAttribute("fileKey", ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + ocrDownPath + "?fileName=" + fileName)) ;
|
model.addAttribute("fileKey", ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + ocrDownPath + "?fileName=" + fileName));
|
||||||
model.addAttribute("editorMode", DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(fileName)) && !"view".equals(request.getAttribute("mode")) ? "edit" : "view") ;
|
model.addAttribute("editorMode", DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(fileName)) && !"view".equals(request.getAttribute("mode")) ? "edit" : "view");
|
||||||
model.addAttribute("editorUserId",DocumentManager.CurUserHostAddress(null)) ;
|
model.addAttribute("editorUserId", DocumentManager.CurUserHostAddress(null));
|
||||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
model.addAttribute("editorUserName", loginUser.getUsername()) ;
|
model.addAttribute("editorUserName", loginUser.getUsername());
|
||||||
|
|
||||||
// model.addAttribute("type", desktopMode ? "desktop" : "embedded");
|
// model.addAttribute("type", desktopMode ? "desktop" : "embedded");
|
||||||
model.addAttribute("type", true ? "desktop" : "embedded");
|
model.addAttribute("type", true ? "desktop" : "embedded");
|
||||||
model.addAttribute("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
|
model.addAttribute("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.api"));
|
||||||
model.addAttribute("docServiceUrlPreloader", ConfigManager.GetProperty("files.docservice.url.preloader")) ;
|
model.addAttribute("docServiceUrlPreloader", ConfigManager.GetProperty("files.docservice.url.preloader"));
|
||||||
model.addAttribute("currentYear", "2022") ;
|
model.addAttribute("currentYear", "2022");
|
||||||
model.addAttribute("convertExts", String.join(",", DocumentManager.GetConvertExts())) ;
|
model.addAttribute("convertExts", String.join(",", DocumentManager.GetConvertExts()));
|
||||||
model.addAttribute("editedExts", String.join(",", DocumentManager.GetEditedExts())) ;
|
model.addAttribute("editedExts", String.join(",", DocumentManager.GetEditedExts()));
|
||||||
model.addAttribute("documentCreated", new SimpleDateFormat("MM/dd/yyyy").format(new Date())) ;
|
model.addAttribute("documentCreated", new SimpleDateFormat("MM/dd/yyyy").format(new Date()));
|
||||||
model.addAttribute("permissionsEdit", Boolean.toString(DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(fileName))).toLowerCase()) ;
|
model.addAttribute("permissionsEdit", Boolean.toString(DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(fileName))).toLowerCase());
|
||||||
return new ModelAndView("editor") ;
|
return new ModelAndView("editor");
|
||||||
|
} finally {
|
||||||
|
// 校核锁定
|
||||||
|
if (StringUtils.isNotBlank(id)) {
|
||||||
|
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||||
|
ocrRecordEO.setId(id);
|
||||||
|
ocrRecordEO.setCheckFlag(CheckFlagEnum.LOCK.getValue());
|
||||||
|
// 校核锁定
|
||||||
|
ocrRecordService.updateById(ocrRecordEO);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,17 +211,25 @@ public class OcrCheckController {
|
|||||||
@ApiOperation(value = "保存文件")
|
@ApiOperation(value = "保存文件")
|
||||||
@RequestMapping("/saveFile")
|
@RequestMapping("/saveFile")
|
||||||
public void saveFile(HttpServletRequest request, HttpServletResponse response) {
|
public void saveFile(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
String id = "";
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
if (request.getParameterMap().containsKey("fileName")) {
|
|
||||||
fileName = request.getParameter("fileName");
|
|
||||||
}
|
|
||||||
PrintWriter writer = null;
|
PrintWriter writer = null;
|
||||||
log.info("==========SaveEditedFile==========");
|
|
||||||
try {
|
try {
|
||||||
|
if (request.getParameterMap().containsKey("id")) {
|
||||||
|
id = request.getParameter("id");
|
||||||
|
OcrRecordEO ocrRecordEO = ocrRecordService.getById(id);
|
||||||
|
if(ObjectUtil.isNotEmpty(ocrRecordEO)){
|
||||||
|
fileName = ocrRecordEO.getDocRealName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("==========SaveEditedFile==========");
|
||||||
|
|
||||||
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() : "";
|
||||||
JSONObject jsonObj = (JSONObject) new JSONParser().parse(body);
|
JSONObject jsonObj = (JSONObject) new JSONParser().parse(body);
|
||||||
|
log.info("返回结果:" + jsonObj.toString());
|
||||||
log.info("status:" + jsonObj.get("status"));
|
log.info("status:" + jsonObj.get("status"));
|
||||||
/*
|
/*
|
||||||
0 - no document with the key identifier could be found,
|
0 - no document with the key identifier could be found,
|
||||||
@@ -185,7 +240,16 @@ public class OcrCheckController {
|
|||||||
6 - document is being edited, but the current document state is saved,
|
6 - document is being edited, but the current document state is saved,
|
||||||
7 - error has occurred while force saving the document.
|
7 - error has occurred while force saving the document.
|
||||||
* */
|
* */
|
||||||
if ((long) jsonObj.get("status") == 2) {
|
if ((long) jsonObj.get("status") == 4) {
|
||||||
|
// status=4 没有编辑内容,直接关闭编辑窗口
|
||||||
|
// 校核解锁
|
||||||
|
if(StringUtils.isNotBlank(id)){
|
||||||
|
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||||
|
ocrRecordEO.setId(id);
|
||||||
|
ocrRecordEO.setCheckFlag(CheckFlagEnum.UNLOCK.getValue());
|
||||||
|
ocrRecordService.updateById(ocrRecordEO);
|
||||||
|
}
|
||||||
|
} else if ((long) jsonObj.get("status") == 2) {
|
||||||
/*
|
/*
|
||||||
* 当我们关闭编辑窗口后,十秒钟左右onlyoffice会将它存储的我们的编辑后的文件,,此时status = 2,通过request发给我们,我们需要做的就是接收到文件然后回写该文件。
|
* 当我们关闭编辑窗口后,十秒钟左右onlyoffice会将它存储的我们的编辑后的文件,,此时status = 2,通过request发给我们,我们需要做的就是接收到文件然后回写该文件。
|
||||||
* */
|
* */
|
||||||
@@ -213,17 +277,40 @@ public class OcrCheckController {
|
|||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
|
// 校核解锁
|
||||||
|
if(StringUtils.isNotBlank(id)){
|
||||||
|
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||||
|
ocrRecordEO.setId(id);
|
||||||
|
ocrRecordEO.setCheckFlag(CheckFlagEnum.UNLOCK.getValue());
|
||||||
|
// 校核解锁
|
||||||
|
ocrRecordService.updateById(ocrRecordEO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
log.error(e.getMessage());
|
||||||
|
// 校核解锁
|
||||||
|
if(StringUtils.isNotBlank(id)){
|
||||||
|
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||||
|
ocrRecordEO.setId(id);
|
||||||
|
ocrRecordEO.setCheckFlag(CheckFlagEnum.UNLOCK.getValue());
|
||||||
|
ocrRecordService.updateById(ocrRecordEO);
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
log.error(e.getMessage());
|
||||||
|
// 校核解锁
|
||||||
|
if(StringUtils.isNotBlank(id)){
|
||||||
|
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||||
|
ocrRecordEO.setId(id);
|
||||||
|
ocrRecordEO.setCheckFlag(CheckFlagEnum.UNLOCK.getValue());
|
||||||
|
ocrRecordService.updateById(ocrRecordEO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* status = 1,我们给onlyoffice的服务返回{"error":"0"}的信息,这样onlyoffice会认为回调接口是没问题的,这样就可以在线编辑文档了,否则的话会弹出窗口说明
|
* status = 1,我们给onlyoffice的服务返回{"error":"0"}的信息,这样onlyoffice会认为回调接口是没问题的,这样就可以在线编辑文档了,否则的话会弹出窗口说明
|
||||||
* */
|
* */
|
||||||
writer.write("{\"error\":0}");
|
writer.write("{\"error\":0}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ public class OcrRecordEO implements Serializable {
|
|||||||
/**文档库关联文件id*/
|
/**文档库关联文件id*/
|
||||||
@ApiModelProperty(value = "文档库关联文件id")
|
@ApiModelProperty(value = "文档库关联文件id")
|
||||||
private String connectId;
|
private String connectId;
|
||||||
|
|
||||||
|
/**校核锁定标识*/
|
||||||
|
@ApiModelProperty(value = "校核锁定标识")
|
||||||
|
private String checkFlag;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String docRealFile;
|
private String docRealFile;
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
package com.jero.modules.ocr.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: liyawei
|
||||||
|
* @Description:
|
||||||
|
* @Date: Created in 11:20 2022/4/14
|
||||||
|
*/
|
||||||
|
public enum CheckFlagEnum {
|
||||||
|
LOCK("锁定","1"),
|
||||||
|
UNLOCK("解锁","0");
|
||||||
|
|
||||||
|
String name;
|
||||||
|
String value;
|
||||||
|
|
||||||
|
CheckFlagEnum(String name, String value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -22,5 +22,6 @@
|
|||||||
<result column="att_id" property="attId" />
|
<result column="att_id" property="attId" />
|
||||||
<result column="sync_state" property="syncState" />
|
<result column="sync_state" property="syncState" />
|
||||||
<result column="connect_id" property="connectId" />
|
<result column="connect_id" property="connectId" />
|
||||||
|
<result column="check_flag" property="checkFlag" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user