diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java index 6bb0cdc0..859b3608 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.cache.Cache; +import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; @@ -43,6 +44,7 @@ import org.jeecg.modules.native_jni.struct.BgAnalyseResult; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.TemplateEngine; @@ -54,10 +56,12 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; +import java.sql.*; import java.text.ParseException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.Date; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -108,6 +112,10 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { @Autowired private IGardsHistogramSpectrumService histogramService; + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override public Result getDBSearchList(HttpServletRequest request, boolean AllUsers, String dbName, String[] menuTypes) { @@ -142,7 +150,58 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { result.error500("The database type does not exist"); return result; } - List sampleData = spectrumAnalysisMapper.getDBSearchList(dbName, stationTypes, userStations, AllUsers); + StringBuilder sbSql = new StringBuilder(); + sbSql.append("SELECT\n" + + " DISTINCT\n" + + " cfg_stations.station_code stationName,\n" + + " cfg_detectors.detector_code detectorsName\n" + + " FROM\n" + + " CONFIGURATION.GARDS_STATIONS cfg_stations,\n" + + " CONFIGURATION.GARDS_DETECTORS cfg_detectors,\n" + + " ORIGINAL.GARDS_SAMPLE_DATA org_samples,\n" + + " (SELECT analyses.sample_id FROM "+dbName+" analyses) analyses_sample_ids\n" + + " where\n" + + " org_samples.sample_id=analyses_sample_ids.sample_id\n" + + " AND org_samples.station_id=cfg_stations.station_id\n" + + " AND org_samples.detector_id=cfg_detectors.detector_id\n" + + " AND cfg_stations.type in ("); + for (String f : stationTypes) { + sbSql.append("'").append(f).append("',"); + } + + sbSql = new StringBuilder(sbSql.substring(0, sbSql.length()-1)); + sbSql.append(") "); + + if (userStations.size() > 0) { + sbSql.append("and org_samples.station_id in ("); + for (String f : userStations) { + sbSql.append("'").append(f).append("',"); + } + sbSql = new StringBuilder(sbSql.substring(0, sbSql.length()-1)); + sbSql.append(") "); + } + System.out.println(sbSql.toString()); + List sampleData = Lists.newArrayList(); + try (Connection connection = jdbcTemplate.getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement(sbSql.toString()); + ResultSet resultSet = statement.executeQuery()) { + ResultSetMetaData metaData = resultSet.getMetaData(); + int columnCount = metaData.getColumnCount(); + while (resultSet.next()) { + + GardsSampleDataSpectrum sp = new GardsSampleDataSpectrum(); + sp.setStationName(resultSet.getObject(1).toString()); + sp.setDetectorsName(resultSet.getObject(2).toString()); + sampleData.add(sp); + for (int i = 1; i <= columnCount; i++) { + Object value = resultSet.getObject(i); + // 处理结果集的每一列数据 + } + } + } catch (SQLException e) { + e.printStackTrace(); + } +// List sampleData = spectrumAnalysisMapper.getDBSearchList(dbName, stationTypes, userStations, AllUsers); //获取台站编码 List stationCodes = new LinkedList<>(); List detectorCodes = new LinkedList<>();