From c0682bcdc8d5eff982faaeb512115cce06a3d4eb Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Wed, 30 Mar 2022 20:15:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E5=A4=8D=E5=88=B6=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E5=90=8D=E7=A7=B0=E4=B8=8D=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/base/mapper/ext/ExtChartViewMapper.xml | 4 ++-- .../java/io/dataease/service/chart/ChartViewService.java | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.xml b/backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.xml index 700328593c..7a638314fa 100644 --- a/backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.xml +++ b/backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.xml @@ -187,11 +187,11 @@ `senior`, `data_from`) SELECT #{newChartId}, - `name`, + GET_CHART_VIEW_COPY_NAME(#{oldChartId},#{panelId}) as `name`, #{panelId}, `table_id`, `type`, - `title`, + GET_CHART_VIEW_COPY_NAME(#{oldChartId},#{panelId}) as `title`, `x_axis`, `x_axis_ext`, `y_axis`, diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index 5862bb8c26..d42d44b804 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -116,6 +116,13 @@ public class ChartViewService { public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) { long timestamp = System.currentTimeMillis(); + // 校验名称 + ChartViewExample queryExample = new ChartViewExample(); + queryExample.createCriteria().andSceneIdEqualTo(chartView.getSceneId()).andNameEqualTo(chartView.getName()); + List result = chartViewMapper.selectByExample(queryExample); + if(CollectionUtils.isNotEmpty(result)){ + DEException.throwException(Translator.get("theme_name_repeat")); + } chartView.setUpdateTime(timestamp); chartView.setId(UUID.randomUUID().toString()); chartView.setCreateBy(AuthUtils.getUser().getUsername()); From dc026ae9b1618947a6ce1ca0aead018a14b4950f Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Wed, 30 Mar 2022 20:29:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0flyway?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/db/migration/V33__1.9.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/backend/src/main/resources/db/migration/V33__1.9.sql b/backend/src/main/resources/db/migration/V33__1.9.sql index e0251c26f2..6812189375 100644 --- a/backend/src/main/resources/db/migration/V33__1.9.sql +++ b/backend/src/main/resources/db/migration/V33__1.9.sql @@ -259,3 +259,33 @@ ADD COLUMN `attach_params` tinyint(1) NULL COMMENT '是否附加点击参数' AF update `sys_menu` set menu_id = 100 where title = '首页'; INSERT INTO `sys_menu` VALUES (101, 1, 4, 1, '插件管理', 'system-plugin', 'system/plugin/index', 1002, 'peoples', 'plugin', b'0', b'0', b'0', 'plugin:read', NULL, NULL, NULL, 1620281952752); + +DROP FUNCTION IF EXISTS `GET_CHART_VIEW_COPY_NAME`; +delimiter ;; +CREATE FUNCTION `GET_CHART_VIEW_COPY_NAME`(chartId varchar(255),pid varchar(255)) + RETURNS varchar(255) CHARSET utf8mb4 + READS SQL DATA +BEGIN + +DECLARE chartName varchar(255); + +DECLARE regexpInfo varchar(255); + +DECLARE chartNameCount INTEGER; + +select `name` into chartName from chart_view where id =chartId; +/** +因为名称存在()等特殊字符,所以不能直接用REGEXP进行查找,qrtz_locks +1.用like 'chartName%' 过滤可能的数据项 +2.REPLACE(name,chartName,'') REGEXP '-copy\\(([0-9])+\\)$' 过滤去掉chartName后的字符以 -copy(/d) 结尾的数据 +3.(LENGTH(REPLACE(name,chartName,''))-LENGTH(replace(REPLACE(name,chartName,''),'-',''))=1) 确定只出现一次 ‘-’ 防止多次copy +**/ +select (count(1)+1) into chartNameCount from chart_view +where (LENGTH(REPLACE(name,chartName,''))-LENGTH(replace(REPLACE(name,chartName,''),'-',''))=1) +and REPLACE(name,chartName,'') REGEXP '-copy\\(([0-9])+\\)$' and name like CONCAT(chartName,'%') and chart_view.scene_id=pid ; + +RETURN concat(chartName,'-copy(',chartNameCount,')'); + +END +;; +delimiter ;