/*
* <<
* Davinci
* ==
* Copyright (C) 2016 - 2019 EDP
* ==
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* >>
*
*/
package edp.davinci.service.impl;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import edp.core.exception.NotFoundException;
import edp.core.exception.ServerException;
import edp.core.exception.UnAuthorizedException;
import edp.core.model.Paginate;
import edp.core.model.PaginateWithQueryColumns;
import edp.core.utils.*;
import edp.davinci.core.common.Constants;
import edp.davinci.core.enums.*;
import edp.davinci.core.model.SqlEntity;
import edp.davinci.core.model.SqlFilter;
import edp.davinci.core.utils.SqlParseUtils;
import edp.davinci.dao.RelRoleViewMapper;
import edp.davinci.dao.SourceMapper;
import edp.davinci.dao.ViewMapper;
import edp.davinci.dao.WidgetMapper;
import edp.davinci.dto.projectDto.ProjectDetail;
import edp.davinci.dto.projectDto.ProjectPermission;
import edp.davinci.dto.sourceDto.SourceBaseInfo;
import edp.davinci.dto.viewDto.*;
import edp.davinci.model.*;
import edp.davinci.service.ProjectService;
import edp.davinci.service.ViewService;
import edp.davinci.service.excel.SQLContext;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupFile;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import static edp.core.consts.Consts.COMMA;
import static edp.core.consts.Consts.MINUS;
import static edp.davinci.core.common.Constants.NO_AUTH_PERMISSION;
import static edp.davinci.core.enums.SqlVariableTypeEnum.AUTHVAR;
import static edp.davinci.core.enums.SqlVariableTypeEnum.QUERYVAR;
@Slf4j
@Service("viewService")
public class
ViewServiceImpl extends BaseEntityService implements ViewService {
private static final Logger optLogger = LoggerFactory.getLogger(LogNameEnum.BUSINESS_OPERATION.getName());
@Autowired
private ViewMapper viewMapper;
@Autowired
private SourceMapper sourceMapper;
@Autowired
private WidgetMapper widgetMapper;
@Autowired
private RelRoleViewMapper relRoleViewMapper;
@Autowired
private SqlUtils sqlUtils;
@Autowired
private RedisUtils redisUtils;
@Autowired
private ProjectService projectService;
@Autowired
private SqlParseUtils sqlParseUtils;
private static final String SQL_VARABLE_KEY = "name";
private static final CheckEntityEnum entity = CheckEntityEnum.VIEW;
private static final ExecutorService ROLEPARAM_THREADPOOL = Executors.newFixedThreadPool(8);
@Override
public boolean isExist(String name, Long id, Long projectId) {
Long viewId = viewMapper.getByNameWithProjectId(name, projectId);
if (null != id && null != viewId) {
return !id.equals(viewId);
}
return null != viewId && viewId.longValue() > 0L;
}
/**
* 获取View列表
*
* @param projectId
* @param user
* @return
*/
@Override
public List<ViewBaseInfo> getViews(Long projectId, User user) throws NotFoundException, UnAuthorizedException, ServerException {
ProjectDetail projectDetail = null;
try {
projectDetail = projectService.getProjectDetail(projectId, user, false);
} catch (UnAuthorizedException e) {
return null;
}
List<ViewBaseInfo> views = viewMapper.getViewBaseInfoByProject(projectId);
if (null == views) {
return null;
}
if (isHiddenPermission(projectDetail, user, true)) {
return null;
}
return views;
}
private boolean isHiddenPermission(ProjectDetail projectDetail, User user, boolean basePermission) {
ProjectPermission projectPermission = projectService.getProjectPermission(projectDetail, user);
return (projectPermission.getVizPermission() == UserPermissionEnum.HIDDEN.getPermission() || basePermission)
&& projectPermission.getWidgetPermission() == UserPermissionEnum.HIDDEN.getPermission()
&& projectPermission.getViewPermission() == UserPermissionEnum.HIDDEN.getPermission();
}
@Override
public ViewWithSourceBaseInfo getView(Long id, User user) throws NotFoundException, UnAuthorizedException, ServerException {
ViewWithSourceBaseInfo view = viewMapper.getViewWithSourceBaseInfo(id);
if (null == view) {
throw new NotFoundException("View is not found");
}
ProjectDetail projectDetail = projectService.getProjectDetail(view.getProjectId(), user, false);
if (isHiddenPermission(projectDetail, user, false)) {
throw new UnAuthorizedException("Insufficient permissions");
}
List<RelRoleView> relRoleViews = relRoleViewMapper.getByView(view.getId());
view.setRoles(relRoleViews);
return view;
}
@Override
public SQLContext getSQLContext(boolean isMaintainer, ViewWithSource viewWithSource, ViewExecuteParam executeParam, User user) {
if (null == executeParam || (CollectionUtils.isEmpty(executeParam.getGroups()) && CollectionUtils.isEmpty(executeParam.getAggregators()))) {
return null;
}
Source source = viewWithSource.getSource();
if (null == source) {
throw new NotFoundException("Source is not found");
}
String sql = viewWithSource.getSql();
if (StringUtils.isEmpty(sql)) {
throw new NotFoundException("Sql is not found");
}
String sqlTempDelimiter = SqlUtils.getSqlTempDelimiter(source.getProperties());
SQLContext context = new SQLContext();
//解析变量
List<SqlVariable> variables = viewWithSource.getVariables();
//解析sql
SqlEntity sqlEntity = sqlParseUtils.parseSql(sql, variables, sqlTempDelimiter, user, isMaintainer);
//列权限(只记录被限制访问的字段)
Set<String> excludeColumns = new HashSet<>();
packageParams(isMaintainer, viewWithSource.getId(), sqlEntity, variables, executeParam.getParams(), excludeColumns, user);
String srcSql = sqlParseUtils.replaceParams(sqlEntity.getSql(), sqlEntity.getQueryParams(), sqlEntity.getAuthParams(), sqlTempDelimiter);
context.setExecuteSql(sqlParseUtils.getSqls(srcSql, Boolean.FALSE));
List<String> querySqlList = sqlParseUtils.getSqls(srcSql, Boolean.TRUE);
if (!CollectionUtils.isEmpty(querySqlList)) {
buildQuerySql(querySqlList, source, executeParam);
executeParam.addExcludeColumn(excludeColumns, source.getJdbcUrl(), source.getDbVersion());
context.setQuerySql(querySqlList);
context.setViewExecuteParam(executeParam);
}
if (!CollectionUtils.isEmpty(excludeColumns)) {
List<String> excludeList = excludeColumns.stream().collect(Collectors.toList());
context.setExcludeColumns(excludeList);
}
return context;
}
/**
* 新建View
*
没有合适的资源?快使用搜索试试~ 我知道了~
Davinci-dev-0.3.zip
共1698个文件
tsx:413个
java:413个
ts:343个
1 下载量 30 浏览量
2022-12-31
13:43:09
上传
评论
收藏 62.81MB ZIP 举报
温馨提示
Davinci面向业务人员/数据工程师/数据分析师/数据科学家,致力于提供一站式数据可视化解决方案。既可作为公有云/私有云独立使用,也可作为可视化插件集成到三方系统。用户只需在可视化UI上简单配置即可满足多种数据可视化需求,并支持高级交互/行业分析/模式探索/社交智能等可视化功能。
资源推荐
资源详情
资源评论
收起资源包目录
Davinci-dev-0.3.zip (1698个子文件)
run.bat 1KB
initdb.bat 866B
start.bat 676B
stop.bat 675B
iconfont.css 25KB
datepicker.css 4KB
antd.css 3KB
codemirror_theme.css 2KB
styles.css 2KB
react-grid.css 672B
.editorconfig 208B
iconfont.eot 28KB
application.yml.example 5KB
datasource_driver.yml.example 2KB
upgrade.exe 6.22MB
upgrade.exe 2.38MB
Gemfile 1KB
2.2.3.gif 3.07MB
1.1.gif 2.59MB
2.2.2.gif 1.92MB
1.3.gif 1.49MB
2.6.3.2.gif 1.3MB
2.2.1.2.gif 1.07MB
2.2.1.1.gif 1.05MB
2.9.1.1.gif 1003KB
2.5.4.gif 842KB
2.2.1.gif 715KB
2.2.1.gif 693KB
2.6.3.1.gif 608KB
2.9.1.gif 509KB
3.2.1.gif 437KB
1.9.gif 402KB
2.9.2.gif 269KB
2.2.1.3.gif 249KB
1.3.gif 12KB
.gitattributes 1KB
.gitattributes 82B
.gitignore 364B
.gitignore 187B
.gitignore 48B
.gitignore 19B
.gitignore 12B
.htaccess 2KB
global.html 6KB
index.html 4KB
zh_single.html 3KB
inviteOrgMemberTemplate.html 3KB
userRestPasswordEmailTemplate.html 3KB
userActivateEmailTemplate.html 3KB
inviteOrgMemberTemplate.html 3KB
zh_masthead.html 2KB
activate.html 2KB
zh_base.html 1KB
emailDefaultTemplate.html 1KB
zh_splash.html 1017B
scheduleEmailTemplate.html 985B
404.html 398B
footer.html 360B
favicon.ico 4KB
favicon.ico 4KB
ViewServiceImpl.java 40KB
SqlUtils.java 39KB
DisplaySlideServiceImpl.java 33KB
DashboardServiceImpl.java 32KB
DisplayController.java 31KB
SourceServiceImpl.java 29KB
ProjectServiceImpl.java 27KB
OrganizationServiceImpl.java 26KB
RoleServiceImpl.java 26KB
UserServiceImpl.java 23KB
DashboardController.java 23KB
SqlParseUtils.java 22KB
ShareServiceImpl.java 21KB
ExcelUtils.java 20KB
WidgetServiceImpl.java 20KB
OrganizationController.java 18KB
DisplayServiceImpl.java 18KB
RoleController.java 17KB
ProjectController.java 17KB
SourceController.java 16KB
EmailScheduleServiceImpl.java 15KB
JdbcDataSource.java 14KB
FileUtils.java 14KB
UserController.java 13KB
BaseScheduleService.java 13KB
ShareAuthAspect.java 12KB
CronJobServiceImpl.java 12KB
ViewController.java 11KB
SourcePasswordEncryptUtils.java 11KB
WorkbookWorker.java 11KB
DateUtils.java 11KB
WidgetController.java 11KB
ScreenshotUtil.java 11KB
DashboardPortalServiceImpl.java 11KB
TokenUtils.java 10KB
AbstractSheetWriter.java 10KB
CheckController.java 10KB
DownloadController.java 10KB
ShareController.java 10KB
SourceUtils.java 9KB
共 1698 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
m0_72731342
- 粉丝: 4
- 资源: 1829
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功