Merge pull request #2011 from dataease/pr@dev@feat_new-template-import
refactor: 复制视图名称不重复
This commit is contained in:
commit
b1b69a3646
@ -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`,
|
||||
|
||||
@ -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<ChartView> 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());
|
||||
|
||||
@ -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 ;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user