feat(util): 添加Excel导出工具类并重构导出功能
- 新增KitExcelExporter工具类,支持普通和分页模式导出 - 新增KitExcelPageWriteHelper分页写入工具,解决大数据量OOM问题 - 替换原有的KitXlsxExportUtil导出实现 - 重构部门、字典、岗位、菜单、角色等模块的导出功能 - 实现用户数据分页导出功能,支持大数据量场景 - 优化导出文件响应头设置和编码处理
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
package cn.odboy.util.xlsx;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.idev.excel.EasyExcel;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* EasyExcel 导出增强工具类 (支持普通/分页模式)
|
||||
*
|
||||
* @author https://mp.weixin.qq.com/s/gnrKCUzHg24sBSDp4IyAvg
|
||||
*/
|
||||
public class KitExcelExporter {
|
||||
|
||||
private static int calculateOptimalPageSize(Class<?> clazz) {
|
||||
// 1. 估算单条数据大小 (字节) - 根据业务模型调整逻辑
|
||||
// 保守估计500字节/行
|
||||
long approxBytesPerRow = 500;
|
||||
// 2. 获取当前JVM可用内存 (转成字节)
|
||||
long freeMemoryBytes = Runtime.getRuntime().freeMemory();
|
||||
// 3. 【安全策略】仅使用一部分可用内存 (例如 40%)
|
||||
long safeMemoryToUse = (long) (freeMemoryBytes * 0.4);
|
||||
// 4. 计算建议分页条数
|
||||
int suggestedPageSize = (int) (safeMemoryToUse / approxBytesPerRow);
|
||||
// 5. 设置合理范围 (防止太大或太小)
|
||||
// 限制在1000~10000条/页
|
||||
return Math.max(1000, Math.min(suggestedPageSize, 10000));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页写入 (大数据量首选)
|
||||
*
|
||||
* @param response /
|
||||
* @param fileName 下载文件名
|
||||
* @param dataModel 数据类 (User.class)
|
||||
* @param totalCount 总条数
|
||||
* @param pageSupplier 分页查询逻辑
|
||||
*/
|
||||
public static <T> void exportByPage(HttpServletResponse response, String fileName, Class<T> dataModel, long totalCount, PageQuerySupplier<T> pageSupplier) {
|
||||
int pageSize = calculateOptimalPageSize(dataModel);
|
||||
String sheetName = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
||||
setupResponse(response, fileName, sheetName);
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
KitExcelPageWriteHelper.writeByPage(out, dataModel, sheetName, pageSize, totalCount, pageSupplier);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("导出失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通导出 (小数据量)
|
||||
*
|
||||
* @param response /
|
||||
* @param fileName 下载文件名
|
||||
* @param dataModel 数据类 (User.class)
|
||||
* @param dataList 全量数据List
|
||||
*/
|
||||
public static <T> void exportSimple(HttpServletResponse response, String fileName, Class<T> dataModel, List<T> dataList) {
|
||||
String sheetName = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
||||
setupResponse(response, fileName, sheetName);
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
EasyExcel.write(out, dataModel)
|
||||
.sheet(sheetName)
|
||||
// 全量写入
|
||||
.doWrite(dataList);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("导出失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置响应头
|
||||
*/
|
||||
private static void setupResponse(HttpServletResponse response, String title, String sheetName) {
|
||||
try {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
String fileName = URLEncoder.encode(sheetName + "_" + title, StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition",
|
||||
"attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("设置响应头失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询供应商
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PageQuerySupplier<T> {
|
||||
|
||||
List<T> getPage(long pageNum, long pageSize); // 函数式接口
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package cn.odboy.util.xlsx;
|
||||
|
||||
import cn.idev.excel.EasyExcel;
|
||||
import cn.idev.excel.ExcelWriter;
|
||||
import cn.idev.excel.write.metadata.WriteSheet;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页写入Excel工具 - 专治各种不服(OOM)
|
||||
*/
|
||||
public class KitExcelPageWriteHelper {
|
||||
|
||||
/**
|
||||
* 执行分页写入
|
||||
*
|
||||
* @param outputStream 输出流 (响应OutputStream)
|
||||
* @param head 数据模型Class (如 User.class)
|
||||
* @param sheetName 表格名称
|
||||
* @param pageSize 【重要】每批次处理条数 (建议 1000~5000)
|
||||
* @param totalCount 总数据量 (用于计算总页数)
|
||||
* @param supplier 分页数据提供器 (你的业务查询逻辑)
|
||||
*/
|
||||
public static <T> void writeByPage(OutputStream outputStream, Class<T> head, String sheetName, long pageSize, long totalCount, KitExcelExporter.PageQuerySupplier<T> supplier) {
|
||||
try (ExcelWriter excelWriter = EasyExcel.write(outputStream, head).build()) {
|
||||
// 默认Sheet
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet(sheetName).build();
|
||||
int totalPage = totalCount > 0 ? (int) Math.ceil((double) totalCount / pageSize) : 1;
|
||||
for (int pageNum = 1; pageNum <= totalPage; pageNum++) {
|
||||
List<T> pageData = supplier.getPage(pageNum, pageSize);
|
||||
excelWriter.write(pageData, writeSheet);
|
||||
pageData.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-5
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.constant.SystemZhConst;
|
||||
@@ -25,9 +24,10 @@ import cn.odboy.system.dal.model.SystemDeptExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryDeptArgs;
|
||||
import cn.odboy.system.service.SystemDeptService;
|
||||
import cn.odboy.util.KitPageUtil;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -55,13 +55,22 @@ public class SystemDeptController {
|
||||
@PreAuthorize("@el.check('dept:list')")
|
||||
public void exportDept(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception {
|
||||
List<SystemDeptTb> systemDeptTbs = systemDeptService.queryAllDeptByArgs(args, false);
|
||||
KitXlsxExportUtil.exportFile(response, "部门数据", systemDeptTbs, SystemDeptExportRowVo.class, (dataObject) -> {
|
||||
// KitXlsxExportUtil.exportFile(response, "部门数据", systemDeptTbs, SystemDeptExportRowVo.class, (dataObject) -> {
|
||||
// SystemDeptExportRowVo rowVo = new SystemDeptExportRowVo();
|
||||
// rowVo.setName(dataObject.getName());
|
||||
// rowVo.setEnabled(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// });
|
||||
List<SystemDeptExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemDeptTb dataObject : systemDeptTbs) {
|
||||
SystemDeptExportRowVo rowVo = new SystemDeptExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setEnabled(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
});
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "部门数据", SystemDeptExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("查询部门")
|
||||
|
||||
+30
-6
@@ -25,7 +25,7 @@ import cn.odboy.system.dal.model.SystemDictExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryDictArgs;
|
||||
import cn.odboy.system.service.SystemDictDetailService;
|
||||
import cn.odboy.system.service.SystemDictService;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -59,7 +59,31 @@ public class SystemDictController {
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
public void exportDict(HttpServletResponse response, SystemQueryDictArgs args) throws IOException {
|
||||
List<SystemDictTb> systemDictTbs = systemDictService.queryDictByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "字典数据", systemDictTbs, SystemDictExportRowVo.class, (dataObject) -> {
|
||||
// KitXlsxExportUtil.exportFile(response, "字典数据", systemDictTbs, SystemDictExportRowVo.class, (dataObject) -> {
|
||||
// List<SystemDictDetailVo> dictDetails = systemDictDetailService.listDictDetailByName(dataObject.getName());
|
||||
// if (CollUtil.isEmpty(dictDetails)) {
|
||||
// SystemDictExportRowVo rowVo = new SystemDictExportRowVo();
|
||||
// rowVo.setName(dataObject.getName());
|
||||
// rowVo.setDescription(dataObject.getDescription());
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// rowVo.setLabel("");
|
||||
// rowVo.setValue("");
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// }
|
||||
// List<SystemDictExportRowVo> rowVos = new ArrayList<>();
|
||||
// for (SystemDictDetailVo dictDetail : dictDetails) {
|
||||
// SystemDictExportRowVo rowVo = new SystemDictExportRowVo();
|
||||
// rowVo.setName(dataObject.getName());
|
||||
// rowVo.setDescription(dataObject.getDescription());
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// rowVo.setLabel(dictDetail.getLabel());
|
||||
// rowVo.setValue(dictDetail.getValue());
|
||||
// rowVos.add(rowVo);
|
||||
// }
|
||||
// return rowVos;
|
||||
// });
|
||||
List<SystemDictExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemDictTb dataObject : systemDictTbs) {
|
||||
List<SystemDictDetailVo> dictDetails = systemDictDetailService.listDictDetailByName(dataObject.getName());
|
||||
if (CollUtil.isEmpty(dictDetails)) {
|
||||
SystemDictExportRowVo rowVo = new SystemDictExportRowVo();
|
||||
@@ -68,9 +92,9 @@ public class SystemDictController {
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVo.setLabel("");
|
||||
rowVo.setValue("");
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
rowVos.add(rowVo);
|
||||
continue;
|
||||
}
|
||||
List<SystemDictExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemDictDetailVo dictDetail : dictDetails) {
|
||||
SystemDictExportRowVo rowVo = new SystemDictExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
@@ -80,8 +104,8 @@ public class SystemDictController {
|
||||
rowVo.setValue(dictDetail.getValue());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
return rowVos;
|
||||
});
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "字典数据", SystemDictExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("查询字典")
|
||||
|
||||
+14
-5
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.dal.dataobject.SystemJobTb;
|
||||
@@ -23,11 +22,12 @@ import cn.odboy.system.dal.model.SystemCreateJobArgs;
|
||||
import cn.odboy.system.dal.model.SystemJobExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryJobArgs;
|
||||
import cn.odboy.system.service.SystemJobService;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -54,13 +54,22 @@ public class SystemJobController {
|
||||
@PreAuthorize("@el.check('job:list')")
|
||||
public void exportJob(HttpServletResponse response, SystemQueryJobArgs args) throws IOException {
|
||||
List<SystemJobTb> systemJobTbs = systemJobService.queryJobByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "岗位数据", systemJobTbs, SystemJobExportRowVo.class, (dataObject) -> {
|
||||
// KitXlsxExportUtil.exportFile(response, "岗位数据", systemJobTbs, SystemJobExportRowVo.class, (dataObject) -> {
|
||||
// SystemJobExportRowVo rowVo = new SystemJobExportRowVo();
|
||||
// rowVo.setName(dataObject.getName());
|
||||
// rowVo.setEnabled(dataObject.getEnabled() ? "启用" : "停用");
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// });
|
||||
List<SystemJobExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemJobTb dataObject : systemJobTbs) {
|
||||
SystemJobExportRowVo rowVo = new SystemJobExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setEnabled(dataObject.getEnabled() ? "启用" : "停用");
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
});
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "岗位数据", SystemJobExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("查询岗位")
|
||||
|
||||
+5
-4
@@ -16,14 +16,13 @@
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.dal.dataobject.SystemLocalStorageTb;
|
||||
import cn.odboy.system.dal.model.SystemLocalStorageExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryStorageArgs;
|
||||
import cn.odboy.system.service.SystemLocalStorageService;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -64,8 +63,10 @@ public class SystemLocalStorageController {
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public void exportFile(HttpServletResponse response, SystemQueryStorageArgs args) throws IOException {
|
||||
List<SystemLocalStorageTb> systemLocalStorageTbs = localStorageService.queryLocalStorageByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "文件上传记录数据", systemLocalStorageTbs, SystemLocalStorageExportRowVo.class,
|
||||
(dataObject) -> CollUtil.newArrayList(BeanUtil.copyProperties(dataObject, SystemLocalStorageExportRowVo.class)));
|
||||
// KitXlsxExportUtil.exportFile(response, "文件上传记录数据", systemLocalStorageTbs, SystemLocalStorageExportRowVo.class,
|
||||
// (dataObject) -> CollUtil.newArrayList(BeanUtil.copyProperties(dataObject, SystemLocalStorageExportRowVo.class)));
|
||||
List<SystemLocalStorageExportRowVo> rowVos = BeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
|
||||
KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
|
||||
+19
-6
@@ -15,20 +15,20 @@
|
||||
*/
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
import cn.odboy.system.constant.SystemYesOrNoChConst;
|
||||
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
||||
import cn.odboy.system.dal.model.SystemMenuVo;
|
||||
import cn.odboy.system.dal.model.SystemMenuExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemMenuVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryMenuArgs;
|
||||
import cn.odboy.system.service.SystemMenuService;
|
||||
import cn.odboy.util.KitPageUtil;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -56,7 +56,19 @@ public class SystemMenuController {
|
||||
@PreAuthorize("@el.check('menu:list')")
|
||||
public void exportMenu(HttpServletResponse response, SystemQueryMenuArgs args) throws Exception {
|
||||
List<SystemMenuTb> systemMenuTbs = systemMenuService.queryAllMenu(args, false);
|
||||
KitXlsxExportUtil.exportFile(response, "菜单数据", systemMenuTbs, SystemMenuExportRowVo.class, (dataObject -> {
|
||||
// KitXlsxExportUtil.exportFile(response, "菜单数据", systemMenuTbs, SystemMenuExportRowVo.class, (dataObject -> {
|
||||
// SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo();
|
||||
// rowVo.setTitle(dataObject.getTitle());
|
||||
// rowVo.setType(dataObject.getType() == null ? "目录" : dataObject.getType() == 1 ? "菜单" : "按钮");
|
||||
// rowVo.setPermission(dataObject.getPermission());
|
||||
// rowVo.setIFrame(dataObject.getIFrame() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
|
||||
// rowVo.setHidden(dataObject.getHidden() ? SystemYesOrNoChConst.NO_STR : SystemYesOrNoChConst.YES_STR);
|
||||
// rowVo.setCache(dataObject.getCache() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// }));
|
||||
List<SystemMenuExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemMenuTb dataObject : systemMenuTbs) {
|
||||
SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo();
|
||||
rowVo.setTitle(dataObject.getTitle());
|
||||
rowVo.setType(dataObject.getType() == null ? "目录" : dataObject.getType() == 1 ? "菜单" : "按钮");
|
||||
@@ -65,8 +77,9 @@ public class SystemMenuController {
|
||||
rowVo.setHidden(dataObject.getHidden() ? SystemYesOrNoChConst.NO_STR : SystemYesOrNoChConst.YES_STR);
|
||||
rowVo.setCache(dataObject.getCache() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
}));
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "菜单数据", SystemMenuExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/buildMenus")
|
||||
|
||||
+6
-2
@@ -19,9 +19,11 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.dal.model.SystemLocalStorageExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemUserOnlineExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemUserOnlineVo;
|
||||
import cn.odboy.system.dal.redis.SystemUserOnlineInfoDAO;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -63,8 +65,10 @@ public class SystemOnlineController {
|
||||
@PreAuthorize("@el.check()")
|
||||
public void exportOnlineUser(HttpServletResponse response, String username) throws IOException {
|
||||
List<SystemUserOnlineVo> userOnlineVos = systemUserOnlineInfoDAO.queryUserOnlineModelListByUsername(username);
|
||||
KitXlsxExportUtil.exportFile(response, "在线用户数据", userOnlineVos, SystemUserOnlineExportRowVo.class,
|
||||
(dataObject) -> CollUtil.newArrayList(BeanUtil.copyProperties(dataObject, SystemUserOnlineExportRowVo.class)));
|
||||
// KitXlsxExportUtil.exportFile(response, "在线用户数据", userOnlineVos, SystemUserOnlineExportRowVo.class,
|
||||
// (dataObject) -> CollUtil.newArrayList(BeanUtil.copyProperties(dataObject, SystemUserOnlineExportRowVo.class)));
|
||||
List<SystemUserOnlineVo> rowVos = BeanUtil.copyToList(userOnlineVos, SystemUserOnlineVo.class);
|
||||
KitExcelExporter.exportSimple(response, "在线用户数据", SystemUserOnlineVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("踢出用户")
|
||||
|
||||
+6
-2
@@ -23,7 +23,9 @@ import cn.odboy.system.dal.dataobject.SystemOssStorageTb;
|
||||
import cn.odboy.system.dal.model.SystemOssStorageExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemOssStorageVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryStorageArgs;
|
||||
import cn.odboy.system.dal.model.SystemUserOnlineVo;
|
||||
import cn.odboy.system.service.SystemOssStorageService;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -67,8 +69,10 @@ public class SystemOssStorageController {
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public void exportFile(HttpServletResponse response, SystemQueryStorageArgs args) throws IOException {
|
||||
List<SystemOssStorageVo> systemOssStorageVos = systemOssStorageService.queryOssStorage(args);
|
||||
KitXlsxExportUtil.exportFile(response, "OSS文件上传记录数据", systemOssStorageVos, SystemOssStorageExportRowVo.class,
|
||||
(dataObject) -> CollUtil.newArrayList(BeanUtil.copyProperties(dataObject, SystemOssStorageExportRowVo.class)));
|
||||
// KitXlsxExportUtil.exportFile(response, "OSS文件上传记录数据", systemOssStorageVos, SystemOssStorageExportRowVo.class,
|
||||
// (dataObject) -> CollUtil.newArrayList(BeanUtil.copyProperties(dataObject, SystemOssStorageExportRowVo.class)));
|
||||
List<SystemOssStorageExportRowVo> rowVos = BeanUtil.copyToList(systemOssStorageVos, SystemOssStorageExportRowVo.class);
|
||||
KitExcelExporter.exportSimple(response, "OSS文件上传记录数据", SystemOssStorageExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
|
||||
+58
-29
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.system.dal.dataobject.SystemQuartzJobTb;
|
||||
@@ -25,11 +24,12 @@ import cn.odboy.system.dal.model.SystemQuartzLogExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemQueryQuartzJobArgs;
|
||||
import cn.odboy.system.dal.model.SystemUpdateQuartzJobArgs;
|
||||
import cn.odboy.system.service.SystemQuartzJobService;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -69,19 +69,33 @@ public class SystemQuartzJobController {
|
||||
@PreAuthorize("@el.check('quartzJob:list')")
|
||||
public void exportQuartzJob(HttpServletResponse response, SystemQueryQuartzJobArgs args) throws IOException {
|
||||
List<SystemQuartzJobTb> systemQuartzJobTbs = systemQuartzJobService.queryQuartzJobByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "定时任务数据", systemQuartzJobTbs, SystemQuartzJobExportRowVo.class,
|
||||
(dataObject) -> {
|
||||
SystemQuartzJobExportRowVo rowVo = new SystemQuartzJobExportRowVo();
|
||||
rowVo.setJobName(dataObject.getJobName());
|
||||
rowVo.setBeanName(dataObject.getBeanName());
|
||||
rowVo.setMethodName(dataObject.getMethodName());
|
||||
rowVo.setParams(dataObject.getParams());
|
||||
rowVo.setCronExpression(dataObject.getCronExpression());
|
||||
rowVo.setIsPause(dataObject.getIsPause() ? "暂停中" : "运行中");
|
||||
rowVo.setDescription(dataObject.getDescription());
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
});
|
||||
// KitXlsxExportUtil.exportFile(response, "定时任务数据", systemQuartzJobTbs, SystemQuartzJobExportRowVo.class,
|
||||
// (dataObject) -> {
|
||||
// SystemQuartzJobExportRowVo rowVo = new SystemQuartzJobExportRowVo();
|
||||
// rowVo.setJobName(dataObject.getJobName());
|
||||
// rowVo.setBeanName(dataObject.getBeanName());
|
||||
// rowVo.setMethodName(dataObject.getMethodName());
|
||||
// rowVo.setParams(dataObject.getParams());
|
||||
// rowVo.setCronExpression(dataObject.getCronExpression());
|
||||
// rowVo.setIsPause(dataObject.getIsPause() ? "暂停中" : "运行中");
|
||||
// rowVo.setDescription(dataObject.getDescription());
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// });
|
||||
List<SystemQuartzJobExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemQuartzJobTb dataObject : systemQuartzJobTbs) {
|
||||
SystemQuartzJobExportRowVo rowVo = new SystemQuartzJobExportRowVo();
|
||||
rowVo.setJobName(dataObject.getJobName());
|
||||
rowVo.setBeanName(dataObject.getBeanName());
|
||||
rowVo.setMethodName(dataObject.getMethodName());
|
||||
rowVo.setParams(dataObject.getParams());
|
||||
rowVo.setCronExpression(dataObject.getCronExpression());
|
||||
rowVo.setIsPause(dataObject.getIsPause() ? "暂停中" : "运行中");
|
||||
rowVo.setDescription(dataObject.getDescription());
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "定时任务数据", SystemQuartzJobExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("导出日志数据")
|
||||
@@ -89,20 +103,35 @@ public class SystemQuartzJobController {
|
||||
@PreAuthorize("@el.check('quartzJob:list')")
|
||||
public void exportQuartzJobLog(HttpServletResponse response, SystemQueryQuartzJobArgs args) throws IOException {
|
||||
List<SystemQuartzLogTb> systemQuartzLogTbs = systemQuartzJobService.queryQuartzLogByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "定时任务日志数据", systemQuartzLogTbs, SystemQuartzLogExportRowVo.class,
|
||||
(dataObject) -> {
|
||||
SystemQuartzLogExportRowVo rowVo = new SystemQuartzLogExportRowVo();
|
||||
rowVo.setJobName(dataObject.getJobName());
|
||||
rowVo.setBeanName(dataObject.getBeanName());
|
||||
rowVo.setMethodName(dataObject.getMethodName());
|
||||
rowVo.setParams(dataObject.getParams());
|
||||
rowVo.setCronExpression(dataObject.getCronExpression());
|
||||
rowVo.setExceptionDetail(dataObject.getExceptionDetail());
|
||||
rowVo.setTime(dataObject.getTime());
|
||||
rowVo.setStatus(dataObject.getIsSuccess() ? "成功" : "失败");
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
});
|
||||
// KitXlsxExportUtil.exportFile(response, "定时任务日志数据", systemQuartzLogTbs, SystemQuartzLogExportRowVo.class,
|
||||
// (dataObject) -> {
|
||||
// SystemQuartzLogExportRowVo rowVo = new SystemQuartzLogExportRowVo();
|
||||
// rowVo.setJobName(dataObject.getJobName());
|
||||
// rowVo.setBeanName(dataObject.getBeanName());
|
||||
// rowVo.setMethodName(dataObject.getMethodName());
|
||||
// rowVo.setParams(dataObject.getParams());
|
||||
// rowVo.setCronExpression(dataObject.getCronExpression());
|
||||
// rowVo.setExceptionDetail(dataObject.getExceptionDetail());
|
||||
// rowVo.setTime(dataObject.getTime());
|
||||
// rowVo.setStatus(dataObject.getIsSuccess() ? "成功" : "失败");
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// });
|
||||
List<SystemQuartzLogExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemQuartzLogTb dataObject : systemQuartzLogTbs) {
|
||||
SystemQuartzLogExportRowVo rowVo = new SystemQuartzLogExportRowVo();
|
||||
rowVo.setJobName(dataObject.getJobName());
|
||||
rowVo.setBeanName(dataObject.getBeanName());
|
||||
rowVo.setMethodName(dataObject.getMethodName());
|
||||
rowVo.setParams(dataObject.getParams());
|
||||
rowVo.setCronExpression(dataObject.getCronExpression());
|
||||
rowVo.setExceptionDetail(dataObject.getExceptionDetail());
|
||||
rowVo.setTime(dataObject.getTime());
|
||||
rowVo.setStatus(dataObject.getIsSuccess() ? "成功" : "失败");
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "定时任务日志数据", SystemQuartzLogExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("查询任务执行日志")
|
||||
|
||||
+15
-5
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
@@ -25,11 +24,12 @@ import cn.odboy.system.dal.model.SystemQueryRoleArgs;
|
||||
import cn.odboy.system.dal.model.SystemRoleExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemRoleVo;
|
||||
import cn.odboy.system.service.SystemRoleService;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -63,14 +63,24 @@ public class SystemRoleController {
|
||||
@PreAuthorize("@el.check('role:list')")
|
||||
public void exportRole(HttpServletResponse response, SystemQueryRoleArgs args) throws IOException {
|
||||
List<SystemRoleVo> systemRoleVos = systemRoleService.queryRoleByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "角色数据", systemRoleVos, SystemRoleExportRowVo.class, (dataObject) -> {
|
||||
// KitXlsxExportUtil.exportFile(response, "角色数据", systemRoleVos, SystemRoleExportRowVo.class, (dataObject) -> {
|
||||
// SystemRoleExportRowVo rowVo = new SystemRoleExportRowVo();
|
||||
// rowVo.setName(dataObject.getName());
|
||||
// rowVo.setLevel(dataObject.getLevel());
|
||||
// rowVo.setDescription(dataObject.getDescription());
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// });
|
||||
List<SystemRoleExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemRoleVo dataObject : systemRoleVos) {
|
||||
SystemRoleExportRowVo rowVo = new SystemRoleExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setLevel(dataObject.getLevel());
|
||||
rowVo.setDescription(dataObject.getDescription());
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
});
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "部门数据", SystemRoleExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
@ApiOperation("返回全部的角色")
|
||||
|
||||
+50
-17
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package cn.odboy.system.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.base.KitSelectOptionVo;
|
||||
@@ -29,11 +28,11 @@ import cn.odboy.system.dal.model.SystemUserExportRowVo;
|
||||
import cn.odboy.system.dal.model.SystemUserVo;
|
||||
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
|
||||
import cn.odboy.system.service.SystemUserService;
|
||||
import cn.odboy.util.xlsx.KitXlsxExportUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -63,20 +62,54 @@ public class SystemUserController {
|
||||
@ApiOperation("导出用户数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('user:list')")
|
||||
public void exportUserExcel(HttpServletResponse response, SystemQueryUserArgs args) throws IOException {
|
||||
List<SystemUserVo> systemUserVos = systemUserService.queryUserVoByArgs(args);
|
||||
KitXlsxExportUtil.exportFile(response, "用户数据", systemUserVos, SystemUserExportRowVo.class, (dataObject) -> {
|
||||
SystemUserExportRowVo rowVo = new SystemUserExportRowVo();
|
||||
rowVo.setUsername(dataObject.getUsername());
|
||||
rowVo.setRoles(dataObject.getRoles().stream().map(SystemRoleTb::getName).collect(Collectors.joining(",")));
|
||||
rowVo.setDept(dataObject.getDept().getName());
|
||||
rowVo.setJobs(dataObject.getJobs().stream().map(SystemJobTb::getName).collect(Collectors.joining(",")));
|
||||
rowVo.setEmail(dataObject.getEmail());
|
||||
rowVo.setStatus(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
rowVo.setMobile(dataObject.getPhone());
|
||||
rowVo.setUpdatePwdTime(dataObject.getPwdResetTime());
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
return CollUtil.newArrayList(rowVo);
|
||||
public void exportUserExcel(HttpServletResponse response, SystemQueryUserArgs args) {
|
||||
// List<SystemUserVo> systemUserVos = systemUserService.queryUserVoByArgs(args);
|
||||
// KitXlsxExportUtil.exportFile(response, "用户数据", systemUserVos, SystemUserExportRowVo.class, (dataObject) -> {
|
||||
// SystemUserExportRowVo rowVo = new SystemUserExportRowVo();
|
||||
// rowVo.setUsername(dataObject.getUsername());
|
||||
// rowVo.setRoles(dataObject.getRoles().stream().map(SystemRoleTb::getName).collect(Collectors.joining(",")));
|
||||
// rowVo.setDept(dataObject.getDept().getName());
|
||||
// rowVo.setJobs(dataObject.getJobs().stream().map(SystemJobTb::getName).collect(Collectors.joining(",")));
|
||||
// rowVo.setEmail(dataObject.getEmail());
|
||||
// rowVo.setStatus(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
// rowVo.setMobile(dataObject.getPhone());
|
||||
// rowVo.setUpdatePwdTime(dataObject.getPwdResetTime());
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// return CollUtil.newArrayList(rowVo);
|
||||
// });
|
||||
// List<SystemUserExportRowVo> rowVos = new ArrayList<>();
|
||||
// for (SystemUserVo dataObject : systemUserVos) {
|
||||
// SystemUserExportRowVo rowVo = new SystemUserExportRowVo();
|
||||
// rowVo.setUsername(dataObject.getUsername());
|
||||
// rowVo.setRoles(dataObject.getRoles().stream().map(SystemRoleTb::getName).collect(Collectors.joining(",")));
|
||||
// rowVo.setDept(dataObject.getDept().getName());
|
||||
// rowVo.setJobs(dataObject.getJobs().stream().map(SystemJobTb::getName).collect(Collectors.joining(",")));
|
||||
// rowVo.setEmail(dataObject.getEmail());
|
||||
// rowVo.setStatus(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
// rowVo.setMobile(dataObject.getPhone());
|
||||
// rowVo.setUpdatePwdTime(dataObject.getPwdResetTime());
|
||||
// rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
// rowVos.add(rowVo);
|
||||
// }
|
||||
// KitExcelExporter.exportSimple(response, "用户数据", SystemUserExportRowVo.class, rowVos);
|
||||
long totalCount = systemUserService.countUserByArgs(args);
|
||||
KitExcelExporter.exportByPage(response, "用户数据", SystemUserExportRowVo.class, totalCount, (long pageNum, long pageSize) -> {
|
||||
KitPageResult<SystemUserVo> pageResult = systemUserService.searchUserByArgs(args, new Page<>(pageNum, pageSize));
|
||||
List<SystemUserExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemUserVo dataObject : pageResult.getContent()) {
|
||||
SystemUserExportRowVo rowVo = new SystemUserExportRowVo();
|
||||
rowVo.setUsername(dataObject.getUsername());
|
||||
rowVo.setRoles(dataObject.getRoles().stream().map(SystemRoleTb::getName).collect(Collectors.joining(",")));
|
||||
rowVo.setDept(dataObject.getDept().getName());
|
||||
rowVo.setJobs(dataObject.getJobs().stream().map(SystemJobTb::getName).collect(Collectors.joining(",")));
|
||||
rowVo.setEmail(dataObject.getEmail());
|
||||
rowVo.setStatus(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
rowVo.setMobile(dataObject.getPhone());
|
||||
rowVo.setUpdatePwdTime(dataObject.getPwdResetTime());
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
return rowVos;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+16
-11
@@ -348,18 +348,23 @@ public class SystemUserService {
|
||||
return KitPageUtil.toPage(userVos, userPage.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部不分页
|
||||
*
|
||||
* @param args 条件
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemUserVo> queryUserVoByArgs(SystemQueryUserArgs args) {
|
||||
// 查询用户基本信息
|
||||
// /**
|
||||
// * 查询全部不分页
|
||||
// *
|
||||
// * @param args 条件
|
||||
// * @return /
|
||||
// */
|
||||
// public List<SystemUserVo> queryUserVoByArgs(SystemQueryUserArgs args) {
|
||||
// // 查询用户基本信息
|
||||
// LambdaQueryWrapper<SystemUserTb> wrapper = buildUserQueryWrapper(args);
|
||||
// List<SystemUserTb> users = systemUserMapper.selectList(wrapper);
|
||||
// // 转换为SystemUserVo并关联查询
|
||||
// return users.stream().map(this::convertToUserVo).collect(Collectors.toList());
|
||||
// }
|
||||
|
||||
public long countUserByArgs(SystemQueryUserArgs args) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = buildUserQueryWrapper(args);
|
||||
List<SystemUserTb> users = systemUserMapper.selectList(wrapper);
|
||||
// 转换为SystemUserVo并关联查询
|
||||
return users.stream().map(this::convertToUserVo).collect(Collectors.toList());
|
||||
return systemUserMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user