fix: 新建仪表板卡顿问题

Co-authored-by: wangjiahao <1522128093@qq.com>
This commit is contained in:
fit2cloudrd 2022-04-02 15:04:35 +08:00 committed by GitHub
parent 4b42e73871
commit f631fc98d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 145 additions and 81 deletions

View File

@ -7,6 +7,6 @@ public interface ExtSysAuthMapper {
Boolean checkTreeNoManageCount(@Param("userId") Long userId, @Param("modelType") String modelType, @Param("nodeId") String nodeId);
String copyAuth(@Param("authSource") String authSource, @Param("authSourceType") String authSourceType, @Param("authUser") String authUser);
}

View File

@ -14,4 +14,8 @@
select if(CHECK_TREE_NO_MANAGE_PRIVILEGE(#{userId},#{modelType},#{nodeId})>0,1,0)
</select>
<select id="copyAuth" resultType="String">
select copy_auth(#{authSource},#{authSourceType},#{authUser})
</select>
</mapper>

View File

@ -0,0 +1,16 @@
package io.dataease.commons.constants;
/**
* Author: wangjiahao
* Date: 2022/4/2
* Description:
*/
public class SysAuthConstants {
public final static String AUTH_SOURCE_TYPE_PANEL = "panel";
public final static String AUTH_SOURCE_TYPE_DATASET = "dataset";
public final static String AUTH_SOURCE_TYPE_DATASOURCE = "link";
}

View File

@ -7,6 +7,7 @@ import io.dataease.base.mapper.DatasetGroupMapper;
import io.dataease.base.mapper.ext.ExtDataSetGroupMapper;
import io.dataease.commons.constants.AuthConstants;
import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.SysAuthConstants;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.TreeUtils;
@ -54,8 +55,10 @@ public class DataSetGroupService {
datasetGroup.setCreateBy(AuthUtils.getUser().getUsername());
datasetGroup.setCreateTime(System.currentTimeMillis());
datasetGroupMapper.insert(datasetGroup);
String userName = AuthUtils.getUser().getUsername();
// 清理权限缓存
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
sysAuthService.copyAuth(datasetGroup.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASET);
} else {
datasetGroupMapper.updateByPrimaryKeySelective(datasetGroup);
}

View File

@ -33,6 +33,7 @@ import io.dataease.provider.datasource.JdbcProvider;
import io.dataease.provider.DDLProvider;
import io.dataease.provider.QueryProvider;
import io.dataease.service.engine.EngineService;
import io.dataease.service.sys.SysAuthService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -102,6 +103,8 @@ public class DataSetTableService {
private PermissionService permissionService;
@Resource
private EngineService engineService;
@Resource
private SysAuthService sysAuthService;
private static boolean isUpdatingDatasetTableStatus = false;
private static final String lastUpdateTime = "${__last_update_time__}";
@ -261,6 +264,10 @@ public class DataSetTableService {
datasetTable.setCreateBy(AuthUtils.getUser().getUsername());
datasetTable.setCreateTime(System.currentTimeMillis());
int insert = datasetTableMapper.insert(datasetTable);
// 清理权限缓存
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
sysAuthService.copyAuth(datasetTable.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASET);
// 添加表成功后获取当前表字段和类型抽象到dataease数据库
if (insert == 1) {
saveTableField(datasetTable);

View File

@ -11,6 +11,7 @@ import io.dataease.base.mapper.DatasourceMapper;
import io.dataease.base.mapper.ext.ExtDataSourceMapper;
import io.dataease.base.mapper.ext.query.GridExample;
import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.SysAuthConstants;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.model.AuthURD;
import io.dataease.commons.utils.AuthUtils;
@ -34,6 +35,7 @@ import io.dataease.provider.datasource.ApiProvider;
import io.dataease.provider.datasource.DatasourceProvider;
import io.dataease.service.dataset.DataSetGroupService;
import io.dataease.service.message.DeMsgutil;
import io.dataease.service.sys.SysAuthService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -57,6 +59,8 @@ public class DatasourceService {
private DataSetGroupService dataSetGroupService;
@Resource
private CommonThreadPool commonThreadPool;
@Resource
private SysAuthService sysAuthService;
private static List<String> dsTypes = Arrays.asList("TiDB", "StarRocks", "excel", "mysql", "hive", "impala", "mariadb", "ds_doris", "pg", "sqlServer", "oracle", "mongo", "ck", "db2", "es", "redshift", "api");
@DeCleaner(DePermissionType.DATASOURCE)
@ -73,6 +77,7 @@ public class DatasourceService {
checkAndUpdateDatasourceStatus(datasource);
datasourceMapper.insertSelective(datasource);
handleConnectionPool(datasource, "add");
sysAuthService.copyAuth(datasource.getId(), SysAuthConstants.AUTH_SOURCE_TYPE_DATASOURCE);
return datasource;
}

View File

@ -6,10 +6,7 @@ import io.dataease.auth.annotation.DeCleaner;
import io.dataease.base.domain.*;
import io.dataease.base.mapper.*;
import io.dataease.base.mapper.ext.*;
import io.dataease.commons.constants.AuthConstants;
import io.dataease.commons.constants.CommonConstants;
import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.PanelConstants;
import io.dataease.commons.constants.*;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.LogUtil;
import io.dataease.commons.utils.TreeUtils;
@ -31,6 +28,7 @@ import io.dataease.service.dataset.DataSetTableService;
import io.dataease.service.sys.SysAuthService;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.pentaho.di.core.util.UUIDUtil;
import org.slf4j.Logger;
@ -94,7 +92,6 @@ public class PanelGroupService {
@Resource
private ExtPanelGroupExtendDataMapper extPanelGroupExtendDataMapper;
public List<PanelGroupDTO> tree(PanelGroupRequest panelGroupRequest) {
String userId = String.valueOf(AuthUtils.getUser().getUserId());
panelGroupRequest.setUserId(userId);
@ -110,22 +107,21 @@ public class PanelGroupService {
}
@DeCleaner(DePermissionType.PANEL)
// @Transactional
public PanelGroup saveOrUpdate(PanelGroupRequest request) {
String userName = AuthUtils.getUser().getUsername();
String panelId = request.getId();
if(StringUtils.isNotEmpty(panelId)){
panelViewService.syncPanelViews(request);
}
if (StringUtils.isEmpty(panelId)) {
// 新建
if (StringUtils.isEmpty(panelId)) { // 新建
checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null, request.getNodeType());
panelId = newPanel(request);
panelGroupMapper.insert(request);
// 清理权限缓存
clearPermissionCache();
} else if ("toDefaultPanel".equals(request.getOptType())) {
sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL);
} else if ("toDefaultPanel".equals(request.getOptType())) { // 转存为默认仪表板
panelId = UUID.randomUUID().toString();
// 转存为默认仪表板
PanelGroupWithBLOBs newDefaultPanel = panelGroupMapper.selectByPrimaryKey(request.getId());
newDefaultPanel.setPanelType(PanelConstants.PANEL_TYPE_SYSTEM);
newDefaultPanel.setNodeType(PanelConstants.PANEL_NODE_TYPE_PANEL);
@ -139,10 +135,12 @@ public class PanelGroupService {
panelGroupMapper.insertSelective(newDefaultPanel);
// 清理权限缓存
clearPermissionCache();
sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL);
} else if ("copy".equals(request.getOptType())) {
panelId = this.panelGroupCopy(request, null, true);
// 清理权限缓存
clearPermissionCache();
sysAuthService.copyAuth(panelId, SysAuthConstants.AUTH_SOURCE_TYPE_PANEL);
} else if ("move".equals(request.getOptType())) {
PanelGroupWithBLOBs panelInfo = panelGroupMapper.selectByPrimaryKey(request.getId());
if (panelInfo.getPid().equalsIgnoreCase(request.getPid())) {
@ -447,5 +445,4 @@ public class PanelGroupService {
CacheUtils.removeAll(AuthConstants.DEPT_PANEL_NAME);
}
}

View File

@ -20,4 +20,9 @@ public class SysAuthService {
}
}
public void copyAuth(String authSource,String authSourceType){
String userName = AuthUtils.getUser().getUsername();
extSysAuthMapper.copyAuth(authSource,authSourceType,userName);
}
}

View File

@ -101,9 +101,7 @@ ADD COLUMN `copy_from` varchar(255) NULL COMMENT '复制来源' AFTER `update_ti
ADD COLUMN `copy_id` varchar(255) NULL COMMENT '复制ID' AFTER `copy_from`;
-- ----------------------------
-- Function structure for copy_auth
-- ----------------------------
DROP FUNCTION IF EXISTS `copy_auth`;
delimiter ;;
CREATE FUNCTION `copy_auth`(authSource varchar(255),authSourceType varchar(255),authUser varchar(255))
@ -197,7 +195,7 @@ SELECT
FROM
sys_auth
WHERE
auth_source IN (
auth_source = (
SELECT
pid
FROM
@ -206,7 +204,9 @@ WHERE
id = authSource
AND model_type = authSourceType
)
AND auth_source_type = authSourceType;
AND auth_source_type = authSourceType
and concat(auth_target,'-',auth_target_type) !=CONCAT(userId,'-','user');
INSERT INTO sys_auth_detail (
id,
auth_id,
@ -250,6 +250,28 @@ END
;;
delimiter ;
-- ----------------------------
-- Function structure for delete_auth_source
-- ----------------------------
DROP FUNCTION IF EXISTS `delete_auth_source`;
delimiter ;;
CREATE FUNCTION `delete_auth_source`(authSource varchar(255),authSourceType varchar(255))
RETURNS varchar(255) CHARSET utf8mb4
READS SQL DATA
BEGIN
delete from sys_auth_detail where auth_id in (
select id from sys_auth where sys_auth.auth_source=authSource and sys_auth.auth_source_type=authSourceType
);
delete from sys_auth where sys_auth.auth_source=authSource and sys_auth.auth_source_type=authSourceType;
RETURN 'success';
END
;;
delimiter ;
INSERT INTO `my_plugin`(`plugin_id`, `name`, `store`, `free`, `cost`, `category`, `descript`, `version`, `install_type`, `creator`, `load_mybatis`, `release_time`, `install_time`, `module_name`, `icon`) VALUES (3, '选项卡插件', 'default', 0, 20000, 'panel', '选项卡插件', '1.0-SNAPSHOT', NULL, 'fit2cloud-chenyw', 0, NULL, NULL, 'dataease-extensions-tabs-backend', NULL);
ALTER TABLE `panel_link_jump_info`
@ -336,3 +358,8 @@ CREATE TABLE `panel_outer_params_target_view_info` (
SET FOREIGN_KEY_CHECKS = 1;
update `my_plugin` set `name` = 'X-Pack默认插件' where `plugin_id` = 1;
update `my_plugin` set `module_name` = 'view-bubblemap-backend' where `plugin_id` = 2;
DROP TRIGGER `new_auth_panel`;
DROP TRIGGER `new_auth_dataset_group`;
DROP TRIGGER `new_auth_dataset_table`;
DROP TRIGGER `new_auth_link`;