From 897782c26ed2f58d3bfc7827dbaf0e1b2fa2c26a Mon Sep 17 00:00:00 2001 From: "zhantiao@tiduyun.com" Date: Thu, 10 Nov 2022 16:14:49 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96=E4=BA=86=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=88=E6=9D=83=E6=A0=91=E6=A8=A1=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataease/dto/authModel/VAuthModelDTO.java | 3 ++- .../service/authModel/VAuthModelService.java | 25 ++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/io/dataease/dto/authModel/VAuthModelDTO.java b/backend/src/main/java/io/dataease/dto/authModel/VAuthModelDTO.java index 2a0fc35736..bf4a027888 100644 --- a/backend/src/main/java/io/dataease/dto/authModel/VAuthModelDTO.java +++ b/backend/src/main/java/io/dataease/dto/authModel/VAuthModelDTO.java @@ -18,12 +18,13 @@ public class VAuthModelDTO extends VAuthModelWithBLOBs implements ITreeBase children; - private long allLeafs = 0l; + private long allLeafs = 0L; private String innerId; private Boolean isPlugin = false; + @Override public String toString(){ return this.getName(); } diff --git a/backend/src/main/java/io/dataease/service/authModel/VAuthModelService.java b/backend/src/main/java/io/dataease/service/authModel/VAuthModelService.java index 76b15bda06..62522a193a 100644 --- a/backend/src/main/java/io/dataease/service/authModel/VAuthModelService.java +++ b/backend/src/main/java/io/dataease/service/authModel/VAuthModelService.java @@ -45,13 +45,10 @@ public class VAuthModelService { return result; } if (request.getPrivileges() != null) { - result = result.stream().filter(vAuthModelDTO -> { - if (vAuthModelDTO.getNodeType().equalsIgnoreCase("spine") || (vAuthModelDTO.getNodeType().equalsIgnoreCase("leaf") && vAuthModelDTO.getPrivileges() != null && vAuthModelDTO.getPrivileges().contains(request.getPrivileges()))) { - return true; - } else { - return false; - } - }).collect(Collectors.toList()); + result = result.stream().filter(vAuthModelDTO -> "spine".equalsIgnoreCase(vAuthModelDTO.getNodeType()) + || ("leaf".equalsIgnoreCase(vAuthModelDTO.getNodeType()) + && vAuthModelDTO.getPrivileges() != null + && vAuthModelDTO.getPrivileges().contains(request.getPrivileges()))).collect(Collectors.toList()); } return result; } @@ -60,10 +57,10 @@ public class VAuthModelService { if (CollectionUtils.isEmpty(result)) { return; } - Iterator iterator = result.listIterator(); + Iterator iterator = result.listIterator(); while (iterator.hasNext()) { - VAuthModelDTO tmp = (VAuthModelDTO) iterator.next(); - if (tmp.getNodeType().equalsIgnoreCase("spine") && tmp.getAllLeafs() == 0) { + VAuthModelDTO tmp = iterator.next(); + if ("spine".equalsIgnoreCase(tmp.getNodeType()) && tmp.getAllLeafs() == 0) { iterator.remove(); } else { removeEmptyDir(tmp.getChildren()); @@ -77,9 +74,9 @@ public class VAuthModelService { vAuthModelDTO.setAllLeafs(0); continue; } - long leafs = 0l; + long leafs = 0L; for (VAuthModelDTO child : vAuthModelDTO.getChildren()) { - if (child.getNodeType().equalsIgnoreCase("leaf")) { + if ("leaf".equalsIgnoreCase(child.getNodeType())) { leafs = leafs + 1; } else { leafs = +leafs + getLeafs(child); @@ -90,13 +87,13 @@ public class VAuthModelService { } private long getLeafs(VAuthModelDTO child) { - long leafs = 0l; + long leafs = 0L; if (CollectionUtils.isEmpty(child.getChildren())) { child.setAllLeafs(0); return leafs; } for (VAuthModelDTO childChild : child.getChildren()) { - if (childChild.getNodeType().equalsIgnoreCase("leaf")) { + if ("leaf".equalsIgnoreCase(childChild.getNodeType())) { leafs = leafs + 1; } else { leafs = +leafs + getLeafs(childChild); From aaca041e0a97c141c23fa05e4469e3f07710c92b Mon Sep 17 00:00:00 2001 From: "zhantiao@tiduyun.com" Date: Thu, 10 Nov 2022 17:32:45 +0800 Subject: [PATCH 2/7] =?UTF-8?q?perf:=E4=BC=98=E5=8C=96=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AuthUserServiceImpl.java | 18 ++++++------ .../service/impl/DynamicMenuServiceImpl.java | 24 +++++++-------- .../auth/service/impl/ExtAuthServiceImpl.java | 8 +++-- .../datasource/DatasourceController.java | 24 +++++++++------ .../controller/engine/EngineController.java | 4 +-- .../controller/engine/KettleController.java | 6 ++-- .../impl/direct/DirectFieldService.java | 11 ++++--- .../service/datasource/DatasourceService.java | 29 +++++++------------ .../service/engine/EngineService.java | 9 +++--- .../service/kettle/KettleService.java | 16 ++++------ 10 files changed, 71 insertions(+), 78 deletions(-) diff --git a/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java index f5329eb743..2c9baa8080 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java @@ -181,7 +181,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public boolean supportLdap() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LdapXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; LdapXpackService ldapXpackService = SpringContextUtil.getBean(LdapXpackService.class); if (ObjectUtils.isEmpty(ldapXpackService)) return false; return ldapXpackService.isOpen(); @@ -190,7 +190,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportOidc() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((OidcXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; OidcXpackService oidcXpackService = SpringContextUtil.getBean(OidcXpackService.class); if (ObjectUtils.isEmpty(oidcXpackService)) return false; return oidcXpackService.isSupportOIDC(); @@ -199,7 +199,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportCas() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((CasXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; CasXpackService casXpackService = SpringContextUtil.getBean(CasXpackService.class); if (ObjectUtils.isEmpty(casXpackService)) return false; return casXpackService.supportCas(); @@ -208,7 +208,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportWecom() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((WecomXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; WecomXpackService wecomXpackService = SpringContextUtil.getBean(WecomXpackService.class); if (ObjectUtils.isEmpty(wecomXpackService)) return false; return wecomXpackService.isOpen(); @@ -217,7 +217,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportDingtalk() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((DingtalkXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; DingtalkXpackService dingtalkXpackService = SpringContextUtil.getBean(DingtalkXpackService.class); if (ObjectUtils.isEmpty(dingtalkXpackService)) return false; return dingtalkXpackService.isOpen(); @@ -226,7 +226,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportLark() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LarkXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class); if (ObjectUtils.isEmpty(larkXpackService)) return false; return larkXpackService.isOpen(); @@ -235,7 +235,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportLarksuite() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LarksuiteXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; LarksuiteXpackService larkXpackService = SpringContextUtil.getBean(LarksuiteXpackService.class); if (ObjectUtils.isEmpty(larkXpackService)) return false; return larkXpackService.isOpen(); @@ -244,7 +244,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportLoginLimit() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LoginLimitXpackService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; LoginLimitXpackService loginLimitXpackService = SpringContextUtil.getBean(LoginLimitXpackService.class); if (ObjectUtils.isEmpty(loginLimitXpackService)) return false; return loginLimitXpackService.isOpen(); @@ -253,7 +253,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean pluginLoaded() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((PluginCommonService.class)); - if (beansOfType.keySet().size() == 0) return false; + if (beansOfType.keySet().isEmpty()) return false; PluginCommonService pluginCommonService = SpringContextUtil.getBean(PluginCommonService.class); if (ObjectUtils.isEmpty(pluginCommonService)) return false; return pluginCommonService.isPluginLoaded(); diff --git a/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java index dc8b5e8954..19f12dc53b 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java @@ -1,12 +1,19 @@ package io.dataease.auth.service.impl; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.Resource; + import io.dataease.auth.api.dto.DynamicMenuDto; import io.dataease.auth.api.dto.MenuMeta; import io.dataease.auth.service.DynamicMenuService; -import io.dataease.plugins.common.base.domain.SysMenu; -import io.dataease.plugins.common.base.mapper.SysMenuMapper; import io.dataease.ext.ExtPluginSysMenuMapper; import io.dataease.ext.ExtSysMenuMapper; +import io.dataease.plugins.common.base.domain.SysMenu; +import io.dataease.plugins.common.base.mapper.SysMenuMapper; import io.dataease.plugins.common.dto.PluginSysMenu; import io.dataease.plugins.util.PluginUtils; import org.apache.commons.collections4.CollectionUtils; @@ -15,13 +22,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - @Service public class DynamicMenuServiceImpl implements DynamicMenuService { @@ -50,7 +50,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService { int sortIndex2 = null == s2.getMenuSort() ? 999 : s2.getMenuSort(); return sortIndex1 - sortIndex2; }).collect(Collectors.toList()); - dynamicMenuDtos.sort((s1, s2) -> s1.getHidden().compareTo(s2.getHidden())); + dynamicMenuDtos.sort(Comparator.comparing(DynamicMenuDto::getHidden)); return buildTree(dynamicMenuDtos); } @@ -91,7 +91,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService { dynamicMenuDto.setMenuSort(sysMenu.getMenuSort()); dynamicMenuDto.setHidden(sysMenu.getHidden()); dynamicMenuDto.setIsPlugin(true); - dynamicMenuDto.setNoLayout(!!sysMenu.isNoLayout()); + dynamicMenuDto.setNoLayout(sysMenu.isNoLayout()); return dynamicMenuDto; } @@ -104,7 +104,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService { lists.forEach(tNode -> { if (tNode.getPid().equals(node.getId())) { if (node.getChildren() == null) { - node.setChildren(new ArrayList()); + node.setChildren(new ArrayList<>()); node.setRedirect(node.getPath() + "/" + tNode.getPath());//第一个子节点的path } node.getChildren().add(tNode); diff --git a/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java index 2761ea7819..c55ff30b7f 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java @@ -121,6 +121,7 @@ public class ExtAuthServiceImpl implements ExtAuthService { return extAuthMapper.panelIdByDept(deptId.toString()); } + @Override @Caching(evict = { @CacheEvict(value = AuthConstants.USER_LINK_NAME, key = "'user' + #userId"), @CacheEvict(value = AuthConstants.USER_DATASET_NAME, key = "'user' + #userId"), @@ -130,6 +131,7 @@ public class ExtAuthServiceImpl implements ExtAuthService { LogUtil.info("all permission resource of user {} is cleaning...", userId); } + @Override @Caching(evict = { @CacheEvict(value = AuthConstants.DEPT_LINK_NAME, key = "'dept' + #deptId"), @CacheEvict(value = AuthConstants.DEPT_DATASET_NAME, key = "'dept' + #deptId"), @@ -139,6 +141,7 @@ public class ExtAuthServiceImpl implements ExtAuthService { LogUtil.info("all permission resource of dept {} is cleaning...", deptId); } + @Override @Caching(evict = { @CacheEvict(value = AuthConstants.ROLE_LINK_NAME, key = "'role' + #roleId"), @CacheEvict(value = AuthConstants.ROLE_DATASET_NAME, key = "'role' + #roleId"), @@ -154,14 +157,13 @@ public class ExtAuthServiceImpl implements ExtAuthService { if (StringUtils.isNotBlank(s)) { String[] split = s.split(","); List results = new ArrayList<>(); - for (int i = 0; i < split.length; i++) { - String s1 = split[i]; + for (String s1 : split) { if (StringUtils.isNotBlank(s1)) { results.add(s1); } } return CollectionUtils.isEmpty(results) ? null : results; } - return null; + return Collections.emptyList(); } } diff --git a/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java b/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java index 4de2848a3e..72cce053af 100644 --- a/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java +++ b/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java @@ -1,6 +1,13 @@ package io.dataease.controller.datasource; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.Resource; + import com.github.xiaoymin.knife4j.annotations.ApiSupport; + import io.dataease.auth.annotation.DeLog; import io.dataease.auth.annotation.DePermission; import io.dataease.commons.constants.DePermissionType; @@ -19,17 +26,16 @@ import io.dataease.plugins.common.base.domain.Datasource; import io.dataease.service.datasource.DatasourceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; -import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - @Api(tags = "数据源:数据源管理") @ApiSupport(order = 30) @RequestMapping("datasource") @@ -56,7 +62,7 @@ public class DatasourceController { @RequiresPermissions("datasource:read") @ApiOperation("数据源类型") @GetMapping("/types") - public Collection types() throws Exception { + public Collection types() { return datasourceService.types(); } @@ -84,7 +90,7 @@ public class DatasourceController { @ApiOperation("查询数据源详情") @PostMapping("/get/{id}") - public DatasourceDTO getDatasource(@PathVariable String id) throws Exception { + public DatasourceDTO getDatasource(@PathVariable String id) { return datasourceService.getDataSourceDetails(id); } diff --git a/backend/src/main/java/io/dataease/controller/engine/EngineController.java b/backend/src/main/java/io/dataease/controller/engine/EngineController.java index 02ddb5d3a3..d221f172b4 100644 --- a/backend/src/main/java/io/dataease/controller/engine/EngineController.java +++ b/backend/src/main/java/io/dataease/controller/engine/EngineController.java @@ -21,14 +21,14 @@ public class EngineController { @ApiIgnore @GetMapping("/mode") - public String runMode() throws Exception{ + public String runMode(){ return engineService.mode(); } @RequiresPermissions("sysparam:read") @ApiOperation("引擎信息") @GetMapping("/info") - public DeEngine info() throws Exception{ + public DeEngine info(){ return engineService.info(); } diff --git a/backend/src/main/java/io/dataease/controller/engine/KettleController.java b/backend/src/main/java/io/dataease/controller/engine/KettleController.java index 2f9c5f5f3c..7bbce75166 100644 --- a/backend/src/main/java/io/dataease/controller/engine/KettleController.java +++ b/backend/src/main/java/io/dataease/controller/engine/KettleController.java @@ -34,14 +34,14 @@ public class KettleController { @ApiIgnore @PostMapping("validate") - public void validate(@RequestBody KettleDTO kettleDTO) throws Exception{ + public void validate(@RequestBody KettleDTO kettleDTO) { kettleService.validate(kettleDTO); } @RequiresPermissions("sysparam:read") @ApiOperation("校验") @PostMapping("validate/{id}") - public ResultHolder validate(@PathVariable String id) throws Exception{ + public ResultHolder validate(@PathVariable String id){ return kettleService.validate(id); } @@ -56,7 +56,7 @@ public class KettleController { @RequiresPermissions("sysparam:read") @ApiOperation("删除") @DeleteMapping("delete/{id}") - public void delete(@PathVariable String id) throws Exception{ + public void delete(@PathVariable String id){ kettleService.delete(id); } } diff --git a/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java b/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java index 1d542f52b3..a1542d4fd8 100644 --- a/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java +++ b/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java @@ -80,10 +80,10 @@ public class DirectFieldService implements DataSetFieldService { public List fieldValues(List fieldIds, DeSortDTO sortDTO, Long userId, Boolean userPermissions, Boolean needMapping, Boolean rowAndColumnMgm) throws Exception { String fieldId = fieldIds.get(0); DatasetTableField field = dataSetTableFieldsService.selectByPrimaryKey(fieldId); - if (field == null || StringUtils.isEmpty(field.getTableId())) return null; + if (field == null || StringUtils.isEmpty(field.getTableId())) return Collections.emptyList(); DatasetTable datasetTable = dataSetTableService.get(field.getTableId()); - if (ObjectUtils.isEmpty(datasetTable) || StringUtils.isEmpty(datasetTable.getName())) return null; + if (ObjectUtils.isEmpty(datasetTable) || StringUtils.isEmpty(datasetTable.getName())) return Collections.emptyList(); DatasetTableField datasetTableField = DatasetTableField.builder().tableId(field.getTableId()).checked(Boolean.TRUE).build(); List fields = dataSetTableFieldsService.list(datasetTableField); @@ -174,8 +174,7 @@ public class DirectFieldService implements DataSetFieldService { LogUtil.info(datasourceRequest.getQuery()); List rows = datasourceProvider.getData(datasourceRequest); if (!needMapping) { - List results = rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList()); - return results; + return rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList()); } Set pkSet = new HashSet<>(); @@ -192,9 +191,9 @@ public class DirectFieldService implements DataSetFieldService { String text = row[i]; parentPkList.add(text); - String val = parentPkList.stream().collect(Collectors.joining(TreeUtils.SEPARATOR)); + String val = String.join(TreeUtils.SEPARATOR, parentPkList); String parentVal = i == 0 ? TreeUtils.DEFAULT_ROOT : row[i - 1]; - String pk = parentPkList.stream().collect(Collectors.joining(TreeUtils.SEPARATOR)); + String pk = String.join(TreeUtils.SEPARATOR, parentPkList); if (pkSet.contains(pk)) continue; pkSet.add(pk); BaseTreeNode node = new BaseTreeNode(val, parentVal, text, pk + TreeUtils.SEPARATOR + i); diff --git a/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java b/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java index c60c17f22a..c7ecf84871 100644 --- a/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java +++ b/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java @@ -94,11 +94,8 @@ public class DatasourceService { private ExtTaskInstanceMapper extTaskInstanceMapper; public Collection types() { - Collection types = new ArrayList<>(); - types.addAll(SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).values()); - SpringContextUtil.getApplicationContext().getBeansOfType(io.dataease.plugins.datasource.service.DatasourceService.class).values().forEach(datasourceService -> { - types.add(datasourceService.getDataSourceType()); - }); + Collection types = new ArrayList<>(SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).values()); + SpringContextUtil.getApplicationContext().getBeansOfType(io.dataease.plugins.datasource.service.DatasourceService.class).values().forEach(datasourceService -> types.add(datasourceService.getDataSourceType())); return types; } @@ -148,12 +145,10 @@ public class DatasourceService { }); } - public List getDatasourceList(DatasourceUnionRequest request) throws Exception { + public List getDatasourceList(DatasourceUnionRequest request) { request.setSort("update_time desc"); List datasourceDTOS = extDataSourceMapper.queryUnion(request); - datasourceDTOS.forEach(datasourceDTO -> { - datasourceTrans(datasourceDTO); - }); + datasourceDTOS.forEach(this::datasourceTrans); return datasourceDTOS; } @@ -434,15 +429,13 @@ public class DatasourceService { public void initAllDataSourceConnectionPool() { List datasources = datasourceMapper.selectByExampleWithBLOBs(new DatasourceExample()); - datasources.forEach(datasource -> { - commonThreadPool.addTask(() -> { - try { - handleConnectionPool(datasource, "add"); - } catch (Exception e) { - LogUtil.error("Failed to init datasource: " + datasource.getName(), e); - } - }); - }); + datasources.forEach(datasource -> commonThreadPool.addTask(() -> { + try { + handleConnectionPool(datasource, "add"); + } catch (Exception e) { + LogUtil.error("Failed to init datasource: " + datasource.getName(), e); + } + })); } public void checkName(String datasourceName, String type, String id) { diff --git a/backend/src/main/java/io/dataease/service/engine/EngineService.java b/backend/src/main/java/io/dataease/service/engine/EngineService.java index 3089f547ca..5b7cae2dd6 100644 --- a/backend/src/main/java/io/dataease/service/engine/EngineService.java +++ b/backend/src/main/java/io/dataease/service/engine/EngineService.java @@ -41,9 +41,9 @@ public class EngineService { @Resource private DatasourceService datasource; - static private List simple_engine = Arrays.asList("engine_mysql"); + private static List simple_engine = Collections.singletonList("engine_mysql"); - static private List cluster_engine = Arrays.asList("engine_doris"); + private static List cluster_engine = Collections.singletonList("engine_doris"); public Boolean isLocalMode() { return env.getProperty("engine_mode", "local").equalsIgnoreCase("local"); @@ -88,7 +88,7 @@ public class EngineService { return ResultHolder.error("Engine is invalid: " + e.getMessage()); } - if (datasource.getType().equalsIgnoreCase("engine_doris")) { + if ("engine_doris".equalsIgnoreCase(datasource.getType())) { DorisConfiguration dorisConfiguration = new Gson().fromJson(datasource.getConfiguration(), DorisConfiguration.class); HttpClientConfig httpClientConfig = new HttpClientConfig(); String authValue = "Basic " + Base64.getUrlEncoder().encodeToString((dorisConfiguration.getUsername() @@ -165,7 +165,7 @@ public class EngineService { Datasource datasource = new Datasource(); if (isLocalMode()) { - Map jsonObjectMap = new HashMap(); + Map jsonObjectMap = new HashMap<>(); jsonObjectMap.put("dataSourceType", "jdbc"); jsonObjectMap.put("dataBase", env.getProperty("doris.db", "doris")); jsonObjectMap.put("username", env.getProperty("doris.user", "root")); @@ -222,7 +222,6 @@ public class EngineService { if (!matcher.find()) { return; } - ; mysqlConfiguration.setHost(matcher.group(1)); mysqlConfiguration.setPort(Integer.valueOf(matcher.group(2))); mysqlConfiguration.setDataBase(matcher.group(3).split("\\?")[0]); diff --git a/backend/src/main/java/io/dataease/service/kettle/KettleService.java b/backend/src/main/java/io/dataease/service/kettle/KettleService.java index 523d8e5b18..288dd3e434 100644 --- a/backend/src/main/java/io/dataease/service/kettle/KettleService.java +++ b/backend/src/main/java/io/dataease/service/kettle/KettleService.java @@ -32,7 +32,7 @@ public class KettleService { @Resource private EngineService engineService; - public ResultHolder save(DeEngine kettle) throws Exception { + public ResultHolder save(DeEngine kettle) { try { validate(new Gson().fromJson(kettle.getConfiguration(), KettleDTO.class)); kettle.setStatus("Success"); @@ -54,12 +54,12 @@ public class KettleService { deEngineMapper.deleteByPrimaryKey(id); } - public void validate(KettleDTO kettleDTO) throws Exception { + public void validate(KettleDTO kettleDTO) { HttpClientConfig httpClientConfig = new HttpClientConfig(); String authValue = "Basic " + Base64.getUrlEncoder().encodeToString((kettleDTO.getUser() + ":" + kettleDTO.getPasswd()).getBytes()); httpClientConfig.addHeader("Authorization", authValue); - String response = HttpClientUtil.get("http://" + kettleDTO.getCarte() + ":" + kettleDTO.getPort() + "/kettle/status/", httpClientConfig); + HttpClientUtil.get("http://" + kettleDTO.getCarte() + ":" + kettleDTO.getPort() + "/kettle/status/", httpClientConfig); } public ResultHolder validate(String id) { @@ -87,9 +87,7 @@ public class KettleService { return; } Listkettles = pageList(); - kettles.forEach(kettle -> { - validate(kettle.getId()); - }); + kettles.forEach(kettle -> validate(kettle.getId())); } public SlaveServer getSlaveServer() throws Exception{ @@ -132,11 +130,7 @@ public class KettleService { if(engineService.isClusterMode()){ List kettles = pageList().stream().filter(kettle -> kettle.getStatus() != null && kettle.getStatus().equalsIgnoreCase("Success")) .collect(Collectors.toList()); - if(CollectionUtils.isEmpty(kettles)){ - return false; - }else { - return true; - } + return !CollectionUtils.isEmpty(kettles); } return false; } From f9460b460ad39b411f2c96ecde2633ce466f469e Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 10 Nov 2022 19:39:19 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=88=87=E6=8D=A2=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/editor/ComponentWrapper.vue | 8 +- .../canvas/components/editor/DeEditor.vue | 8 ++ .../canvas/components/editor/EditBar.vue | 23 +++- .../canvas/customComponent/UserView.vue | 4 + frontend/src/components/deDrag/index.vue | 5 + .../widget/deWidget/inputStyleMixin.js | 8 +- frontend/src/lang/en.js | 1 + frontend/src/lang/tw.js | 1 + frontend/src/lang/zh.js | 1 + frontend/src/views/chart/chart/map/map.js | 24 +++- .../views/chart/components/ChartComponent.vue | 58 +++----- .../chart/components/map/MapController.vue | 93 +++++++++++++ .../components/map/MapLayerController.vue | 126 ++++++++++++++++++ frontend/src/views/chart/view/ChartEdit.vue | 6 +- 14 files changed, 314 insertions(+), 52 deletions(-) create mode 100644 frontend/src/views/chart/components/map/MapController.vue create mode 100644 frontend/src/views/chart/components/map/MapLayerController.vue diff --git a/frontend/src/components/canvas/components/editor/ComponentWrapper.vue b/frontend/src/components/canvas/components/editor/ComponentWrapper.vue index 1750ae9ec6..ea6ad0d9da 100644 --- a/frontend/src/components/canvas/components/editor/ComponentWrapper.vue +++ b/frontend/src/components/canvas/components/editor/ComponentWrapper.vue @@ -11,6 +11,7 @@ :terminal="terminal" :element="config" :canvas-id="canvasId" + :chart="chart" :show-position="showPosition" @showViewDetails="showViewDetails" /> @@ -65,6 +66,7 @@ :screen-shot="screenShot" :canvas-style-data="canvasStyleData" :show-position="showPosition" + @fill-chart-2-parent="setChartData" /> @@ -146,7 +148,8 @@ export default { }, data() { return { - previewVisible: false + previewVisible: false, + chart: null } }, computed: { @@ -211,6 +214,9 @@ export default { runAnimation(this.$el, this.config.animations) }, methods: { + setChartData(chart) { + this.chart = chart + }, getStyle, getShapeStyleIntDeDrag(style, prop) { if (prop === 'rotate') { diff --git a/frontend/src/components/canvas/components/editor/DeEditor.vue b/frontend/src/components/canvas/components/editor/DeEditor.vue index cf74a1599e..99be1148b5 100644 --- a/frontend/src/components/canvas/components/editor/DeEditor.vue +++ b/frontend/src/components/canvas/components/editor/DeEditor.vue @@ -107,6 +107,7 @@ :canvas-style-data="canvasStyleData" @input="handleInput" @trigger-plugin-edit="pluginEditHandler" + @fill-chart-2-parent="setChartData" /> @@ -1096,6 +1097,13 @@ export default { created() { }, methods: { + setChartData(chart) { + this.componentData.forEach((item, index) => { + if (item.type === 'view' && item.component === 'user-view' && item.propValue.viewId === chart.id) { + this.$refs['deDragRef'][index].setChartData(chart) + } + }) + }, triggerResetButton() { this.triggerSearchButton(true) }, diff --git a/frontend/src/components/canvas/components/editor/EditBar.vue b/frontend/src/components/canvas/components/editor/EditBar.vue index ac4ca871e9..c3ae7549bc 100644 --- a/frontend/src/components/canvas/components/editor/EditBar.vue +++ b/frontend/src/components/canvas/components/editor/EditBar.vue @@ -94,7 +94,7 @@ > @@ -140,6 +140,11 @@ + + @@ -185,9 +190,10 @@ import toast from '@/components/canvas/utils/toast' import FieldsList from '@/components/canvas/components/editor/FieldsList' import LinkJumpSet from '@/views/panel/linkJumpSet' import Background from '@/views/background/index' +import MapLayerController from '@/views/chart/components/map/MapLayerController' export default { - components: { Background, LinkJumpSet, FieldsList, SettingMenu, LinkageField }, + components: { Background, LinkJumpSet, FieldsList, SettingMenu, LinkageField, MapLayerController }, props: { canvasId: { @@ -226,6 +232,10 @@ export default { type: String, required: false, default: 'NotProvided' + }, + chart: { + type: Object, + default: null } }, data() { @@ -249,6 +259,13 @@ export default { }, computed: { + yaxis() { + if (!this.chart) return [] + return JSON.parse(this.chart.yaxis) + }, + showMapLayerController() { + return this.curComponent.type === 'view' && this.terminal === 'pc' && this.curComponent.propValue.innerType === 'map' && this.yaxis.length > 1 + }, detailsShow() { return this.curComponent.type === 'view' && this.terminal === 'pc' && this.curComponent.propValue.innerType !== 'richTextView' }, @@ -519,7 +536,7 @@ export default { background-color: var(--primary, #3370ff); } -.bar-main i { +.bar-main ::v-deep i { color: white; float: right; margin-right: 3px; diff --git a/frontend/src/components/canvas/customComponent/UserView.vue b/frontend/src/components/canvas/customComponent/UserView.vue index fa814f692c..eb526b646d 100644 --- a/frontend/src/components/canvas/customComponent/UserView.vue +++ b/frontend/src/components/canvas/customComponent/UserView.vue @@ -518,6 +518,9 @@ export default { this.chartScale(this.changeScaleIndex) }, deep: true + }, + 'chart.yaxis': function(newVal, oldVal) { + this.$emit('fill-chart-2-parent', this.chart) } }, mounted() { @@ -691,6 +694,7 @@ export default { // 将视图传入echart组件 if (response.success) { this.chart = response.data + this.$emit('fill-chart-2-parent', this.chart) this.getDataOnly(response.data, dataBroadcast) this.chart['position'] = this.inTab ? 'tab' : 'panel' // 记录当前数据 diff --git a/frontend/src/components/deDrag/index.vue b/frontend/src/components/deDrag/index.vue index 36589b10a1..b52f2d563a 100644 --- a/frontend/src/components/deDrag/index.vue +++ b/frontend/src/components/deDrag/index.vue @@ -39,6 +39,7 @@ :active-model="'edit'" :canvas-id="canvasId" :element="element" + :chart="chart" @showViewDetails="showViewDetails" @amRemoveItem="amRemoveItem" @amAddItem="amAddItem" @@ -384,6 +385,7 @@ export default { }, data: function() { return { + chart: null, contentDisplay: true, // 当画布在tab中是 宽度左右拓展的余量 parentWidthTabOffset: 40, @@ -802,6 +804,9 @@ export default { this.beforeDestroyFunction() }, methods: { + setChartData(chart) { + this.chart = chart + }, // 重置边界和鼠标状态 resetBoundsAndMouseState() { this.mouseClickPosition = { mouseX: 0, mouseY: 0, x: 0, y: 0, w: 0, h: 0 } diff --git a/frontend/src/components/widget/deWidget/inputStyleMixin.js b/frontend/src/components/widget/deWidget/inputStyleMixin.js index 5efdbd95d4..362ba87875 100644 --- a/frontend/src/components/widget/deWidget/inputStyleMixin.js +++ b/frontend/src/components/widget/deWidget/inputStyleMixin.js @@ -58,7 +58,7 @@ export default { mounted() { if (!this.isFilterComponent) return this.typeTransform().forEach(item => { - const nodeCache = this.$refs.deOutWidget?.$refs[item].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget.$refs[item].$el + const nodeCache = this.$refs.deOutWidget?.$refs[item].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget?.$refs[item].$el this.styleAttrs.forEach(ele => { nodeCache.style[this.attrsMap[ele]] = this.element.style[ele] this[this.element.serviceName] && this[this.element.serviceName](this.selectRange(item), ele, this.element.style[ele]) @@ -70,9 +70,11 @@ export default { let nodeCache = '' this.styleAttrs.forEach(ele => { if (!nodeCache) { - nodeCache = this.$refs.deOutWidget?.$refs[type].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget.$refs[type].$el + nodeCache = this.$refs.deOutWidget?.$refs[type].$el.querySelector('.el-input__inner') || this.$refs.deOutWidget?.$refs[type].$el + } + if (nodeCache) { + nodeCache.style[this.attrsMap[ele]] = newValue[ele] } - nodeCache.style[this.attrsMap[ele]] = newValue[ele] this[this.element.serviceName] && this[this.element.serviceName](this.selectRange(type), ele, newValue[ele]) }) }, diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index ab85919e2c..1c29812fce 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -915,6 +915,7 @@ export default { password_input_error: 'Original password input error' }, chart: { + layer_controller: 'Quota switch', suspension: 'Suspension', chart_background: 'Component background', solid_color: 'Solid color', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index d62580b15b..b9cb26303c 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -915,6 +915,7 @@ export default { password_input_error: '原始密碼輸入錯誤' }, chart: { + layer_controller: '指標切換', suspension: '懸浮', chart_background: '組件背景', solid_color: '純色', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index ee387a98f6..6de5ff7443 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -914,6 +914,7 @@ export default { password_input_error: '原始密码输入错误' }, chart: { + layer_controller: '指标切换', suspension: '悬浮', chart_background: '组件背景', solid_color: '纯色', diff --git a/frontend/src/views/chart/chart/map/map.js b/frontend/src/views/chart/chart/map/map.js index bf9f18311c..2675295976 100644 --- a/frontend/src/views/chart/chart/map/map.js +++ b/frontend/src/views/chart/chart/map/map.js @@ -41,8 +41,22 @@ export function baseMapOption(chart_option, chart, themeStyle, curAreaCode) { // 处理shape attr let customAttr = {} let isGradient = false + let seriesIndex = 0 if (chart.customAttr) { customAttr = JSON.parse(chart.customAttr) + if (chart.yaxis && chart.yaxis.length > 1) { + let currentSeriesId = customAttr.currentSeriesId + const yAxis = JSON.parse(chart.yaxis) + if (!currentSeriesId || !yAxis.some(item => item.id === currentSeriesId)) { + currentSeriesId = yAxis[0].id + } + chart.data.series.forEach((item, index) => { + if (item.data[0].quotaList[0].id === currentSeriesId) { + seriesIndex = index + return false + } + }) + } if (customAttr.color) { const colorValue = customAttr.color.value @@ -57,7 +71,7 @@ export function baseMapOption(chart_option, chart, themeStyle, curAreaCode) { const tooltip = JSON.parse(JSON.stringify(customAttr.tooltip)) const reg = new RegExp('\n', 'g') const text = tooltip.formatter.replace(reg, '
') - tooltip.formatter = function(params) { + tooltip.formatter = params => { const a = params.seriesName const b = params.name const c = params.value ? params.value : '' @@ -74,14 +88,14 @@ export function baseMapOption(chart_option, chart, themeStyle, curAreaCode) { if (chart.data) { chart_option.title.text = chart.title if (chart.data.series && chart.data.series.length > 0) { - chart_option.series[0].name = chart.data.series[0].name + chart_option.series[0].name = chart.data.series[seriesIndex].name chart_option.series[0].selectedMode = true chart_option.series[0].select = BASE_ECHARTS_SELECT // label if (customAttr.label) { const text = customAttr.label.formatter chart_option.series[0].label = customAttr.label - chart_option.series[0].label.formatter = function(params) { + chart_option.series[0].label.formatter = params => { const a = params.seriesName const b = params.name const c = params.value ? params.value : '' @@ -97,12 +111,12 @@ export function baseMapOption(chart_option, chart, themeStyle, curAreaCode) { } chart_option.series[0].itemStyle.emphasis.label.show = customAttr.label.show } - const valueArr = chart.data.series[0].data + const valueArr = chart.data.series[seriesIndex].data // visualMap if (!isGradient) { if (valueArr && valueArr.length > 0) { const values = [] - valueArr.forEach(function(ele) { + valueArr.forEach(ele => { values.push(ele.value) }) chart_option.visualMap.min = Math.min(...values) diff --git a/frontend/src/views/chart/components/ChartComponent.vue b/frontend/src/views/chart/components/ChartComponent.vue index e4cfcfce24..9e7693e8b1 100644 --- a/frontend/src/views/chart/components/ChartComponent.vue +++ b/frontend/src/views/chart/components/ChartComponent.vue @@ -12,41 +12,14 @@ style="width: 100%;height: 100%;overflow: hidden;" :style="{ borderRadius: borderRadius}" /> -
-
- -
- -
- -
- -
- -
- -
+ :chart="chart" + :button-text-color="buttonTextColor" + @roam-map="roamMap" + @reset-zoom="resetZoom" + />
@@ -81,12 +54,14 @@ import { uuid } from 'vue-uuid' import { geoJson } from '@/api/map/map' import ViewTrackBar from '@/components/canvas/components/editor/ViewTrackBar' import { reverseColor } from '../chart/common/common' +import MapController from './map/MapController.vue' import { mapState } from 'vuex' - +import bus from '@/utils/bus' export default { name: 'ChartComponent', components: { - ViewTrackBar + ViewTrackBar, + MapController }, props: { chart: { @@ -178,9 +153,11 @@ export default { } }, mounted() { + bus.$on('change-series-id', this.changeSeriesId) this.preDraw() }, beforeDestroy() { + bus.$off('change-series-id', this.changeSeriesId) window.removeEventListener('resize', this.myChart.resize) this.myChart.dispose() this.myChart = null @@ -189,6 +166,15 @@ export default { this.loadThemeStyle() }, methods: { + changeSeriesId(param) { + const { id, seriesId } = param + if (id !== this.chart.id) { + return + } + const customAttr = JSON.parse(this.chart.customAttr) + customAttr.currentSeriesId = seriesId + this.chart.customAttr = JSON.stringify(customAttr) + }, reDrawView() { this.myChart.dispatchAction({ type: 'unselect', diff --git a/frontend/src/views/chart/components/map/MapController.vue b/frontend/src/views/chart/components/map/MapController.vue new file mode 100644 index 0000000000..706abe3663 --- /dev/null +++ b/frontend/src/views/chart/components/map/MapController.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/frontend/src/views/chart/components/map/MapLayerController.vue b/frontend/src/views/chart/components/map/MapLayerController.vue new file mode 100644 index 0000000000..5f33a6d5cf --- /dev/null +++ b/frontend/src/views/chart/components/map/MapLayerController.vue @@ -0,0 +1,126 @@ + + + + + diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index 07ae672ac8..4bbdea9122 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -2069,9 +2069,7 @@ export default { } }) } - if (view.type === 'map' && view.yaxis.length > 1) { - view.yaxis = [view.yaxis[0]] - } + view.yaxis.forEach(function(ele) { if (!ele.chartType) { ele.chartType = 'bar' @@ -2823,7 +2821,7 @@ export default { addYaxis(e) { this.dragCheckType(this.view.yaxis, 'q') this.dragMoveDuplicate(this.view.yaxis, e) - if ((this.view.type === 'map' || this.view.type === 'waterfall' || this.view.type === 'word-cloud' || this.view.type.includes('group')) && this.view.yaxis.length > 1) { + if ((this.view.type === 'waterfall' || this.view.type === 'word-cloud' || this.view.type.includes('group')) && this.view.yaxis.length > 1) { this.view.yaxis = [this.view.yaxis[0]] } this.calcData(true) From 0a5c9de4c4838f7051d59a8246cd75504875e6e9 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Fri, 11 Nov 2022 10:00:42 +0800 Subject: [PATCH 4/7] =?UTF-8?q?perf(=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83):?= =?UTF-8?q?=20=E6=B6=88=E6=81=AF=E7=BB=84=E4=BB=B6=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/db/migration/V44__1.17.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/src/main/resources/db/migration/V44__1.17.sql b/backend/src/main/resources/db/migration/V44__1.17.sql index 13a33cb876..213e8c73ea 100644 --- a/backend/src/main/resources/db/migration/V44__1.17.sql +++ b/backend/src/main/resources/db/migration/V44__1.17.sql @@ -4,3 +4,7 @@ ALTER TABLE `sys_log` CHANGE COLUMN `nick_name` `nick_name` VARCHAR (255) NULL COMMENT '姓名'; UPDATE `sys_menu` SET `component` = 'dataset/Form' WHERE (`menu_id` = '800'); + + +UPDATE `sys_menu` SET `component` = 'msg/All' WHERE (`component` = 'msg/all'); +UPDATE `sys_menu` SET `component` = 'msg/Setting' WHERE (`component` = 'msg/setting'); From 7c126041ed874462bd5f3fb0fda85994cfb17cc2 Mon Sep 17 00:00:00 2001 From: "zhantiao@tiduyun.com" Date: Fri, 11 Nov 2022 10:10:34 +0800 Subject: [PATCH 5/7] =?UTF-8?q?Revert=20"perf:=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BB=A3=E7=A0=81"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit aaca041e --- .../service/impl/AuthUserServiceImpl.java | 18 ++++++------ .../service/impl/DynamicMenuServiceImpl.java | 24 +++++++-------- .../auth/service/impl/ExtAuthServiceImpl.java | 8 ++--- .../datasource/DatasourceController.java | 24 ++++++--------- .../controller/engine/EngineController.java | 4 +-- .../controller/engine/KettleController.java | 6 ++-- .../impl/direct/DirectFieldService.java | 11 +++---- .../service/datasource/DatasourceService.java | 29 ++++++++++++------- .../service/engine/EngineService.java | 9 +++--- .../service/kettle/KettleService.java | 16 ++++++---- 10 files changed, 78 insertions(+), 71 deletions(-) diff --git a/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java index 2c9baa8080..f5329eb743 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/AuthUserServiceImpl.java @@ -181,7 +181,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public boolean supportLdap() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LdapXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; LdapXpackService ldapXpackService = SpringContextUtil.getBean(LdapXpackService.class); if (ObjectUtils.isEmpty(ldapXpackService)) return false; return ldapXpackService.isOpen(); @@ -190,7 +190,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportOidc() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((OidcXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; OidcXpackService oidcXpackService = SpringContextUtil.getBean(OidcXpackService.class); if (ObjectUtils.isEmpty(oidcXpackService)) return false; return oidcXpackService.isSupportOIDC(); @@ -199,7 +199,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportCas() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((CasXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; CasXpackService casXpackService = SpringContextUtil.getBean(CasXpackService.class); if (ObjectUtils.isEmpty(casXpackService)) return false; return casXpackService.supportCas(); @@ -208,7 +208,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportWecom() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((WecomXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; WecomXpackService wecomXpackService = SpringContextUtil.getBean(WecomXpackService.class); if (ObjectUtils.isEmpty(wecomXpackService)) return false; return wecomXpackService.isOpen(); @@ -217,7 +217,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportDingtalk() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((DingtalkXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; DingtalkXpackService dingtalkXpackService = SpringContextUtil.getBean(DingtalkXpackService.class); if (ObjectUtils.isEmpty(dingtalkXpackService)) return false; return dingtalkXpackService.isOpen(); @@ -226,7 +226,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportLark() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LarkXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class); if (ObjectUtils.isEmpty(larkXpackService)) return false; return larkXpackService.isOpen(); @@ -235,7 +235,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportLarksuite() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LarksuiteXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; LarksuiteXpackService larkXpackService = SpringContextUtil.getBean(LarksuiteXpackService.class); if (ObjectUtils.isEmpty(larkXpackService)) return false; return larkXpackService.isOpen(); @@ -244,7 +244,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean supportLoginLimit() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LoginLimitXpackService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; LoginLimitXpackService loginLimitXpackService = SpringContextUtil.getBean(LoginLimitXpackService.class); if (ObjectUtils.isEmpty(loginLimitXpackService)) return false; return loginLimitXpackService.isOpen(); @@ -253,7 +253,7 @@ public class AuthUserServiceImpl implements AuthUserService { @Override public Boolean pluginLoaded() { Map beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((PluginCommonService.class)); - if (beansOfType.keySet().isEmpty()) return false; + if (beansOfType.keySet().size() == 0) return false; PluginCommonService pluginCommonService = SpringContextUtil.getBean(PluginCommonService.class); if (ObjectUtils.isEmpty(pluginCommonService)) return false; return pluginCommonService.isPluginLoaded(); diff --git a/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java index 19f12dc53b..dc8b5e8954 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/DynamicMenuServiceImpl.java @@ -1,19 +1,12 @@ package io.dataease.auth.service.impl; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -import javax.annotation.Resource; - import io.dataease.auth.api.dto.DynamicMenuDto; import io.dataease.auth.api.dto.MenuMeta; import io.dataease.auth.service.DynamicMenuService; -import io.dataease.ext.ExtPluginSysMenuMapper; -import io.dataease.ext.ExtSysMenuMapper; import io.dataease.plugins.common.base.domain.SysMenu; import io.dataease.plugins.common.base.mapper.SysMenuMapper; +import io.dataease.ext.ExtPluginSysMenuMapper; +import io.dataease.ext.ExtSysMenuMapper; import io.dataease.plugins.common.dto.PluginSysMenu; import io.dataease.plugins.util.PluginUtils; import org.apache.commons.collections4.CollectionUtils; @@ -22,6 +15,13 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + @Service public class DynamicMenuServiceImpl implements DynamicMenuService { @@ -50,7 +50,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService { int sortIndex2 = null == s2.getMenuSort() ? 999 : s2.getMenuSort(); return sortIndex1 - sortIndex2; }).collect(Collectors.toList()); - dynamicMenuDtos.sort(Comparator.comparing(DynamicMenuDto::getHidden)); + dynamicMenuDtos.sort((s1, s2) -> s1.getHidden().compareTo(s2.getHidden())); return buildTree(dynamicMenuDtos); } @@ -91,7 +91,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService { dynamicMenuDto.setMenuSort(sysMenu.getMenuSort()); dynamicMenuDto.setHidden(sysMenu.getHidden()); dynamicMenuDto.setIsPlugin(true); - dynamicMenuDto.setNoLayout(sysMenu.isNoLayout()); + dynamicMenuDto.setNoLayout(!!sysMenu.isNoLayout()); return dynamicMenuDto; } @@ -104,7 +104,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService { lists.forEach(tNode -> { if (tNode.getPid().equals(node.getId())) { if (node.getChildren() == null) { - node.setChildren(new ArrayList<>()); + node.setChildren(new ArrayList()); node.setRedirect(node.getPath() + "/" + tNode.getPath());//第一个子节点的path } node.getChildren().add(tNode); diff --git a/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java index c55ff30b7f..2761ea7819 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java @@ -121,7 +121,6 @@ public class ExtAuthServiceImpl implements ExtAuthService { return extAuthMapper.panelIdByDept(deptId.toString()); } - @Override @Caching(evict = { @CacheEvict(value = AuthConstants.USER_LINK_NAME, key = "'user' + #userId"), @CacheEvict(value = AuthConstants.USER_DATASET_NAME, key = "'user' + #userId"), @@ -131,7 +130,6 @@ public class ExtAuthServiceImpl implements ExtAuthService { LogUtil.info("all permission resource of user {} is cleaning...", userId); } - @Override @Caching(evict = { @CacheEvict(value = AuthConstants.DEPT_LINK_NAME, key = "'dept' + #deptId"), @CacheEvict(value = AuthConstants.DEPT_DATASET_NAME, key = "'dept' + #deptId"), @@ -141,7 +139,6 @@ public class ExtAuthServiceImpl implements ExtAuthService { LogUtil.info("all permission resource of dept {} is cleaning...", deptId); } - @Override @Caching(evict = { @CacheEvict(value = AuthConstants.ROLE_LINK_NAME, key = "'role' + #roleId"), @CacheEvict(value = AuthConstants.ROLE_DATASET_NAME, key = "'role' + #roleId"), @@ -157,13 +154,14 @@ public class ExtAuthServiceImpl implements ExtAuthService { if (StringUtils.isNotBlank(s)) { String[] split = s.split(","); List results = new ArrayList<>(); - for (String s1 : split) { + for (int i = 0; i < split.length; i++) { + String s1 = split[i]; if (StringUtils.isNotBlank(s1)) { results.add(s1); } } return CollectionUtils.isEmpty(results) ? null : results; } - return Collections.emptyList(); + return null; } } diff --git a/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java b/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java index 72cce053af..4de2848a3e 100644 --- a/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java +++ b/backend/src/main/java/io/dataease/controller/datasource/DatasourceController.java @@ -1,13 +1,6 @@ package io.dataease.controller.datasource; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import javax.annotation.Resource; - import com.github.xiaoymin.knife4j.annotations.ApiSupport; - import io.dataease.auth.annotation.DeLog; import io.dataease.auth.annotation.DePermission; import io.dataease.commons.constants.DePermissionType; @@ -26,16 +19,17 @@ import io.dataease.plugins.common.base.domain.Datasource; import io.dataease.service.datasource.DatasourceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + @Api(tags = "数据源:数据源管理") @ApiSupport(order = 30) @RequestMapping("datasource") @@ -62,7 +56,7 @@ public class DatasourceController { @RequiresPermissions("datasource:read") @ApiOperation("数据源类型") @GetMapping("/types") - public Collection types() { + public Collection types() throws Exception { return datasourceService.types(); } @@ -90,7 +84,7 @@ public class DatasourceController { @ApiOperation("查询数据源详情") @PostMapping("/get/{id}") - public DatasourceDTO getDatasource(@PathVariable String id) { + public DatasourceDTO getDatasource(@PathVariable String id) throws Exception { return datasourceService.getDataSourceDetails(id); } diff --git a/backend/src/main/java/io/dataease/controller/engine/EngineController.java b/backend/src/main/java/io/dataease/controller/engine/EngineController.java index d221f172b4..02ddb5d3a3 100644 --- a/backend/src/main/java/io/dataease/controller/engine/EngineController.java +++ b/backend/src/main/java/io/dataease/controller/engine/EngineController.java @@ -21,14 +21,14 @@ public class EngineController { @ApiIgnore @GetMapping("/mode") - public String runMode(){ + public String runMode() throws Exception{ return engineService.mode(); } @RequiresPermissions("sysparam:read") @ApiOperation("引擎信息") @GetMapping("/info") - public DeEngine info(){ + public DeEngine info() throws Exception{ return engineService.info(); } diff --git a/backend/src/main/java/io/dataease/controller/engine/KettleController.java b/backend/src/main/java/io/dataease/controller/engine/KettleController.java index 7bbce75166..2f9c5f5f3c 100644 --- a/backend/src/main/java/io/dataease/controller/engine/KettleController.java +++ b/backend/src/main/java/io/dataease/controller/engine/KettleController.java @@ -34,14 +34,14 @@ public class KettleController { @ApiIgnore @PostMapping("validate") - public void validate(@RequestBody KettleDTO kettleDTO) { + public void validate(@RequestBody KettleDTO kettleDTO) throws Exception{ kettleService.validate(kettleDTO); } @RequiresPermissions("sysparam:read") @ApiOperation("校验") @PostMapping("validate/{id}") - public ResultHolder validate(@PathVariable String id){ + public ResultHolder validate(@PathVariable String id) throws Exception{ return kettleService.validate(id); } @@ -56,7 +56,7 @@ public class KettleController { @RequiresPermissions("sysparam:read") @ApiOperation("删除") @DeleteMapping("delete/{id}") - public void delete(@PathVariable String id){ + public void delete(@PathVariable String id) throws Exception{ kettleService.delete(id); } } diff --git a/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java b/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java index a1542d4fd8..1d542f52b3 100644 --- a/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java +++ b/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java @@ -80,10 +80,10 @@ public class DirectFieldService implements DataSetFieldService { public List fieldValues(List fieldIds, DeSortDTO sortDTO, Long userId, Boolean userPermissions, Boolean needMapping, Boolean rowAndColumnMgm) throws Exception { String fieldId = fieldIds.get(0); DatasetTableField field = dataSetTableFieldsService.selectByPrimaryKey(fieldId); - if (field == null || StringUtils.isEmpty(field.getTableId())) return Collections.emptyList(); + if (field == null || StringUtils.isEmpty(field.getTableId())) return null; DatasetTable datasetTable = dataSetTableService.get(field.getTableId()); - if (ObjectUtils.isEmpty(datasetTable) || StringUtils.isEmpty(datasetTable.getName())) return Collections.emptyList(); + if (ObjectUtils.isEmpty(datasetTable) || StringUtils.isEmpty(datasetTable.getName())) return null; DatasetTableField datasetTableField = DatasetTableField.builder().tableId(field.getTableId()).checked(Boolean.TRUE).build(); List fields = dataSetTableFieldsService.list(datasetTableField); @@ -174,7 +174,8 @@ public class DirectFieldService implements DataSetFieldService { LogUtil.info(datasourceRequest.getQuery()); List rows = datasourceProvider.getData(datasourceRequest); if (!needMapping) { - return rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList()); + List results = rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList()); + return results; } Set pkSet = new HashSet<>(); @@ -191,9 +192,9 @@ public class DirectFieldService implements DataSetFieldService { String text = row[i]; parentPkList.add(text); - String val = String.join(TreeUtils.SEPARATOR, parentPkList); + String val = parentPkList.stream().collect(Collectors.joining(TreeUtils.SEPARATOR)); String parentVal = i == 0 ? TreeUtils.DEFAULT_ROOT : row[i - 1]; - String pk = String.join(TreeUtils.SEPARATOR, parentPkList); + String pk = parentPkList.stream().collect(Collectors.joining(TreeUtils.SEPARATOR)); if (pkSet.contains(pk)) continue; pkSet.add(pk); BaseTreeNode node = new BaseTreeNode(val, parentVal, text, pk + TreeUtils.SEPARATOR + i); diff --git a/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java b/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java index c7ecf84871..c60c17f22a 100644 --- a/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java +++ b/backend/src/main/java/io/dataease/service/datasource/DatasourceService.java @@ -94,8 +94,11 @@ public class DatasourceService { private ExtTaskInstanceMapper extTaskInstanceMapper; public Collection types() { - Collection types = new ArrayList<>(SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).values()); - SpringContextUtil.getApplicationContext().getBeansOfType(io.dataease.plugins.datasource.service.DatasourceService.class).values().forEach(datasourceService -> types.add(datasourceService.getDataSourceType())); + Collection types = new ArrayList<>(); + types.addAll(SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).values()); + SpringContextUtil.getApplicationContext().getBeansOfType(io.dataease.plugins.datasource.service.DatasourceService.class).values().forEach(datasourceService -> { + types.add(datasourceService.getDataSourceType()); + }); return types; } @@ -145,10 +148,12 @@ public class DatasourceService { }); } - public List getDatasourceList(DatasourceUnionRequest request) { + public List getDatasourceList(DatasourceUnionRequest request) throws Exception { request.setSort("update_time desc"); List datasourceDTOS = extDataSourceMapper.queryUnion(request); - datasourceDTOS.forEach(this::datasourceTrans); + datasourceDTOS.forEach(datasourceDTO -> { + datasourceTrans(datasourceDTO); + }); return datasourceDTOS; } @@ -429,13 +434,15 @@ public class DatasourceService { public void initAllDataSourceConnectionPool() { List datasources = datasourceMapper.selectByExampleWithBLOBs(new DatasourceExample()); - datasources.forEach(datasource -> commonThreadPool.addTask(() -> { - try { - handleConnectionPool(datasource, "add"); - } catch (Exception e) { - LogUtil.error("Failed to init datasource: " + datasource.getName(), e); - } - })); + datasources.forEach(datasource -> { + commonThreadPool.addTask(() -> { + try { + handleConnectionPool(datasource, "add"); + } catch (Exception e) { + LogUtil.error("Failed to init datasource: " + datasource.getName(), e); + } + }); + }); } public void checkName(String datasourceName, String type, String id) { diff --git a/backend/src/main/java/io/dataease/service/engine/EngineService.java b/backend/src/main/java/io/dataease/service/engine/EngineService.java index 5b7cae2dd6..3089f547ca 100644 --- a/backend/src/main/java/io/dataease/service/engine/EngineService.java +++ b/backend/src/main/java/io/dataease/service/engine/EngineService.java @@ -41,9 +41,9 @@ public class EngineService { @Resource private DatasourceService datasource; - private static List simple_engine = Collections.singletonList("engine_mysql"); + static private List simple_engine = Arrays.asList("engine_mysql"); - private static List cluster_engine = Collections.singletonList("engine_doris"); + static private List cluster_engine = Arrays.asList("engine_doris"); public Boolean isLocalMode() { return env.getProperty("engine_mode", "local").equalsIgnoreCase("local"); @@ -88,7 +88,7 @@ public class EngineService { return ResultHolder.error("Engine is invalid: " + e.getMessage()); } - if ("engine_doris".equalsIgnoreCase(datasource.getType())) { + if (datasource.getType().equalsIgnoreCase("engine_doris")) { DorisConfiguration dorisConfiguration = new Gson().fromJson(datasource.getConfiguration(), DorisConfiguration.class); HttpClientConfig httpClientConfig = new HttpClientConfig(); String authValue = "Basic " + Base64.getUrlEncoder().encodeToString((dorisConfiguration.getUsername() @@ -165,7 +165,7 @@ public class EngineService { Datasource datasource = new Datasource(); if (isLocalMode()) { - Map jsonObjectMap = new HashMap<>(); + Map jsonObjectMap = new HashMap(); jsonObjectMap.put("dataSourceType", "jdbc"); jsonObjectMap.put("dataBase", env.getProperty("doris.db", "doris")); jsonObjectMap.put("username", env.getProperty("doris.user", "root")); @@ -222,6 +222,7 @@ public class EngineService { if (!matcher.find()) { return; } + ; mysqlConfiguration.setHost(matcher.group(1)); mysqlConfiguration.setPort(Integer.valueOf(matcher.group(2))); mysqlConfiguration.setDataBase(matcher.group(3).split("\\?")[0]); diff --git a/backend/src/main/java/io/dataease/service/kettle/KettleService.java b/backend/src/main/java/io/dataease/service/kettle/KettleService.java index 288dd3e434..523d8e5b18 100644 --- a/backend/src/main/java/io/dataease/service/kettle/KettleService.java +++ b/backend/src/main/java/io/dataease/service/kettle/KettleService.java @@ -32,7 +32,7 @@ public class KettleService { @Resource private EngineService engineService; - public ResultHolder save(DeEngine kettle) { + public ResultHolder save(DeEngine kettle) throws Exception { try { validate(new Gson().fromJson(kettle.getConfiguration(), KettleDTO.class)); kettle.setStatus("Success"); @@ -54,12 +54,12 @@ public class KettleService { deEngineMapper.deleteByPrimaryKey(id); } - public void validate(KettleDTO kettleDTO) { + public void validate(KettleDTO kettleDTO) throws Exception { HttpClientConfig httpClientConfig = new HttpClientConfig(); String authValue = "Basic " + Base64.getUrlEncoder().encodeToString((kettleDTO.getUser() + ":" + kettleDTO.getPasswd()).getBytes()); httpClientConfig.addHeader("Authorization", authValue); - HttpClientUtil.get("http://" + kettleDTO.getCarte() + ":" + kettleDTO.getPort() + "/kettle/status/", httpClientConfig); + String response = HttpClientUtil.get("http://" + kettleDTO.getCarte() + ":" + kettleDTO.getPort() + "/kettle/status/", httpClientConfig); } public ResultHolder validate(String id) { @@ -87,7 +87,9 @@ public class KettleService { return; } Listkettles = pageList(); - kettles.forEach(kettle -> validate(kettle.getId())); + kettles.forEach(kettle -> { + validate(kettle.getId()); + }); } public SlaveServer getSlaveServer() throws Exception{ @@ -130,7 +132,11 @@ public class KettleService { if(engineService.isClusterMode()){ List kettles = pageList().stream().filter(kettle -> kettle.getStatus() != null && kettle.getStatus().equalsIgnoreCase("Success")) .collect(Collectors.toList()); - return !CollectionUtils.isEmpty(kettles); + if(CollectionUtils.isEmpty(kettles)){ + return false; + }else { + return true; + } } return false; } From 9354dc92eaf234a13d34237591f6e6a356a0356b Mon Sep 17 00:00:00 2001 From: "zhantiao@tiduyun.com" Date: Fri, 11 Nov 2022 10:11:21 +0800 Subject: [PATCH 6/7] =?UTF-8?q?perf:=E6=95=B0=E6=8D=AE=E9=9B=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97=E7=9A=84=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 161 +++++++----------- 1 file changed, 65 insertions(+), 96 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index d7ddee0749..5defcafe70 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -149,7 +149,7 @@ public class DataSetTableService { @Value("${upload.file.path}") private String path; - private static Logger logger = LoggerFactory.getLogger(ClassloaderResponsity.class); + private static final Logger logger = LoggerFactory.getLogger(ClassloaderResponsity.class); @DeCleaner(value = DePermissionType.DATASET, key = "sceneId") public List batchInsert(List datasetTable) throws Exception { @@ -185,7 +185,7 @@ public class DataSetTableService { @Transactional(propagation = Propagation.NOT_SUPPORTED) @DeCleaner(value = DePermissionType.DATASET, key = "sceneId") - public List saveExcel(DataSetTableRequest datasetTable) throws Exception { + public List saveExcel(DataSetTableRequest datasetTable) { List datasetIdList = new ArrayList<>(); if (StringUtils.isEmpty(datasetTable.getId())) { @@ -234,10 +234,9 @@ public class DataSetTableService { list.add(sheetTable); DeLogUtils.save(SysLogConstants.OPERATE_TYPE.CREATE, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } - datasetIdList.forEach(datasetId -> { - commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetId, "all_scope", "初始导入", - null, datasetIdList)); - }); + datasetIdList.forEach(datasetId -> commonThreadPool.addTask(() -> + extractDataService.extractExcelData(datasetId, "all_scope", "初始导入", + null, datasetIdList))); } else { for (ExcelSheetData sheet : datasetTable.getSheets()) { String[] fieldArray = sheet.getFields().stream().map(TableField::getFieldName) @@ -269,10 +268,9 @@ public class DataSetTableService { list.add(sheetTable); DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); } - datasetIdList.forEach(datasetId -> { - commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetId, "all_scope", "初始导入", - null, datasetIdList)); - }); + datasetIdList.forEach(datasetId -> commonThreadPool.addTask(() -> + extractDataService.extractExcelData(datasetId, "all_scope", "初始导入", + null, datasetIdList))); } return list; @@ -303,15 +301,15 @@ public class DataSetTableService { DataTableInfoDTO info = new DataTableInfoDTO(); info.setExcelSheetDataList(excelSheetDataList); datasetTable.setInfo(new Gson().toJson(info)); - int update = datasetTableMapper.updateByPrimaryKeySelective(datasetTable); + // 替換時,先不刪除旧字段;同步成功后再删除 if (datasetTable.getEditType() == 0) { commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetTable.getId(), "all_scope", "替换", saveExcelTableField(datasetTable.getId(), datasetTable.getSheets().get(0).getFields(), false), - Arrays.asList(datasetTable.getId()))); + Collections.singletonList(datasetTable.getId()))); } else if (datasetTable.getEditType() == 1) { commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetTable.getId(), "add_scope", "追加", - null, Arrays.asList(datasetTable.getId()))); + null, Collections.singletonList(datasetTable.getId()))); } DeLogUtils.save(SysLogConstants.OPERATE_TYPE.MODIFY, SysLogConstants.SOURCE_TYPE.DATASET, datasetTable.getId(), datasetTable.getSceneId(), null, null); return Collections.singletonList(datasetTable); @@ -362,12 +360,12 @@ public class DataSetTableService { return datasetTable; } - public void alter(DataSetTableRequest request) throws Exception { + public void alter(DataSetTableRequest request) { checkName(request); datasetTableMapper.updateByPrimaryKeySelective(request); } - public void delete(String id) throws Exception { + public void delete(String id) { DatasetTable table = datasetTableMapper.selectByPrimaryKey(id); SysLogDTO sysLogDTO = DeLogUtils.buildLog(SysLogConstants.OPERATE_TYPE.DELETE, SysLogConstants.SOURCE_TYPE.DATASET, table.getId(), table.getSceneId(), null, null); datasetTableMapper.deleteByPrimaryKey(id); @@ -489,9 +487,8 @@ public class DataSetTableService { List res = new ArrayList<>(); Map map = new TreeMap<>(); group.forEach(ele -> map.put(ele.getId(), ele)); - Iterator> iterator = map.entrySet().iterator(); - while (iterator.hasNext()) { - res.add(iterator.next().getValue()); + for (Map.Entry stringDataSetTableDTOEntry : map.entrySet()) { + res.add(stringDataSetTableDTOEntry.getValue()); } res.sort(Comparator.comparing(DatasetTable::getName)); res.addAll(ds); @@ -521,8 +518,7 @@ public class DataSetTableService { return datasourceProvider.getTableFields(datasourceRequest); } - public Map> getFieldsFromDE(DataSetTableRequest dataSetTableRequest) - throws Exception { + public Map> getFieldsFromDE(DataSetTableRequest dataSetTableRequest) { DatasetTableField datasetTableField = DatasetTableField.builder().build(); datasetTableField.setTableId(dataSetTableRequest.getId()); datasetTableField.setChecked(Boolean.TRUE); @@ -1015,15 +1011,11 @@ public class DataSetTableService { break; case "TEXT": sqlVariableDetails = sqlVariableDetails.stream().filter(item -> item.getType().get(0).contains("TEXT")).collect(Collectors.toList()); - sqlVariableDetails.forEach(item -> { - item.setAlias(item.getVariableName()); - }); + sqlVariableDetails.forEach(item -> item.setAlias(item.getVariableName())); break; case "NUM": sqlVariableDetails = sqlVariableDetails.stream().filter(item -> item.getType().get(0).contains("LONG") || item.getType().get(0).contains("DOUBLE")).collect(Collectors.toList()); - sqlVariableDetails.forEach(item -> { - item.setAlias(item.getVariableName()); - }); + sqlVariableDetails.forEach(item -> item.setAlias(item.getVariableName())); break; } return sqlVariableDetails; @@ -1087,15 +1079,15 @@ public class DataSetTableService { if (select.getSelectBody() instanceof PlainSelect) { return handlePlainSelect((PlainSelect) select.getSelectBody(), select, dsType); } else { - String result = ""; + StringBuilder result = new StringBuilder(); SetOperationList setOperationList = (SetOperationList) select.getSelectBody(); for (int i = 0; i < setOperationList.getSelects().size(); i++) { - result = result + handlePlainSelect((PlainSelect) setOperationList.getSelects().get(i), null, dsType); + result.append(handlePlainSelect((PlainSelect) setOperationList.getSelects().get(i), null, dsType)); if (i < setOperationList.getSelects().size() - 1) { - result = result + " " + setOperationList.getOperations().get(i).toString() + " "; + result.append(" ").append(setOperationList.getOperations().get(i).toString()).append(" "); } } - return result; + return result.toString(); } } @@ -1140,14 +1132,14 @@ public class DataSetTableService { builder.append(" "); for (Iterator iter = select.getWithItemsList().iterator(); iter.hasNext(); ) { WithItem withItem = iter.next(); - builder.append(withItem.getName() + " AS ( " + removeVariables(withItem.getSubSelect().toString(), dsType) + " ) "); + builder.append(withItem.getName()).append(" AS ( ").append(removeVariables(withItem.getSubSelect().toString(), dsType)).append(" ) "); if (iter.hasNext()) { builder.append(","); } } } - builder.append(" " + plainSelect); + builder.append(" ").append(plainSelect); return builder.toString(); } @@ -1230,7 +1222,7 @@ public class DataSetTableService { String sqlAsTable = qp.createSQLPreview(sql, null); datasourceRequest.setQuery(sqlAsTable); - Map result = new HashMap<>(); + Map result; try { datasetSqlLog.setStartTime(System.currentTimeMillis()); result = datasourceProvider.fetchResultAndField(datasourceRequest); @@ -1275,7 +1267,7 @@ public class DataSetTableService { public Map getUnionPreview(DataSetTableRequest dataSetTableRequest) throws Exception { DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class); - Map sqlMap = new HashMap<>(); + Map sqlMap; DatasourceRequest datasourceRequest = new DatasourceRequest(); Datasource ds; if (dataSetTableRequest.getMode() == 0) { @@ -1289,7 +1281,6 @@ public class DataSetTableService { } String sql = (String) sqlMap.get("sql"); List fieldList = (List) sqlMap.get("field"); - List join = (List) sqlMap.get("join"); Map res = new HashMap<>(); // 处理结果 @@ -1423,9 +1414,7 @@ public class DataSetTableService { DataTableInfoCustomUnion first = dataTableInfoDTO.getList().get(0); if (CollectionUtils.isNotEmpty(list)) { StringBuilder field = new StringBuilder(); - Iterator> iterator = customInfo.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry next = iterator.next(); + for (Map.Entry next : customInfo.entrySet()) { field.append(StringUtils.join(next.getValue(), ",")).append(","); } String f = field.substring(0, field.length() - 1); @@ -1493,9 +1482,7 @@ public class DataSetTableService { String tableName = new Gson().fromJson(table.getInfo(), DataTableInfoDTO.class).getTable(); if (CollectionUtils.isNotEmpty(list)) { StringBuilder field = new StringBuilder(); - Iterator> iterator = customInfo.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry next = iterator.next(); + for (Map.Entry next : customInfo.entrySet()) { field.append(StringUtils.join(next.getValue(), ",")).append(","); } String f = field.substring(0, field.length() - 1); @@ -1601,9 +1588,7 @@ public class DataSetTableService { if (CollectionUtils.isNotEmpty(unionList)) { // field StringBuilder field = new StringBuilder(); - Iterator> iterator = checkedInfo.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry next = iterator.next(); + for (Map.Entry next : checkedInfo.entrySet()) { field.append(StringUtils.join(next.getValue(), ",")).append(","); } String f = subPrefixSuffixChar(field.toString()); @@ -1664,8 +1649,7 @@ public class DataSetTableService { // 递归计算出所有子级的checkedFields和unionParam private void getUnionSQLDorisJoin(List childrenDs, Map checkedInfo, List unionList, List checkedFields) { - for (int i = 0; i < childrenDs.size(); i++) { - UnionDTO unionDTO = childrenDs.get(i); + for (UnionDTO unionDTO : childrenDs) { String tableId = unionDTO.getCurrentDs().getId(); String table = TableUtils.tableName(tableId); DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(tableId); @@ -1752,9 +1736,7 @@ public class DataSetTableService { if (CollectionUtils.isNotEmpty(unionList)) { // field StringBuilder field = new StringBuilder(); - Iterator> iterator = checkedInfo.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry next = iterator.next(); + for (Map.Entry next : checkedInfo.entrySet()) { field.append(StringUtils.join(next.getValue(), ",")).append(","); } String f = subPrefixSuffixChar(field.toString()); @@ -1825,9 +1807,7 @@ public class DataSetTableService { // 递归计算出所有子级的checkedFields和unionParam private void getUnionSQLDatasourceJoin(List childrenDs, Map checkedInfo, List unionList, String keyword, List checkedFields) { - for (int i = 0; i < childrenDs.size(); i++) { - UnionDTO unionDTO = childrenDs.get(i); - + for (UnionDTO unionDTO : childrenDs) { DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(unionDTO.getCurrentDs().getId()); String tableId = unionDTO.getCurrentDs().getId(); if (ObjectUtils.isEmpty(datasetTable)) { @@ -1976,7 +1956,7 @@ public class DataSetTableService { Map sqlMap = getUnionSQLDoris(dataTableInfoDTO); String sql = (String) sqlMap.get("sql"); List fieldList = (List) sqlMap.get("field"); - List join = (List) sqlMap.get("join"); + // custom 创建doris视图 createDorisView(TableUtils.tableName(datasetTable.getId()), sql); @@ -2003,7 +1983,7 @@ public class DataSetTableService { Map sqlMap = getUnionSQLDatasource(dt, ds); String sql = (String) sqlMap.get("sql"); List fieldList = (List) sqlMap.get("field"); - List join = (List) sqlMap.get("join"); + datasourceRequest.setQuery(sql); fields = datasourceProvider.fetchResultField(datasourceRequest); @@ -2157,16 +2137,15 @@ public class DataSetTableService { private void checkColumes(DatasetTableIncrementalConfig datasetTableIncrementalConfig) throws Exception { DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(datasetTableIncrementalConfig.getTableId()); List datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(datasetTable.getId()) - .stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).collect(Collectors.toList()); - datasetTableFields.sort((o1, o2) -> { - if (o1.getColumnIndex() == null) { - return -1; - } - if (o2.getColumnIndex() == null) { - return 1; - } - return o1.getColumnIndex().compareTo(o2.getColumnIndex()); - }); + .stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).sorted((o1, o2) -> { + if (o1.getColumnIndex() == null) { + return -1; + } + if (o2.getColumnIndex() == null) { + return 1; + } + return o1.getColumnIndex().compareTo(o2.getColumnIndex()); + }).collect(Collectors.toList()); List originNameFields = datasetTableFields.stream().map(DatasetTableField::getOriginName) .collect(Collectors.toList()); @@ -2184,9 +2163,7 @@ public class DataSetTableService { List sqlFields = new ArrayList<>(); try { datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableField::getFieldName) - .forEach(field -> { - sqlFields.add(field); - }); + .forEach(sqlFields::add); } catch (Exception e) { DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage()); } @@ -2204,7 +2181,7 @@ public class DataSetTableService { List sqlFields = new ArrayList<>(); try { datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableField::getFieldName) - .forEach(field -> sqlFields.add(field)); + .forEach(sqlFields::add); } catch (Exception e) { DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage()); } @@ -2228,7 +2205,7 @@ public class DataSetTableService { criteria.andNameEqualTo(datasetTable.getName()); } List list = datasetTableMapper.selectByExample(datasetTableExample); - if (list.size() > 0) { + if (!list.isEmpty()) { throw new RuntimeException(Translator.get("i18n_name_cant_repeat_same_group")); } } @@ -2253,7 +2230,7 @@ public class DataSetTableService { criteria.andNameIn(new ArrayList<>(nameSet)); } List list = datasetTableMapper.selectByExample(datasetTableExample); - if (list.size() > 0) { + if (!list.isEmpty()) { throw new RuntimeException(Translator.get("i18n_name_cant_repeat_same_group")); } } @@ -2278,8 +2255,7 @@ public class DataSetTableService { if (StringUtils.isNotEmpty(tableId)) { List fields = dataSetTableFieldsService.getFieldsByTableId(tableId); - List datasetTableFields = fields.stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).collect(Collectors.toList()); - datasetTableFields.sort((o1, o2) -> { + List datasetTableFields = fields.stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).sorted((o1, o2) -> { if (o1.getColumnIndex() == null) { return -1; } @@ -2287,7 +2263,7 @@ public class DataSetTableService { return 1; } return o1.getColumnIndex().compareTo(o2.getColumnIndex()); - }); + }).collect(Collectors.toList()); List oldFields = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()); @@ -2299,7 +2275,7 @@ public class DataSetTableService { returnSheetDataList.add(excelSheetData); } } - if (returnSheetDataList.size() == 0) { + if (returnSheetDataList.isEmpty()) { DataEaseException.throwException(Translator.get("i18n_excel_column_change")); } } else { @@ -2321,22 +2297,19 @@ public class DataSetTableService { for (ExcelSheetData excelSheetData : excelSheetDataList) { List tableFields = excelSheetData.getFields(); List newFields = tableFields.stream().map(TableField::getRemarks).collect(Collectors.toList()); - if (oldFields.equals(newFields)) { - excelSheetData.setChangeFiled(false); - } else { - excelSheetData.setChangeFiled(true); - } + excelSheetData.setChangeFiled(!oldFields.equals(newFields)); boolean effectExtField = false; for (String extFieldsRefName : extFieldsRefNames) { if (!newFields.contains(extFieldsRefName)) { effectExtField = true; + break; } } excelSheetData.setEffectExtField(effectExtField); returnSheetDataList.add(excelSheetData); } - if (returnSheetDataList.size() == 0) { + if (returnSheetDataList.isEmpty()) { DataEaseException.throwException(Translator.get("i18n_excel_column_change")); } } @@ -2403,7 +2376,7 @@ public class DataSetTableService { } List> data = new ArrayList<>(); int num = 1; - String line = null; + String line; while ((line = reader.readLine()) != null) { if (num > 100) { break; @@ -2450,7 +2423,7 @@ public class DataSetTableService { try { double d = cell.getNumericCellValue(); try { - Double value = new Double(d); + Double value = d; double eps = 1e-10; if (value - Math.floor(value) < eps) { if (cellType) { @@ -2469,7 +2442,7 @@ public class DataSetTableService { return nf.format(value); } } catch (Exception e) { - BigDecimal b = new BigDecimal(d); + BigDecimal b = BigDecimal.valueOf(d); return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + ""; } } catch (IllegalStateException e) { @@ -2502,7 +2475,7 @@ public class DataSetTableService { } else { double d = cell.getNumericCellValue(); try { - Double value = new Double(d); + Double value = d; double eps = 1e-10; if (value - Math.floor(value) < eps) { if (cellType) { @@ -2521,7 +2494,7 @@ public class DataSetTableService { return nf.format(value); } } catch (Exception e) { - BigDecimal b = new BigDecimal(d); + BigDecimal b = BigDecimal.valueOf(d); return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + ""; } } @@ -2655,18 +2628,14 @@ public class DataSetTableService { * 判断数组中是否有重复的值 */ public static boolean checkIsRepeat(String[] array) { - HashSet hashSet = new HashSet(); - for (int i = 0; i < array.length; i++) { - if (StringUtils.isEmpty(array[i])) { + HashSet hashSet = new HashSet<>(); + for (String s : array) { + if (StringUtils.isEmpty(s)) { throw new RuntimeException(Translator.get("i18n_excel_empty_column")); } - hashSet.add(array[i]); - } - if (hashSet.size() == array.length) { - return false; - } else { - return true; + hashSet.add(s); } + return hashSet.size() != array.length; } public DatasetTable syncDatasetTableField(String id) throws Exception { @@ -2857,7 +2826,7 @@ public class DataSetTableService { return expressionDeParser; } - static private boolean hasVariable(String sql) { + private static boolean hasVariable(String sql) { return sql.contains(SubstitutedParams); } @@ -2936,7 +2905,7 @@ public class DataSetTableService { //设置列的宽度 detailsSheet.setColumnWidth(j, 255 * 20); } else { - if ((fields.get(j).getDeType() == DeTypeConstants.DE_INT || fields.get(j).getDeType() == DeTypeConstants.DE_FLOAT) && StringUtils.isNotEmpty(rowData.get(j))) { + if ((fields.get(j).getDeType().equals(DeTypeConstants.DE_INT) || fields.get(j).getDeType() == DeTypeConstants.DE_FLOAT) && StringUtils.isNotEmpty(rowData.get(j))) { try { cell.setCellValue(Double.valueOf(rowData.get(j))); } catch (Exception e) { From 589cf235cf0f72ce5a67de05ad752549371fad17 Mon Sep 17 00:00:00 2001 From: zhantiao <67528597+zhantiao@users.noreply.github.com> Date: Fri, 11 Nov 2022 10:33:33 +0800 Subject: [PATCH 7/7] Update DataSetTableService.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在review中,我发现我遗漏了一行代码 --- .../java/io/dataease/service/dataset/DataSetTableService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 5defcafe70..ea29c59d76 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -301,7 +301,7 @@ public class DataSetTableService { DataTableInfoDTO info = new DataTableInfoDTO(); info.setExcelSheetDataList(excelSheetDataList); datasetTable.setInfo(new Gson().toJson(info)); - + datasetTableMapper.updateByPrimaryKeySelective(datasetTable); // 替換時,先不刪除旧字段;同步成功后再删除 if (datasetTable.getEditType() == 0) { commonThreadPool.addTask(() -> extractDataService.extractExcelData(datasetTable.getId(), "all_scope", "替换",