|
|
@@ -3,7 +3,6 @@ package com.zhongshu.card.server.core.service.oss;
|
|
|
import com.github.microservice.core.util.response.ResponseUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.net.ResultState;
|
|
|
-import com.github.microservice.netdisk.client.example.AccountExample;
|
|
|
import com.github.microservice.netdisk.client.model.file.CopyFileModel;
|
|
|
import com.github.microservice.netdisk.client.model.file.FileItemModel;
|
|
|
import com.github.microservice.netdisk.client.model.file.FileStoreModel;
|
|
|
@@ -37,17 +36,12 @@ import org.springframework.data.mongodb.gridfs.GridFsResource;
|
|
|
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StreamUtils;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -82,9 +76,12 @@ public class NetDiskOssBusService extends SuperService {
|
|
|
@Value("${spring.application.name}")
|
|
|
private String applicationName;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InterfaceUseRecordService interfaceUseRecordService;
|
|
|
+
|
|
|
/**
|
|
|
- * @return
|
|
|
* @param file
|
|
|
+ * @return
|
|
|
*/
|
|
|
public ResultContent<String> uploadMinioFile(MultipartFile file, OidParam param) throws IOException {
|
|
|
@Cleanup var inputStream = file.getInputStream();
|
|
|
@@ -101,7 +98,14 @@ public class NetDiskOssBusService extends SuperService {
|
|
|
if (StringUtils.isEmpty(accountId)) {
|
|
|
return ResultContent.buildFail("");
|
|
|
}
|
|
|
+ String faceName = "uploadMinioFile";
|
|
|
+ String key = getOpenId();
|
|
|
+ ResultContent fileContent = interfaceUseRecordService.judge(key, faceName);
|
|
|
+ if (fileContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(fileContent.getMsg());
|
|
|
+ }
|
|
|
|
|
|
+ String projectOid = getCurrentProjectOid();
|
|
|
final String filename = CommonUtil.UUID() + "_" + file.getOriginalFilename();
|
|
|
String mimeTypeName = ResponseUtil.getMimeType(FilenameUtils.getExtension(filename));
|
|
|
gridFsTemplate.store(inputStream, filename, mimeTypeName).toHexString();
|
|
|
@@ -118,6 +122,12 @@ public class NetDiskOssBusService extends SuperService {
|
|
|
this.gridFsTemplate.delete(makeQuery(filename));
|
|
|
if (fileStoreModelResultContent.getState() == com.github.microservice.netdisk.client.content.ResultState.Success) {
|
|
|
FileStoreModel fileStoreModel = fileStoreModelResultContent.getContent();
|
|
|
+ Map<String, Object> metaInfo = new HashMap<String, Object>();
|
|
|
+ metaInfo.put("fileName", filename);
|
|
|
+ metaInfo.put("size", file.getSize());
|
|
|
+ metaInfo.put("fileType", file.getOriginalFilename());
|
|
|
+ metaInfo.put("url", fileStoreModel.getUrl());
|
|
|
+ interfaceUseRecordService.saveRecord(key, projectOid, faceName, metaInfo);
|
|
|
return ResultContent.buildSuccess(fileStoreModel.getUrl());
|
|
|
} else {
|
|
|
return ResultContent.buildFail(String.format("上传文件失败:%s", fileStoreModelResultContent.getMsg()));
|