From a9234ab77e97bc669a73ce20f2534049a9d95fa1 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 1 Nov 2023 14:24:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=95=B0=E6=8D=AE=E9=9B=86=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E9=89=B4=E6=9D=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/manage/DatasetGroupManage.java | 78 +++++++------------ .../dataset/manage/DatasetSQLManage.java | 30 +++---- .../system/manage/CorePermissionManage.java | 14 ++++ de-xpack | 2 +- 4 files changed, 57 insertions(+), 67 deletions(-) create mode 100644 core/core-backend/src/main/java/io/dataease/system/manage/CorePermissionManage.java diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java index 85fb492f54..ae5d7e6628 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java @@ -9,8 +9,6 @@ import io.dataease.api.dataset.union.DatasetGroupInfoDTO; import io.dataease.api.dataset.union.UnionDTO; import io.dataease.api.dataset.vo.DataSetBarVO; import io.dataease.api.ds.vo.DatasourceDTO; -import io.dataease.api.permissions.user.api.UserApi; -import io.dataease.api.permissions.user.vo.UserFormVO; import io.dataease.commons.constants.OptConstants; import io.dataease.dataset.dao.auto.entity.CoreDatasetGroup; import io.dataease.dataset.dao.auto.entity.CoreDatasetTable; @@ -36,7 +34,6 @@ import io.dataease.utils.*; import jakarta.annotation.Resource; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -69,8 +66,7 @@ public class DatasetGroupManage { private CoreDatasetTableMapper coreDatasetTableMapper; @Resource private CoreDatasourceMapper coreDatasourceMapper; - @Autowired(required = false) - private UserApi userApi; + @Resource private CoreUserManage coreUserManage; @@ -92,13 +88,9 @@ public class DatasetGroupManage { CoreDatasetGroup coreDatasetGroup = coreDatasetGroupMapper.selectById(datasetGroupInfoDTO.getId()); datasetGroupInfoDTO.setPid(coreDatasetGroup.getPid()); } - if (userApi == null) { - checkName(datasetGroupInfoDTO); - } - if (userApi != null) { - datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + ""); - datasetGroupInfoDTO.setLastUpdateTime(System.currentTimeMillis()); - } + checkName(datasetGroupInfoDTO); + datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + ""); + datasetGroupInfoDTO.setLastUpdateTime(System.currentTimeMillis()); if (StringUtils.equalsIgnoreCase(datasetGroupInfoDTO.getNodeType(), leafType)) { if (!rename && ObjectUtils.isEmpty(datasetGroupInfoDTO.getAllFields())) { DEException.throwException(Translator.get("i18n_no_fields")); @@ -116,10 +108,8 @@ public class DatasetGroupManage { if (ObjectUtils.isEmpty(datasetGroupInfoDTO.getId())) { isCreate = true; datasetGroupInfoDTO.setId(IDUtils.snowID()); - if (userApi != null) { - datasetGroupInfoDTO.setCreateBy(userApi.info().getId() + ""); - datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + ""); - } + datasetGroupInfoDTO.setCreateBy(AuthUtils.getUser().getUserId() + ""); + datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + ""); datasetGroupInfoDTO.setCreateTime(time); datasetGroupInfoDTO.setLastUpdateTime(time); datasetGroupInfoDTO.setPid(datasetGroupInfoDTO.getPid() == null ? 0L : datasetGroupInfoDTO.getPid()); @@ -156,21 +146,19 @@ public class DatasetGroupManage { CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO); coreDatasetGroup.setLastUpdateTime(System.currentTimeMillis()); coreDatasetGroupMapper.updateById(coreDatasetGroup); - coreOptRecentManage.saveOpt(datasetGroupInfoDTO.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.UPDATE); + coreOptRecentManage.saveOpt(datasetGroupInfoDTO.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.UPDATE); } @XpackInteract(value = "authResourceTree", before = false) public void innerSave(DatasetGroupInfoDTO datasetGroupInfoDTO) { CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO); coreDatasetGroupMapper.insert(coreDatasetGroup); - coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.NEW); + coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.NEW); } @XpackInteract(value = "authResourceTree", before = false) public DatasetGroupInfoDTO move(DatasetGroupInfoDTO datasetGroupInfoDTO) { - if (userApi == null) { - checkName(datasetGroupInfoDTO); - } + checkName(datasetGroupInfoDTO); if (datasetGroupInfoDTO.getPid() != 0) { checkMove(datasetGroupInfoDTO); } @@ -178,12 +166,10 @@ public class DatasetGroupManage { long time = System.currentTimeMillis(); CoreDatasetGroup coreDatasetGroup = new CoreDatasetGroup(); BeanUtils.copyBean(coreDatasetGroup, datasetGroupInfoDTO); - if (userApi != null) { - datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + ""); - } + datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + ""); coreDatasetGroup.setLastUpdateTime(time); coreDatasetGroupMapper.updateById(coreDatasetGroup); - coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.UPDATE); + coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.UPDATE); return datasetGroupInfoDTO; } @@ -194,7 +180,7 @@ public class DatasetGroupManage { DEException.throwException("resource not exist"); } Objects.requireNonNull(CommonBeanFactory.getBean(this.getClass())).recursionDel(id); - coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.DELETE); + coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.DELETE); } public void recursionDel(Long id) { @@ -235,15 +221,13 @@ public class DatasetGroupManage { public DataSetBarVO queryBarInfo(Long id) { DataSetBarVO dataSetBarVO = coreDataSetExtMapper.queryBarInfo(id); // get creator - if (userApi != null) { - String userName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getCreateBy())); - if (StringUtils.isNotBlank(userName)) { - dataSetBarVO.setCreator(userName); - } - String updateUserName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getUpdateBy())); - if (StringUtils.isNotBlank(updateUserName)) { - dataSetBarVO.setUpdater(updateUserName); - } + String userName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getCreateBy())); + if (StringUtils.isNotBlank(userName)) { + dataSetBarVO.setCreator(userName); + } + String updateUserName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getUpdateBy())); + if (StringUtils.isNotBlank(updateUserName)) { + dataSetBarVO.setUpdater(updateUserName); } dataSetBarVO.setDatasourceDTOList(getDatasource(id)); return dataSetBarVO; @@ -258,13 +242,13 @@ public class DatasetGroupManage { QueryWrapper datasourceQueryWrapper = new QueryWrapper<>(); datasourceQueryWrapper.in("id", ids); - List datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> { + List datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> { DatasourceDTO dto = new DatasourceDTO(); BeanUtils.copyBean(dto, ele); dto.setConfiguration(null); return dto; }).collect(Collectors.toList()); - if(ids.size() != datasourceDTOList.size()){ + if (ids.size() != datasourceDTOList.size()) { DEException.throwException("由于数据集所用的数据源已被删除,无法显示数据集"); } return datasourceDTOList; @@ -370,15 +354,13 @@ public class DatasetGroupManage { DatasetGroupInfoDTO dto = new DatasetGroupInfoDTO(); BeanUtils.copyBean(dto, coreDatasetGroup); // get creator - if (userApi != null) { - UserFormVO userFormVO = userApi.queryById(Long.valueOf(dto.getCreateBy())); - if (userFormVO != null) { - dto.setCreator(userFormVO.getName()); - } - UserFormVO userFormVOUpdateBy = userApi.queryById(Long.valueOf(dto.getUpdateBy())); - if (userFormVOUpdateBy != null) { - dto.setUpdater(userFormVOUpdateBy.getName()); - } + String userName = coreUserManage.getUserName(Long.valueOf(dto.getCreateBy())); + if (StringUtils.isNotBlank(userName)) { + dto.setCreator(userName); + } + String updateUserName = coreUserManage.getUserName(Long.valueOf(dto.getUpdateBy())); + if (StringUtils.isNotBlank(updateUserName)) { + dto.setUpdater(updateUserName); } dto.setUnionSql(null); if (StringUtils.equalsIgnoreCase(dto.getNodeType(), "dataset")) { @@ -444,8 +426,8 @@ public class DatasetGroupManage { for (CoreDatasetTable datasetTable : datasetTables) { if (StringUtils.isNotEmpty(datasetTable.getSqlVariableDetails())) { List defaultsSqlVariableDetails = JsonUtil.parseList(datasetTable.getSqlVariableDetails(), listTypeReference); - if(CollectionUtil.isNotEmpty(defaultsSqlVariableDetails)){ - List fullName = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(defaultsSqlVariableDetails)) { + List fullName = new ArrayList<>(); geFullName(id, fullName); List finalFullName = CollectionUtil.reverse(fullName); defaultsSqlVariableDetails.forEach(sqlVariableDetails -> { diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java index 9b892bc21a..67762b324c 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java @@ -6,12 +6,10 @@ import io.dataease.api.dataset.dto.DatasetTableDTO; import io.dataease.api.dataset.dto.SqlVariableDetails; import io.dataease.api.dataset.union.*; import io.dataease.api.dataset.union.model.SQLObj; -import io.dataease.api.permissions.auth.api.InteractiveAuthApi; import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO; import io.dataease.commons.utils.SqlparserUtils; import io.dataease.constant.AuthEnum; import io.dataease.dataset.constant.DatasetTableType; -import io.dataease.dataset.dao.auto.mapper.CoreDatasetTableMapper; import io.dataease.dataset.dto.DatasourceSchemaDTO; import io.dataease.dataset.utils.DatasetTableTypeConstants; import io.dataease.dataset.utils.SqlUtils; @@ -24,6 +22,7 @@ import io.dataease.engine.constant.ExtFieldConstant; import io.dataease.engine.constant.SQLConstants; import io.dataease.exception.DEException; import io.dataease.i18n.Translator; +import io.dataease.system.manage.CorePermissionManage; import io.dataease.utils.BeanUtils; import io.dataease.utils.JsonUtil; import jakarta.annotation.Resource; @@ -31,7 +30,6 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -44,16 +42,14 @@ import java.util.stream.Collectors; */ @Component public class DatasetSQLManage { - @Resource - private CoreDatasetTableMapper coreDatasetTableMapper; - @Resource - private DatasetTableFieldManage datasetTableFieldManage; + @Resource private CoreDatasourceMapper coreDatasourceMapper; @Resource private EngineServer engineServer; - @Autowired(required = false) - private InteractiveAuthApi interactiveAuthApi; + + @Resource + private CorePermissionManage corePermissionManage; private static Logger logger = LoggerFactory.getLogger(DatasetSQLManage.class); @@ -328,17 +324,15 @@ public class DatasetSQLManage { private String putObj2Map(Map dsMap, DatasetTableDTO ds) throws Exception { // 通过datasource id校验数据源权限 - if (interactiveAuthApi != null) { - BusiPerCheckDTO dto = new BusiPerCheckDTO(); - dto.setId(ds.getDatasourceId()); - dto.setAuthEnum(AuthEnum.READ); - try { - interactiveAuthApi.checkAuth(dto); - } catch (Exception e) { - DEException.throwException(Translator.get("i18n_no_datasource_permission")); - } + BusiPerCheckDTO dto = new BusiPerCheckDTO(); + dto.setId(ds.getDatasourceId()); + dto.setAuthEnum(AuthEnum.READ); + boolean checked = corePermissionManage.checkAuth(dto); + if (!checked) { + DEException.throwException(Translator.get("i18n_no_datasource_permission")); } + String schemaAlias; if (StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.DB) || StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.SQL)) { CoreDatasource coreDatasource = coreDatasourceMapper.selectById(ds.getDatasourceId()); diff --git a/core/core-backend/src/main/java/io/dataease/system/manage/CorePermissionManage.java b/core/core-backend/src/main/java/io/dataease/system/manage/CorePermissionManage.java new file mode 100644 index 0000000000..e01e24a0d5 --- /dev/null +++ b/core/core-backend/src/main/java/io/dataease/system/manage/CorePermissionManage.java @@ -0,0 +1,14 @@ +package io.dataease.system.manage; + +import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO; +import io.dataease.license.config.XpackInteract; +import org.springframework.stereotype.Component; + +@Component +public class CorePermissionManage { + + @XpackInteract(value = "corePermissionManage", replace = true) + public boolean checkAuth(BusiPerCheckDTO dto) { + return true; + } +} diff --git a/de-xpack b/de-xpack index 7a4f9a2de6..91f3ae7939 160000 --- a/de-xpack +++ b/de-xpack @@ -1 +1 @@ -Subproject commit 7a4f9a2de62a8ff0b544f2660bef3838cc09d6de +Subproject commit 91f3ae793906139d6d761704b95c162de7d26a3d