diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRecordEOController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRecordEOController.java index e506e9d8c..686997b33 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRecordEOController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRecordEOController.java @@ -7,11 +7,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.jero.common.api.vo.Result; import com.jero.common.aspect.annotation.AutoLog; import com.jero.common.system.base.controller.JeroController; -import com.jero.modules.document.entity.BussDocumentLibraryEO; import com.jero.modules.document.service.IBussDocumentLibraryEOService; import com.jero.modules.ocr.entity.OcrRecordEO; +import com.jero.modules.ocr.enums.FileSourceEnum; import com.jero.modules.ocr.enums.FileSyncStateEnum; -import com.jero.modules.ocr.enums.FileTypeEnum; import com.jero.modules.ocr.page.OcrRecordEOPage; import com.jero.modules.ocr.service.IOcrRecordEOService; import com.jero.modules.oss.entity.OSSFile; @@ -28,7 +27,9 @@ import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** @@ -72,6 +73,11 @@ public class OcrRecordEOController extends JeroController pageList = ocrRecordService.page(page, queryWrapper); List rows = pageList.getRecords(); for (OcrRecordEO row : rows){ + if(StringUtils.isNotEmpty(row.getConnectId())) { + row.setFileSource(FileSourceEnum.IMPORT.getValue()); + }else{ + row.setFileSource(FileSourceEnum.UPLOAD.getValue()); + } if(StringUtils.isNotEmpty(row.getDocRealName())) { row.setDocRealFile(ocrDownPath + row.getDocRealName()); } @@ -86,97 +92,29 @@ public class OcrRecordEOController extends JeroController syncToDocument(@RequestBody OcrRecordEO ocrRecordEO) { - if(StringUtils.isBlank(ocrRecordEO.getAttId())){ - return Result.error("没有可同步的文档"); + if(StringUtils.isBlank(ocrRecordEO.getConnectId())){ + return Result.error("同步失败"); } - if (StringUtils.isBlank(ocrRecordEO.getStandName()) - || StringUtils.isBlank(ocrRecordEO.getStandNumber())){ - return Result.error("参数不能为空"); + //查询doc文件的id + LambdaQueryWrapper ossFileLambdaQueryWrapper = new LambdaQueryWrapper<>(); + ossFileLambdaQueryWrapper.eq(OSSFile::getUrl, ocrRecordEO.getDocName()); + List ossFiles = ossFileService.list(ossFileLambdaQueryWrapper); + if (CollectionUtil.isEmpty(ossFiles)) { + return Result.error("没有可同步的文件"); } - if (StringUtils.isBlank(ocrRecordEO.getFileType())) { - return Result.error("文本状态不能为空"); - } - //通过编号和标题查询对应文档 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(BussDocumentLibraryEO::getTitle, ocrRecordEO.getStandName()) - .eq(BussDocumentLibraryEO::getSerialNumber, ocrRecordEO.getStandNumber()); - List bussDocumentLibraryEOList = bussDocumentLibraryEOService.list(queryWrapper); - if(CollectionUtil.isNotEmpty(bussDocumentLibraryEOList)){ - //查询doc文件的id - LambdaQueryWrapper ossFileLambdaQueryWrapper = new LambdaQueryWrapper<>(); - ossFileLambdaQueryWrapper.eq(OSSFile::getUrl, ocrRecordEO.getDocName()); - List ossFiles = ossFileService.list(ossFileLambdaQueryWrapper); - if (CollectionUtil.isEmpty(ossFiles)) { - return Result.error("没有可同步的文件"); - } - //开始同步 - int countSuccess = 0; - for(BussDocumentLibraryEO documentLibraryEO : bussDocumentLibraryEOList) { - OSSFile ossFile = new OSSFile(); - String docFileId = ossFiles.get(0).getId(); - ossFile.setId(docFileId); - //设置doc文件的关联id - if (FileTypeEnum.RELEASE_DRAFT.getValue().equals(ocrRecordEO.getFileType())) { - String connectId = documentLibraryEO.getReleaseDraft(); - if (StringUtils.isBlank(connectId)) { - connectId = UUID.randomUUID().toString().replace("-", ""); - //修改文档库相关字段 - BussDocumentLibraryEO bussDocumentLibraryEO = new BussDocumentLibraryEO(); - bussDocumentLibraryEO.setId(documentLibraryEO.getId()); - bussDocumentLibraryEO.setReleaseDraft(connectId); - bussDocumentLibraryEOService.updateById(bussDocumentLibraryEO); - } - ossFile.setConnectId(connectId); + OSSFile ossFile = new OSSFile(); + String docFileId = ossFiles.get(0).getId(); + ossFile.setId(docFileId); + ossFile.setConnectId(ocrRecordEO.getConnectId()); + ossFileService.updateById(ossFile); - } else if (FileTypeEnum.SUPPLEMENT.getValue().equals(ocrRecordEO.getFileType())) { - String connectId = documentLibraryEO.getSupplement(); - if (StringUtils.isBlank(connectId)) { - connectId = UUID.randomUUID().toString().replace("-", ""); - //修改文档库相关字段 - BussDocumentLibraryEO bussDocumentLibraryEO = new BussDocumentLibraryEO(); - bussDocumentLibraryEO.setId(documentLibraryEO.getId()); - bussDocumentLibraryEO.setSupplement(connectId); - bussDocumentLibraryEOService.updateById(bussDocumentLibraryEO); - } - ossFile.setConnectId(connectId); + //修改记录表的同步情况 + OcrRecordEO updateOcrRecordEO = new OcrRecordEO(); + updateOcrRecordEO.setId(ocrRecordEO.getId()); + updateOcrRecordEO.setSyncState(FileSyncStateEnum.SYNC_YES.getValue()); + ocrRecordService.editById(updateOcrRecordEO); - } else if (FileTypeEnum.APPROVAL_DRAFT.getValue().equals(ocrRecordEO.getFileType())) { - String connectId = documentLibraryEO.getApprovalDraft(); - if (StringUtils.isBlank(connectId)) { - connectId = UUID.randomUUID().toString().replace("-", ""); - //修改文档库相关字段 - BussDocumentLibraryEO bussDocumentLibraryEO = new BussDocumentLibraryEO(); - bussDocumentLibraryEO.setId(documentLibraryEO.getId()); - bussDocumentLibraryEO.setApprovalDraft(connectId); - bussDocumentLibraryEOService.updateById(bussDocumentLibraryEO); - } - ossFile.setConnectId(connectId); - - } else if (FileTypeEnum.EXPOSURE_DRAFT.getValue().equals(ocrRecordEO.getFileType())) { - String connectId = documentLibraryEO.getExposureDraft(); - if (StringUtils.isBlank(connectId)) { - connectId = UUID.randomUUID().toString().replace("-", ""); - //修改文档库相关字段 - BussDocumentLibraryEO bussDocumentLibraryEO = new BussDocumentLibraryEO(); - bussDocumentLibraryEO.setId(documentLibraryEO.getId()); - bussDocumentLibraryEO.setExposureDraft(connectId); - bussDocumentLibraryEOService.updateById(bussDocumentLibraryEO); - } - ossFile.setConnectId(connectId); - - } - ossFileService.updateById(ossFile); - //修改记录表的同步情况 - OcrRecordEO updateOcrRecordEO = new OcrRecordEO(); - updateOcrRecordEO.setId(ocrRecordEO.getId()); - updateOcrRecordEO.setSyncState(FileSyncStateEnum.SYNC_YES.getValue()); - ocrRecordService.editById(updateOcrRecordEO); - countSuccess++; - } - return Result.OK("同步成功", countSuccess); - }else{ - return Result.error("没有可同步的文档"); - } + return Result.OK("同步成功", ossFile); } /** diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRestfulController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRestfulController.java index 73a8c5d45..dec4efd75 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRestfulController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/controller/OcrRestfulController.java @@ -105,7 +105,9 @@ public class OcrRestfulController{ * OCR回调 * @param wordFile * @param jsonFile - * @param ocrCallBackResultEo + * @param taskId + * @param result + * @param key * @return */ @ApiOperation(value = "OCR回调") diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/entity/OcrRecordEO.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/entity/OcrRecordEO.java index c23b80c5c..1c49f6f67 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/entity/OcrRecordEO.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/entity/OcrRecordEO.java @@ -1,22 +1,20 @@ package com.jero.modules.ocr.entity; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; import com.fasterxml.jackson.annotation.JsonFormat; -import org.springframework.format.annotation.DateTimeFormat; -import org.jeecgframework.poi.excel.annotation.Excel; import com.jero.common.aspect.annotation.Dict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; /** @@ -128,9 +126,15 @@ public class OcrRecordEO implements Serializable { @Excel(name = "同步状态", width = 15) @ApiModelProperty(value = "同步状态") private String syncState; + + /**文档库关联文件id*/ + @ApiModelProperty(value = "文档库关联文件id") + private String connectId; @TableField(exist = false) private String docRealFile; @TableField(exist = false) private String jsonRealFile; + @TableField(exist = false) + private String fileSource; //文件来源:0-上传 1-导入 } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/enums/FileSourceEnum.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/enums/FileSourceEnum.java new file mode 100644 index 000000000..92e6f5b38 --- /dev/null +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/enums/FileSourceEnum.java @@ -0,0 +1,36 @@ +package com.jero.modules.ocr.enums; + +/** + * @Author: liyawei + * @Description: + * @Date: Created in 16:04 2022/3/8 + */ +public enum FileSourceEnum { + UPLOAD("上传","0"), + IMPORT("导入","1"); + + String name; + String value; + + FileSourceEnum(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; + } + +} diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/mapper/xml/OcrRecordEOMapper.xml b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/mapper/xml/OcrRecordEOMapper.xml index 1f4706a18..6c646df99 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/mapper/xml/OcrRecordEOMapper.xml +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/mapper/xml/OcrRecordEOMapper.xml @@ -21,5 +21,6 @@ + \ No newline at end of file diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/service/impl/OcrRestfulServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/service/impl/OcrRestfulServiceImpl.java index 8ec0cc294..a54460046 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/service/impl/OcrRestfulServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ocr/service/impl/OcrRestfulServiceImpl.java @@ -11,6 +11,8 @@ import com.jero.modules.ocr.service.IOcrRestfulService; import com.jero.modules.ocr.util.Base64Util; import com.jero.modules.ocr.util.RsaUtil; import com.jero.modules.ocr.util.UUIDUtils; +import com.jero.modules.oss.entity.OSSFile; +import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.system.vo.OcrVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; @@ -32,6 +34,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.UUID; /** * @program: OcrDemo @@ -52,6 +55,8 @@ public class OcrRestfulServiceImpl implements IOcrRestfulService { @Autowired private IOcrRecordEOService ocrRecordEOService; + @Autowired + private IOSSFileService ossFileService; //请求处理文件url @@ -202,7 +207,15 @@ public class OcrRestfulServiceImpl implements IOcrRestfulService { ocrRecordEO.setJsonFileCode(null); ocrRecordEO.setUpdateTime(new Date()); ocrRecordEO.setResultContent("转换成功"); - ocrRecordEOService.editById(ocrRecordEO); + ocrRecordEOService.updateById(ocrRecordEO); + + //记录doc文件信息 + OSSFile docFile = new OSSFile(); + docFile.setId(UUID.randomUUID().toString().replace("-", "")); + docFile.setUrl(saveWordFilePath); + docFile.setFileName(saveWordFilePath.substring(saveWordFilePath.lastIndexOf("_")+1)); + ossFileService.save(docFile); + return "{\"result\":\"success\"}"; }else{ updateDb(taskId,"error:File does not exist");