From ade105364cfd388f5c112d3899e9fb9dc9763107 Mon Sep 17 00:00:00 2001 From: sky_iroi Date: Wed, 29 Apr 2026 09:47:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=A4=A7=E5=B1=8F=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=A4=84=E7=90=86=E5=8E=8B=E7=BC=A9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReportDashboardController.java | 73 ++++++++++++++++++- lidee-server/src/main/resources/bootstrap.yml | 8 +- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/lidee-server/src/main/java/top/lidee/taie/business/modules/dashboard/controller/ReportDashboardController.java b/lidee-server/src/main/java/top/lidee/taie/business/modules/dashboard/controller/ReportDashboardController.java index a342d98..88cdc02 100644 --- a/lidee-server/src/main/java/top/lidee/taie/business/modules/dashboard/controller/ReportDashboardController.java +++ b/lidee-server/src/main/java/top/lidee/taie/business/modules/dashboard/controller/ReportDashboardController.java @@ -1,6 +1,7 @@ package top.lidee.taie.business.modules.dashboard.controller; +import com.alibaba.fastjson.JSONObject; import top.lidee.taie.annotation.Permission; import top.lidee.taie.annotation.log.LideeAuditLog; import top.lidee.taie.bean.ResponseBean; @@ -18,6 +19,12 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Map; +import java.util.zip.GZIPInputStream; /** * @desc 大屏设计 controller @@ -49,14 +56,20 @@ public class ReportDashboardController { /** * 保存大屏设计 - * @param dto + * @param payload * @return */ @PostMapping @Permission(code = "design", name = "设计大屏") @LideeAuditLog(pageTitle = "新增") - public ResponseBean insert(@RequestBody ReportDashboardObjectDto dto) { - reportDashboardService.insertDashboard(dto); + public ResponseBean insert(@RequestBody Map payload) { + try{ + String json = decodeGzip(payload); + ReportDashboardObjectDto dto = JSONObject.parseObject(json,ReportDashboardObjectDto.class); + reportDashboardService.insertDashboard(dto); + } catch (IOException e) { + return ResponseBean.builder().code("500").message("保存失败").build(); + } return ResponseBean.builder().build(); } @@ -105,4 +118,58 @@ public class ReportDashboardController { return ResponseBean.builder().data(reportShareService.insertShare(dto)).build(); } + /** + * 处理测压缩请求的接口方法 + * @param payload 包含请求体的Map,其中content字段为Base64编码的内容,compressed字段表示是否压缩 + * @return ResponseBean 响应对象 + * @throws IOException 可能抛出的IO异常 + */ + private String decodeGzip(Map payload) throws IOException { + // 1. 获取 Base64 编码的压缩内容 + String base64Content = (String) payload.get("content"); + // 获取是否压缩的标志,默认为false + boolean isCompressed = (Boolean) payload.getOrDefault("compressed", false); + String json; + // 判断内容是否被压缩 + if (isCompressed && base64Content != null) { + // 2. Base64 解码:将Base64字符串解码为字节数组 + byte[] compressedBytes = Base64.getDecoder().decode(base64Content); + + // 3. Gzip 解压:将Gzip压缩的字节数组解压为JSON字符串 + json = decompressGzip(compressedBytes); + } else { + // 如果未压缩,直接使用Base64内容 + json = base64Content; // 未压缩的情况 + } + + // 打印解压后的数据到控制台,用于调试 + System.out.println("解压后的数据: " + json); + // 返回响应对象 + return json; + } + + + /** + * 解压GZIP压缩的字节数组并返回解压后的字符串 + * @param compressedData GZIP压缩的字节数组 + * @return 解压后的字符串 + * @throws IOException 如果发生I/O错误 + */ + private String decompressGzip(byte[] compressedData) throws IOException { + // 使用try-with-resources语句确保资源自动关闭 + try (GZIPInputStream gzipIn = new GZIPInputStream(new ByteArrayInputStream(compressedData)); + // 创建BufferedReader以行为单位读取解压后的数据 + java.io.BufferedReader reader = new java.io.BufferedReader( + new java.io.InputStreamReader(gzipIn, StandardCharsets.UTF_8))) { + + // 使用StringBuilder高效地构建解压后的字符串 + StringBuilder sb = new StringBuilder(); + String line; + // 逐行读取解压后的数据 + while ((line = reader.readLine()) != null) { + sb.append(line); + } + return sb.toString(); + } + } } diff --git a/lidee-server/src/main/resources/bootstrap.yml b/lidee-server/src/main/resources/bootstrap.yml index d24dafe..2b74fe3 100644 --- a/lidee-server/src/main/resources/bootstrap.yml +++ b/lidee-server/src/main/resources/bootstrap.yml @@ -1,5 +1,7 @@ server: port: 48090 + compression: + enabled: true servlet: encoding: charset: UTF-8 @@ -32,11 +34,11 @@ spring: messages: basename: i18n/messages datasource: - url: jdbc:mysql://127.0.0.1:3306/lidee_report?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true + url: jdbc:mysql://192.168.1.243:3306/lidee_report?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true username: root # password: root password: gryy@8888 -# url: jdbc:mysql://127.0.0.1:3306/lidee_report?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true +# url: jdbc:mysql://192.168.1.243:3306/lidee_report?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true # username: root # password: Lidee@654! driver-class-name: com.mysql.cj.jdbc.Driver @@ -47,7 +49,7 @@ spring: min-idle: 50 max-active: 100 # 获取连接等待超时的时间 - max-wait: 5000 + max-wait: 50000 # 配置间隔多久才进行一次检测 time-between-eviction-runs-millis: 60000 # 配置一个连接在池中最小生存时间