From d3e00b166073903f9dc3a2b9ddfbef6eafe2d557 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Sat, 28 Oct 2023 09:54:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E6=97=A5=E5=BF=97=E7=94=9F?= =?UTF-8?q?=E6=88=90=20=E5=8F=B0=E7=AB=99=E8=BF=90=E8=A1=8C=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=9F=A5=E7=9C=8B=E5=8F=B0=E7=AB=99=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=8E=87=E5=8F=8A=E6=9C=89=E6=95=88=E7=8E=87?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=E4=B8=BAredis=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E7=BC=93=E5=AD=98=E6=96=B9=E5=BC=8F=20?= =?UTF-8?q?=E5=8F=B0=E7=AB=99=E8=BF=90=E8=A1=8C=E7=AE=A1=E7=90=86=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=8F=B0=E7=AB=99=E6=9F=A5=E8=AF=A2=E5=8F=B0=E7=AB=99?= =?UTF-8?q?=E7=9B=91=E6=B5=8B=E6=95=B0=E6=8D=AE=E4=BF=A1=E6=81=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BAredis=E5=90=AF=E5=8A=A8=E6=97=B6=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=96=B9=E5=BC=8F=20beta=E5=8A=9F=E8=83=BD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E7=9C=8BAuto=E6=97=A5=E5=BF=97=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 40 +- .../java/org/jeecg/common/util/FTPUtil.java | 5 + .../org/jeecg/common/util/LogFileUtil.java | 25 +- .../jeecg/modules/EmailParsingActuator.java | 10 +- .../modules/FileSourceHandleManager.java | 4 +- .../jeecg/modules/UndealHandleManager.java | 2 +- .../AbstractS_D_Q_G_SpectrumHandler.java | 5 + .../spectrum/SpectrumParsingActuator.java | 78 +- .../test/controller/JeecgDemoController.java | 59 +- .../org/jeecg/common/util/PHDFileUtil.java | 1299 +++++++++++++++++ .../SpectrumAnalysesController.java | 17 +- .../mapper/xml/SpectrumAnalysisMapper.xml | 19 +- .../service/ISpectrumAnalysisService.java | 6 +- .../impl/SpectrumAnalysisServiceImpl.java | 144 +- .../jeecg/DataProvisionEfficiencyManager.java | 99 ++ .../org/jeecg/DataReceivingStatusManager.java | 242 +++ .../jeecg/common/CalculateDataRateThread.java | 20 +- .../jeecg/common/CalculateStationData.java | 169 ++- .../modules/mapper/StationMetDataMapper.java | 2 +- .../modules/mapper/StationSohDataMapper.java | 2 +- .../modules/service/ICacheTimeService.java | 3 +- .../impl/StationOperationServiceImpl.java | 383 ++--- .../impl/SysUserFocusStationServiceImpl.java | 6 +- .../system/entity/GardsDetectorsSystem.java | 18 + .../controller/GardsDetectorsController.java | 2 +- .../service/IGardsDetectorsService.java | 2 +- .../impl/GardsDetectorsServiceImpl.java | 15 +- .../JeecgStationOperationApplication.java | 9 +- 28 files changed, 2305 insertions(+), 380 deletions(-) create mode 100644 jeecg-module-station-operation/src/main/java/org/jeecg/DataProvisionEfficiencyManager.java create mode 100644 jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java create mode 100644 jeecg-module-station-operation/src/main/java/org/jeecg/modules/system/entity/GardsDetectorsSystem.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 2b716902..723f3004 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -10,8 +10,12 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.email.emuns.MailContentType; +import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.LogFileUtil; import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; import javax.mail.*; @@ -35,6 +39,7 @@ import java.util.stream.Collectors; public class EmailServiceManager { private SysEmail email; + private SpectrumPathProperties spectrumPathProperties; /** * 系统启动时间 */ @@ -65,11 +70,12 @@ public class EmailServiceManager { * 初始化邮件服务管理器 * @param email 邮件属性 */ - public void init(SysEmail email,Integer receiveNum,String temporaryStoragePath,Date systemStartupTime){ + public void init(SysEmail email,Integer receiveNum,String temporaryStoragePath,Date systemStartupTime, SpectrumPathProperties pathProperties){ this.email = email; this.receiveNum = receiveNum; this.temporaryStoragePath = temporaryStoragePath; this.systemStartupTime = systemStartupTime; + this.spectrumPathProperties = pathProperties; } /** @@ -274,14 +280,24 @@ public class EmailServiceManager { * @throws IOException */ public void getMailContent(@NotNull Part part, StringBuilder content) throws MessagingException, IOException { - if(part.isMimeType(MailContentType.PLAIN.getContentType())){ - content.append(part.getContent()); - }else if(part.isMimeType("multipart/*")){ - Multipart multipart = (Multipart) part.getContent(); - for(int i=0;i { + + public static void main(String[] args) throws IOException { + //连接ftp + //声明FTP客户端 + FTPClient ftpClient = new FTPClient(); + //连接 + ftpClient.connect("172.21.70.87", 21); + //登录 + ftpClient.login("rmsops", "cnndc66367220"); + //判断ftp是否连接成功 + if (Objects.isNull(ftpClient)){ + throw new RuntimeException("ftp connection failed!"); + } + InputStream iStream= null; + File file = null; + try { + //被动模式 + ftpClient.enterLocalPassiveMode(); + //设置文件类型--二进制文件 + ftpClient.setFileType(FTP.BINARY_FILE_TYPE); + // + ftpClient.setControlEncoding("UTF-8"); + ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); + System.out.println(ftpClient.printWorkingDirectory()); + //读取ftp文件的输入流 + iStream=ftpClient.retrieveFileStream("/savefile/Spectrum/Xenon/Sauna/Samplephd/2023/10/SEX63_007-20231026_0452_S_FULL_22495.8.PHD"); + System.out.println(Objects.isNull(iStream)); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (Objects.nonNull(iStream)){ + iStream.close(); + } + if (Objects.nonNull(file)) { + file.delete(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + + @Autowired private IJeecgDemoService jeecgDemoService; diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java index c2f3c2bb..4d328ec3 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java @@ -1029,5 +1029,1304 @@ public class PHDFileUtil { } map.put("QCBoundary", boundaryList); } + //todo---待实现的BG日志内容 +// public void OutPutRnLog(BgAnalyseResult bgAnalyseResult) { +// String logName = ""; +// BgSample sample = bgwork.GetSampleUseData(); +// BgGas gas = bgwork.GetGasUseData(); +// BgDetbgr detBgr = bgwork.GetDetbgrUseData(); +// BgAllGenerate allGenerate = bgwork.GetAllValue(); +// allGenerate.bProcessed = true; +// +// QVector logAtributeData; +// LOGFORMCREATE::AttributeContext logAtributeItem; +// +// QVector temp; +// for(int pos=0; pos s_channel = sample.s_e_c.b_e_c.channel; +// temp.clear(); +// for(int pos=0;pos s_energy = sample.s_e_c.b_e_c.energy; +// temp.clear(); +// for(int pos=0; pos s_uncertainty = sample.s_e_c.b_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos s_gchannel = sample.s_e_c.g_e_c.channel; +// temp.clear(); +// for(int pos=0;pos s_genergy = sample.s_e_c.g_e_c.energy; +// temp.clear(); +// for(int pos=0;pos s_guncertainty = sample.s_e_c.g_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos sample_gChannel = sample.s_e_c.g_e_c.channel; +// temp.clear(); +// for(int pos=0;pos sample_genergy = sample.s_e_c.g_e_c.energy; +// temp.clear(); +// for(int pos=0;pos sample_gerror = sample.s_e_c.g_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos d_bchannel = detBgr.d_e_c.b_e_c.channel; +// temp.clear(); +// for(int pos=0;pos d_benergy = detBgr.d_e_c.b_e_c.energy; +// temp.clear(); +// for(int pos=0;pos d_buncertainty = detBgr.d_e_c.b_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos deta_bChannel = detBgr.d_e_c.b_e_c.channel; +// temp.clear(); +// for(int pos=0;pos deta_benergy = detBgr.d_e_c.b_e_c.energy; +// temp.clear(); +// for(int pos=0;pos deta_berror = detBgr.d_e_c.b_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos d_gchannel = detBgr.d_e_c.g_e_c.channel; +// temp.clear(); +// for(int pos=0;pos d_genergy = detBgr.d_e_c.g_e_c.energy; +// temp.clear(); +// for(int pos=0;pos d_guncertainty = detBgr.d_e_c.g_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos deta_gChannel = detBgr.d_e_c.g_e_c.channel; +// temp.clear(); +// for( int pos=0; pos deta_genergy = detBgr.d_e_c.g_e_c.energy; +// temp.clear(); +// for(int pos=0;pos deta_gerror = detBgr.d_e_c.g_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos gas_bChannel = gas.g_e_c.b_e_c.channel; +// temp.clear(); +// for(int pos=0;pos gas_benergy = gas.g_e_c.b_e_c.energy; +// temp.clear(); +// for(int pos=0;pos gas_berror = gas.g_e_c.b_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos g_gchannel = gas.g_e_c.g_e_c.channel; +// temp.clear(); +// for(int pos=0; pos g_genergy = gas.g_e_c.g_e_c.energy; +// temp.clear(); +// for(int pos=0;pos g_guncertainty = gas.g_e_c.g_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos gas_gChannel = gas.g_e_c.g_e_c.channel; +// temp.clear(); +// for(int pos=0;pos gas_genergy = gas.g_e_c.g_e_c.energy; +// temp.clear(); +// for(int pos=0;pos gas_gerror = gas.g_e_c.g_e_c.uncertainty; +// temp.clear(); +// for(int pos=0;pos logAtributeData_roi_c; +// LOGFORMCREATE::AttributeContext logAtributeItem_roi_c; +// +// QVector report_limit_roi; +// QVector report_limit_beta; +// QVector report_limit_gama; +// +// temp.clear(); +// for(int pos=1;pos<=sample.s_limit.ROI_B_start_x1.size();pos++) +// { +// temp.append(QString::number(pos)); +// } +// +// logAtributeItem_roi_c.context.clear(); +// logAtributeItem_roi_c.atrribute= QLatin1String("ROI"); +// logAtributeItem_roi_c.unit = QLatin1String(""); +// logAtributeItem_roi_c.context = temp; +// logAtributeData_roi_c.append(logAtributeItem_roi_c); +// report_limit_roi = temp; +// temp.clear(); +// for(int pos=0;pos begin; +// QVector end; +// QVector result; +// QString flag; +// begin.clear(); +// end.clear(); +// result.clear(); +// +// begin = temp; +// temp.clear(); +// for(int pos=0;pos e_c; +// QVector c_e; +// +// //报告使用 +// QVector report_b_e_c; +// QVector report_b_c_e; +// QVector report_g_e_c; +// QVector report_g_c_e; +// QVector report_s_b_boundary; +// QVector report_s_g_boundary; +// QVector report_s_boundary_roi; +// for(int pos=0;pos e_c; +// // QVector c_e; +// e_c.clear(); +// c_e.clear(); +// +// //报告使用 +// QVector report_g_b_e_c; +// QVector report_g_b_c_e; +// +// QVector report_g_g_e_c; +// QVector report_g_g_c_e; +// +// QVector report_g_b_boundary; +// QVector report_g_g_boundary; +// QVector report_g_boundary_roi; +// +// for(int pos=0;pos report_d_b_e_c; +// QVector report_d_b_c_e; +// QVector report_d_g_e_c; +// QVector report_d_g_c_e; +// QVector report_d_b_boundary; +// QVector report_d_g_boundary; +// QVector report_d_boundary_roi; +// for(int pos=0;posallGenerate.BgOther.MDCPara.MDC_Xe131m) +// { +// NID_FLAG=1; +// } +// NID_FLAG=0; +// if(allGenerate.BgOther.XeConUncer.Xe133_con>allGenerate.BgOther.MDCPara.MDC_Xe133) +// { +// NID_FLAG=1; +// } +// NID_FLAG=0; +// if(allGenerate.BgOther.XeConUncer.Xe133m_con>allGenerate.BgOther.MDCPara.MDC_Xe133m) +// { +// NID_FLAG=1; +// } +// NID_FLAG=0; +// if(allGenerate.BgOther.XeConUncer.Xe135_con>allGenerate.BgOther.MDCPara.MDC_Xe135) +// { +// NID_FLAG=1; +// } +// +// //报告使用 +// QVector report_gross_roi; +// QVector report_gross_sample; +// QVector report_gross_gasbkgnd; +// QVector report_gross_detbkgnd; +// +// QVector ROI_ID=temp; +// logAtributeData.clear(); +// logAtributeItem.context.clear(); +// logAtributeItem.atrribute= QLatin1String("ROI"); +// logAtributeItem.unit = QLatin1String(""); +// logAtributeItem.context = ROI_ID; +// logAtributeData.append(logAtributeItem); +// +// report_gross_roi = ROI_ID; +// +// QVector LC; +// temp.clear(); +// temp.append(UNASSIGNFLAG); +// for(int pos=0;pos netTemp; +// QVector netErrTemp; +// QVector netBq; +// netTemp.append(UNASSIGNFLAG); +// netErrTemp.append(UNASSIGNFLAG); +// netBq.append(UNASSIGNFLAG); +// +// if ( allGenerate.bProcessed ) +// { +// for(int pos=6;pos concTemp; +// QVector concErrTemp; +// concTemp.append(UNASSIGNFLAG); +// concErrTemp.append(UNASSIGNFLAG); +// +// if ( allGenerate.bProcessed ) +// { +// for(int pos=4;pos dNidFlag; +// dNidFlag.append(UNASSIGNFLAG); +// temp.clear(); +// temp.append(UNASSIGNFLAG); +// for(int pos=0;pos dTemp) +// { +// dNidFlag.append(QLatin1String("1")); +// } +// else +// { +// dNidFlag.append(QLatin1String("0")); +// } +// +// } +// } +// +// QVector MDC; +// MDC=temp; +// //Net counts and Lc per ROI... +// //报告使用 +// QVector report_net_counts_roi; +// QVector report_net_counts_netcount; +// QVector report_net_counts_lc; +// logAtributeData.clear(); +// logAtributeItem.context.clear(); +// logAtributeItem.atrribute= QLatin1String("ROI"); +// logAtributeItem.unit = QLatin1String(""); +// logAtributeItem.context = ROI_ID; +// logAtributeData.append(logAtributeItem); +// report_net_counts_roi = ROI_ID; +// flag = QLatin1String(" +/- "); +// begin.clear(); +// if(netTemp.size() == netBq.size()) +// { +// for(int pos=0;pos report_concentration_roi; +// QVector report_concentration_conc; +// QVector report_concentration_lc; +// QVector report_concentration_mdc; +// logAtributeData.clear(); +// logAtributeItem.context.clear(); +// logAtributeItem.atrribute= QLatin1String("ROI"); +// logAtributeItem.unit = QLatin1String(""); +// logAtributeItem.context = ROI_ID; +// logAtributeData.append(logAtributeItem); +// report_concentration_roi= ROI_ID; +// +// flag = QLatin1String(" +/- "); +// begin.clear(); +// if(concTemp.size() == concErrTemp.size()) +// { +// for(int pos=0;pos report_result_nulclide; +// QVector report_result_conc; +// QVector report_result_uncertainty; +// QVector report_result_MDC; +// QVector report_result_NID_flag; +// +// flag = QLatin1String(" +/- "); +// QVector title_mdc; +// title_mdc< conc_mdc; +// conc_mdc< lc_isotope; +// lc_isotope< mdc_isotope; +// mdc_isotope< nidFlag; +// if(allGenerate.BgOther.XeConUncer.Xe135_con>allGenerate.BgOther.MDCPara.MDC_Xe135) +// { +// nidFlag<allGenerate.BgOther.MDCPara.MDC_Xe131m) +// { +// nidFlag<allGenerate.BgOther.MDCPara.MDC_Xe133m) +// { +// nidFlag<allGenerate.BgOther.MDCPara.MDC_Xe133) +// { +// nidFlag< - org_samples.sample_id=analyses_sample_ids.sample_id - AND org_samples.station_id=cfg_stations.station_id - AND org_samples.detector_id=cfg_detectors.detector_id - AND cfg_stations.type in + cfg_stations.type in #{stationType} @@ -52,13 +49,11 @@ CONFIGURATION.GARDS_DETECTORS a, CONFIGURATION.GARDS_STATIONS b, ORIGINAL.GARDS_SAMPLE_DATA c, - ${dbName} d, - (SELECT analyses.sample_id FROM ${dbName} analyses) analyses_sample_ids + ${dbName} d - c.sample_id = analyses_sample_ids.sample_id + c.sample_id = d.sample_id and c.detector_id = a.detector_id and c.station_id = b.station_id - and c.sample_id = d.sample_id and b.type in #{stationType} diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java index 1e08145d..6655d250 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java @@ -74,6 +74,10 @@ public interface ISpectrumAnalysisService { Result analyseAllSpectrum(List dbNames, List sampleIds, List sampleFileNames, List gasFileNames, List detFileNames, List qcFileNames, String currentFileName, HttpServletRequest request); + void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response); + + Result viewBGLogViewer(String dbName, Integer sampleId, String sampleFileName, String gasFileName, String detFileName, String qcFileName, HttpServletRequest request); + Result saveToDB(BgDataAnlyseResultIn anlyseResultIn, HttpServletRequest request); void saveToHTML(BgDataAnlyseResultIn anlyseResultIn, HttpServletResponse response); @@ -81,6 +85,4 @@ public interface ISpectrumAnalysisService { void saveToExcel(BgDataAnlyseResultIn anlyseResultIn, HttpServletResponse response); void saveToTxt(BgDataAnlyseResultIn anlyseResultIn, HttpServletResponse response); - - void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response); } 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 771e32cf..2c640bf3 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 @@ -3865,6 +3865,130 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { return result; } + @Override + public void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response) { + String logPath = spectrumAnalysisMapper.findAutomaticLogPath(sampleId); + if (StringUtils.isBlank(logPath)){ + throw new RuntimeException("自动处理程序生成日志不存在!"); + } + String pathName = StringPool.SLASH + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath.substring(0, logPath.lastIndexOf(StringPool.SLASH)); + String fileName = logPath.substring(logPath.lastIndexOf(StringPool.SLASH) + 1); + //连接ftp + FTPClient ftpClient = ftpUtil.LoginFTP(); + if (Objects.isNull(ftpClient)){ + throw new RuntimeException("ftp连接失败"); + } + InputStream inputStream = null; + ServletOutputStream outputStream = null; + try { + //切换被动模式 + ftpClient.enterLocalPassiveMode(); + ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); + // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 + ftpClient.setControlEncoding("UTF-8"); + ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); + ftpClient.changeWorkingDirectory(pathName); + inputStream = ftpClient.retrieveFileStream(fileName); + if (Objects.nonNull(inputStream)){ + outputStream = response.getOutputStream(); + byte[] buffer = new byte[1024]; + int bytesRead; + // 将文件输出流写入到输出流中 + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(ftpClient)){ + ftpClient.disconnect(); + } + if (ObjectUtil.isNotNull(inputStream)){ + inputStream.close(); + } + if (ObjectUtil.isNotNull(outputStream)){ + outputStream.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + public Result viewBGLogViewer(String dbName, Integer sampleId, String sampleFileName, String gasFileName, String detFileName, String qcFileName, HttpServletRequest request) { + Result result = new Result(); + //获取用户名 + String userName = JwtUtil.getUserNameByToken(request); + //从本地缓存获取beta gamma的数组 + Cache> cache = betaCache.getBetaCache(); + //拼接ftp上传临时文件路径 + String path = StringPool.SLASH + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + //声明一个实体类获取数据库中文件路径 + SpectrumFileRecord dbSpectrumFilePath = new SpectrumFileRecord(); + Integer analysisID = null; + String samplePath = ""; + String gasPath = ""; + String detPath = ""; + String qcPath = ""; + File sampleTmp = null; + File gasTmp = null; + File detTmp = null; + BgCalibratePara BgCalPara = null; + try { + //如果sampleId不为空 说明数据来源数据库 查询出对应的文件路径 + if (Objects.nonNull(sampleId) && StringUtils.isNotBlank(dbName)){ + if (dbName.equalsIgnoreCase("auto")){ + dbName = "RNAUTO"; + analysisID = spectrumAnalysisMapper.getAnalysisID(dbName, sampleId, "RNAUTO"); + } else if (dbName.equalsIgnoreCase("man")){ + dbName = "RNMAN"; + analysisID = spectrumAnalysisMapper.getAnalysisID(dbName, sampleId, userName); + } + dbSpectrumFilePath = spectrumAnalysisMapper.getDBSpectrumFilePath(dbName, sampleId, analysisID); + samplePath = StringPool.SLASH + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + dbSpectrumFilePath.getSampleFilePath().substring(0, dbSpectrumFilePath.getSampleFilePath().lastIndexOf(StringPool.SLASH)); + gasPath = StringPool.SLASH + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + dbSpectrumFilePath.getGasBgFilePath().substring(0, dbSpectrumFilePath.getGasBgFilePath().lastIndexOf(StringPool.SLASH)); + detPath = StringPool.SLASH + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + dbSpectrumFilePath.getDetBgFilePath().substring(0, dbSpectrumFilePath.getDetBgFilePath().lastIndexOf(StringPool.SLASH)); + GardsSampleData sampleData = spectrumAnalysisMapper.getSampleData(sampleId); + String collectStartStr = DateUtils.formatDate(sampleData.getCollectStart(), "yyyy/MM/dd HH:mm:ss"); + String dbQcFilePath = spectrumAnalysisMapper.getQCFilePath(sampleData.getSiteDetCode(), collectStartStr); + if (StringUtils.isNotBlank(dbQcFilePath)) { + qcPath=StringPool.SLASH + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + dbQcFilePath.substring(0, dbQcFilePath.lastIndexOf(StringPool.SLASH)); + } + } else if ( (Objects.isNull(sampleId) && StringUtils.isNotBlank(dbName)) || (Objects.nonNull(sampleId) && StringUtils.isBlank(dbName)) ){ + result.error500("Data load From DB need to pass in sampleId and dbName"); + return result; + } else {//如果sampleId,dbNamed都为空 就指向ftp上传文件临时路径 + samplePath = path; + gasPath = path; + detPath = path; + qcPath = path; + } + //根据文件路径 文件名称获取对应的临时文件 + sampleTmp = phdFileUtil.analyzeFile(samplePath, sampleFileName); + gasTmp = phdFileUtil.analyzeFile(gasPath, gasFileName); + detTmp = phdFileUtil.analyzeFile(detPath, detFileName); + //调用动态库解析文件 + //Gamma Energy Calibration页面 如果点击过fitting使BGammaEnergyValid并且有勾选 + //如果三个sampleData,GasData,DetData数据都是被勾选状态 则需要传递新的参数重新分析 否则不需要改变数据分析当前文件内容 + BgAnalyseResult bgAnalyseResult = null; + if (Objects.isNull(BgCalPara)) { + bgAnalyseResult = EnergySpectrumHandler.bgAnalyse(sampleTmp.getAbsolutePath(), gasTmp.getAbsolutePath(), detTmp.getAbsolutePath()); + } else { + bgAnalyseResult = EnergySpectrumHandler.bgReAnalyse(sampleTmp.getAbsolutePath(), gasTmp.getAbsolutePath(), detTmp.getAbsolutePath(), BgCalPara); + } + //拿分析的结果去生成日志内容 + + } catch (Exception e) { + + } finally { + + } + return result; + } + @Override @Transactional public Result saveToDB(BgDataAnlyseResultIn anlyseResultIn, HttpServletRequest request) { @@ -4450,26 +4574,6 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { } } - @Override - public void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response) { - try { - String path = "C:\\Users\\a\\Desktop\\demo.log"; - InputStream inputStream = new FileInputStream(new File(path)); - OutputStream outputStream = ExportUtil.stream(response, "demo.log"); - - // 缓冲区大小 - byte[] buffer = new byte[4096]; - int bytesRead; - - // 将文件输出流写入到输出流中 - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - private List calibrations(GardsCalibrationSpectrum gammaCalibrationCE,GardsCalibrationSpectrum gammaCalibrationEC, GardsCalibrationSpectrum betaCalibrationCE, GardsCalibrationSpectrum betaCalibrationEC) { int min = 79; String space = StrUtil.SPACE; diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/DataProvisionEfficiencyManager.java b/jeecg-module-station-operation/src/main/java/org/jeecg/DataProvisionEfficiencyManager.java new file mode 100644 index 00000000..28ac462e --- /dev/null +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/DataProvisionEfficiencyManager.java @@ -0,0 +1,99 @@ +package org.jeecg; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.CalculateStationData; +import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.base.entity.configuration.GardsStations; +import org.jeecg.modules.entity.data.RateParam; +import org.jeecg.modules.entity.data.StationInfo; +import org.springframework.scheduling.concurrent.CustomizableThreadFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.io.File; +import java.util.*; +import java.util.concurrent.*; +import java.util.stream.Collectors; + +@Slf4j +@Component +@RequiredArgsConstructor +public class DataProvisionEfficiencyManager { + + + private final RedisUtil redisUtil; + + private final CalculateStationData calCulateStationData; + + /** + * 开始 + */ + public void start(){ + ProvisionEfficiencyThreadManager manager = new ProvisionEfficiencyThreadManager(); + manager.init(); + manager.start(); + } + + /** + * 台站状态线程管理器 + */ + private class ProvisionEfficiencyThreadManager extends Thread{ + + private ThreadPoolExecutor poolExecutor; + + public void init(){ + //获取机器可用核心数 + int systemCores = Runtime.getRuntime().availableProcessors(); + //初始化线程池 + ThreadFactory threadFactory = new CustomizableThreadFactory("undeal-file-parsing-"); + poolExecutor = new ThreadPoolExecutor(systemCores-1,systemCores,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory); + } + + @Override + public void run() { + for(;;){ + long start = System.currentTimeMillis(); + // 获取所有的台站信息 + HashMap stationInfoMap = (HashMap) redisUtil.get("stationInfoMap"); + List detectorsUsedList = (List) redisUtil.get("detectorsUsedList"); + // 获取所有的台站信息 + List stations = stationInfoMap.values().stream().sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList()); + List stationInfos = new ArrayList<>(); + for (GardsStations gardsStations : stations) { + StationInfo stationInfo = new StationInfo(); + stationInfo.setId(gardsStations.getStationId().toString()); + stationInfo.setStationCode(gardsStations.getStationCode()); + stationInfo.setCountryCode(gardsStations.getCountryCode()); + stationInfo.setLon(gardsStations.getLon().toString()); + stationInfo.setLat(gardsStations.getLat().toString()); + stationInfo.setType(gardsStations.getType()); + stationInfo.setDescription(gardsStations.getDescription()); + stationInfo.setStatus(gardsStations.getStatus()); + boolean contains = detectorsUsedList.contains(gardsStations.getStationId()); + if (contains) { + stationInfo.setUsed("YES"); + } else { + stationInfo.setUsed("NO"); + } + stationInfos.add(stationInfo); + } + RateParam mRateParam = calCulateStationData.initParameter(); + calCulateStationData.mutiThreadGetStationInfo(stationInfos,mRateParam); + long end = System.currentTimeMillis(); + long sleepTime = 3600000 - (end-start); + //如果sleepTime > 0 需要睡眠到指定时间,否则继续下次获取邮件 + if(sleepTime > 0){ + try { + //如果本次 + TimeUnit.MILLISECONDS.sleep(sleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + +} diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java b/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java new file mode 100644 index 00000000..348e1bcc --- /dev/null +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java @@ -0,0 +1,242 @@ +package org.jeecg; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.CacheName; +import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.base.entity.configuration.GardsStations; +import org.jeecg.modules.base.entity.original.GardsMetData; +import org.jeecg.modules.base.entity.original.GardsSampleData; +import org.jeecg.modules.base.entity.original.GardsSohData; +import org.jeecg.modules.base.entity.postgre.SysUserFocusStation; +import org.jeecg.modules.entity.SysUserFocusStationStation; +import org.jeecg.modules.entity.data.*; +import org.jeecg.modules.mapper.StationMetDataMapper; +import org.jeecg.modules.mapper.StationSampleDataMapper; +import org.jeecg.modules.mapper.StationSohDataMapper; +import org.jeecg.modules.service.ICacheTimeService; +import org.jeecg.modules.system.entity.GardsDetectorsSystem; +import org.springframework.scheduling.concurrent.CustomizableThreadFactory; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +@Slf4j +@Component +@RequiredArgsConstructor +public class DataReceivingStatusManager { + + private final RedisUtil redisUtil; + + private final ICacheTimeService cacheTimeService; + + private final StationMetDataMapper stationMetDataMapper; + + private final StationSampleDataMapper stationSampleDataMapper; + + private final StationSohDataMapper stationSohDataMapper; + + public void start() { + ReceivingStatusThreadManager receivingStatusManager = new ReceivingStatusThreadManager(); + receivingStatusManager.init(); + receivingStatusManager.start(); + } + + /** + * 台站接收状态线程管理器 + */ + private class ReceivingStatusThreadManager extends Thread{ + + private ThreadPoolExecutor poolExecutor; + + public void init(){ + //获取机器可用核心数 + int systemCores = Runtime.getRuntime().availableProcessors(); + //初始化线程池 + ThreadFactory threadFactory = new CustomizableThreadFactory("undeal-file-parsing-"); + poolExecutor = new ThreadPoolExecutor(systemCores-1,systemCores,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory); + } + + @Override + public void run() { + for(;;){ + long start = System.currentTimeMillis(); + + //获取四项缓存数据的对应内容 + List> cacheList = cacheTimeService.findCacheTime(); + //缓存时间 + String cacheTime = ""; + for (int i=0; i< cacheList.size(); i++) { + if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ) { + cacheTime = cacheList.get(i).get(CacheName.cacheTime); + break; + } + } + //从redis中获取台站信息 + Map stationInfoMap = (Map)redisUtil.get("stationMap"); + List stationIds = stationInfoMap.keySet().stream().collect(Collectors.toList()); + //从redis中获取探测器信息 + Map detectorInfoMap = (Map)redisUtil.get("detectorsMap"); + //声明存储所有台站id对应的数据信息的集合 + List stationDataList = Objects.nonNull(redisUtil.get("stationDataList"))? (List) redisUtil.get("stationDataList") : new LinkedList<>(); + //遍历台站id + if (CollectionUtils.isNotEmpty(stationIds)) { + //获取当前日期时间 作为结束查询时间 + LocalDateTime endDate = LocalDateTime.now(); + //根据缓存日期 得到开始查询时间 + LocalDateTime startDate = endDate.minusDays(Integer.valueOf(cacheTime)); + String startDateTime = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + //根据台站id,开始时间查询出台站下的气象数据 + List metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime); + //根据台站id查询出当前台站下处于运行状态的数据 + Map> stationDetectors = cacheTimeService.findStationDetectors(stationIds); + //遍历台站id 获取台站下的探测器数据 + if (CollectionUtils.isNotEmpty(stationDetectors)) { + for (Integer stationId : stationIds) { + Map>> stationMap = new HashMap<>(); + //获取台站下对应的探测器数据 + List detectors = stationDetectors.get(String.valueOf(stationId)); + if (CollectionUtils.isNotEmpty(detectors)) { + StationData stationData = new StationData(); + //stream流获取探测器id + List detectorIds = detectors.stream().map(GardsDetectorsSystem::getDetectorId).collect(Collectors.toList()); + //根据探测器id 开始时间查询样品基础数据 + List sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime); + //根据台站id,探测器id,开始时间 + List sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime); + //用于接收当前台站下所有探测器及探测器所有的样品数据,气体数据,状态数据集合 + List> detectorDataList = new LinkedList<>(); + for (Integer detectorId : detectorIds) { + Map detectorMap = new HashMap<>(); + DetectorData detectorData = new DetectorData(); + detectorData.setDetectorId(detectorId); + //声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据 + List dataInfoList = new LinkedList<>(); + if (CollectionUtils.isNotEmpty(sampleDataList)) { + //根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo + List dataListSample = sampleDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(dataListSample)) { + for (GardsSampleData sampleData : dataListSample) { + DataInfoVo dataInfo = new DataInfoVo(); + //根据样品数据类型判断 数据类型 根据不同的样品数据状态 + String dataType = sampleData.getDataType(); + String spectralQualifie = sampleData.getSpectralQualifie(); + if (StrUtil.equals(dataType, "S")) { + dataInfo.setType("PHD"); + if (StrUtil.equals(spectralQualifie, "PREL")) { + dataInfo.setStatus("SPREL"); + } else if (StrUtil.equals(spectralQualifie, "FULL")) { + dataInfo.setStatus("SFULL"); + } + } else if (StrUtil.equals(dataType, "Q")) { + dataInfo.setType("QC"); + dataInfo.setStatus("QC"); + } else if (StrUtil.equals(dataType, "G")) { + dataInfo.setType("PHD"); + if (StrUtil.equals(spectralQualifie, "PREL")) { + dataInfo.setStatus("GPREL"); + } else if (StrUtil.equals(spectralQualifie, "FULL")) { + dataInfo.setStatus("GFULL"); + } + } else { + continue; + } + //处理开始时间 + Date acquisitionStart = sampleData.getAcquisitionStart(); + dataInfo.setBeginTime(Double.valueOf(acquisitionStart.getTime() / 1000)); + //处理结束时间 + Date acquisitionStop = sampleData.getAcquisitionStop(); + dataInfo.setEndTime(Double.valueOf(acquisitionStop.getTime() / 1000)); + //时间间隔 + Double span = Double.valueOf(acquisitionStop.getTime() / 1000) - Double.valueOf(acquisitionStart.getTime() / 1000); + dataInfo.setSpanTime(span); + dataInfoList.add(dataInfo); + } + } + } + if (CollectionUtils.isNotEmpty(sohDataList)) { + List dataListSoh = sohDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); + //根据探测器id 台站id 开始时间查询状态数据 + if (CollectionUtils.isNotEmpty(dataListSoh)) { + for (GardsSohData sohData : dataListSoh) { + DataInfoVo dataInfo = new DataInfoVo(); + dataInfo.setType("SOH"); + dataInfo.setStatus("SOH"); + Date startTime = sohData.getStartTime(); + dataInfo.setBeginTime(Double.valueOf(startTime.getTime() / 1000)); + dataInfo.setSpanTime(Double.valueOf(sohData.getTime())); + dataInfoList.add(dataInfo); + } + } + } + if (CollectionUtils.isNotEmpty(metDataList)) { + List dataListMet = metDataList.stream().filter(item -> item.getStationId().equals(stationId)).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(dataListMet)) { + for (GardsMetData metData : dataListMet) { + DataInfoVo dataInfo = new DataInfoVo(); + dataInfo.setType("MET"); + dataInfo.setStatus("MET"); + Date startTime = metData.getStartTime(); + dataInfo.setBeginTime(Double.valueOf(startTime.getTime() / 1000)); + Date endTime = metData.getEndTime(); + dataInfo.setEndTime(Double.valueOf(endTime.getTime() / 1000)); + Double span = Double.valueOf(startTime.getTime() / 1000) - Double.valueOf(endTime.getTime() / 1000); + dataInfo.setSpanTime(span); + dataInfoList.add(dataInfo); + } + } + } + detectorData.setDataList(dataInfoList); + if (CollectionUtils.isNotEmpty(detectorInfoMap)) { + if (StringUtils.isNotBlank(detectorInfoMap.get(detectorId.toString()))) { + detectorData.setDetectorCode(detectorInfoMap.get(detectorId.toString())); + } + } + detectorMap.put(String.valueOf(detectorId), detectorData); + detectorDataList.add(detectorMap); + } + + stationMap.put(String.valueOf(stationId), detectorDataList); + stationData.setStationId(String.valueOf(stationId)); + if (CollectionUtils.isNotEmpty(stationInfoMap)) { + if (StringUtils.isNotBlank(stationInfoMap.get(stationId))) { + stationData.setStationCode(stationInfoMap.get(stationId)); + } + } + stationData.setDetectors(stationMap); + stationDataList.add(stationData); + redisUtil.set("stationDataList", stationDataList); + } + } + } + } + + long end = System.currentTimeMillis(); + long sleepTime = 3600000 - (end-start); + //如果sleepTime > 0 需要睡眠到指定时间,否则继续下次获取邮件 + if(sleepTime > 0){ + try { + //如果本次 + TimeUnit.MILLISECONDS.sleep(sleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + + +} diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java index e831dd38..ef44aed5 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java @@ -2,9 +2,11 @@ package org.jeecg.common; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.entity.data.*; import org.jeecg.modules.service.ICalCulStationDataService; import org.jeecgframework.core.util.ApplicationContextUtil; +import org.springframework.beans.BeanUtils; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -18,13 +20,15 @@ public class CalculateDataRateThread implements Runnable{ private ICalCulStationDataService calCulStationDataService = ApplicationContextUtil.getContext().getBean(ICalCulStationDataService.class); + private RedisUtil redisUtil = ApplicationContextUtil.getContext().getBean(RedisUtil.class); + private final GetStationinfoAndDataRate stationinfoAndDataRate; - private final List finallySta; + private final Map finallySta; private CountDownLatch countDownLatch; - CalculateDataRateThread(List finallySta, GetStationinfoAndDataRate stationinfoAndDataRate, CountDownLatch countDownLatch) { + CalculateDataRateThread(Map finallySta, GetStationinfoAndDataRate stationinfoAndDataRate, CountDownLatch countDownLatch) { this.stationinfoAndDataRate = stationinfoAndDataRate; this.finallySta = finallySta; this.countDownLatch = countDownLatch; @@ -32,11 +36,14 @@ public class CalculateDataRateThread implements Runnable{ @Override public void run() { + long start = System.currentTimeMillis(); try { this.calCulStationInfo(); }catch (Exception e){ e.printStackTrace(); } finally { + long end = System.currentTimeMillis(); + System.out.println("单线程时长:"+(end-start)); // CountDownLatch 计数器减 1 countDownLatch.countDown(); } @@ -60,8 +67,10 @@ public class CalculateDataRateThread implements Runnable{ CalculateDataRate calculateDataRate = new CalculateDataRate(); calculateDataRate.setParameter(mRateparam); //根据台站编码 查询 台站信息 - StationInfo stationInfo = calCulStationDataService.getStationInfo(originalstationsinfo.getStationCode()); - stationInfo.setUsed(calCulStationDataService.getUsed(Integer.valueOf(stationInfo.getId()))); +// StationInfo stationInfo = calCulStationDataService.getStationInfo(originalstationsinfo.getStationCode()); + StationInfo stationInfo = new StationInfo(); + BeanUtils.copyProperties(originalstationsinfo, stationInfo); +// stationInfo.setUsed(calCulStationDataService.getUsed(Integer.valueOf(stationInfo.getId()))); //赋值台站信息 calculateDataRate.setMStationId(stationInfo.getId()); calculateDataRate.setMStationCode(stationInfo.getStationCode()); @@ -81,7 +90,8 @@ public class CalculateDataRateThread implements Runnable{ stationInfo.setQuality("bad"); } //赋值最后的结果 - finallySta.add(stationInfo); + finallySta.put(stationInfo.getStationCode(), stationInfo); + redisUtil.set("dataStationInfoList", finallySta); } } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java index 9903f738..4104f4b0 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java @@ -2,9 +2,10 @@ package org.jeecg.common; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.properties.ParameterProperties; +import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.entity.data.*; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.w3c.dom.*; import org.xml.sax.SAXException; @@ -15,10 +16,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.util.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; @Slf4j @Component @@ -26,6 +24,8 @@ public class CalculateStationData { @Autowired private ParameterProperties parameterProperties; + @Autowired + private RedisUtil redisUtil; /** * 初始化配置信息 @@ -813,37 +813,50 @@ public class CalculateStationData { * 多线程获取台站数据的提供率和有效率 * @param stationInfos 台站信息列表 */ - public List mutiThreadGetStationInfo(List stationInfos, RateParam mRateParam){ + public void mutiThreadGetStationInfo(List stationInfos, RateParam mRateParam) { // 声明当前开始执行时间 Date startTime = new Date(); //声明一个数组用于接收最后的结果情况 - List finallySta = new ArrayList<>(); + Map finallySta = Objects.nonNull(redisUtil.get("dataStationInfoList"))? (Map) redisUtil.get("dataStationInfoList"):new HashMap<>(); //声明一个线程池 ThreadPoolExecutor poolExecutor = null; //声明一个CountDownLatch监听是否完成全部线程 CountDownLatch countDownLatch = null; //初始化线程数量=0 int threadNum = 0; - //获取当前设备的理想线程数 - int idealnum = Runtime.getRuntime().availableProcessors(); +// //获取当前设备的理想线程数 +// int idealnum = Runtime.getRuntime().availableProcessors(); //获取需要处理的台站信息数量 int works = stationInfos.size(); - // 如果需要工作处理的数量 小于 理想线程数 - if(works < idealnum) { +// // 如果需要工作处理的数量 小于 理想线程数 +// if(works < idealnum) { //将需要处理的工作数量赋值给线程数,按照需要处理的工作数量处理数据 threadNum = works; - } else { - //否则按照理想线程数 处理数据 - threadNum = idealnum; - } +// } else { +// //否则按照理想线程数 处理数据 +// threadNum = idealnum; +// } // 如果线程数不等于0 if (threadNum != 0){ + //获取机器可用核心数 + int maximumPoolSize = Runtime.getRuntime().availableProcessors(); //初始化线程池 - poolExecutor = new ThreadPoolExecutor(threadNum, threadNum, 5, TimeUnit.MINUTES, new LinkedBlockingQueue<>()); - }else { - return stationInfos; + ThreadFactory threadFactory = new ThreadFactory() { + @Override + public Thread newThread(@NotNull Runnable r) { + Thread t = new Thread(r); + t.setPriority(10); + t.setName("worker-"); + return t; + } + }; + poolExecutor = new ThreadPoolExecutor(15,maximumPoolSize,10, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),threadFactory); + //初始化线程池 +// poolExecutor = new ThreadPoolExecutor(16, 32, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); } - +// else { +// return finallySta; +// } // 线程数 等于 需要处理的台站数量 if( threadNum == works ){ countDownLatch = new CountDownLatch(threadNum); @@ -869,63 +882,67 @@ public class CalculateStationData { poolExecutor.shutdownNow(); } } - }else { // 线程数 不等于 需要处理的台站数量时 - //将台站数组按照线程数分成多组 - //声明一个变量 看当前台站信息需要分为多少组 - int Tworks = 0; - //如果当前需要处理的台站数量是线程数量的整数倍 - if(works % threadNum == 0){ - //变量值 等于 需要处理的台站数量与线程数的商 - Tworks = works / threadNum; // 300 30 10 - } else { - // 变量值 等于 需要处理的台站数量与线程数的商 +1 - Tworks = works / threadNum + 1; // 301 30 11 - } - //遍历需要查询的组数 - for (int i = 0; i < Tworks; i++){ - //根据每组的台站大小 分割台站数组 - List infos = new ArrayList<>(); - int startIndex = i * threadNum; - int endIndex = ((i + 1) * threadNum); - //判断当前结束下标是否超出台站数量 没有超出说明还在范围内 正常截取数组 - if (endIndex <= works){ - infos = stationInfos.subList(startIndex, endIndex); - }else {//如果超出台站数量 则从截取开始下标 截取到台站数组长度 - infos = stationInfos.subList(startIndex, works); - } - countDownLatch = new CountDownLatch(infos.size()); - //遍历当前组的台站并进行计算 - for (int j = 0; j < infos.size(); j++){ - //获取台站信息 - StationInfo stationInfo = infos.get(j); - //声明一个实体类 - GetStationinfoAndDataRate stationinfoAndDataRate = new GetStationinfoAndDataRate(); - stationinfoAndDataRate.setMOriginalstationsinfo(stationInfo); - stationinfoAndDataRate.setMRateparam(mRateParam); - CalculateDataRateThread calculateDataRateThread = new CalculateDataRateThread(finallySta, stationinfoAndDataRate, countDownLatch); - //调用线程计算率值 - poolExecutor.execute(calculateDataRateThread); - } - if (i == Tworks - 1){ - try { - countDownLatch.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } finally { - //关闭线程池 - if(poolExecutor != null) { - poolExecutor.shutdownNow(); - } - } - }else { - try { - countDownLatch.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - } } - return finallySta; +// else { // 线程数 不等于 需要处理的台站数量时 +// //将台站数组按照线程数分成多组 +// //声明一个变量 看当前台站信息需要分为多少组 +// int Tworks = 0; +// //如果当前需要处理的台站数量是线程数量的整数倍 +// if(works % threadNum == 0){ +// //变量值 等于 需要处理的台站数量与线程数的商 +// Tworks = works / threadNum; // 300 30 10 +// } else { +// // 变量值 等于 需要处理的台站数量与线程数的商 +1 +// Tworks = works / threadNum + 1; // 301 30 11 +// } +// //遍历需要查询的组数 +// for (int i = 0; i < Tworks; i++){ +// long start = System.currentTimeMillis(); +// //根据每组的台站大小 分割台站数组 +// List infos = new ArrayList<>(); +// int startIndex = i * threadNum; +// int endIndex = ((i + 1) * threadNum); +// //判断当前结束下标是否超出台站数量 没有超出说明还在范围内 正常截取数组 +// if (endIndex <= works){ +// infos = stationInfos.subList(startIndex, endIndex); +// }else {//如果超出台站数量 则从截取开始下标 截取到台站数组长度 +// infos = stationInfos.subList(startIndex, works); +// } +// countDownLatch = new CountDownLatch(infos.size()); +// //遍历当前组的台站并进行计算 +// for (int j = 0; j < infos.size(); j++){ +// //获取台站信息 +// StationInfo stationInfo = infos.get(j); +// //声明一个实体类 +// GetStationinfoAndDataRate stationinfoAndDataRate = new GetStationinfoAndDataRate(); +// stationinfoAndDataRate.setMOriginalstationsinfo(stationInfo); +// stationinfoAndDataRate.setMRateparam(mRateParam); +// CalculateDataRateThread calculateDataRateThread = new CalculateDataRateThread(finallySta, stationinfoAndDataRate, countDownLatch); +// //调用线程计算率值 +// poolExecutor.execute(calculateDataRateThread); +// } +// if (i == Tworks - 1){ +// try { +// countDownLatch.await(); +// } catch (InterruptedException e) { +// throw new RuntimeException(e); +// } finally { +// //关闭线程池 +// if(poolExecutor != null) { +// poolExecutor.shutdownNow(); +// } +// } +// }else { +// try { +// countDownLatch.await(); +// } catch (InterruptedException e) { +// throw new RuntimeException(e); +// } +// } +// long end = System.currentTimeMillis(); +// System.out.println("单次线程执行总时长:"+ (end-start)); +// } +// } +// return finallySta; } } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationMetDataMapper.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationMetDataMapper.java index 83822d7c..7f237f99 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationMetDataMapper.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationMetDataMapper.java @@ -13,6 +13,6 @@ import java.util.List; @Mapper public interface StationMetDataMapper extends BaseMapper { - List findMetDataList(@Param("stationIds") List stationIds, @Param("startDate") String startDate); + List findMetDataList(@Param("stationIds") List stationIds, @Param("startDate") String startDate); } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationSohDataMapper.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationSohDataMapper.java index 7b5779e2..b249c1cf 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationSohDataMapper.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationSohDataMapper.java @@ -13,5 +13,5 @@ import java.util.List; @Mapper public interface StationSohDataMapper extends BaseMapper { - List findSohDataList(@Param("stationId") String stationId, @Param("detectorIds") List detectorIds, @Param("startDate") String startDate); + List findSohDataList(@Param("stationId") Integer stationId, @Param("detectorIds") List detectorIds, @Param("startDate") String startDate); } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java index 3dffeae0..4c5c7d55 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java @@ -2,6 +2,7 @@ package org.jeecg.modules.service; import org.jeecg.modules.base.entity.configuration.GardsDetectors; import org.jeecg.modules.base.entity.postgre.SysUser; +import org.jeecg.modules.system.entity.GardsDetectorsSystem; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestBody; @@ -19,7 +20,7 @@ public interface ICacheTimeService { List> findCacheTime(); @RequestMapping("/gardsDetectors/findStationDetectors") - Map> findStationDetectors(@RequestBody List stationIds); + Map> findStationDetectors(@RequestBody List stationIds); @RequestMapping("/sys/user/findUserByName") SysUser findUserByName(@RequestParam String userName); diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/StationOperationServiceImpl.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/StationOperationServiceImpl.java index 1c4c02b2..3718df1f 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/StationOperationServiceImpl.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/StationOperationServiceImpl.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.spatial4j.core.context.SpatialContext; import com.spatial4j.core.distance.DistanceUtils; import com.spatial4j.core.shape.Rectangle; +import com.spatial4j.core.shape.impl.PointImpl; import org.jeecg.common.CacheName; import org.jeecg.common.CalculateStationData; import org.jeecg.common.PointUtil; @@ -26,6 +27,7 @@ import org.jeecg.modules.entity.data.*; import org.jeecg.modules.mapper.*; import org.jeecg.modules.service.ICacheTimeService; import org.jeecg.modules.service.IStationOperationService; +import org.jeecg.modules.system.entity.GardsDetectorsSystem; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -251,12 +253,12 @@ public class StationOperationServiceImpl extends ServiceImpl StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && - (Double.valueOf(item.getLon())>=rectangle.getMinX() && Double.valueOf(item.getLon())<= rectangle.getMaxX()) - && (Double.valueOf(item.getLat())>=rectangle.getMinY() && Double.valueOf(item.getLat())<= rectangle.getMaxY())).collect(Collectors.toList()); + if (rectangle.getMaxX() > rectangle.getMinX() && rectangle.getMaxY() > rectangle.getMinY()) { + nuclearFacilityPoints = nuclearFacilityPoints.stream().filter(item-> StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && + (Double.valueOf(item.getLon())>=rectangle.getMinX() && Double.valueOf(item.getLon())<= rectangle.getMaxX()) + && (Double.valueOf(item.getLat())>=rectangle.getMinY() && Double.valueOf(item.getLat())<= rectangle.getMaxY())).collect(Collectors.toList()); + } else if (rectangle.getMaxX() < rectangle.getMinX() && rectangle.getMaxY() > rectangle.getMinY()) { + nuclearFacilityPoints = nuclearFacilityPoints.stream().filter(item-> StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && + (Double.valueOf(item.getLon())>=rectangle.getMaxX() && Double.valueOf(item.getLon())<= rectangle.getMinX()) + && (Double.valueOf(item.getLat())>=rectangle.getMinY() && Double.valueOf(item.getLat())<= rectangle.getMaxY())).collect(Collectors.toList()); + } else if (rectangle.getMaxX() > rectangle.getMinX() && rectangle.getMaxY() < rectangle.getMinY()) { + nuclearFacilityPoints = nuclearFacilityPoints.stream().filter(item-> StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && + (Double.valueOf(item.getLon())>=rectangle.getMinX() && Double.valueOf(item.getLon())<= rectangle.getMaxX()) + && (Double.valueOf(item.getLat())>=rectangle.getMaxY() && Double.valueOf(item.getLat())<= rectangle.getMinY())).collect(Collectors.toList()); + } else if (rectangle.getMaxX() < rectangle.getMinX() && rectangle.getMaxY() < rectangle.getMinY()) { + nuclearFacilityPoints = nuclearFacilityPoints.stream().filter(item-> StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && + (Double.valueOf(item.getLon())>=rectangle.getMaxX() && Double.valueOf(item.getLon())<= rectangle.getMinX()) + && (Double.valueOf(item.getLat())>=rectangle.getMaxY() && Double.valueOf(item.getLat())<= rectangle.getMinY())).collect(Collectors.toList()); + } //遍历在正方形范围内的数据 根据点的经纬度信息以及圆心的经纬度信息 计算出两者之间的距离 与 半径进行比较 <=半径则说明点在范围内,否则点超出半径范围 nuclearFacilityPoints = nuclearFacilityPoints.stream() .filter(equ -> getDistance(Double.valueOf(equ.getLon()), Double.valueOf(equ.getLat()), longitudeD, latitudeD) <= radius).collect(Collectors.toList()); @@ -350,9 +366,7 @@ public class StationOperationServiceImpl extends ServiceImpl> cacheList = cacheTimeService.findCacheTime(); - //缓存时间 - String cacheTime = ""; - for (int i=0; i< cacheList.size(); i++){ - if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ){ - cacheTime = cacheList.get(i).get(CacheName.cacheTime); - break; - } - } - if (StringUtils.isBlank(cacheTime)){ - result.error500("The cache time cannot be empty"); - return result; - } + List stationDataList = (List) redisUtil.get("stationDataList"); +// //获取四项缓存数据的对应内容 +// List> cacheList = cacheTimeService.findCacheTime(); +// //缓存时间 +// String cacheTime = ""; +// for (int i=0; i< cacheList.size(); i++) { +// if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ) { +// cacheTime = cacheList.get(i).get(CacheName.cacheTime); +// break; +// } +// } +// if (StringUtils.isBlank(cacheTime)) { +// result.error500("The cache time cannot be empty"); +// return result; +// } //根据用户id查询出当前用户关注的台站信息 LambdaQueryWrapper userFocusStationQueryWrapper = new LambdaQueryWrapper<>(); userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId); List userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper); List stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList()); - //从redis中获取台站信息 - Map stationInfoMap = (Map)redisUtil.get("stationMap"); - //从redis中获取探测器信息 - Map detectorInfoMap = (Map)redisUtil.get("detectorsMap"); - //遍历台站id - if (CollectionUtils.isNotEmpty(stationIds)){ - //获取当前日期时间 作为结束查询时间 - LocalDateTime endDate = LocalDateTime.now(); - //根据缓存日期 得到开始查询时间 - LocalDateTime startDate = endDate.minusDays(Integer.valueOf(cacheTime)); - String startDateTime = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - //根据台站id,开始时间查询出台站下的气象数据 - List metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime); - //根据台站id查询出当前台站下处于运行状态的数据 - Map> stationDetectors = cacheTimeService.findStationDetectors(stationIds); - //声明存储所有台站id对应的数据信息的集合 - List stationDataList = new LinkedList<>(); - //遍历台站id 获取台站下的探测器数据 - if (CollectionUtils.isNotEmpty(stationDetectors)){ - for (String stationId:stationIds) { - Map>> stationMap = new HashMap<>(); - //获取台站下对应的探测器数据 - List detectors = stationDetectors.get(stationId); - if (CollectionUtils.isNotEmpty(detectors)){ - StationData stationData = new StationData(); - //stream流获取探测器id - List detectorIds = detectors.stream().map(GardsDetectors::getDetectorId).collect(Collectors.toList()); - //根据探测器id 开始时间查询样品基础数据 - List sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime); - //根据台站id,探测器id,开始时间 - List sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime); - //用于接收当前台站下所有探测器及探测器所有的样品数据,气体数据,状态数据集合 - List> detectorDataList = new LinkedList<>(); - - for (Integer detectorId:detectorIds) { - Map detectorMap = new HashMap<>(); - DetectorData detectorData = new DetectorData(); - detectorData.setDetectorId(detectorId); - //声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据 - List dataInfoList = new LinkedList<>(); - if (CollectionUtils.isNotEmpty(sampleDataList)){ - //根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo - List dataListSample = sampleDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(dataListSample)){ - for (GardsSampleData sampleData:dataListSample) { - DataInfoVo dataInfo = new DataInfoVo(); - //根据样品数据类型判断 数据类型 根据不同的样品数据状态 - String dataType = sampleData.getDataType(); - String spectralQualifie = sampleData.getSpectralQualifie(); - if (StrUtil.equals(dataType,"S")){ - dataInfo.setType("PHD"); - if (StrUtil.equals(spectralQualifie,"PREL")){ - dataInfo.setStatus("SPREL"); - } else if (StrUtil.equals(spectralQualifie,"FULL")) { - dataInfo.setStatus("SFULL"); - } - } else if (StrUtil.equals(dataType,"Q")){ - dataInfo.setType("QC"); - dataInfo.setStatus("QC"); - } else if (StrUtil.equals(dataType,"G")){ - dataInfo.setType("PHD"); - if (StrUtil.equals(spectralQualifie,"PREL")){ - dataInfo.setStatus("GPREL"); - } else if (StrUtil.equals(spectralQualifie,"FULL")) { - dataInfo.setStatus("GFULL"); - } - } else { - continue; - } - //处理开始时间 - Date acquisitionStart = sampleData.getAcquisitionStart(); - dataInfo.setBeginTime(Double.valueOf(acquisitionStart.getTime()/1000)); - //处理结束时间 - Date acquisitionStop = sampleData.getAcquisitionStop(); - dataInfo.setEndTime(Double.valueOf(acquisitionStop.getTime()/1000)); - //时间间隔 - Double span = Double.valueOf(acquisitionStop.getTime()/1000) - Double.valueOf(acquisitionStart.getTime()/1000); - dataInfo.setSpanTime(span); - dataInfoList.add(dataInfo); - } - } - } - if (CollectionUtils.isNotEmpty(sohDataList)){ - List dataListSoh = sohDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); - //根据探测器id 台站id 开始时间查询状态数据 - if (CollectionUtils.isNotEmpty(dataListSoh)){ - for (GardsSohData sohData:dataListSoh) { - DataInfoVo dataInfo = new DataInfoVo(); - dataInfo.setType("SOH"); - dataInfo.setStatus("SOH"); - Date startTime = sohData.getStartTime(); - dataInfo.setBeginTime(Double.valueOf(startTime.getTime()/1000)); - dataInfo.setSpanTime(Double.valueOf(sohData.getTime())); - dataInfoList.add(dataInfo); - } - } - } - if (CollectionUtils.isNotEmpty(metDataList)){ - List dataListMet = metDataList.stream().filter(item -> item.getStationId().equals(stationId)).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(dataListMet)){ - for (GardsMetData metData:dataListMet) { - DataInfoVo dataInfo = new DataInfoVo(); - dataInfo.setType("MET"); - dataInfo.setStatus("MET"); - Date startTime = metData.getStartTime(); - dataInfo.setBeginTime(Double.valueOf(startTime.getTime()/1000)); - Date endTime = metData.getEndTime(); - dataInfo.setEndTime(Double.valueOf(endTime.getTime()/1000)); - Double span = Double.valueOf(startTime.getTime() / 1000) - Double.valueOf(endTime.getTime() / 1000); - dataInfo.setSpanTime(span); - dataInfoList.add(dataInfo); - } - } - } - detectorData.setDataList(dataInfoList); - if (CollectionUtils.isNotEmpty(detectorInfoMap)){ - if (StringUtils.isNotBlank(detectorInfoMap.get(detectorId.toString()))){ - detectorData.setDetectorCode(detectorInfoMap.get(detectorId.toString())); - } - } - detectorMap.put(String.valueOf(detectorId), detectorData); - detectorDataList.add(detectorMap); - } - - stationMap.put(stationId, detectorDataList); - stationData.setStationId(stationId); - if (CollectionUtils.isNotEmpty(stationInfoMap)){ - if (StringUtils.isNotBlank(stationInfoMap.get(stationId))){ - stationData.setStationCode(stationInfoMap.get(stationId)); - } - } - stationData.setDetectors(stationMap); - stationDataList.add(stationData); - } - } - } + //过滤出当前用户关注的台站信息 + stationDataList = stationDataList.stream().filter(item-> stationIds.equals(item.getStationId())).collect(Collectors.toList()); +// //从redis中获取台站信息 +// Map stationInfoMap = (Map)redisUtil.get("stationMap"); +// //从redis中获取探测器信息 +// Map detectorInfoMap = (Map)redisUtil.get("detectorsMap"); +// //遍历台站id +// if (CollectionUtils.isNotEmpty(stationIds)) { +// //获取当前日期时间 作为结束查询时间 +// LocalDateTime endDate = LocalDateTime.now(); +// //根据缓存日期 得到开始查询时间 +// LocalDateTime startDate = endDate.minusDays(Integer.valueOf(cacheTime)); +// String startDateTime = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); +// //根据台站id,开始时间查询出台站下的气象数据 +// List metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime); +// //根据台站id查询出当前台站下处于运行状态的数据 +// Map> stationDetectors = cacheTimeService.findStationDetectors(stationIds); +// //声明存储所有台站id对应的数据信息的集合 +// List stationDataList = new LinkedList<>(); +// //遍历台站id 获取台站下的探测器数据 +// if (CollectionUtils.isNotEmpty(stationDetectors)) { +// for (String stationId:stationIds) { +// Map>> stationMap = new HashMap<>(); +// //获取台站下对应的探测器数据 +// List detectors = stationDetectors.get(stationId); +// if (CollectionUtils.isNotEmpty(detectors)) { +// StationData stationData = new StationData(); +// //stream流获取探测器id +// List detectorIds = detectors.stream().map(GardsDetectorsSystem::getDetectorId).collect(Collectors.toList()); +// //根据探测器id 开始时间查询样品基础数据 +// List sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime); +// //根据台站id,探测器id,开始时间 +// List sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime); +// //用于接收当前台站下所有探测器及探测器所有的样品数据,气体数据,状态数据集合 +// List> detectorDataList = new LinkedList<>(); +// +// for (Integer detectorId:detectorIds) { +// Map detectorMap = new HashMap<>(); +// DetectorData detectorData = new DetectorData(); +// detectorData.setDetectorId(detectorId); +// //声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据 +// List dataInfoList = new LinkedList<>(); +// if (CollectionUtils.isNotEmpty(sampleDataList)) { +// //根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo +// List dataListSample = sampleDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); +// if (CollectionUtils.isNotEmpty(dataListSample)) { +// for (GardsSampleData sampleData:dataListSample) { +// DataInfoVo dataInfo = new DataInfoVo(); +// //根据样品数据类型判断 数据类型 根据不同的样品数据状态 +// String dataType = sampleData.getDataType(); +// String spectralQualifie = sampleData.getSpectralQualifie(); +// if (StrUtil.equals(dataType,"S")){ +// dataInfo.setType("PHD"); +// if (StrUtil.equals(spectralQualifie,"PREL")){ +// dataInfo.setStatus("SPREL"); +// } else if (StrUtil.equals(spectralQualifie,"FULL")) { +// dataInfo.setStatus("SFULL"); +// } +// } else if (StrUtil.equals(dataType,"Q")){ +// dataInfo.setType("QC"); +// dataInfo.setStatus("QC"); +// } else if (StrUtil.equals(dataType,"G")){ +// dataInfo.setType("PHD"); +// if (StrUtil.equals(spectralQualifie,"PREL")){ +// dataInfo.setStatus("GPREL"); +// } else if (StrUtil.equals(spectralQualifie,"FULL")) { +// dataInfo.setStatus("GFULL"); +// } +// } else { +// continue; +// } +// //处理开始时间 +// Date acquisitionStart = sampleData.getAcquisitionStart(); +// dataInfo.setBeginTime(Double.valueOf(acquisitionStart.getTime()/1000)); +// //处理结束时间 +// Date acquisitionStop = sampleData.getAcquisitionStop(); +// dataInfo.setEndTime(Double.valueOf(acquisitionStop.getTime()/1000)); +// //时间间隔 +// Double span = Double.valueOf(acquisitionStop.getTime()/1000) - Double.valueOf(acquisitionStart.getTime()/1000); +// dataInfo.setSpanTime(span); +// dataInfoList.add(dataInfo); +// } +// } +// } +// if (CollectionUtils.isNotEmpty(sohDataList)) { +// List dataListSoh = sohDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); +// //根据探测器id 台站id 开始时间查询状态数据 +// if (CollectionUtils.isNotEmpty(dataListSoh)) { +// for (GardsSohData sohData:dataListSoh) { +// DataInfoVo dataInfo = new DataInfoVo(); +// dataInfo.setType("SOH"); +// dataInfo.setStatus("SOH"); +// Date startTime = sohData.getStartTime(); +// dataInfo.setBeginTime(Double.valueOf(startTime.getTime()/1000)); +// dataInfo.setSpanTime(Double.valueOf(sohData.getTime())); +// dataInfoList.add(dataInfo); +// } +// } +// } +// if (CollectionUtils.isNotEmpty(metDataList)) { +// List dataListMet = metDataList.stream().filter(item -> item.getStationId().equals(stationId)).collect(Collectors.toList()); +// if (CollectionUtils.isNotEmpty(dataListMet)) { +// for (GardsMetData metData:dataListMet) { +// DataInfoVo dataInfo = new DataInfoVo(); +// dataInfo.setType("MET"); +// dataInfo.setStatus("MET"); +// Date startTime = metData.getStartTime(); +// dataInfo.setBeginTime(Double.valueOf(startTime.getTime()/1000)); +// Date endTime = metData.getEndTime(); +// dataInfo.setEndTime(Double.valueOf(endTime.getTime()/1000)); +// Double span = Double.valueOf(startTime.getTime() / 1000) - Double.valueOf(endTime.getTime() / 1000); +// dataInfo.setSpanTime(span); +// dataInfoList.add(dataInfo); +// } +// } +// } +// detectorData.setDataList(dataInfoList); +// if (CollectionUtils.isNotEmpty(detectorInfoMap)) { +// if (StringUtils.isNotBlank(detectorInfoMap.get(detectorId.toString()))) { +// detectorData.setDetectorCode(detectorInfoMap.get(detectorId.toString())); +// } +// } +// detectorMap.put(String.valueOf(detectorId), detectorData); +// detectorDataList.add(detectorMap); +// } +// +// stationMap.put(stationId, detectorDataList); +// stationData.setStationId(stationId); +// if (CollectionUtils.isNotEmpty(stationInfoMap)) { +// if (StringUtils.isNotBlank(stationInfoMap.get(stationId))) { +// stationData.setStationCode(stationInfoMap.get(stationId)); +// } +// } +// stationData.setDetectors(stationMap); +// stationDataList.add(stationData); +// } +// } +// } result.setSuccess(true); result.setResult(stationDataList); - } +// } return result; } @Override public Result getDataProvisionEfficiency() { - // 获取所有的台站信息 - HashMap stationInfoMap = (HashMap) redisUtil.get("stationInfoMap"); - // 获取所有的台站信息 - List stations = stationInfoMap.values().stream() - .sorted(Comparator.comparing(GardsStations::getStationId)) - .collect(Collectors.toList()); - List stationInfos = new ArrayList<>(); - for (GardsStations gardsStations : stations) { - StationInfo stationInfo = new StationInfo(); - stationInfo.setStationCode(gardsStations.getStationCode()); - stationInfo.setCountryCode(gardsStations.getCountryCode()); - stationInfos.add(stationInfo); - } - RateParam mRateParam = calCulateStationData.initParameter(); - List stationInfoList = calCulateStationData.mutiThreadGetStationInfo(stationInfos,mRateParam); - + Map stationInfoMap = (Map) redisUtil.get("dataStationInfoList"); + List stationInfoList = stationInfoMap.values().stream().collect(Collectors.toList()); +// // 获取所有的台站信息 +// HashMap stationInfoMap = (HashMap) redisUtil.get("stationInfoMap"); +// List detectorsUsedList = (List) redisUtil.get("detectorsUsedList"); +// // 获取所有的台站信息 +// List stations = stationInfoMap.values().stream().sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList()); +// List stationInfos = new ArrayList<>(); +// for (GardsStations gardsStations : stations) { +// StationInfo stationInfo = new StationInfo(); +// stationInfo.setId(gardsStations.getStationId().toString()); +// stationInfo.setStationCode(gardsStations.getStationCode()); +// stationInfo.setCountryCode(gardsStations.getCountryCode()); +// stationInfo.setLon(gardsStations.getLon().toString()); +// stationInfo.setLat(gardsStations.getLat().toString()); +// stationInfo.setType(gardsStations.getType()); +// stationInfo.setDescription(gardsStations.getDescription()); +// stationInfo.setStatus(gardsStations.getStatus()); +// boolean contains = detectorsUsedList.contains(gardsStations.getStationId()); +// if (contains) { +// stationInfo.setUsed("YES"); +// } else { +// stationInfo.setUsed("NO"); +// } +// stationInfos.add(stationInfo); +// } +// RateParam mRateParam = calCulateStationData.initParameter(); +// List stationInfoList = calCulateStationData.mutiThreadGetStationInfo(stationInfos,mRateParam); return Result.OK(stationInfoList); } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java index b88fcb80..7ee0251a 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java @@ -117,6 +117,7 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl userFocusStationQueryWrapper = new LambdaQueryWrapper<>(); userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, sysUser.getId()); this.baseMapper.delete(userFocusStationQueryWrapper); + List focusStationStationList = new LinkedList<>(); for (Integer stationId:userFocusStation.getStationIds()) { SysUserFocusStationStation sysUserFocusStation = new SysUserFocusStationStation(); Long id = IdWorker.getId(); @@ -127,7 +128,10 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl0) { + this.saveBatch(focusStationStationList); } } result.success("Save successfully"); diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/system/entity/GardsDetectorsSystem.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/system/entity/GardsDetectorsSystem.java new file mode 100644 index 00000000..42e9a6aa --- /dev/null +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/system/entity/GardsDetectorsSystem.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.system.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import org.jeecg.modules.base.entity.configuration.GardsDetectors; + +@Data +@TableName("CONFIGURATION.GARDS_DETECTORS") +public class GardsDetectorsSystem extends GardsDetectors { + + /** + * 台站名称 + */ + @TableField(exist = false) + private String stationName; + +} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/GardsDetectorsController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/GardsDetectorsController.java index f986567f..027f0def 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/GardsDetectorsController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/GardsDetectorsController.java @@ -67,7 +67,7 @@ public class GardsDetectorsController { } @RequestMapping("findStationDetectors") - public Map> findStationDetectors(@RequestBody List stationIds){ + public Map> findStationDetectors(@RequestBody List stationIds){ return gardsDetectorsService.findStationDetectors(stationIds); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java index e2e30219..7fa12fce 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java @@ -63,6 +63,6 @@ public interface IGardsDetectorsService extends IService { * @param stationIds * @return */ - Map> findStationDetectors(List stationIds); + Map> findStationDetectors(List stationIds); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java index 46b361bc..2ee51c3c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java @@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.base.entity.configuration.GardsDetectors; import org.jeecg.modules.system.entity.GardsDetectorsSystem; import org.jeecg.modules.system.mapper.GardsDetectorsMapper; import org.jeecg.modules.system.service.IGardsDetectorsService; @@ -133,24 +134,24 @@ public class GardsDetectorsServiceImpl extends ServiceImpl gardsDetectors = this.baseMapper.selectList(new LambdaQueryWrapper<>()); Map detectorsMap = gardsDetectors.stream().collect(Collectors.toMap(GardsDetectorsSystem::getDetectorId, GardsDetectorsSystem::getDetectorCode)); + List detectorsUsedList = gardsDetectors.stream().filter(item -> item.getStatus()!=null && "Operating".equals(item.getStatus().trim())).map(GardsDetectorsSystem::getStationId).collect(Collectors.toList()); redisUtil.set("detectorsMap",detectorsMap); + redisUtil.set("detectorsUsedList", detectorsUsedList); } @Override - public Map> findStationDetectors(List stationIds) { + public Map> findStationDetectors(List stationIds) { Map> map = new HashMap<>(); if (CollectionUtils.isNotEmpty(stationIds)){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(GardsDetectorsSystem::getStationId, stationIds); List detectorsList = this.baseMapper.selectList(queryWrapper); - for (String stationId:stationIds) { - List detectors = detectorsList.stream().filter(item -> item.getStationId().equals(Integer.valueOf(stationId)) && item.getStatus().trim().equals("Operating")).collect(Collectors.toList()); - map.put(stationId, detectors); + for (Integer stationId:stationIds) { + List detectors = detectorsList.stream().filter(item -> item.getStationId()!=null && item.getStationId().equals(stationId) && item.getStatus()!=null && item.getStatus().trim().equals("Operating")).collect(Collectors.toList()); + map.put(String.valueOf(stationId), detectors); } } return map; diff --git a/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java b/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java index a158b8da..87ed7deb 100644 --- a/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java +++ b/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java @@ -1,5 +1,6 @@ package org.jeecg; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.oConvertUtils; import org.springframework.boot.CommandLineRunner; @@ -19,8 +20,13 @@ import java.net.UnknownHostException; @SpringBootApplication @EnableFeignClients(basePackages = {"org.jeecg"}) @EnableScheduling +@RequiredArgsConstructor public class JeecgStationOperationApplication extends SpringBootServletInitializer implements CommandLineRunner { + private final DataProvisionEfficiencyManager dataProvisionEfficiencyManager; + + private final DataReceivingStatusManager dataReceivingStatusManager; + @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(JeecgStationOperationApplication.class); @@ -42,6 +48,7 @@ public class JeecgStationOperationApplication extends SpringBootServletInitializ @Override public void run(String... args) throws Exception { - + dataProvisionEfficiencyManager.start(); +// dataReceivingStatusManager.start(); } } \ No newline at end of file