|
@@ -132,7 +132,7 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
|
|
|
@GetMapping("/exportActiveCode")
|
|
@GetMapping("/exportActiveCode")
|
|
@ApiOperation(value = "导出模板")
|
|
@ApiOperation(value = "导出模板")
|
|
- public void exportActiveCode(HttpServletResponse response,String orderNo) {
|
|
|
|
|
|
+ public HttpResponseResult<TenantActivationCodeWrapper.ExportFile> exportActiveCode(HttpServletResponse response, String orderNo) {
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
if (sysUser == null) {
|
|
if (sysUser == null) {
|
|
throw new BizException("请登录");
|
|
throw new BizException("请登录");
|
|
@@ -154,23 +154,56 @@ public class TenantActivationCodeController extends BaseController {
|
|
throw new BizException("没有可导出数据");
|
|
throw new BizException("没有可导出数据");
|
|
}
|
|
}
|
|
|
|
|
|
- try (OutputStream outputStream = response.getOutputStream()) {
|
|
|
|
- HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"激活码", "手机号"}, new String[]{
|
|
|
|
- "activationCode", "activationPhone"}, rows);
|
|
|
|
- response.setContentType("application/octet-stream");
|
|
|
|
- response.setHeader("Content-Disposition", "attac:wq" +
|
|
|
|
- "hment;filename=active_code-" + DateUtil.getDate(new Date()) + ".xls");
|
|
|
|
- workbook.write(outputStream);
|
|
|
|
- outputStream.flush();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("导出激活码异常", e);
|
|
|
|
- }
|
|
|
|
|
|
+ List<TenantActivationCodeWrapper.ExportTemplate> templates = JSONArray.parseArray(JSON.toJSONString(rows), TenantActivationCodeWrapper.ExportTemplate.class);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ TenantActivationCodeWrapper.ExportFile exportFile = generateExportExcelFile(templates, TenantActivationCodeWrapper.ExportTemplate.class, "激活码导出", "激活码");
|
|
|
|
+ return succeed(exportFile);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ private TenantActivationCodeWrapper.ExportFile 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)
|
|
|
|
+ //.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 TenantActivationCodeWrapper.ExportFile
|
|
|
|
+ .builder()
|
|
|
|
+ .fileName(MessageFormat.format("{0}.xlsx", fileName))
|
|
|
|
+ .downloadPath(downloadPath)
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@GetMapping("/exportOrderCode")
|
|
@GetMapping("/exportOrderCode")
|
|
@ApiOperation(value = "导出订单激活码模板")
|
|
@ApiOperation(value = "导出订单激活码模板")
|
|
- public void exportOrderCode(HttpServletResponse response,String orderNo) {
|
|
|
|
|
|
+ public HttpResponseResult<TenantActivationCodeWrapper.ExportFile> exportOrderCode(HttpServletResponse response, String orderNo) {
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
if (sysUser == null) {
|
|
if (sysUser == null) {
|
|
throw new BizException("请登录");
|
|
throw new BizException("请登录");
|
|
@@ -191,19 +224,12 @@ public class TenantActivationCodeController extends BaseController {
|
|
throw new BizException("没有可导出数据");
|
|
throw new BizException("没有可导出数据");
|
|
}
|
|
}
|
|
|
|
|
|
- try (OutputStream outputStream = response.getOutputStream()) {
|
|
|
|
- HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"激活码"}, new String[]{
|
|
|
|
- "activationCode"}, rows);
|
|
|
|
- response.setContentType("application/octet-stream");
|
|
|
|
- response.setHeader("Content-Disposition", "attac:wq" +
|
|
|
|
- "hment;filename=active_code-" + DateUtil.getDate(new Date()) + ".xls");
|
|
|
|
- workbook.write(outputStream);
|
|
|
|
- outputStream.flush();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("导出激活码异常", e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<TenantActivationCodeWrapper.ExportTemplate> templates = JSONArray.parseArray(JSON.toJSONString(rows), TenantActivationCodeWrapper.ExportTemplate.class);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ TenantActivationCodeWrapper.ExportFile exportFile = generateExportExcelFile(templates, TenantActivationCodeWrapper.ExportTemplate.class, "激活码导出", "激活码");
|
|
|
|
+ return succeed(exportFile);
|
|
|
|
+ }
|
|
@PostMapping("/importActiveCode")
|
|
@PostMapping("/importActiveCode")
|
|
@ApiOperation(value = "导入", notes = "传入file")
|
|
@ApiOperation(value = "导入", notes = "传入file")
|
|
public HttpResponseResult<List<ErrMsg>> importActiveCode(
|
|
public HttpResponseResult<List<ErrMsg>> importActiveCode(
|