|
@@ -1,14 +1,9 @@
|
|
|
package com.ym.mec.web.controller;
|
|
|
|
|
|
-import com.alibaba.excel.EasyExcel;
|
|
|
-import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.microsvc.toolkit.common.response.paging.PageInfo;
|
|
|
import com.microsvc.toolkit.common.response.paging.QueryInfo;
|
|
|
-import com.microsvc.toolkit.common.tools.DownloadManager;
|
|
|
-import com.microsvc.toolkit.middleware.oss.OssPluginContext;
|
|
|
-import com.microsvc.toolkit.middleware.oss.impl.TencentOssPlugin;
|
|
|
import com.ym.mec.biz.dal.entity.TempDirectorTrainingCamp;
|
|
|
import com.ym.mec.biz.dal.wrapper.TempDirectorTrainingCampDetailWrapper;
|
|
|
import com.ym.mec.biz.service.TempDirectorTrainingCampDetailService;
|
|
@@ -22,7 +17,6 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
-import org.joda.time.DateTime;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -30,10 +24,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
-import java.text.MessageFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -45,8 +37,6 @@ public class TempDirectorTrainingCampDetailController extends BaseController {
|
|
|
@Resource
|
|
|
private TempDirectorTrainingCampDetailService tempDirectorTrainingCampDetailService;
|
|
|
@Resource
|
|
|
- private OssPluginContext ossPluginContext;
|
|
|
- @Resource
|
|
|
private TempDirectorTrainingCampService tempDirectorTrainingCampService;
|
|
|
|
|
|
|
|
@@ -117,44 +107,5 @@ public class TempDirectorTrainingCampDetailController extends BaseController {
|
|
|
return succeed(tempDirectorTrainingCampDetailService.queryPageStat(queryInfo));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private TempDirectorTrainingCampDetailWrapper.DownloadInfo generateExportExcelFile(List<?> orderExports, Class<?> clazz, String fileName, String sheetName) {
|
|
|
-
|
|
|
- // OSS上传文件目录
|
|
|
- String uploadOssPath = MessageFormat.format("excel-download/{0}", DateTime.now().toString("yyyy-MM"));
|
|
|
-
|
|
|
- // 文件上传下载地址
|
|
|
- String uploadPath = MessageFormat.format("{0}/{1}-{2}.xlsx", uploadOssPath, fileName, DateTime.now().toString("MMddHHmmss"));
|
|
|
-
|
|
|
- // 本地文件地址
|
|
|
- String localPath = DownloadManager.getInstance().path(uploadPath);
|
|
|
-// log.debug("pageExport localPath={}", localPath);
|
|
|
-
|
|
|
- // 模板文件保存在springboot项目的resources/static下
|
|
|
- // Resource resource = new ClassPathResource("static/预报名模板导出.xlsx");
|
|
|
-
|
|
|
- EasyExcel
|
|
|
- .write(localPath, clazz)
|
|
|
- .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
|
|
- //.withTemplate(resource.getStream()) // 利用模板的输出流
|
|
|
- .sheet(0, sheetName)
|
|
|
- .doWrite(orderExports);
|
|
|
-
|
|
|
- // 上传本地文件到OSS服务器
|
|
|
- String downloadPath = ossPluginContext.getPluginService(TencentOssPlugin.PLUGIN_NAME)
|
|
|
- .uploadFile(uploadOssPath, new File(localPath));
|
|
|
- log.debug("pageExport downloadPath={}", downloadPath);
|
|
|
-
|
|
|
- // 删除本地缓存文件
|
|
|
- DownloadManager.getInstance().deleteOnExit(localPath);
|
|
|
-
|
|
|
- // 学生统计下载
|
|
|
- return TempDirectorTrainingCampDetailWrapper.DownloadInfo
|
|
|
- .builder()
|
|
|
- .fileName(MessageFormat.format("{0}.xlsx", fileName))
|
|
|
- .downloadPath(downloadPath)
|
|
|
- .build();
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|