|
@@ -1,12 +1,18 @@
|
|
|
package com.yonge.cooleshow.tenant.controller;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+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;
|
|
@@ -32,6 +38,7 @@ 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.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
@@ -46,7 +53,12 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.text.ParsePosition;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -71,6 +83,8 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private TenantStaffService tenantStaffService;
|
|
|
+ @Autowired
|
|
|
+ private OssPluginContext ossPluginContext;
|
|
|
|
|
|
@ApiOperation(value = "详情", notes = "机构激活码-根据详情ID查询单条, 传入id")
|
|
|
// @GetMapping("/detail/{id}")
|
|
@@ -88,6 +102,19 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
TenantInfo tenantInfo = getTenantInfo();
|
|
|
query.setTenantId(tenantInfo.getId());
|
|
|
// 查询数据
|
|
|
+ String activationTime = query.getActivationTime();
|
|
|
+ if (StringUtils.isNotEmpty(activationTime)) {
|
|
|
+ Date parse = new SimpleDateFormat("yyyy-MM").parse(activationTime, new ParsePosition(0));
|
|
|
+ query.setActivationStartTime(parse);
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ instance.setTime(parse);
|
|
|
+ instance.add(Calendar.MONTH, 1);
|
|
|
+ instance.add(Calendar.DATE, -1);
|
|
|
+ instance.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
+ instance.set(Calendar.MINUTE, 59);
|
|
|
+ instance.set(Calendar.MILLISECOND, 59);
|
|
|
+ query.setActivationEndTime(instance.getTime());
|
|
|
+ }
|
|
|
IPage<TenantActivationCodeWrapper.TenantActivationCode> pages =
|
|
|
tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
|
|
|
PageInfo<TenantActivationCodeWrapper.TenantActivationCode> pageInfo = QueryInfo.pageInfo(pages,
|
|
@@ -124,7 +151,7 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
}
|
|
|
boolean update = tenantActivationCodeService.lambdaUpdate()
|
|
|
.set(TenantActivationCode::getSendStatus, EActivationCode.WAIT)
|
|
|
- .eq(TenantActivationCode::getTenantId, id)
|
|
|
+ .eq(TenantActivationCode::getId, id)
|
|
|
.eq(TenantActivationCode::getActivationStatus, false)
|
|
|
.eq(TenantActivationCode::getSendStatus, EActivationCode.SEND)
|
|
|
.update();
|
|
@@ -136,7 +163,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("请登录");
|
|
@@ -158,23 +185,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("请登录");
|
|
@@ -195,19 +255,12 @@ 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")
|
|
|
@ApiOperation(value = "导入", notes = "传入file")
|
|
|
public HttpResponseResult<List<ErrMsg>> importActiveCode(
|
|
@@ -268,8 +321,7 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
|
|
|
private TenantInfo getTenantInfo() {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- TenantInfo tenantInfo = tenantInfoService.lambdaQuery().eq(TenantInfo::getUserId, sysUser.getId())
|
|
|
- .last("limit 1").one();
|
|
|
+ TenantInfo tenantInfo = tenantInfoService.getById(sysUser.getTenantId());
|
|
|
if (tenantInfo == null) {
|
|
|
throw new BizException("非法请求");
|
|
|
}
|