|
@@ -1,19 +1,37 @@
|
|
|
package com.hfln.portal.infrastructure.service.impl;
|
|
|
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
+import com.aliyun.oss.model.ObjectMetadata;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hfln.portal.infrastructure.mapper.TblOssFileMapper;
|
|
|
import com.hfln.portal.infrastructure.po.BasePO;
|
|
|
import com.hfln.portal.infrastructure.po.TblOssFile;
|
|
|
import com.hfln.portal.infrastructure.service.OssFileService;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class OssFileServiceImpl extends ServiceImpl<TblOssFileMapper, TblOssFile> implements OssFileService {
|
|
|
|
|
|
+ @Value("${oss.endpoint}")
|
|
|
+ private String ENDPOINT;
|
|
|
+
|
|
|
+ @Value("${oss.accessKey.id}")
|
|
|
+ private String ACCESS_KEY_ID;
|
|
|
+
|
|
|
+ @Value("${oss.accessKey.secret}")
|
|
|
+ private String ACCESS_KEY_SECRET;
|
|
|
+
|
|
|
+ public String BUCKET_NAME = "hflnxx";
|
|
|
+
|
|
|
@Override
|
|
|
public List<TblOssFile> queryFile(String busiType, String busiKey) {
|
|
|
|
|
@@ -37,4 +55,75 @@ public class OssFileServiceImpl extends ServiceImpl<TblOssFileMapper, TblOssFile
|
|
|
}
|
|
|
return this.baseMapper.selectOne(queryWrapper);
|
|
|
}
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 上传文件到 OSS 并设置为 inline 显示
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public String uploadFile(MultipartFile file, String objectName) throws IOException {
|
|
|
+// // 1. 获取文件名后缀
|
|
|
+// String originalFilename = file.getOriginalFilename();
|
|
|
+// String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
|
|
|
+// // 2. 通过后缀获取 contentType
|
|
|
+// String contentType = getContentType(suffix);
|
|
|
+//
|
|
|
+//
|
|
|
+// OSS ossClient = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
|
|
+//
|
|
|
+// try (InputStream inputStream = file.getInputStream()) {
|
|
|
+// ObjectMetadata metadata = new ObjectMetadata();
|
|
|
+//
|
|
|
+// // 设置内容类型
|
|
|
+// metadata.setContentType(contentType);
|
|
|
+//
|
|
|
+// // 设置浏览器打开方式为 inline(非 attachment)
|
|
|
+// metadata.setContentDisposition("inline");
|
|
|
+//
|
|
|
+// // 上传文件
|
|
|
+// ossClient.putObject(BUCKET_NAME, objectName, inputStream, metadata);
|
|
|
+// } finally {
|
|
|
+// ossClient.shutdown();
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 返回文件的公网地址
|
|
|
+// return "http://" +"static.radar-power.asia/" + objectName;
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static String getContentType(String filenameExtension) {
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".bmp")) {
|
|
|
+// return "image/bmp";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".gif")) {
|
|
|
+// return "image/gif";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".jpeg") ||
|
|
|
+// filenameExtension.equalsIgnoreCase(".jpg")) {
|
|
|
+// return "image/jpeg";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".png")) {
|
|
|
+// return "image/png";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".html")) {
|
|
|
+// return "text/html";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".txt")) {
|
|
|
+// return "text/plain";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".vsd")) {
|
|
|
+// return "application/vnd.visio";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".pptx") ||
|
|
|
+// filenameExtension.equalsIgnoreCase(".ppt")) {
|
|
|
+// return "application/vnd.ms-powerpoint";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".docx") ||
|
|
|
+// filenameExtension.equalsIgnoreCase(".doc")) {
|
|
|
+// return "application/msword";
|
|
|
+// }
|
|
|
+// if (filenameExtension.equalsIgnoreCase(".xml")) {
|
|
|
+// return "text/xml";
|
|
|
+// }
|
|
|
+// return "application/octet-stream"; // 默认类型(通用二进制)
|
|
|
+// }
|
|
|
}
|