From 65f6b8bf7c6234a5cf46dabf87facb47ed578957 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 11 Dec 2025 09:50:21 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B0=86=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E5=86=85=E5=AE=B9=E8=A7=A3=E5=8E=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1573782001516551]增加一个将表字段压缩内容解压接口 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1573782001516551 --- .../api/util/ToggleTableGzipContentApi.java | 87 +++++++++++++++++++ .../module/tenant/dao/mapper/TestMapper.java | 8 ++ .../module/tenant/dao/mapper/TestMapper.xml | 16 ++++ 3 files changed, 111 insertions(+) create mode 100644 src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java diff --git a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java new file mode 100644 index 00000000..9517aae0 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2025 TechSure Co., Ltd. All Rights Reserved. + * This file is part of the NeatLogic software. + * Licensed under the NeatLogic Sustainable Use License (NSUL), Version 4.x – 2025. + * You may use this file only in compliance with the License. + * See the LICENSE file distributed with this work for the full license text. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + */ + +package neatlogic.module.tenant.api.util; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.ADMIN; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.GzipUtil; +import neatlogic.module.tenant.dao.mapper.TestMapper; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +@Service +@AuthAction(action = ADMIN.class) +@OperationType(type = OperationTypeEnum.UPDATE) +public class ToggleTableGzipContentApi extends PrivateApiComponentBase { + + @Resource + private TestMapper testMapper; + + @Override + public String getName() { + return "转换表压缩内容"; + } + + @Input({ + @Param(name = "tableName", type = ApiParamType.STRING, isRequired = true, desc = "表名"), + @Param(name = "columnName", type = ApiParamType.STRING, isRequired = true, desc = "字段名") + }) + @Output({ + @Param(name = "updateCount", type = ApiParamType.INTEGER, isRequired = true, desc = "影响行数"), + }) + @Description(desc = "转换表压缩内容") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + String tableName = paramObj.getString("tableName"); + String columnName = paramObj.getString("columnName"); + int rowNum = testMapper.getGzipContentCountByTableNameAndColumnName(tableName, columnName); + String prefix = "GZIP:"; + int updateCount = 0; + while (updateCount < rowNum) { + List> gzipContentList = testMapper.getGzipContentListByTableNameAndColumnName(tableName, columnName); + if (CollectionUtils.isNotEmpty(gzipContentList)) { + for (Map map : gzipContentList) { + if (MapUtils.isNotEmpty(map)) { + String content = map.get("content"); + if (StringUtils.isNotBlank(content)) { + if (content.startsWith(prefix)) { + String newContent = GzipUtil.uncompress(content.substring(prefix.length())); + testMapper.updateGzipContentByTableNameAndColumnName(tableName, columnName, content, newContent); + updateCount++; + } + } + } + } + } else { + break; + } + } + JSONObject resultObj = new JSONObject(); + resultObj.put("updateCount", updateCount); + return resultObj; + } + + @Override + public String getToken() { + return "/util/table/togglegzipcontent"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java index db9e03ee..b52575ff 100644 --- a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java +++ b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java @@ -12,6 +12,8 @@ package neatlogic.module.tenant.dao.mapper; +import org.apache.ibatis.annotations.Param; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,4 +26,10 @@ public interface TestMapper { void insertContent(String content); Map getProcessTaskByIdForUpdate(Long id); + + int getGzipContentCountByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName); + + List> getGzipContentListByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName); + + int updateGzipContentByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName, @Param("oldContent") String oldContent, @Param("newContent") String newContent); } diff --git a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml index c94b89e3..0b7f79a7 100644 --- a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml +++ b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml @@ -23,5 +23,21 @@ + + + + + + + + + + + UPDATE `${tableName}` SET `${columnName}` = #{newContent} WHERE `${columnName}` = #{oldContent} + -- Gitee From 1c7a0f8f9bf8955d8dd2a2557c0a391686e03823 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 11 Dec 2025 11:52:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B0=86=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E5=86=85=E5=AE=B9=E8=A7=A3=E5=8E=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1573782001516551]增加一个将表字段压缩内容解压接口 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1573782001516551 --- .../api/util/ToggleTableGzipContentApi.java | 50 ++++++++++++++++--- .../module/tenant/dao/mapper/TestMapper.java | 6 ++- .../module/tenant/dao/mapper/TestMapper.xml | 17 ++++++- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java index 9517aae0..8d6fbac9 100644 --- a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java +++ b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java @@ -14,6 +14,7 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.ADMIN; import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dao.plugin.CompressHandler; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; @@ -25,8 +26,10 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; @Service @AuthAction(action = ADMIN.class) @@ -43,7 +46,8 @@ public class ToggleTableGzipContentApi extends PrivateApiComponentBase { @Input({ @Param(name = "tableName", type = ApiParamType.STRING, isRequired = true, desc = "表名"), - @Param(name = "columnName", type = ApiParamType.STRING, isRequired = true, desc = "字段名") + @Param(name = "columnName", type = ApiParamType.STRING, isRequired = true, desc = "字段名"), + @Param(name = "action", type = ApiParamType.ENUM, rule = "compress,uncompress", isRequired = true, desc = "操作,压缩或解压") }) @Output({ @Param(name = "updateCount", type = ApiParamType.INTEGER, isRequired = true, desc = "影响行数"), @@ -53,20 +57,51 @@ public class ToggleTableGzipContentApi extends PrivateApiComponentBase { public Object myDoService(JSONObject paramObj) throws Exception { String tableName = paramObj.getString("tableName"); String columnName = paramObj.getString("columnName"); - int rowNum = testMapper.getGzipContentCountByTableNameAndColumnName(tableName, columnName); + String action = paramObj.getString("action"); + JSONObject resultObj = new JSONObject(); + Object fieldType = null; + List> tableStructureList = testMapper.getDatabaseTableStructure(tableName); + for (Map map : tableStructureList) { + Object field = map.get("Field"); + if (Objects.equals(field, columnName)) { + fieldType = map.get("Type"); + } + } + if (fieldType == null) { + resultObj.put("message", "数据库表`" + tableName + "`没有`" + columnName + "`字段"); + return resultObj; + } + CompressHandler compressHandler = null; + if (Objects.equals(action, "compress")) { + List list = Arrays.asList("text", "mediumtext", "longtext"); + if (!list.contains(fieldType.toString())) { + resultObj.put("message", "数据库表`" + tableName + "` 字段`" + columnName + "`是" +fieldType + "类型" + "不能压缩"); + return resultObj; + } + compressHandler = new CompressHandler(); + } + int rowNum = testMapper.getGzipContentCountByTableNameAndColumnName(tableName, columnName, action); String prefix = "GZIP:"; int updateCount = 0; while (updateCount < rowNum) { - List> gzipContentList = testMapper.getGzipContentListByTableNameAndColumnName(tableName, columnName); + List> gzipContentList = testMapper.getGzipContentListByTableNameAndColumnName(tableName, columnName, action); if (CollectionUtils.isNotEmpty(gzipContentList)) { for (Map map : gzipContentList) { if (MapUtils.isNotEmpty(map)) { String content = map.get("content"); if (StringUtils.isNotBlank(content)) { - if (content.startsWith(prefix)) { - String newContent = GzipUtil.uncompress(content.substring(prefix.length())); - testMapper.updateGzipContentByTableNameAndColumnName(tableName, columnName, content, newContent); - updateCount++; + if (Objects.equals(action, "uncompress")) { + if (content.startsWith(prefix)) { + String newContent = GzipUtil.uncompress(content.substring(prefix.length())); + testMapper.updateGzipContentByTableNameAndColumnName(tableName, columnName, content, newContent); + updateCount++; + } + } else if (Objects.equals(action, "compress")) { + if (!content.startsWith(prefix) && compressHandler != null) { + String newContent = compressHandler.handleParameter(content); + testMapper.updateGzipContentByTableNameAndColumnName(tableName, columnName, content, newContent); + updateCount++; + } } } } @@ -75,7 +110,6 @@ public class ToggleTableGzipContentApi extends PrivateApiComponentBase { break; } } - JSONObject resultObj = new JSONObject(); resultObj.put("updateCount", updateCount); return resultObj; } diff --git a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java index b52575ff..a807439e 100644 --- a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java +++ b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.java @@ -27,9 +27,11 @@ public interface TestMapper { Map getProcessTaskByIdForUpdate(Long id); - int getGzipContentCountByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName); + List> getDatabaseTableStructure(@Param("tableName") String tableName); - List> getGzipContentListByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName); + int getGzipContentCountByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName, @Param("action") String action); + + List> getGzipContentListByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName, @Param("action") String action); int updateGzipContentByTableNameAndColumnName(@Param("tableName") String tableName, @Param("columnName") String columnName, @Param("oldContent") String oldContent, @Param("newContent") String newContent); } diff --git a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml index 0b7f79a7..3886a3f4 100644 --- a/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml +++ b/src/main/java/neatlogic/module/tenant/dao/mapper/TestMapper.xml @@ -24,8 +24,17 @@ select `id` from `processtask` where `id` = #{value} for update + + @@ -33,7 +42,11 @@ -- Gitee From 0aafce03429e992a495e9486da1f5bed147dbb21 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 11 Dec 2025 11:55:00 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B0=86=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E5=86=85=E5=AE=B9=E8=A7=A3=E5=8E=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1573782001516551]增加一个将表字段压缩内容解压接口 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1573782001516551 --- .../module/tenant/api/util/ToggleTableGzipContentApi.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java index 8d6fbac9..b4c610a8 100644 --- a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java +++ b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java @@ -59,6 +59,7 @@ public class ToggleTableGzipContentApi extends PrivateApiComponentBase { String columnName = paramObj.getString("columnName"); String action = paramObj.getString("action"); JSONObject resultObj = new JSONObject(); + // 先查询表结构,检查字段是否存在,压缩时字段是否是text、mediumtext、longtext类型 Object fieldType = null; List> tableStructureList = testMapper.getDatabaseTableStructure(tableName); for (Map map : tableStructureList) { -- Gitee From 486577d9d023671cac942e9d64beb66c7d9bca10 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 11 Dec 2025 12:02:27 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B0=86=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E5=86=85=E5=AE=B9=E8=A7=A3=E5=8E=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1573782001516551]增加一个将表字段压缩内容解压接口 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1573782001516551 --- .../module/tenant/api/util/ToggleTableGzipContentApi.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java index b4c610a8..23d23124 100644 --- a/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java +++ b/src/main/java/neatlogic/module/tenant/api/util/ToggleTableGzipContentApi.java @@ -119,4 +119,9 @@ public class ToggleTableGzipContentApi extends PrivateApiComponentBase { public String getToken() { return "/util/table/togglegzipcontent"; } + + @Override + public int needAudit() { + return 1; + } } -- Gitee