From d32eaa44a895eb1104dd59bf8a86c40509a5140a Mon Sep 17 00:00:00 2001 From: linrf Date: Tue, 29 Aug 2023 14:30:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E4=B8=8A=E4=BC=A0=E5=BD=92?= =?UTF-8?q?=E6=A1=A3=E7=B3=BB=E7=BB=9F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/event/FlowEventListener.java | 12 ++- .../server/controller/FileController.java | 13 ++- .../service/impl/DownloadServiceImpl.java | 72 ----------------- .../service/impl/PlatformServiceImpl.java | 80 +++++++++++++++++++ 4 files changed, 97 insertions(+), 80 deletions(-) delete mode 100644 docus-segmentation/src/main/java/com/docus/server/service/impl/DownloadServiceImpl.java create mode 100644 docus-segmentation/src/main/java/com/docus/server/service/impl/PlatformServiceImpl.java diff --git a/docus-segmentation/src/main/java/com/docus/server/common/event/FlowEventListener.java b/docus-segmentation/src/main/java/com/docus/server/common/event/FlowEventListener.java index 217bb3c..49ce06e 100644 --- a/docus-segmentation/src/main/java/com/docus/server/common/event/FlowEventListener.java +++ b/docus-segmentation/src/main/java/com/docus/server/common/event/FlowEventListener.java @@ -1,13 +1,22 @@ package com.docus.server.common.event; +import com.docus.server.api.ocr.OcrApi; +import com.docus.server.service.impl.PlatformServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import javax.annotation.Resource; +import java.util.List; + @Component @Slf4j public class FlowEventListener { + @Resource + private OcrApi ocrApi; + @Resource + private PlatformServiceImpl downloadService; @EventListener @Async("threadPoolExecutor") @@ -39,7 +48,7 @@ public class FlowEventListener { * @param patientId */ private void startUpload(String patientId) { - System.out.println(patientId); + downloadService.uploadPlatform(null, null); } /** @@ -49,6 +58,7 @@ public class FlowEventListener { */ private void startOcr(String patientId) { System.out.println(patientId); + List text = ocrApi.getText("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg"); } /** diff --git a/docus-segmentation/src/main/java/com/docus/server/controller/FileController.java b/docus-segmentation/src/main/java/com/docus/server/controller/FileController.java index b3b6465..096b446 100644 --- a/docus-segmentation/src/main/java/com/docus/server/controller/FileController.java +++ b/docus-segmentation/src/main/java/com/docus/server/controller/FileController.java @@ -5,7 +5,7 @@ import com.docus.server.common.service.IFileUploadService; import com.docus.server.dto.segmentation.UploadBatchFileRequest; import com.docus.server.service.IPublishEventService; import com.docus.server.service.impl.CommonService; -import com.docus.server.service.impl.DownloadServiceImpl; +import com.docus.server.service.impl.PlatformServiceImpl; import com.docus.server.vo.scheduling.management.schcollectorversionfile.UploadFileVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -36,7 +36,7 @@ public class FileController { @Resource private IFileUploadService iFileUploadService; @Resource - private DownloadServiceImpl downloadService; + private PlatformServiceImpl downloadService; @Resource private CommonService commonService; @Resource @@ -62,15 +62,14 @@ public class FileController { iPublishEventService.publishEvent(request.getPatientId(), FlowEvent.FlowTypeEnum.START_SEGMENT); } - /** * 下载平台 * * @throws Exception */ - @ApiOperation("test") - @GetMapping("/test") - public void test() throws Exception { - downloadService.upload(""); + @ApiOperation("批量上传文件到归档系统") + @GetMapping("/uploadPlatform") + public void uploadPlatform() throws Exception { + downloadService.uploadPlatform(null, null); } } diff --git a/docus-segmentation/src/main/java/com/docus/server/service/impl/DownloadServiceImpl.java b/docus-segmentation/src/main/java/com/docus/server/service/impl/DownloadServiceImpl.java deleted file mode 100644 index 7927cf5..0000000 --- a/docus-segmentation/src/main/java/com/docus/server/service/impl/DownloadServiceImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.docus.server.service.impl; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpRequest; -import com.alibaba.fastjson.JSON; -import com.docus.server.dto.segmentation.FileDTO; -import com.docus.server.vo.ocr.OcrResponse; -import com.google.common.collect.Lists; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -@Service -@Slf4j -public class DownloadServiceImpl { - - @Value("${download.api-url:http://localhost:9291/api/downplatform/uploadFileBatch}") - private String downloadUrl; - - private final static Lock HTTP_POST_LOCK = new ReentrantLock(); - - public OcrResponse upload(String path) { - - FileDTO fileDTO = new FileDTO(); - fileDTO.setAssortId("3"); - fileDTO.setFileTitle("4"); - fileDTO.setFileType(2); - fileDTO.setSerialNumber("5"); - fileDTO.setUploadFileName("6"); - - ArrayList fileDTOS = Lists.newArrayList(fileDTO); - - File file = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg"); - File file1 = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174052\\麻醉.jpg"); - ArrayList files = Lists.newArrayList(file, file1); - - Map data = new HashMap<>(); - data.put("files", files.toArray(new File[files.size()])); - data.put("patientId", "1"); - data.put("collectorId", "2"); - data.put("fileInfo", JSON.toJSONString(fileDTOS)); - return uploadFile(data); - } - - public OcrResponse uploadFile(Map params) { - - HTTP_POST_LOCK.lock(); - try { - - String body = HttpRequest.post(downloadUrl) - .form(params) - .contentType("multipart/form-data") - .execute() - .body(); - - if (StrUtil.isNotBlank(body)) { - return JSON.parseObject(body, OcrResponse.class); - } - - return new OcrResponse(); - } finally { - HTTP_POST_LOCK.unlock(); - } - } -} diff --git a/docus-segmentation/src/main/java/com/docus/server/service/impl/PlatformServiceImpl.java b/docus-segmentation/src/main/java/com/docus/server/service/impl/PlatformServiceImpl.java new file mode 100644 index 0000000..9d0ad10 --- /dev/null +++ b/docus-segmentation/src/main/java/com/docus/server/service/impl/PlatformServiceImpl.java @@ -0,0 +1,80 @@ +package com.docus.server.service.impl; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.docus.infrastructure.web.api.CommonResult; +import com.docus.server.dto.segmentation.UploadBatchFileRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +@Service +@Slf4j +public class PlatformServiceImpl { + + @Value("${download.api-url:http://localhost:9291/api/downplatform/uploadFileBatch}") + private String downloadUrl; + + private final static Lock HTTP_POST_LOCK = new ReentrantLock(); + + public CommonResult uploadPlatform(List files, UploadBatchFileRequest request) { + +// FileDTO fileDTO = new FileDTO(); +// fileDTO.setAssortId("3"); +// fileDTO.setFileTitle("4"); +// fileDTO.setFileType(2); +// fileDTO.setSerialNumber(UUIDUtils.generateUuid()); +// fileDTO.setUploadFileName("6"); +// +// +// FileDTO fileDTO1 = new FileDTO(); +// fileDTO1.setAssortId("3"); +// fileDTO1.setFileTitle("4"); +// fileDTO1.setFileType(2); +// fileDTO1.setSerialNumber(UUIDUtils.generateUuid()); +// fileDTO1.setUploadFileName("7"); +// +// +// ArrayList fileDTOS = Lists.newArrayList(fileDTO, fileDTO1); +// +// File file = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg"); +// File file1 = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174052\\麻醉.jpg"); +// ArrayList files = Lists.newArrayList(file, file1); + + try { + Map data = new HashMap<>(); + data.put("files", files.toArray(new File[files.size()])); + data.put("patientId", request.getPatientId()); + data.put("fileInfo", request.getFileInfo()); + return uploadFile(data); + } catch (Exception ex) { + return CommonResult.failed(ex.getMessage()); + } + + } + + public CommonResult uploadFile(Map params) { + + HTTP_POST_LOCK.lock(); + try { + + String body = HttpRequest.post(downloadUrl) + .form(params) + .contentType("multipart/form-data") + .execute() + .body(); + + return JSON.parseObject(body, CommonResult.class); + + } finally { + HTTP_POST_LOCK.unlock(); + } + } +}