|
@@ -7,6 +7,7 @@ import com.flow.dao.ReportDatasourceDao;
|
|
|
import com.flow.entity.ReportDatasource;
|
|
|
import com.flow.model.ExecSql;
|
|
|
import com.flow.service.ReportDatasourceService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -14,7 +15,6 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.sql.DataSource;
|
|
|
import java.util.*;
|
|
|
|
|
|
-
|
|
|
@Service
|
|
|
public class ReportDatasourceServiceImpl extends BaseServiceImpl<ReportDatasourceDao, ReportDatasource> implements ReportDatasourceService {
|
|
|
@Autowired
|
|
@@ -44,6 +44,9 @@ public class ReportDatasourceServiceImpl extends BaseServiceImpl<ReportDatasourc
|
|
|
if(StringUtils.isBlank(sql)){
|
|
|
throw new BaseException("sql不能为空");
|
|
|
}
|
|
|
+ if(!sql.matches("^\\s*select\\s+.*\\s+from\\s+.*$")){
|
|
|
+ throw new BaseException("sql格式错误");
|
|
|
+ }
|
|
|
Optional<ReportDatasource> optional = this.lambdaQuery()
|
|
|
.eq(ReportDatasource::getId, execSql.getDatasourceId())
|
|
|
.oneOpt();
|
|
@@ -53,6 +56,6 @@ public class ReportDatasourceServiceImpl extends BaseServiceImpl<ReportDatasourc
|
|
|
ReportDatasource reportDatasource = optional.get();
|
|
|
DataSource dataSource = reportDatasource.getDataSource();
|
|
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
- return jdbcTemplate.queryForList(sql);
|
|
|
+ return jdbcTemplate.queryForList(sql,execSql.getParams());
|
|
|
}
|
|
|
}
|