excel导出大文件到Excel(2)

news/2024/7/21 7:45:13 标签: 导入导出, excel

excelExcel2_0">excel导出大文件到Excel(2)

  1. 实体类
/**
 * 日志实体类
 *
 * @author xiaohui
 * @version 1.0
 * @date 2019-05-29 16:45:54
 */
@Entity
@Table(name = "jc_sys_log")
public class SysLog extends AbstractDomain<Integer> implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer id;
	/**
	 * 日志分类(1-系统日志)
	 */
	@Excel(name = "日志分类", replace = {"系统_1", "业务_2", "审计_3", "安全_4", "告警_5"},
			suffix = "日志", isImportField = "true_st")
	private Integer logCategory;
	/**
	 * 日志类别(1-信息   2-警告)
	 */
	@Excel(name = "日志类别", replace = {"信息_1", "警告_2"}, isImportField = "true_st")
	private Integer logType;
	/**
	 * 事件类型(1-系统事件  2-业务事件)
	 */
	@Excel(name = "事件类型", replace = {"系统事件_1", "业务事件_2"}, isImportField = "true_st")
	private Integer eventType;
	/**
	 * 日志级别(1-高   2-中  3-低)
	 */
	@Excel(name = "日志级别", replace = {"高_1", "中_2", "低_3"}, isImportField = "true_st")
	private Integer logLevel;
	/**
	 * 操作类型(1-查询  2-新增  3-修改   4-删除  5-导出  6-导入 7-上传 8-下载)
	 */
	@Excel(name = "操作类型", replace = {"查询_1", "新增_2", "修改_3", "删除_4", "导出_5", "导入_6", "上传_7", "下载_8", "登录_9", "退出_10"},
			isImportField = "true_st")
	private Integer operateType;
	/**
	 * 事件子类型
	 */
	@Excel(name = "事件子类型", width = 25, isImportField = "true_st")
	private String subEventType;
	/**
	 * 操作用户名
	 */
	@Excel(name = "用户名", isImportField = "true_st")
	private String username;
	/**
	 * 客户端请求IP地址
	 */
	@Excel(name = "客户端IP", width = 25, isImportField = "true_st")
	private String clientIp;
	/**
	 * 日志请求地址
	 */
	@Excel(name = "请求路径", width = 50, isImportField = "true_st")
	private String uri;
	/**
	 * 请求方式method,post,get等
	 */
	@Excel(name = "请求方式", isImportField = "true_st")
	private String method;
	/**
	 * 请求参数内容,json
	 */
	private String paramData;
	/**
	 * 请求接口唯一session标识'
	 */
	private String sessionId;
	/**
	 * 接口返回时间
	 */
	private String returmTime;
	/**
	 * 接口返回数据json
	 */
	private String returnData;
	/**
	 * 请求时httpStatusCode代码,如:200,400,404等
	 */
	private String httpStatusCode;
	/**
	 * 请求耗时(毫秒单位)
	 */
	@Excel(name = "响应时间(毫秒)", suffix = "ms", isImportField = "true_st")
	private Integer timeConsuming;
	/**
	 * 请求结果(1-成功   2-失败)
	 */
	@Excel(name = "请求结果", replace = {"成功_1", "失败_2"}, isImportField = "true_st")
	private Integer requestResult;
	/**
	 * 创建时间
	 */
	@Excel(name = "操作时间", width = 35, databaseFormat = "yyyy-MM-dd HH:mm:ss", isImportField = "true_st")
	private Date createTime;
	/**
	 * 浏览器
	 */
	private String browser;
	/**
	 * 操作系统
	 */
	private String os;
	/**
	 * 用户代理
	 */
	private String userAgent;
	/**
	 * 备注
	 */
	private String remark;
	/**
	 * 响应时间(毫秒)
	 */
	private String responseTime;
  1. 查询条件
@Data
public class SearchLogDto {

	private String username;
	private String clientIp;
	private String subEventType;
	private Integer logLevel;
	private Integer operateType;
	private Integer requestResult;
	private Integer logCategory;
	private Date beginDate;
	private Date endDate;
}
  1. 控制器
/**
	 * 导出日志
	 *
	 * @param dto      查询日志Dto
	 * @param response {@link HttpServletResponse}
	 * @throws GlobalException 异常
	 */
	@PostMapping("/export")
	public void export(@RequestBody SearchLogDto dto, HttpServletResponse response) {
		ExportParams exportParams = new ExportParams();
		Integer logCategory = dto.getLogCategory() == null ? 1 : dto.getLogCategory();
		exportParams.setSheetName(LogConstants.category(logCategory));
		Map<String, String[]> params = new HashMap<>(9);
		params.put("LIKE_subEventType_String", new String[]{dto.getSubEventType()});
		if (dto.getBeginDate() != null) {
			params.put("GTE_createTime_Timestamp", new String[]{MyDateUtils.formatDate(dto.getBeginDate(),
					MyDateUtils.COM_Y_M_D_H_M_S_PATTERN)});
		}
		if (dto.getEndDate() != null) {
			params.put("LTE_createTime_Timestamp", new String[]{MyDateUtils.formatDate(dto.getEndDate(),
					MyDateUtils.COM_Y_M_D_H_M_S_PATTERN)});
		}
		params.put("LIKE_clientIp_String", new String[]{dto.getClientIp()});
		params.put("LIKE_username_String", new String[]{dto.getUsername()});
		params.put("EQ_logLevel_Integer", new String[]{dto.getLogLevel() != null ? String.valueOf(dto.getLogLevel()) : ""});
		params.put("EQ_operateType_Integer", new String[]{dto.getOperateType() != null
				? String.valueOf(dto.getOperateType()) : ""});
		params.put("EQ_requestResult_Integer", new String[]{dto.getRequestResult() != null
				? String.valueOf(dto.getRequestResult()) : ""});
		params.put("EQ_logCategory_Integer", new String[]{String.valueOf(logCategory)});
		List<SysLog> list = service.getList(params, null, false);
		Workbook workbook = ExcelExportUtil.exportBigExcel(exportParams, SysLog.class, list);

		ExcelExportUtil.closeExportBigExcel();
		response.setContentType("application/x-download;charset=UTF-8");
		String category = LogConstants.category(logCategory);
		RequestUtils.setDownloadHeader(response, new String(category.getBytes(), StandardCharsets.ISO_8859_1) + ".xlsx");
		FileOutputStream fos = null;
		InputStream input = null;
		OutputStream output = null;
		File file = null;
		try {
			fos = new FileOutputStream(WebConstants.SPT + category + ".xlsx");
			workbook.write(fos);
			file = new File(WebConstants.SPT + category + ".xlsx");
			input = new FileInputStream(file);
			output = response.getOutputStream();
			byte[] buff = new byte[1024];
			int len = 0;
			while ((len = input.read(buff)) > -1) {
				output.write(buff, 0, len);
			}
		} catch (IOException e) {
			log.error(e.getMessage());
		} finally {
			try {
				if (fos != null) {
					fos.close();
				}
			} catch (IOException e) {
				log.error(e.getMessage());
			}
			try {
				if (output != null) {
					output.close();
				}
			} catch (IOException e) {
				log.error(e.getMessage());
			}
			try {
				if (input != null) {
					input.close();
				}
			} catch (IOException e) {
				log.error(e.getMessage());

			}
		}
		if (file != null) {
			file.delete();
		}
	}

http://www.niftyadmin.cn/n/1302237.html

相关文章

redis 安全漏洞防御

redis 安全漏洞防御 一、端口安全(限制客户端ip以及修改密码) 置redis密码 找到requirepass&#xff0c;设置新的密码将 redis 启动在 127.0.0.1 上 一般建议方案是将 redis 启动在 127.0.0.1 上 但是这种方式不能跨服务器访问&#xff0c;一般方式是将 Redis 放到内网&…

记录一个奇葩问题-----微信转码空格

记录一个奇葩问题----微信转码空格 微信发送文本信息 有的时候&#xff0c;可能通过微信发送某些请求的信息&#xff0c;这个时候问题就来了 自己在本地&#xff0c;用postman测试&#xff0c;接口完全没问题&#xff0c;但是&#xff0c;通过微信发送给他人&#xff0c;他人测…

springboot学习(五十一) springboot中使用openfeign实现调用本地接口访问远程服务

文章目录前言一、Feign是什么&#xff1f;二、使用步骤1.引入库2.编写远程服务示例3.本地编写访问接口1.GET请求&#xff0c;使用RequestParam传参2.DELETE请求&#xff0c;使用PathVariable传参3.POST请求&#xff0c;使用RequestBody传参4.PUT请求&#xff0c;使用RequestBod…

java poi导出带有下拉框的模板(1)

java poi导出带有下拉框的模板(1) 实体类 Data EqualsAndHashCode(callSuper false) Accessors(chain true) public class ImportCommonUser {Excel(name "账号类型",width 25,isImportField "true_st",replace {"长期_1", "临时_2…

管理员已阻止你运行此应用有关详细信息请与管理员联系

安装应用程序提示&#xff1a;管理员已阻止你运行此应用有关详细信息请与管理员联系 转载&#xff1a;https://blog.csdn.net/wsyzxss/article/details/79171084 我的电脑是win10 家庭版&#xff0c;没有策略组

springboot学习(五十二) springboot中使用retrofit实现调用本地接口访问远程服务

文章目录前言一、retrofit是什么&#xff1f;二、使用步骤1.引入库2.编写远程测试接口3.编写本地接口和测试接口3.1. retrofit的配置信息3.2. 本地和测试接口3.3. 测试4.编写拦截器5.自定义注解拦截器总结前言 上一篇文章我们学习了使用openfeign来调用本地接口访问远程服务&am…

fastjson序列化出现StackOverflowError

fastjson序列化出现StackOverflowError 看到StackOverflowError这个就会想到死循环 所以解决该问题的步骤 是否用了递归 若是用了递归&#xff0c;百分之八十估计就是递归的问题若是没有用递归&#xff0c;可能是返回的数据过多

java使用commons-pool2创建对象池

文章目录一、对象池是什么&#xff1f;二、使用步骤1.引入库2.对象实体3.生产对象的工厂4.使用对象池5.补充第三步代码中用到的ReflectUtils#initObj总结一、对象池是什么&#xff1f; 对象池模式经常用在频繁创建、销毁对象&#xff08;并且对象创建、销毁开销很大&#xff0…