Merge pull request #3251 from dataease/pr@dev@refactor_view-copy

refactor: 更新视图复制自动命名函数,兼容富文本视图不需要显示标题的情况
This commit is contained in:
xuwei-fit2cloud 2022-09-29 13:42:30 +08:00 committed by GitHub
commit 109e78b819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -209,3 +209,33 @@ RETURN oTemp;
END END
;; ;;
delimiter ; delimiter ;
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 (case when `type`='richTextView' then 'RICH_TEXT_VIEW' else `name` end) into chartName from chart_view where id =chartId;
/**
因为名称存在等特殊字符所以不能直接用REGEXP进行查找
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 ;