|
@@ -1,13 +1,18 @@
|
|
|
package com.flow.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.flow.common.core.exception.BaseException;
|
|
|
import com.flow.common.mybatis.service.impl.BaseServiceImpl;
|
|
|
import com.flow.dao.ReportDatasourceDao;
|
|
|
import com.flow.entity.ReportDatasource;
|
|
|
+import com.flow.model.ExecSql;
|
|
|
import com.flow.service.ReportDatasourceService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Set;
|
|
|
+import javax.sql.DataSource;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -18,16 +23,36 @@ public class ReportDatasourceServiceImpl extends BaseServiceImpl<ReportDatasourc
|
|
|
|
|
|
@Override
|
|
|
public ReportDatasource create(ReportDatasource reportDatasource) {
|
|
|
- return null;
|
|
|
+ reportDatasourceDao.insert(reportDatasource);
|
|
|
+ return reportDatasource;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ReportDatasource update(ReportDatasource reportDatasource) {
|
|
|
- return null;
|
|
|
+ reportDatasourceDao.updateById(reportDatasource);
|
|
|
+ return reportDatasource;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void delete(Set<Long> ids) {
|
|
|
+ reportDatasourceDao.deleteBatchIds(ids);
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> execSql(ExecSql execSql) {
|
|
|
+ String sql = execSql.getSql();
|
|
|
+ if(StringUtils.isBlank(sql)){
|
|
|
+ throw new BaseException("sql不能为空");
|
|
|
+ }
|
|
|
+ Optional<ReportDatasource> optional = this.lambdaQuery()
|
|
|
+ .eq(ReportDatasource::getId, execSql.getDatasourceId())
|
|
|
+ .oneOpt();
|
|
|
+ if(!optional.isPresent()){
|
|
|
+ throw new BaseException("数据源不存在");
|
|
|
+ }
|
|
|
+ ReportDatasource reportDatasource = optional.get();
|
|
|
+ DataSource dataSource = reportDatasource.getDataSource();
|
|
|
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
+ return jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
}
|