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