|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package com.supervision.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.manage.service.FileManageService;
|
|
|
|
|
import com.supervision.model.FileResource;
|
|
|
|
|
import com.supervision.service.FileResourceService;
|
|
|
|
@ -15,10 +17,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
@ -95,6 +94,9 @@ public class FileManageServiceImpl implements FileManageService {
|
|
|
|
|
outputStream.write(bytes, 0, len);
|
|
|
|
|
}
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("文件下载失败",e);
|
|
|
|
|
throw new BusinessException("下载文件失败",e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -123,6 +125,12 @@ public class FileManageServiceImpl implements FileManageService {
|
|
|
|
|
fileOutputStream.write(bytes, 0, len);
|
|
|
|
|
}
|
|
|
|
|
fileOutputStream.flush();
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
if (tempFile.exists()){
|
|
|
|
|
tempFile.delete();
|
|
|
|
|
}
|
|
|
|
|
log.error("文件下载失败",e);
|
|
|
|
|
throw new BusinessException("文件下载失败",e);
|
|
|
|
|
}
|
|
|
|
|
return tempFile;
|
|
|
|
|
}
|
|
|
|
@ -142,4 +150,11 @@ public class FileManageServiceImpl implements FileManageService {
|
|
|
|
|
}
|
|
|
|
|
return fileResourceService.removeById(fileId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String loadFileBase64(String fileId) throws Exception {
|
|
|
|
|
File file = downloadFile(fileId);
|
|
|
|
|
|
|
|
|
|
return Base64.encode(new FileInputStream(file));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|