|
@@ -11,6 +11,7 @@ import com.yonge.cooleshow.biz.dal.wrapper.OssFileWrapper;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.utils.http.HttpUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -71,6 +72,47 @@ public class OssFileServiceImpl implements OssFileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public OssFileWrapper.ExportFile uploadFile(List<?> dataList, Class<?> clazz, String fileName, String sheetName,
|
|
|
+ String tag) {
|
|
|
+ if (CollectionUtils.isEmpty(dataList)) {
|
|
|
+ throw new BizException("导出数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // OSS上传文件目录
|
|
|
+ String uploadOssPath = MessageFormat.format("excel-download/{0}/{1}", DateTime.now().toString("yyyy-MM"), tag);
|
|
|
+
|
|
|
+ // 文件上传下载地址
|
|
|
+ String uploadPath = MessageFormat.format("{0}/{1}-{2}/{3}.xlsx", uploadOssPath,
|
|
|
+ String.valueOf(IdWorker.getId()),
|
|
|
+ DateTime.now().toString("MMddHHmmss"), fileName);
|
|
|
+
|
|
|
+ // 本地文件地址
|
|
|
+ String localPath = DownloadManager.getInstance().path(uploadPath);
|
|
|
+ log.debug("pageExport localPath={}", localPath);
|
|
|
+
|
|
|
+ EasyExcel
|
|
|
+ .write(localPath, clazz)
|
|
|
+ //.withTemplate(resource.getStream()) // 利用模板的输出流
|
|
|
+ .sheet(0, sheetName)
|
|
|
+ .doWrite(dataList);
|
|
|
+
|
|
|
+ // 上传本地文件到OSS服务器
|
|
|
+ String downloadPath = ossPluginContext.getPluginService(TencentOssPlugin.PLUGIN_NAME)
|
|
|
+ .uploadFile(uploadOssPath, new File(localPath));
|
|
|
+ log.debug("pageExport downloadPath={}", downloadPath);
|
|
|
+
|
|
|
+ // 删除本地缓存文件
|
|
|
+ DownloadManager.getInstance().deleteOnExit(localPath);
|
|
|
+
|
|
|
+ // 学生统计下载
|
|
|
+ return OssFileWrapper.ExportFile
|
|
|
+ .builder()
|
|
|
+ .fileName(MessageFormat.format("{0}.xlsx", fileName))
|
|
|
+ .downloadPath(downloadPath)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public OssFileWrapper.ExportFile uploadFileWithShortUrl(List<?> dataList, Class<?> clazz,
|
|
|
String fileName, String sheetName) {
|
|
|
if (CollectionUtils.isEmpty(dataList)) {
|