编写上传归档系统接口
parent
ff376539e9
commit
d32eaa44a8
@ -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<FileDTO> 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<File> files = Lists.newArrayList(file, file1);
|
|
||||||
|
|
||||||
Map<String, Object> 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<String, Object> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<String> uploadPlatform(List<File> 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<FileDTO> 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<File> files = Lists.newArrayList(file, file1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Map<String, Object> 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<String> uploadFile(Map<String, Object> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue