feature(报告提交)
This commit is contained in:
@@ -19,6 +19,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -64,6 +66,11 @@ public class IReportServiceImpl implements IReportService {
|
||||
@Resource
|
||||
private OSSClientUtil ossClientUtil;
|
||||
|
||||
@Value("${uploadType}")
|
||||
private String uploadType;
|
||||
|
||||
@Autowired
|
||||
private ObsBootUtil obsBootUtil;
|
||||
/**
|
||||
* 新增或编辑报告
|
||||
*
|
||||
@@ -274,7 +281,12 @@ public class IReportServiceImpl implements IReportService {
|
||||
FileEntity fileEntity = fileDao.selectById(fileId);
|
||||
String path = uploadFile + fileEntity.getSavePath();
|
||||
FileOutputStream outputStream = new FileOutputStream(path);
|
||||
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream);
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||
if (uploadType.equals("hwobs")){
|
||||
obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream);
|
||||
}else if (uploadType.equals("alioss")){
|
||||
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream);
|
||||
}
|
||||
|
||||
String html = null;
|
||||
switch (fileEntity.getFileType()) {
|
||||
|
||||
@@ -95,6 +95,29 @@ public class ObsBootUtil {
|
||||
|
||||
}
|
||||
|
||||
public void getFileFromOBS(String objectKey, FileOutputStream outputStream) throws IOException {
|
||||
obsClient = new ObsClient(configProperties.getAccessKey(), configProperties.getSecretKey(), configProperties.getEndPoint());
|
||||
InputStream objectContent = null;
|
||||
try {
|
||||
ObsObject obsObject = obsClient.getObject(configProperties.getBucketName(), objectKey);
|
||||
objectContent = obsObject.getObjectContent();
|
||||
if (!Objects.isNull(objectContent)){
|
||||
byte[] bt = new byte[1024 * 1024];
|
||||
int len = 0;
|
||||
while ((len = objectContent.read(bt)) != -1) {
|
||||
outputStream.write(bt, 0, len);
|
||||
}
|
||||
}
|
||||
}catch (ObsException | IOException oe){
|
||||
throw new AdcDaBaseException("OBS下载文件失败");
|
||||
}finally {
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
objectContent.close();
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//文件删除
|
||||
public void deleteFile(String objectKey) {
|
||||
obsClient.deleteObject(configProperties.getBucketName(), objectKey);
|
||||
|
||||
Reference in New Issue
Block a user