逻辑变更

segment2.0
zhanglb 2 years ago
parent 1589297772
commit 2ff3bed247

@ -16,4 +16,8 @@ public interface IFileUploadService {
void getImage(String filePath, HttpServletResponse response, HttpServletRequest request) throws Exception;
List<UploadFileVO> uploadFile(MultipartFile[] files, String segmentation, Double height, Double widthStart, Double widthEnd) throws Exception;
void compressFile(String compressPath,String picPath,String fileName,Double compressWidth);
void cutPic(String saveCutFilePath,String compressPath,String fileName,Double widthStart, Double heightStart);
}

@ -92,7 +92,7 @@ public class FileUploadServiceImpl implements IFileUploadService {
uploadFileVOList.add(actionUploadFile(multipartFile, pathKey, height, widthStart, widthEnd));
System.out.println(multipartFile.getOriginalFilename() + "====图片压缩和剪切总耗时=======>" + watch.elapsedTime() + "(ms)" + "<===========");
System.out.println(multipartFile.getOriginalFilename() + "====图片上传总耗时=======>" + watch.elapsedTime() + "(ms)" + "<===========");
}
return uploadFileVOList;
}
@ -109,7 +109,6 @@ public class FileUploadServiceImpl implements IFileUploadService {
}
String fileName = path + multipartFile.getOriginalFilename();
File dest = new File(saveFilePath + fileName);
UploadFileVO uploadFileVO = new UploadFileVO();
@ -120,57 +119,65 @@ public class FileUploadServiceImpl implements IFileUploadService {
uploadFileVO.setFilePath(fileName);
uploadFileVO.setSaveFilePath(saveFilePath);
uploadFileVO.setParams(ParamsUtils.addParam("compressWidth", compressWidth).addParam("widthStart", widthStart).addParam("heightStart", heightStart).param());
uploadFileVO.setSaveCutFilePath(saveCutFilePath);
uploadFileVO.setSaveCompressFilePath(saveCompressFilePath);
multipartFile.transferTo(dest);
return uploadFileVO;
}
if (Func.isNotBlank(saveCompressFilePath)) {
File compressFileDir = new File(saveCompressFilePath + path);
if (!compressFileDir.exists()) {
compressFileDir.mkdirs();
}
File compressDest = new File(saveCompressFilePath + fileName);
BufferedImage image = ImageIO.read(multipartFile.getInputStream());
int width = image.getWidth();
//图片压缩
ImgUtil.scale(image, FileUtil.file(compressDest), (float) (compressWidth / width));
uploadFileVO.setSaveCompressFilePath(saveCompressFilePath);
@Override
public void compressFile(String compressPath,String picPath,String fileName,Double compressWidth) {
if (Func.isNotBlank(compressPath)) {
try {
File compressFileDir = new File(compressPath);
if (!compressFileDir.exists()) {
compressFileDir.mkdirs();
}
File compressDest = new File(saveCompressFilePath+fileName);
BufferedImage image = ImageIO.read(new File(picPath));
int width = image.getWidth();
//图片压缩
ImgUtil.scale(image, FileUtil.file(compressDest), (float) (compressWidth / width));
}catch (Exception e){
}finally {
}
}
}
@Override
public void cutPic(String saveCutFilePath,String compressPath,String fileName,Double widthStart, Double heightStart){
if (Func.isNotBlank(saveCutFilePath)) {
File cutFileDir = new File(saveCutFilePath + path);
if (!cutFileDir.exists()) {
cutFileDir.mkdirs();
try {
File cutFileDir = new File(saveCutFilePath + fileName);
if (!cutFileDir.exists()) {
cutFileDir.mkdirs();
}
File cutDest = new File(saveCutFilePath + fileName);
BufferedImage image = ImageIO.read(FileUtil.file(compressPath+fileName));
int height = image.getHeight();
int width = image.getWidth();
int startY = height / 100 * widthStart.intValue();
int endY = height / 100 * (heightStart.intValue() - widthStart.intValue());
//剪切
ImgUtil.cut(image, FileUtil.file(cutDest), new Rectangle(0, startY, width, endY));
}catch (Exception e){
}finally {
}
File cutDest = new File(saveCutFilePath + fileName);
BufferedImage image = ImageIO.read(FileUtil.file(saveCompressFilePath + fileName));
int height = image.getHeight();
int width = image.getWidth();
int minX = image.getMinX();
int minY = image.getMinY();
int startY = height /100 * widthStart.intValue();
int endY = height /100 * (heightStart.intValue() - widthStart.intValue());
log.info("cutInfo :" +height +" "+width+" "+startY+" "+endY);
//剪切
ImgUtil.cut(image, FileUtil.file(cutDest), new Rectangle(0, startY, width, endY));
uploadFileVO.setWidth(width);
uploadFileVO.setHeight(height);
uploadFileVO.setX(minX);
uploadFileVO.setY(minY);
uploadFileVO.setSaveCutFilePath(saveCutFilePath);
}
multipartFile.transferTo(dest);
return uploadFileVO;
}
@Override
public void downloadFile(String path, HttpServletResponse response) {
//创建输入流
FileInputStream inputStream = null;
BufferedInputStream buffInputStream = null;
//创建输出流
ServletOutputStream outputStream = null;
BufferedOutputStream buffOutputStream = null;
try {
//获取要下载的文件
// File file = new File(saveFilePath + "/" + path);
@ -183,12 +190,12 @@ public class FileUploadServiceImpl implements IFileUploadService {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
//创建输入流
FileInputStream inputStream = new FileInputStream(file);
BufferedInputStream buffInputStream = new BufferedInputStream(inputStream);
inputStream = new FileInputStream(file);
buffInputStream = new BufferedInputStream(inputStream);
//创建输出流
ServletOutputStream outputStream = response.getOutputStream();
BufferedOutputStream buffOutputStream = new BufferedOutputStream(outputStream);
outputStream = response.getOutputStream();
buffOutputStream = new BufferedOutputStream(outputStream);
//循环读取数据并写入到响应输出流中
byte[] buffer = new byte[1024];
@ -206,6 +213,20 @@ public class FileUploadServiceImpl implements IFileUploadService {
inputStream.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
}finally {
try {
if (inputStream!=null){
inputStream.close();
}
if (buffOutputStream!=null){
buffOutputStream.close();
}
if (outputStream!=null){
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -75,22 +75,22 @@ public class FileController {
public Object uploadFile(@RequestPart("files") MultipartFile[] files, @Validated UploadBatchFileRequest request) throws Exception {
int testData = request.getTestData();
Double height;
Double widthStart;
Double widthEnd;
if (testData == 1) {
OcrCutConfigTestVO ocrCutConfigTestVO = iOcrCutConfigTestService.findAll().get(0);
height = ocrCutConfigTestVO.getHeight();
widthStart = ocrCutConfigTestVO.getWidthStart();
widthEnd = ocrCutConfigTestVO.getWidthEnd();
} else {
OcrVersion ocrVersion = iOcrVersionService.finEnableVersion();
OcrCutConfigVO ocrCutConfigVO = iOcrCutConfigService.findByVersion(ocrVersion.getVersion());
height = ocrCutConfigVO.getHeight();
widthStart = ocrCutConfigVO.getWidthStart();
widthEnd = ocrCutConfigVO.getWidthEnd();
}
Double height = null ;
Double widthStart = null ;
Double widthEnd = null ;
// if (testData == 1) {
// OcrCutConfigTestVO ocrCutConfigTestVO = iOcrCutConfigTestService.findAll().get(0);
// height = ocrCutConfigTestVO.getHeight();
// widthStart = ocrCutConfigTestVO.getWidthStart();
// widthEnd = ocrCutConfigTestVO.getWidthEnd();
// } else {
// OcrVersion ocrVersion = iOcrVersionService.finEnableVersion();
// OcrCutConfigVO ocrCutConfigVO = iOcrCutConfigService.findByVersion(ocrVersion.getVersion());
// height = ocrCutConfigVO.getHeight();
// widthStart = ocrCutConfigVO.getWidthStart();
// widthEnd = ocrCutConfigVO.getWidthEnd();
// }
List<UploadFileVO> segmentation = iFileUploadService.uploadFile(files, "segmentation", height, widthStart, widthEnd);
@ -114,21 +114,21 @@ public class FileController {
})
public OcrFileInfoTest singleUpload(@RequestPart("files") MultipartFile[] files, @Validated UploadBatchFileRequest request) throws Exception {
int testData = request.getTestData();
Double height;
Double widthStart;
Double widthEnd;
if (testData == 1) {
OcrCutConfigTestVO ocrCutConfigTestVO = iOcrCutConfigTestService.findAll().get(0);
height = ocrCutConfigTestVO.getHeight();
widthStart = ocrCutConfigTestVO.getWidthStart();
widthEnd = ocrCutConfigTestVO.getWidthEnd();
} else {
OcrCutConfigVO ocrCutConfigVO = iOcrCutConfigService.findAll().get(0);
height = ocrCutConfigVO.getHeight();
widthStart = ocrCutConfigVO.getWidthStart();
widthEnd = ocrCutConfigVO.getWidthEnd();
}
Double height = null ;
Double widthStart= null;
Double widthEnd= null;
// if (testData == 1) {
// OcrCutConfigTestVO ocrCutConfigTestVO = iOcrCutConfigTestService.findAll().get(0);
// height = ocrCutConfigTestVO.getHeight();
// widthStart = ocrCutConfigTestVO.getWidthStart();
// widthEnd = ocrCutConfigTestVO.getWidthEnd();
// } else {
// OcrCutConfigVO ocrCutConfigVO = iOcrCutConfigService.findAll().get(0);
// height = ocrCutConfigVO.getHeight();
// widthStart = ocrCutConfigVO.getWidthStart();
// widthEnd = ocrCutConfigVO.getWidthEnd();
// }
List<UploadFileVO> segmentation = iFileUploadService.uploadFile(files, "singleSegmentation", height, widthStart, widthEnd);

@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
import com.docus.core.util.Func;
import com.docus.log.annotation.TrackRetryListener;
import com.docus.server.api.ocr.OcrApi;
import com.docus.server.common.service.IFileUploadService;
import com.docus.server.dto.segmentation.FileDTO;
import com.docus.server.dto.segmentation.UploadBatchFileRequest;
import com.docus.server.entity.segmentation.*;
@ -12,9 +13,11 @@ import com.docus.server.infrastructure.dao.IOcrBasicDao;
import com.docus.server.infrastructure.dao.IOcrFileInfoDao;
import com.docus.server.infrastructure.dao.IOcrUrlConfigDao;
import com.docus.server.infrastructure.dao.IOcrVersionDao;
import com.docus.server.service.IOcrCutConfigService;
import com.docus.server.service.IOcrRuleService;
import com.docus.server.service.IOcrSpecialRuleService;
import com.docus.server.service.impl.PlatformServiceImpl;
import com.docus.server.vo.segmentation.ocrcutconfig.OcrCutConfigVO;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -45,7 +48,11 @@ public class StartSegmentHandler {
@Resource
private IOcrBasicDao iOcrBasicDao;
@Resource
private PlatformServiceImpl platformService;
private PlatformServiceImpl platformService;
@Resource
private IFileUploadService iFileUploadService;
@Resource
private IOcrCutConfigService iOcrCutConfigService;
@TrackRetryListener("START_SEGMENT")
public void startSegment(String patientId) {
@ -53,21 +60,27 @@ public class StartSegmentHandler {
boolean isSpecialFile = false;
OcrSpecialResult lastSpecialResul = null;
OcrVersion ocrVersion = iOcrVersionDao.findOneBy("isEnable", "1");
if (ocrVersion==null){
if (ocrVersion == null) {
throw new RuntimeException("当前没有启用的版本号");
}
Integer version = ocrVersion.getVersion();
//根据病案号查询文件列表
List<OcrBasic> ocrBasicList = iOcrBasicDao.findBy("patientId",patientId);
String url = iOcrUrlConfigDao.findBy("version",version).get(0).getUrl();
List<OcrFileInfo> fileInfoList = iOcrFileInfoDao.findBy("patientId",patientId);
List<OcrBasic> ocrBasicList = iOcrBasicDao.findBy("patientId", patientId);
String url = iOcrUrlConfigDao.findBy("version", version).get(0).getUrl();
List<OcrFileInfo> fileInfoList = iOcrFileInfoDao.findBy("patientId", patientId);
OcrCutConfigVO ocrCutConfigVO = iOcrCutConfigService.findByVersion(ocrVersion.getVersion());
Double height = ocrCutConfigVO.getHeight();
Double widthStart = ocrCutConfigVO.getWidthStart();
Double widthEnd = ocrCutConfigVO.getWidthEnd();
List<File> files = new ArrayList<>(fileInfoList.size());
List<FileDTO> fileDTOList = new ArrayList<>(fileInfoList.size());
for (OcrFileInfo fileInfo:fileInfoList) {
for (OcrFileInfo fileInfo : fileInfoList) {
iFileUploadService.compressFile(fileInfo.getPicCompressUrl(),fileInfo.getPicUrl(),fileInfo.getPicName(),height);
iFileUploadService.cutPic(fileInfo.getPicCutUrl(),fileInfo.getPicCompressUrl(),fileInfo.getPicName(),widthStart,widthEnd);
boolean assortFlag = false;
String assortId = null;
String assortName = null;
@ -76,19 +89,16 @@ public class StartSegmentHandler {
Double rate = null;
//遍历文件列表 获取ocr识别结果
List<String> ocrTextList = ocrApi.getText(fileInfo.getPicCutUrl(),url);
List<String> ocrTextList = ocrApi.getText(fileInfo.getPicCutUrl(), url);
fileInfo.setOcrText(Func.toJson(ocrTextList));
fileInfo.setOcrStatus(OcrStatusEnum.COMPLETE);
fileInfo.setOcrFinishTime(new Date());
//判断上次是否特殊文件开始 需要判断是否特殊文件结尾
if (isSpecialFile){
assortId = lastSpecialResul.getAssortId();
assortName = lastSpecialResul.getAssortName();
ruleId = lastSpecialResul.getRuleId();
if (isSpecialFile) {
assortId = lastSpecialResul.getAssortId();
assortName = lastSpecialResul.getAssortName();
ruleId = lastSpecialResul.getRuleId();
boolean b = iOcrSpecialRuleService.handleSpecialRuleEnd(lastSpecialResul, ocrTextList);
if (b){
if (b) {
//当前分段为特殊分段结尾
isSpecialFile = false;
lastSpecialResul = null;
@ -96,15 +106,15 @@ public class StartSegmentHandler {
}
}
//优先判断是否特殊规则开始
if (!assortFlag){
OcrSpecialResult ocrSpecialResult = iOcrSpecialRuleService.handleSpecialRule(ocrTextList,version);
if (!assortFlag) {
OcrSpecialResult ocrSpecialResult = iOcrSpecialRuleService.handleSpecialRule(ocrTextList, version);
//判断是否属于某个分段
if (ocrSpecialResult!=null){
assortId = ocrSpecialResult.getAssortId();
assortName = ocrSpecialResult.getAssortName();
ruleId = ocrSpecialResult.getRuleId();
hitKey = ocrSpecialResult.getHitKey();
rate = ocrSpecialResult.getRate();
if (ocrSpecialResult != null) {
assortId = ocrSpecialResult.getAssortId();
assortName = ocrSpecialResult.getAssortName();
ruleId = ocrSpecialResult.getRuleId();
hitKey = ocrSpecialResult.getHitKey();
rate = ocrSpecialResult.getRate();
isSpecialFile = true;
lastSpecialResul = ocrSpecialResult;
@ -112,18 +122,18 @@ public class StartSegmentHandler {
}
}
if (!assortFlag){
OcrRuleResult ocrRuleResult = iOcrRuleService.handleRule(ocrTextList,version);
if (!assortFlag) {
OcrRuleResult ocrRuleResult = iOcrRuleService.handleRule(ocrTextList, version);
//更新文件数据的分段
if (ocrRuleResult!=null){
if (ocrRuleResult != null) {
assortId = ocrRuleResult.getAssortId();
assortName = ocrRuleResult.getAssortName();
ruleId = ocrRuleResult.getRuleId();
hitKey = ocrRuleResult.getHitKey();
rate = ocrRuleResult.getRate();
}else {
} else {
assortId = "-1";
assortName="其他";
assortName = "其他";
}
}
@ -132,9 +142,11 @@ public class StartSegmentHandler {
fileInfo.setRuleId(ruleId);
fileInfo.setHitKey(hitKey);
fileInfo.setRate(rate);
fileInfo.setOcrText(Func.toJson(ocrTextList));
fileInfo.setOcrStatus(OcrStatusEnum.COMPLETE);
fileInfo.setOcrFinishTime(new Date());
File file = new File(fileInfo.getPicUrl());
File file = new File(fileInfo.getPicUrl());
files.add(file);
FileDTO fileDTO = new FileDTO();
@ -153,11 +165,11 @@ public class StartSegmentHandler {
p.setOcrStatue(OcrStatusEnum.COMPLETE);
}).collect(Collectors.toList());
iOcrBasicDao.updateBatchById(collect,iOcrBasicDao.DEFAULT_BATCH_SIZE);
iOcrFileInfoDao.updateBatchById(fileInfoList,iOcrFileInfoDao.DEFAULT_BATCH_SIZE);
iOcrBasicDao.updateBatchById(collect, iOcrBasicDao.DEFAULT_BATCH_SIZE);
iOcrFileInfoDao.updateBatchById(fileInfoList, iOcrFileInfoDao.DEFAULT_BATCH_SIZE);
//数据上传到3.0
OcrBasic ocrBasic =ocrBasicList.get(0);
OcrBasic ocrBasic = ocrBasicList.get(0);
UploadBatchFileRequest request = new UploadBatchFileRequest();
request.setInpatientNo(ocrBasic.getInpatientNo());

@ -3,6 +3,7 @@ package com.docus.server.service.handler;
import com.docus.core.util.Func;
import com.docus.log.annotation.TrackRetryListener;
import com.docus.server.api.ocr.OcrApi;
import com.docus.server.common.service.IFileUploadService;
import com.docus.server.entity.segmentation.OcrBasicTest;
import com.docus.server.entity.segmentation.OcrFileInfoTest;
import com.docus.server.entity.segmentation.OcrRuleResult;
@ -11,8 +12,10 @@ import com.docus.server.enums.OcrStatusEnum;
import com.docus.server.infrastructure.dao.IOcrBasicTestDao;
import com.docus.server.infrastructure.dao.IOcrFileInfoTestDao;
import com.docus.server.infrastructure.dao.IOcrUrlConfigTestDao;
import com.docus.server.service.IOcrCutConfigTestService;
import com.docus.server.service.IOcrRuleTestService;
import com.docus.server.service.IOcrSpecialRuleTestService;
import com.docus.server.vo.segmentation.ocrcutconfigtest.OcrCutConfigTestVO;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -37,10 +40,15 @@ public class StartSegmentTestHandler {
private IOcrBasicTestDao iOcrBasicTestDao;
@Resource
private IOcrUrlConfigTestDao iOcrUrlConfigTestDao;
@Resource
private IOcrCutConfigTestService iOcrCutConfigTestService;
@Resource
private IFileUploadService iFileUploadService;
@TrackRetryListener("START_SEGMENT_TEST")
public List<OcrFileInfoTest> startSegment(String patientId) {
boolean isSpecialFile = false;
OcrSpecialResult lastSpecialResul = null;
@ -48,7 +56,16 @@ public class StartSegmentTestHandler {
List<OcrBasicTest> ocrBasicTestList = iOcrBasicTestDao.findBy("patientId",patientId);
List<OcrFileInfoTest> fileInfoTestList = iOcrFileInfoTestDao.findBy("patientId", patientId);
String url = iOcrUrlConfigTestDao.findAll().get(0).getUrl();
OcrCutConfigTestVO ocrCutConfigTestVO = iOcrCutConfigTestService.findAll().get(0);
Double height = ocrCutConfigTestVO.getHeight();
Double widthStart = ocrCutConfigTestVO.getWidthStart();
Double widthEnd = ocrCutConfigTestVO.getWidthEnd();
for (OcrFileInfoTest fileInfoTest : fileInfoTestList) {
iFileUploadService.compressFile(fileInfoTest.getPicCompressUrl(),fileInfoTest.getPicUrl(),fileInfoTest.getPicName(),height);
iFileUploadService.cutPic(fileInfoTest.getPicCutUrl(),fileInfoTest.getPicCompressUrl(),fileInfoTest.getPicName(),widthStart,widthEnd);
boolean assortFlag = false;
String assortId = null;
String assortName = null;

@ -85,7 +85,9 @@ public class OcrRuleServiceImpl implements IOcrRuleService {
@Override
public OcrRuleResult handleRule(List<String> ocrTextList,Integer version) {
//查询所有规则列表
List<OcrRule> ocrRules = iOcrRuleDao.findBy("version",version);
List<OcrRule> ocrRules = iOcrRuleDao.findBy("version",version)
.stream().sorted(Comparator.comparing(OcrRule::getMatchRatio).reversed())
.collect(Collectors.toList());
//判断是否符合某个条件的开始条件
for (OcrRule ocrRule : ocrRules) {
if (Func.isEmpty(ocrRule.getKeyWord())){

@ -8,10 +8,7 @@ import com.docus.server.convert.OcrRuleTestConvert;
import com.docus.server.dto.segmentation.ocrruletest.AddOcrRuleTestDTO;
import com.docus.server.dto.segmentation.ocrruletest.DeleteOcrRuleTestDTO;
import com.docus.server.dto.segmentation.ocrruletest.EditOcrRuleTestDTO;
import com.docus.server.entity.segmentation.OcrRuleJson;
import com.docus.server.entity.segmentation.OcrRuleResult;
import com.docus.server.entity.segmentation.OcrRuleSecondJson;
import com.docus.server.entity.segmentation.OcrRuleTest;
import com.docus.server.entity.segmentation.*;
import com.docus.server.infrastructure.dao.IOcrRuleTestDao;
import com.docus.server.service.IOcrRuleTestService;
import com.docus.server.vo.segmentation.ocrruletest.OcrRuleTestVO;
@ -39,7 +36,9 @@ public class OcrRuleTestServiceImpl implements IOcrRuleTestService {
@Override
public OcrRuleResult handleRule(List<String> ocrTextList) {
//查询所有规则列表
List<OcrRuleTest> ocrRuleTestList = iOcrRuleTestDao.findAll();
List<OcrRuleTest> ocrRuleTestList = iOcrRuleTestDao.findAll()
.stream().sorted(Comparator.comparing(OcrRuleTest::getMatchRatio).reversed())
.collect(Collectors.toList());
//判断是否符合某个条件的开始条件
for (OcrRuleTest ocrRuleTest : ocrRuleTestList) {
String assortName = ocrRuleTest.getAssortName();

Loading…
Cancel
Save