邮箱日志生成

台站运行管理查看台站数据提供率及有效率接口修改为redis启动时缓存方式
台站运行管理查询台站查询台站监测数据信息修改为redis启动时缓存方式
beta功能增加查看Auto日志接口
This commit is contained in:
qiaoqinzheng 2023-10-28 09:54:33 +08:00
parent 8dd0ddd2dd
commit d3e00b1660
28 changed files with 2305 additions and 380 deletions

View File

@ -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,6 +280,7 @@ public class EmailServiceManager {
* @throws IOException
*/
public void getMailContent(@NotNull Part part, StringBuilder content) throws MessagingException, IOException {
try {
if(part.isMimeType(MailContentType.PLAIN.getContentType())){
content.append(part.getContent());
}else if(part.isMimeType("multipart/*")){
@ -283,6 +290,15 @@ public class EmailServiceManager {
getMailContent(bodyPart,content);
}
}
} catch (MessagingException e) {
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(),"Get", null, "Error", "GETALLID", "", "");
throw e;
} catch (IOException e) {
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(),"Get", null, "Error", "GETALLID", "", "");
throw e;
}
}
/**
@ -330,7 +346,13 @@ public class EmailServiceManager {
* @throws MessagingException
*/
public void removeMail(@NotNull Message message) throws MessagingException {
try {
message.setFlag(Flags.Flag.DELETED,true);
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(), "Get", null, "Successful", "DELETEID", message.getSubject(), "");
} catch (MessagingException e) {
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(), "Get", null, "Error", "DELETEID", message.getSubject(), "");
throw e;
}
}
/**

View File

@ -40,6 +40,9 @@ public class FTPUtil {
@Value("${ftp.encoding}")
private String encoding;
@Value("${ftp.ftpRootPath}")
private String ftpRootPath;
public String getUserName(){
return this.userName;
}
@ -66,6 +69,8 @@ public class FTPUtil {
ftp.login(userName, password);
// 切换为本地被动模式可以解决FTP上传后文件为空的问题但需要服务器将FTP服务添加至防火墙白名单
ftp.enterLocalPassiveMode();
//切换工作路径
ftp.changeWorkingDirectory(ftpRootPath);
//判断是否连接成功
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {

View File

@ -2,7 +2,6 @@ package org.jeecg.common.util;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -11,21 +10,15 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;
@Component
public class LogFileUtil {
/**
* 相关Spring组件引用
*/
@Autowired
private SpectrumPathProperties spectrumPathProperties;
public void errorLog(String spectrumFileName, String warning) {
String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Error";
public static void errorLog(String logHeadPath, String spectrumFileName, String warning) {
String logFilePath = logHeadPath + File.separator + "Error";
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdir();
@ -63,7 +56,7 @@ public class LogFileUtil {
* @param state
* @param logProcess
*/
public void emailLog(String GSType, SysEmail email, String state, String logProcess) {
public static void emailLog(String logHeadPath, String GSType, SysEmail email, String state, String logProcess, String subjectName, String fileName) {
String warning = "";
switch (logProcess) {
case "CONNECT":
@ -76,19 +69,19 @@ public class LogFileUtil {
warning="Get FileNameHeader "+state+".....";
break;
case "GETIDBODY":
warning="Get File "+"FileName"+" FileNameBody "+state+".....";
warning="Get File "+fileName+" FileNameBody "+state+".....";
break;
case "GETIDATTACH":
warning="Get File "+"subject"+" AttachFile "+"FileName"+" "+state+".....";
warning="Get File "+subjectName+" AttachFile "+fileName+" "+state+".....";
break;
case "GETIDEML":
warning="Get File "+"subject"+" EmlFile "+"FileName";
warning="Get File "+subjectName+" EmlFile .....";
break;
case "DELETEID":
warning="Delete File "+"subject"+" "+state+".....";
warning="Delete File "+subjectName+" "+state+".....";
break;
case "EXPUNGE":
warning="Expunge File "+"subject"+" "+state+".....";
warning="Expunge File "+subjectName+" "+state+".....";
break;
case "DONE":
warning="Done";
@ -97,7 +90,7 @@ public class LogFileUtil {
break;
}
LocalDateTime now = LocalDateTime.now();
String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Mail" + File.separator + GSType + File.separator + now.getYear() + File.separator + now.getMonthValue();
String logFilePath = logHeadPath + File.separator + "Mail" + File.separator + GSType + File.separator + now.getYear() + File.separator + now.getMonthValue();
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdirs();

View File

@ -1,8 +1,10 @@
package org.jeecg.modules;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.apache.commons.lang3.ArrayUtils;
import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.spectrum.EmailCounter;
import org.jeecg.modules.spectrum.SpectrumParsingActuator;
@ -10,6 +12,7 @@ import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import javax.mail.Message;
import javax.mail.MessagingException;
import java.io.File;
import java.util.Date;
import java.util.concurrent.*;
@ -47,9 +50,11 @@ public class EmailParsingActuator extends Thread{
for(;;){
long start = System.currentTimeMillis();
final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(),this.systemStartupTime);
emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(),this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties());
try {
final Message[] messages = emailServiceManager.receiveMail();
//连接成功写入日志内容
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Successful", "CONNECT", "", "");
if(ArrayUtils.isNotEmpty(messages)){
CountDownLatch taskLatch = new CountDownLatch(messages.length);
for(Message message : messages){
@ -61,6 +66,7 @@ public class EmailParsingActuator extends Thread{
taskLatch.await();
}
}catch (MessagingException | InterruptedException e) {
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Error", "CONNECT", "", "");
e.printStackTrace();
}finally {
//关闭资源

View File

@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.exception.StationNotFoundException;
import org.jeecg.modules.service.BlockConstant;
import org.jeecg.modules.file.FileOperation;
@ -154,8 +155,7 @@ public class FileSourceHandleManager{
} else {
warning = e.getMessage();
}
spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning);
LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
log.error("Parsing the {} file of the filesource directory failed.The reason is {}",spectrumFile.getName(),e.getMessage());
e.printStackTrace();
}finally {

View File

@ -164,7 +164,7 @@ public class UndealHandleManager{
} else {
warning = e.getMessage();
}
spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning);
LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
log.error("The {} file of the undeal directory fails to be parsed again.The reason is {}",spectrumFile.getName(),e.getMessage());
e.printStackTrace();
}finally {

View File

@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.config.datasource.DataSourceSwitcher;
@ -71,8 +72,10 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
*/
protected void checkHeaderBlock(){
if(this.mailContent.indexOf("#Header") == -1){
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Error", "GETIDHEADER", "", "");
throw new HeaderBlockException("header data error");
}
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Successful", "GETIDHEADER", "", "");
}
/**
@ -91,8 +94,10 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
protected void parseingEmail() throws Exception {
final EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(super.spectrumFile.getAbsolutePath());
if(Objects.isNull(sourceData) || StringUtils.isBlank(sourceData.data_type)){
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Error", "GETIDBODY", "", "");
throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath());
}
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Successful", "GETIDBODY", "", "");
this.sourceData = sourceData;
}

View File

@ -7,6 +7,7 @@ import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.exception.StationNotFoundException;
@ -90,9 +91,11 @@ public class SpectrumParsingActuator implements Runnable{
mailContent = new StringBuilder();
emailServiceManager.getMailContent(message,mailContent);
//读取文件内容成功后写入日志
spectrumServiceQuotes.getLogFileUtil().emailLog("Get", emailProperties, "Successful", "GETALLID");
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Successful", "GETALLID", "", "");
//所有邮件都需以.eml格式存储到eml文件夹中
downloadEmailToEmlDir();
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Successful", "GETIDEML", subject, "");
//判断是否是IMS2.0协议文件
if(checkMailContent(mailContent,subject)){
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
@ -108,9 +111,6 @@ public class SpectrumParsingActuator implements Runnable{
}
}
} catch (Exception e) {
if (e.getClass().equals(MessagingException.class)) {
spectrumServiceQuotes.getLogFileUtil().emailLog("Get", emailProperties, "Error", "GETALLID");
}
//生成日志
String warning = "";
if (e.getClass().equals(StationNotFoundException.class)) {
@ -118,7 +118,7 @@ public class SpectrumParsingActuator implements Runnable{
} else {
warning = e.getMessage();
}
spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning);
LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
log.error("This email failed to parse. The email subject is: {}, sent on: {}, received on: {}, and the reason for the failure is: {}",subject,sendTime,receiveTime,e.getMessage());
e.printStackTrace();
}finally {
@ -129,6 +129,7 @@ public class SpectrumParsingActuator implements Runnable{
e.printStackTrace();
}
this.taskLatch.countDown();
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Successful", "DONE", "", "");
}
}
@ -168,6 +169,7 @@ public class SpectrumParsingActuator implements Runnable{
* 当计数大于10000后从0开始服务重启后也从0开始
*/
private void downloadEmailToEmlDir() throws Exception{
try {
//获取发件人
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
final String from = address.substring(0,address.indexOf(StringConstant.AT));
@ -200,5 +202,11 @@ public class SpectrumParsingActuator implements Runnable{
file.createNewFile();
}
message.writeTo(new FileOutputStream(file));
} catch (Exception e) {
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Error", "GETIDEML", message.getSubject(), "");
throw e;
}
}
}

View File

@ -10,6 +10,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
@ -27,10 +30,10 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
/**
* @Description: 单表示例
@ -43,6 +46,54 @@ import java.util.List;
@RestController
@RequestMapping("/test/jeecgDemo")
public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoService> {
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;

View File

@ -208,6 +208,18 @@ public class SpectrumAnalysesController {
return spectrumAnalysisService.analyseAllSpectrum(analyseBetaInfo.getDbNames(), analyseBetaInfo.getSampleIds(), analyseBetaInfo.getSampleFileNames(), analyseBetaInfo.getGasFileNames(), analyseBetaInfo.getDetFileNames(), analyseBetaInfo.getQcFileNames(), analyseBetaInfo.getCurrentFileName(), request);
}
@GetMapping("viewAutomaticAnalysisLog")
@ApiOperation(value = "查看Automatic Analysis Log页面数据", notes = "查看Automatic Analysis Log页面数据")
public void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response) {
spectrumAnalysisService.viewAutomaticAnalysisLog(sampleId, response);
}
@GetMapping("viewBGLogViewer")
@ApiOperation(value = "查看BG Log Viewer数据", notes = "查看BG Log Viewer数据")
public Result viewBGLogViewer(String dbName, Integer sampleId, String sampleFileName, String gasFileName, String detFileName, String qcFileName, HttpServletRequest request) {
return null;
}
@PostMapping("saveToDB")
public Result saveToDB(@RequestBody BgDataAnlyseResultIn anlyseResultIn, HttpServletRequest request) {
return spectrumAnalysisService.saveToDB(anlyseResultIn, request);
@ -231,9 +243,4 @@ public class SpectrumAnalysesController {
spectrumAnalysisService.saveToTxt(anlyseResultIn, response);
}
@GetMapping("viewAutomaticAnalysisLog")
@ApiOperation(value = "查看Automatic Analysis Log页面数据", notes = "查看Automatic Analysis Log页面数据")
public void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response) {
spectrumAnalysisService.viewAutomaticAnalysisLog(sampleId, response);
}
}

View File

@ -8,15 +8,12 @@
cfg_stations.station_code stationName,
cfg_detectors.detector_code detectorsName
FROM
CONFIGURATION.GARDS_STATIONS cfg_stations,
CONFIGURATION.GARDS_DETECTORS cfg_detectors,
ORIGINAL.GARDS_SAMPLE_DATA org_samples,
(SELECT analyses.sample_id FROM ${dbName} analyses) analyses_sample_ids
ORIGINAL.GARDS_SAMPLE_DATA org_samples
inner join CONFIGURATION.GARDS_STATIONS cfg_stations on org_samples.station_id=cfg_stations.station_id
inner join CONFIGURATION.GARDS_DETECTORS cfg_detectors on org_samples.detector_id=cfg_detectors.detector_id
inner join ${dbName} analyses_sample_ids on org_samples.sample_id=analyses_sample_ids.sample_id
<where>
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
<foreach collection="stationTypes" item="stationType" open="(" close=")" separator=",">
#{stationType}
</foreach>
@ -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
<where>
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
<foreach collection="stationTypes" item="stationType" open="(" close=")" separator=",">
#{stationType}

View File

@ -74,6 +74,10 @@ public interface ISpectrumAnalysisService {
Result analyseAllSpectrum(List<String> dbNames, List<Integer> sampleIds, List<String> sampleFileNames, List<String> gasFileNames, List<String> detFileNames, List<String> 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);
}

View File

@ -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<String, Map<String, Object>> 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<String> calibrations(GardsCalibrationSpectrum gammaCalibrationCE,GardsCalibrationSpectrum gammaCalibrationEC, GardsCalibrationSpectrum betaCalibrationCE, GardsCalibrationSpectrum betaCalibrationEC) {
int min = 79;
String space = StrUtil.SPACE;

View File

@ -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<String, GardsStations> stationInfoMap = (HashMap<String, GardsStations>) redisUtil.get("stationInfoMap");
List<Integer> detectorsUsedList = (List<Integer>) redisUtil.get("detectorsUsedList");
// 获取所有的台站信息
List<GardsStations> stations = stationInfoMap.values().stream().sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList());
List<StationInfo> 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();
}
}
}
}
}
}

View File

@ -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<Map<String, String>> 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<Integer, String> stationInfoMap = (Map<Integer, String>)redisUtil.get("stationMap");
List<Integer> stationIds = stationInfoMap.keySet().stream().collect(Collectors.toList());
//从redis中获取探测器信息
Map<Integer, String> detectorInfoMap = (Map<Integer, String>)redisUtil.get("detectorsMap");
//声明存储所有台站id对应的数据信息的集合
List<StationData> stationDataList = Objects.nonNull(redisUtil.get("stationDataList"))? (List<StationData>) 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<GardsMetData> metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime);
//根据台站id查询出当前台站下处于运行状态的数据
Map<String, List<GardsDetectorsSystem>> stationDetectors = cacheTimeService.findStationDetectors(stationIds);
//遍历台站id 获取台站下的探测器数据
if (CollectionUtils.isNotEmpty(stationDetectors)) {
for (Integer stationId : stationIds) {
Map<String, List<Map<String, DetectorData>>> stationMap = new HashMap<>();
//获取台站下对应的探测器数据
List<GardsDetectorsSystem> detectors = stationDetectors.get(String.valueOf(stationId));
if (CollectionUtils.isNotEmpty(detectors)) {
StationData stationData = new StationData();
//stream流获取探测器id
List<Integer> detectorIds = detectors.stream().map(GardsDetectorsSystem::getDetectorId).collect(Collectors.toList());
//根据探测器id 开始时间查询样品基础数据
List<GardsSampleData> sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime);
//根据台站id探测器id开始时间
List<GardsSohData> sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime);
//用于接收当前台站下所有探测器及探测器所有的样品数据气体数据状态数据集合
List<Map<String, DetectorData>> detectorDataList = new LinkedList<>();
for (Integer detectorId : detectorIds) {
Map<String, DetectorData> detectorMap = new HashMap<>();
DetectorData detectorData = new DetectorData();
detectorData.setDetectorId(detectorId);
//声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据
List<DataInfoVo> dataInfoList = new LinkedList<>();
if (CollectionUtils.isNotEmpty(sampleDataList)) {
//根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo
List<GardsSampleData> 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<GardsSohData> 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<GardsMetData> 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();
}
}
}
}
}
}

View File

@ -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<StationInfo> finallySta;
private final Map<String, StationInfo> finallySta;
private CountDownLatch countDownLatch;
CalculateDataRateThread(List<StationInfo> finallySta, GetStationinfoAndDataRate stationinfoAndDataRate, CountDownLatch countDownLatch) {
CalculateDataRateThread(Map<String, StationInfo> 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);
}
}

View File

@ -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<StationInfo> mutiThreadGetStationInfo(List<StationInfo> stationInfos, RateParam mRateParam){
public void mutiThreadGetStationInfo(List<StationInfo> stationInfos, RateParam mRateParam) {
// 声明当前开始执行时间
Date startTime = new Date();
//声明一个数组用于接收最后的结果情况
List<StationInfo> finallySta = new ArrayList<>();
Map<String, StationInfo> finallySta = Objects.nonNull(redisUtil.get("dataStationInfoList"))? (Map<String, StationInfo>) 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<StationInfo> 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<StationInfo> 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;
}
}

View File

@ -13,6 +13,6 @@ import java.util.List;
@Mapper
public interface StationMetDataMapper extends BaseMapper<GardsMetData> {
List<GardsMetData> findMetDataList(@Param("stationIds") List<String> stationIds, @Param("startDate") String startDate);
List<GardsMetData> findMetDataList(@Param("stationIds") List<Integer> stationIds, @Param("startDate") String startDate);
}

View File

@ -13,5 +13,5 @@ import java.util.List;
@Mapper
public interface StationSohDataMapper extends BaseMapper<GardsSohData> {
List<GardsSohData> findSohDataList(@Param("stationId") String stationId, @Param("detectorIds") List<Integer> detectorIds, @Param("startDate") String startDate);
List<GardsSohData> findSohDataList(@Param("stationId") Integer stationId, @Param("detectorIds") List<Integer> detectorIds, @Param("startDate") String startDate);
}

View File

@ -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<Map<String, String>> findCacheTime();
@RequestMapping("/gardsDetectors/findStationDetectors")
Map<String, List<GardsDetectors>> findStationDetectors(@RequestBody List<String> stationIds);
Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<Integer> stationIds);
@RequestMapping("/sys/user/findUserByName")
SysUser findUserByName(@RequestParam String userName);

View File

@ -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<StationOperationMap
point.setNuclearFacilityName(facilityInfoValue.getFacilityName());
if (StringUtils.isNotBlank(facilityInfoValue.getLongitude())){
String pointValue = PointUtil.calculate(facilityInfoValue.getLongitude());
facilityInfoValue.setLatitude(pointValue);
// facilityInfoValue.setLatitude(pointValue);
point.setLat(pointValue);
}
if (StringUtils.isNotBlank(facilityInfoValue.getLatitude())){
String pointValue = PointUtil.calculate(facilityInfoValue.getLatitude());
facilityInfoValue.setLongitude(pointValue);
// facilityInfoValue.setLongitude(pointValue);
point.setLon(pointValue);
}
nuclearPoints.add(point);
@ -287,9 +289,23 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
// 1.获取外接正方形
Rectangle rectangle = getRectangle(radius, longitudeD, latitudeD);
// 2.获取位置在正方形内的所有设备 判断核设施的经纬度是否为空 不为空 判断经纬度是否在正方形的最大最小范围内 如果在则过滤出来继续使用否则弃用
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<StationOperationMap
* @param latitude 圆心纬度
*/
private Rectangle getRectangle(Double radius, Double longitude, Double latitude) {
return spatialContext.getDistCalc()
.calcBoxByDistFromPt(spatialContext.makePoint(longitude, latitude),
radius * DistanceUtils.KM_TO_DEG, spatialContext, null);
return spatialContext.getDistCalc().calcBoxByDistFromPt(spatialContext.makePoint(longitude, latitude), radius * DistanceUtils.KM_TO_DEG, spatialContext, null);
}
/***
@ -365,192 +379,207 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
* @return 返回距离单位km
*/
private double getDistance(Double lon, Double lat, double longitude, double latitude) {
return spatialContext.calcDistance(spatialContext.makePoint(longitude, latitude),
spatialContext.makePoint(lon, lat)) * DistanceUtils.DEG_TO_KM;
double distance = spatialContext.getDistCalc().distance(spatialContext.makePoint(longitude, latitude), spatialContext.makePoint(lon, lat)) * DistanceUtils.DEG_TO_KM;
return distance;
}
@Override
public Result getDataReceivingStatus(String userId) {
Result result = new Result();
//获取四项缓存数据的对应内容
List<Map<String, String>> 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<StationData> stationDataList = (List<StationData>) redisUtil.get("stationDataList");
// //获取四项缓存数据的对应内容
// List<Map<String, String>> 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<SysUserFocusStationStation> userFocusStationQueryWrapper = new LambdaQueryWrapper<>();
userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
List<SysUserFocusStationStation> userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper);
List<String> stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList());
//从redis中获取台站信息
Map<Integer, String> stationInfoMap = (Map<Integer, String>)redisUtil.get("stationMap");
//从redis中获取探测器信息
Map<Integer, String> detectorInfoMap = (Map<Integer, String>)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<GardsMetData> metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime);
//根据台站id查询出当前台站下处于运行状态的数据
Map<String, List<GardsDetectors>> stationDetectors = cacheTimeService.findStationDetectors(stationIds);
//声明存储所有台站id对应的数据信息的集合
List<StationData> stationDataList = new LinkedList<>();
//遍历台站id 获取台站下的探测器数据
if (CollectionUtils.isNotEmpty(stationDetectors)){
for (String stationId:stationIds) {
Map<String, List<Map<String, DetectorData>>> stationMap = new HashMap<>();
//获取台站下对应的探测器数据
List<GardsDetectors> detectors = stationDetectors.get(stationId);
if (CollectionUtils.isNotEmpty(detectors)){
StationData stationData = new StationData();
//stream流获取探测器id
List<Integer> detectorIds = detectors.stream().map(GardsDetectors::getDetectorId).collect(Collectors.toList());
//根据探测器id 开始时间查询样品基础数据
List<GardsSampleData> sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime);
//根据台站id探测器id开始时间
List<GardsSohData> sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime);
//用于接收当前台站下所有探测器及探测器所有的样品数据气体数据状态数据集合
List<Map<String, DetectorData>> detectorDataList = new LinkedList<>();
for (Integer detectorId:detectorIds) {
Map<String, DetectorData> detectorMap = new HashMap<>();
DetectorData detectorData = new DetectorData();
detectorData.setDetectorId(detectorId);
//声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据
List<DataInfoVo> dataInfoList = new LinkedList<>();
if (CollectionUtils.isNotEmpty(sampleDataList)){
//根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo
List<GardsSampleData> 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<GardsSohData> 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<GardsMetData> 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<Integer, String> stationInfoMap = (Map<Integer, String>)redisUtil.get("stationMap");
// //从redis中获取探测器信息
// Map<Integer, String> detectorInfoMap = (Map<Integer, String>)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<GardsMetData> metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime);
// //根据台站id查询出当前台站下处于运行状态的数据
// Map<String, List<GardsDetectorsSystem>> stationDetectors = cacheTimeService.findStationDetectors(stationIds);
// //声明存储所有台站id对应的数据信息的集合
// List<StationData> stationDataList = new LinkedList<>();
// //遍历台站id 获取台站下的探测器数据
// if (CollectionUtils.isNotEmpty(stationDetectors)) {
// for (String stationId:stationIds) {
// Map<String, List<Map<String, DetectorData>>> stationMap = new HashMap<>();
// //获取台站下对应的探测器数据
// List<GardsDetectorsSystem> detectors = stationDetectors.get(stationId);
// if (CollectionUtils.isNotEmpty(detectors)) {
// StationData stationData = new StationData();
// //stream流获取探测器id
// List<Integer> detectorIds = detectors.stream().map(GardsDetectorsSystem::getDetectorId).collect(Collectors.toList());
// //根据探测器id 开始时间查询样品基础数据
// List<GardsSampleData> sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime);
// //根据台站id探测器id开始时间
// List<GardsSohData> sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime);
// //用于接收当前台站下所有探测器及探测器所有的样品数据气体数据状态数据集合
// List<Map<String, DetectorData>> detectorDataList = new LinkedList<>();
//
// for (Integer detectorId:detectorIds) {
// Map<String, DetectorData> detectorMap = new HashMap<>();
// DetectorData detectorData = new DetectorData();
// detectorData.setDetectorId(detectorId);
// //声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据
// List<DataInfoVo> dataInfoList = new LinkedList<>();
// if (CollectionUtils.isNotEmpty(sampleDataList)) {
// //根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo
// List<GardsSampleData> 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<GardsSohData> 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<GardsMetData> 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<String, GardsStations> stationInfoMap = (HashMap<String, GardsStations>) redisUtil.get("stationInfoMap");
// 获取所有的台站信息
List<GardsStations> stations = stationInfoMap.values().stream()
.sorted(Comparator.comparing(GardsStations::getStationId))
.collect(Collectors.toList());
List<StationInfo> 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<StationInfo> stationInfoList = calCulateStationData.mutiThreadGetStationInfo(stationInfos,mRateParam);
Map<String, StationInfo> stationInfoMap = (Map<String, StationInfo>) redisUtil.get("dataStationInfoList");
List<StationInfo> stationInfoList = stationInfoMap.values().stream().collect(Collectors.toList());
// // 获取所有的台站信息
// HashMap<String, GardsStations> stationInfoMap = (HashMap<String, GardsStations>) redisUtil.get("stationInfoMap");
// List<Integer> detectorsUsedList = (List<Integer>) redisUtil.get("detectorsUsedList");
// // 获取所有的台站信息
// List<GardsStations> stations = stationInfoMap.values().stream().sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList());
// List<StationInfo> 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<StationInfo> stationInfoList = calCulateStationData.mutiThreadGetStationInfo(stationInfos,mRateParam);
return Result.OK(stationInfoList);
}

View File

@ -117,6 +117,7 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
LambdaQueryWrapper<SysUserFocusStationStation> userFocusStationQueryWrapper = new LambdaQueryWrapper<>();
userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, sysUser.getId());
this.baseMapper.delete(userFocusStationQueryWrapper);
List<SysUserFocusStationStation> focusStationStationList = new LinkedList<>();
for (Integer stationId:userFocusStation.getStationIds()) {
SysUserFocusStationStation sysUserFocusStation = new SysUserFocusStationStation();
Long id = IdWorker.getId();
@ -127,7 +128,10 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
sysUserFocusStation.setStationType(stationType);
sysUserFocusStation.setCreateTime(LocalDateTime.now());
sysUserFocusStation.setCreateBy(username);
this.baseMapper.insert(sysUserFocusStation);
focusStationStationList.add(sysUserFocusStation);
}
if (focusStationStationList.size()>0) {
this.saveBatch(focusStationStationList);
}
}
result.success("Save successfully");

View File

@ -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;
}

View File

@ -67,7 +67,7 @@ public class GardsDetectorsController {
}
@RequestMapping("findStationDetectors")
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<String> stationIds){
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<Integer> stationIds){
return gardsDetectorsService.findStationDetectors(stationIds);
}

View File

@ -63,6 +63,6 @@ public interface IGardsDetectorsService extends IService<GardsDetectorsSystem> {
* @param stationIds
* @return
*/
Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<String> stationIds);
Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<Integer> stationIds);
}

View File

@ -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<GardsDetectorsMapper,
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void findDetectors(){
if (redisUtil.hasKey("detectorsMap")){
redisUtil.del("detectorsMap");
}
redisUtil.del("detectorsMap", "detectorsUsedList");
List<GardsDetectorsSystem> gardsDetectors = this.baseMapper.selectList(new LambdaQueryWrapper<>());
Map<Integer, String> detectorsMap = gardsDetectors.stream().collect(Collectors.toMap(GardsDetectorsSystem::getDetectorId, GardsDetectorsSystem::getDetectorCode));
List<Integer> 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<String, List<GardsDetectorsSystem>> findStationDetectors(List<String> stationIds) {
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<Integer> stationIds) {
Map<String, List<GardsDetectorsSystem>> map = new HashMap<>();
if (CollectionUtils.isNotEmpty(stationIds)){
LambdaQueryWrapper<GardsDetectorsSystem> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(GardsDetectorsSystem::getStationId, stationIds);
List<GardsDetectorsSystem> detectorsList = this.baseMapper.selectList(queryWrapper);
for (String stationId:stationIds) {
List<GardsDetectorsSystem> 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<GardsDetectorsSystem> 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;

View File

@ -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();
}
}