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 580f763..16996c1 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 @@ -2,6 +2,7 @@ package com.docus.server.controller; import com.docus.server.common.service.IFileUploadService; import com.docus.server.dto.segmentation.UploadBatchFileRequest; +import com.docus.server.service.impl.DownloadServiceImpl; import com.docus.server.vo.scheduling.management.schcollectorversionfile.UploadFileVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -31,6 +32,8 @@ import java.util.List; public class FileController { @Resource private IFileUploadService iFileUploadService; + @Resource + private DownloadServiceImpl downloadService; @ApiOperation("文件下载") @GetMapping("/download") @@ -48,4 +51,9 @@ public class FileController { //将基础信息存到库表里面,后面自动分段后,需要上传到归档系统 } + @ApiOperation("test") + @GetMapping("/test") + public void test() throws Exception { + downloadService.upload(""); + } } 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 new file mode 100644 index 0000000..2e5e97f --- /dev/null +++ b/docus-segmentation/src/main/java/com/docus/server/service/impl/DownloadServiceImpl.java @@ -0,0 +1,73 @@ +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.dto.segmentation.UploadBatchFileRequest; +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/resources/bootstrap.yml b/docus-segmentation/src/main/resources/bootstrap.yml index 29ebeef..06d4ad8 100644 --- a/docus-segmentation/src/main/resources/bootstrap.yml +++ b/docus-segmentation/src/main/resources/bootstrap.yml @@ -57,6 +57,9 @@ file: ocr: api-url: http://192.168.16.85:9999/uploadfile +download: + api-url: http://localhost:9291/api/downplatform/uploadFileBatch + docus: vm-task-cron: 0/30 * * * * ? collector-package-download-url: http://192.168.16.110:9113