Revert "perf:优化了一些代码"

This reverts commit aaca041e
This commit is contained in:
zhantiao@tiduyun.com 2022-11-11 10:10:34 +08:00
parent 963e005043
commit 7c126041ed
10 changed files with 78 additions and 71 deletions

View File

@ -181,7 +181,7 @@ public class AuthUserServiceImpl implements AuthUserService {
@Override
public boolean supportLdap() {
Map<String, LdapXpackService> 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<String, OidcXpackService> 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<String, CasXpackService> 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<String, WecomXpackService> 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<String, DingtalkXpackService> 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<String, LarkXpackService> 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<String, LarksuiteXpackService> 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<String, LoginLimitXpackService> 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<String, PluginCommonService> 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();

View File

@ -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<DynamicMenuDto>());
node.setRedirect(node.getPath() + "/" + tNode.getPath());//第一个子节点的path
}
node.getChildren().add(tNode);

View File

@ -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<String> 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;
}
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -80,10 +80,10 @@ public class DirectFieldService implements DataSetFieldService {
public List<Object> fieldValues(List<String> 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<DatasetTableField> fields = dataSetTableFieldsService.list(datasetTableField);
@ -174,7 +174,8 @@ public class DirectFieldService implements DataSetFieldService {
LogUtil.info(datasourceRequest.getQuery());
List<String[]> rows = datasourceProvider.getData(datasourceRequest);
if (!needMapping) {
return rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList());
List<Object> results = rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList());
return results;
}
Set<String> 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);

View File

@ -94,8 +94,11 @@ public class DatasourceService {
private ExtTaskInstanceMapper extTaskInstanceMapper;
public Collection<DataSourceType> types() {
Collection<DataSourceType> 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<DataSourceType> 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<DatasourceDTO> getDatasourceList(DatasourceUnionRequest request) {
public List<DatasourceDTO> getDatasourceList(DatasourceUnionRequest request) throws Exception {
request.setSort("update_time desc");
List<DatasourceDTO> 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<Datasource> 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) {

View File

@ -41,9 +41,9 @@ public class EngineService {
@Resource
private DatasourceService datasource;
private static List<String> simple_engine = Collections.singletonList("engine_mysql");
static private List<String> simple_engine = Arrays.asList("engine_mysql");
private static List<String> cluster_engine = Collections.singletonList("engine_doris");
static private List<String> 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<String, String> 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]);

View File

@ -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;
}
List<DeEngine>kettles = 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<DeEngine> 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;
}