From 8b04e0d7df3da04b84334531ffe652d7aaf6b379 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Fri, 27 Oct 2023 19:08:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20BDSearchList=E6=8E=A5=E5=8F=A3=E6=94=B9?= =?UTF-8?q?=E4=B8=BAjdbc=E8=BF=9B=E8=A1=8C=E6=B5=8B=E8=AF=95=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SpectrumAnalysisServiceImpl.java | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) 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<>();