|
@@ -1,20 +1,23 @@
|
|
|
package com.yonge.cooleshow.tenant.controller;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.microsvc.toolkit.common.response.paging.PageInfo;
|
|
|
import com.microsvc.toolkit.common.response.paging.QueryInfo;
|
|
|
import com.microsvc.toolkit.common.response.template.R;
|
|
|
+import com.microsvc.toolkit.common.tools.DownloadManager;
|
|
|
import com.microsvc.toolkit.common.webportal.exception.BizException;
|
|
|
+import com.microsvc.toolkit.middleware.oss.OssPluginContext;
|
|
|
+import com.microsvc.toolkit.middleware.oss.impl.TencentOssPlugin;
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.TenantActivationCode;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.TenantAlbumPurchase;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.TenantStaff;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.SendStatusEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.im.EImSendStatus;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TenantAlbumPurchaseService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
|
|
@@ -25,16 +28,14 @@ import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.cooleshow.common.enums.BizHttpStatus;
|
|
|
import com.yonge.cooleshow.common.enums.EActivationCode;
|
|
|
import com.yonge.cooleshow.tenant.vo.TenantActivationCodeVo;
|
|
|
-import com.yonge.toolset.utils.date.DateUtil;
|
|
|
import com.yonge.toolset.utils.easyexcel.ErrMsg;
|
|
|
import com.yonge.toolset.utils.easyexcel.ExcelDataReader;
|
|
|
import com.yonge.toolset.utils.easyexcel.ExcelException;
|
|
|
import com.yonge.toolset.utils.easyexcel.ExcelUtils;
|
|
|
-import com.yonge.toolset.utils.excel.POIUtil;
|
|
|
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.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -49,8 +50,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.util.Date;
|
|
|
+import java.io.File;
|
|
|
+import java.text.MessageFormat;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@@ -75,6 +76,8 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private TenantStaffService tenantStaffService;
|
|
|
+ @Autowired
|
|
|
+ private OssPluginContext ossPluginContext;
|
|
|
|
|
|
@ApiOperation(value = "详情", notes = "机构激活码-根据详情ID查询单条, 传入id")
|
|
|
// @GetMapping("/detail/{id}")
|
|
@@ -140,7 +143,7 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
|
|
|
@GetMapping("/exportActiveCode")
|
|
|
@ApiOperation(value = "导出模板")
|
|
|
- public void exportActiveCode(HttpServletResponse response,String orderNo) {
|
|
|
+ public HttpResponseResult<TenantActivationCodeWrapper.ExportFile> exportActiveCode(HttpServletResponse response, String orderNo) {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
if (sysUser == null) {
|
|
|
throw new BizException("请登录");
|
|
@@ -162,23 +165,56 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
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")
|
|
|
@ApiOperation(value = "导出订单激活码模板")
|
|
|
- public void exportOrderCode(HttpServletResponse response,String orderNo) {
|
|
|
+ public HttpResponseResult<TenantActivationCodeWrapper.ExportFile> exportOrderCode(HttpServletResponse response, String orderNo) {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
if (sysUser == null) {
|
|
|
throw new BizException("请登录");
|
|
@@ -199,17 +235,11 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
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")
|