|
|
@ -45,33 +45,44 @@ public class DataSourceService { |
|
|
|
}); |
|
|
|
}); |
|
|
|
String sql = sqlVO.getSql(); |
|
|
|
String sql = sqlVO.getSql(); |
|
|
|
String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); |
|
|
|
String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); |
|
|
|
List<Map<String,String>> tempViewList = Lists.newArrayList(); |
|
|
|
for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { |
|
|
|
try { |
|
|
|
String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp"; |
|
|
|
for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { |
|
|
|
sql = sql.replace(tableAuthVO.getTableName(),tableSubStr); |
|
|
|
// 创建视图语句
|
|
|
|
|
|
|
|
String viewName = "V_TEMP_" + UUID.randomUUID().toString().replace("-", ""); |
|
|
|
|
|
|
|
String createView = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableAuthVO.getTableName() + " where " + userAuthDataSQL; |
|
|
|
|
|
|
|
this.updateOnSpecificDataSource(createView,tableAuthVO.getDatasourceName()); |
|
|
|
|
|
|
|
Map<String,String> viewMap = new HashMap(2); |
|
|
|
|
|
|
|
viewMap.put("datasource",tableAuthVO.getDatasourceName()); |
|
|
|
|
|
|
|
viewMap.put("viewName",viewName); |
|
|
|
|
|
|
|
tempViewList.add(viewMap); |
|
|
|
|
|
|
|
sql = sql.replace(tableAuthVO.getTableName(),viewName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("执行sql:{}",sql); |
|
|
|
|
|
|
|
return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch(Exception e) { |
|
|
|
|
|
|
|
log.error("An Error occurred!",e); |
|
|
|
|
|
|
|
throw new ServiceException("sql执行失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tempViewList)) { |
|
|
|
|
|
|
|
tempViewList.forEach(viewMap -> { |
|
|
|
|
|
|
|
this.updateOnSpecificDataSource("DROP VIEW IF EXISTS `" + viewMap.get("viewName")+"`;",viewMap.get("datasource")); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); |
|
|
|
|
|
|
|
// 过滤更新、删除语句
|
|
|
|
|
|
|
|
// Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> {
|
|
|
|
|
|
|
|
// throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!");
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// String sql = sqlVO.getSql();
|
|
|
|
|
|
|
|
// String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId()));
|
|
|
|
|
|
|
|
// List<Map<String,String>> tempViewList = Lists.newArrayList();
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) {
|
|
|
|
|
|
|
|
// // 创建视图语句
|
|
|
|
|
|
|
|
// String viewName = "V_TEMP_" + UUID.randomUUID().toString().replace("-", "");
|
|
|
|
|
|
|
|
// String createView = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableAuthVO.getTableName() + " where " + userAuthDataSQL;
|
|
|
|
|
|
|
|
// this.updateOnSpecificDataSource(createView,tableAuthVO.getDatasourceName());
|
|
|
|
|
|
|
|
// Map<String,String> viewMap = new HashMap(2);
|
|
|
|
|
|
|
|
// viewMap.put("datasource",tableAuthVO.getDatasourceName());
|
|
|
|
|
|
|
|
// viewMap.put("viewName",viewName);
|
|
|
|
|
|
|
|
// tempViewList.add(viewMap);
|
|
|
|
|
|
|
|
// sql = sql.replace(tableAuthVO.getTableName(),viewName);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// log.info("执行sql:{}",sql);
|
|
|
|
|
|
|
|
// return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// catch(Exception e) {
|
|
|
|
|
|
|
|
// log.error("An Error occurred!",e);
|
|
|
|
|
|
|
|
// throw new ServiceException("sql执行失败!");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// finally {
|
|
|
|
|
|
|
|
// if(CollectionUtil.isNotEmpty(tempViewList)) {
|
|
|
|
|
|
|
|
// tempViewList.forEach(viewMap -> {
|
|
|
|
|
|
|
|
// this.updateOnSpecificDataSource("DROP VIEW IF EXISTS `" + viewMap.get("viewName")+"`;",viewMap.get("datasource"));
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|