diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DictConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DictConstant.java index 4220699d..8ecfeb7b 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DictConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/DictConstant.java @@ -13,6 +13,4 @@ public interface DictConstant { String NOBLE_GAS_BETAGAMMA = "Noble Gas Beta-Gamma"; String NOBLE_GAS_HPGE = "Noble Gas HPGe"; - - String ALERT_SYSTEM_CODE = "Alert_System_Code"; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java index 8a1fa80f..2e885a34 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java @@ -13,16 +13,10 @@ public interface RedisConstant { */ String PREFIX_SILENCE = "SilenceCycle:"; - String STREAM_ALARM = "Stream:Alarm"; - String STREAM_ANALYSIS = "Stream:Analysis"; - String GROUP_ALARM = "Group_Alarm"; - String GROUP_ANALYSIS = "Group_Analysis"; - String CONSUMER_ALARM = "Consumer_Alarm"; - String CONSUMER_ANALYSIS = "Consumer_Analysis"; String NUCLIDE_LINES_LIB = "Nuclide_Lines_Lib:"; 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 c8742bbe..222d5ffb 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 @@ -1,14 +1,7 @@ package org.jeecg.common.email; -import cn.hutool.core.codec.Base64; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.collection.ListUtil; -import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ArrayUtil; -import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.crypto.digest.MD5; import com.google.common.collect.Lists; import com.sun.mail.imap.IMAPStore; import com.sun.mail.smtp.SMTPAddressFailedException; @@ -23,7 +16,6 @@ import org.jeecg.common.exception.DownloadEmailException; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.Md5Util; import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jetbrains.annotations.NotNull; @@ -37,11 +29,10 @@ import javax.mail.search.SearchTerm; import java.io.*; import java.net.InetSocketAddress; import java.net.Socket; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; -import java.util.zip.InflaterOutputStream; /** * 邮件服务管理器 @@ -75,6 +66,8 @@ public class EmailServiceManager { private Object downloadEmlLocal = new Object(); + private final ReentrantLock lock = new ReentrantLock(); + @NotNull public static EmailServiceManager getInstance(){ return new EmailServiceManager(); @@ -131,7 +124,7 @@ public class EmailServiceManager { /** * 接收邮件 */ - public Message[] receiveMail() { + public Message[] receiveMail() throws Exception { String status = EmailLogManager.STATUS_SUCCESS; try{ //配置邮件服务属性 @@ -139,14 +132,15 @@ public class EmailServiceManager { properties.put("mail.store.protocol", "imap"); properties.put("mail.imap.host", email.getEmailServerAddress()); properties.put("mail.imap.port",email.getPort()); - Integer isQiye = email.getIsQiye(); - if (ObjectUtil.isNotNull(isQiye) && isQiye == 1) { + properties.put("mail.imap.connectiontimeout", "3000"); // 设置连接超时时间为3秒 + properties.put("mail.imap.timeout", "3000"); // 设置读取超时时间为3秒 + if (email.getIsQiye() == 1) { properties.put("mail.imap.ssl.enable", "true"); } else { properties.put("mail.imap.ssl.enable", "false"); } - HashMap IAM = new HashMap<>(); + HashMap IAM = new HashMap(); //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。 IAM.put("name","myname"); IAM.put("version","1.0.0"); @@ -182,6 +176,7 @@ public class EmailServiceManager { return o1.getReceivedDate().compareTo(o2.getReceivedDate()); } catch (MessagingException e) { e.printStackTrace(); + log.error(e.getMessage(), e); } return 0; }); @@ -191,12 +186,11 @@ public class EmailServiceManager { return Arrays.copyOfRange(messages,0,this.receiveNum-1); } } - }catch (MessagingException e){ + } catch (Exception e){ status = EmailLogManager.STATUS_ERROR; log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); - e.printStackTrace(); - return null; - }finally { + throw e; + } finally { EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); EmailLogManager.getInstance().setConnectLogEvent(connectEvent); //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 @@ -535,11 +529,129 @@ public class EmailServiceManager { * 当计数大于10000后从0开始,服务重启后也从0开始 */ public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException { + synchronized (downloadEmlLocal) { + String subject = ""; + File emlFile = null; + String status = EmailLogManager.STATUS_SUCCESS; + Date receivedDate = null; + InputStream inputStream = null; + BufferedOutputStream outputStream = null; + try { + //获取发件人 + final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); + final String from = address.substring(0,address.indexOf(StringConstant.AT)); + //获取主题 + subject = MimeUtility.decodeText(message.getSubject()); + if(subject.indexOf(StringConstant.SLASH) != -1){ + subject = StringUtils.replace(subject,StringConstant.SLASH,""); + } + if(subject.indexOf(StringConstant.COLON) != -1){ + subject = StringUtils.replace(subject,StringConstant.COLON,""); + } + receivedDate = message.getReceivedDate(); + StringBuilder fileName = new StringBuilder(); + fileName.append(from); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(subject); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append("receive"); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(emailCounter); + fileName.append(SAVE_EML_SUFFIX); + final String rootPath = spectrumPathProperties.getRootPath(); + final String emlPath = spectrumPathProperties.getEmlPath(); + emlFile = new File(rootPath+emlPath+File.separator+fileName); +// outputStream = new FileOutputStream(emlFile); +// message.writeTo(outputStream); + + int bufferSize = 1024 * 1024; // 1M + inputStream = message.getInputStream(); + outputStream = new BufferedOutputStream(new FileOutputStream(emlFile), bufferSize); + // 从邮件的输入流读取内容,并写入到本地文件 + byte[] buffer = new byte[bufferSize]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + } catch (MessagingException | IOException e) { + // 下载邮件失败 抛出自定义邮件下载异常 + status = EmailLogManager.STATUS_ERROR; + String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); + log.error(errorMsg); + throw new DownloadEmailException(errorMsg); + }catch (Exception e) { + log.error("",e); + }finally { + EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), + (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); + EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); + try { + if (Objects.nonNull(inputStream)) { + inputStream.close(); + } + if (Objects.nonNull(outputStream)) { + outputStream.flush(); + outputStream.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return emlFile; + } + } + + /*public File downloadEmailToEmlDir(@NotNull Message message, Integer emailCounter, Integer batchesCounter) throws MessagingException, IOException { + AtomicReference outputStream = new AtomicReference<>(); + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + try { + lock.lock(); // 获取锁 + // 执行需要获取锁才能进行的操作 + // return executeWithLock(message, emailCounter, batchesCounter); + File file = executeWithLock(message, emailCounter, batchesCounter); + outputStream.set(new FileOutputStream(file)); + a(outputStream,message); + return null; + } catch (MessagingException e) { + throw new RuntimeException(e); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + // 如果成功拿到锁 释放锁 + lock.unlock(); + } + }); + + try { + return future.get(5, TimeUnit.SECONDS); + // return future.get(5, TimeUnit.SECONDS);// 等待任务执行,超过5秒则抛出TimeoutException + } catch (InterruptedException | ExecutionException | TimeoutException e) { + future.cancel(true); // 取消任务执行 + if (ObjectUtil.isNotNull(outputStream) && ObjectUtil.isNotNull(outputStream.get())) + outputStream.get().close(); + log.error("下载 eml 执行超时", e); + throw new RuntimeException("下载 eml 执行超时"); + } + }*/ + public File executeWithLock(Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException { + String subject = ""; File emlFile = null; String status = EmailLogManager.STATUS_SUCCESS; Date receivedDate = null; try { + // 获取锁 设置超时 //获取发件人 final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); final String from = address.substring(0,address.indexOf(StringConstant.AT)); @@ -571,45 +683,22 @@ public class EmailServiceManager { fileName.append(SAVE_EML_SUFFIX); final String rootPath = spectrumPathProperties.getRootPath(); final String emlPath = spectrumPathProperties.getEmlPath(); - emlFile = new File(rootPath + emlPath + File.separator + fileName); - /* 如果邮件内容经过Base64编码 需要解码后再生成.eml文件 否则直接生成.eml文件 */ - // 先将邮件的内容保存为.eml文件 - // message.writeTo(Files.newOutputStream(emlFile.toPath())); - FileUtil.writeFromStream(message.getInputStream(), emlFile); - // 判断是否需要对正文内容进行解码 - // String content = (String) message.getContent(); - String content = FileUtil.readUtf8String(emlFile); - List contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL)); - // 如果邮件正文被|分割为4部分 说明邮件内容经过了编码 尝试进行解码 - if (contents.size() == 4){ - contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL_CHAR, 2)); - String md5 = contents.get(0); - content = contents.get(1); - // 去除可能产生的多余的空格 否则影响MD5的生成结果 - content = StrUtil.cleanBlank(content); - String md5Verified = MD5.create().digestHex(content); - // 如果md5验证失败 则不进行解码 - if (!StrUtil.equals(md5, md5Verified)) return emlFile; - contents = ListUtil.toList(StrUtil.split(content, SymbolConstant.VERTICAL)); - String base64 = contents.get(contents.size() - 1); - // 解码Base64字符串 并用解码后的内容覆盖原始文件内容 - byte[] data = Base64.decode(base64); - try (OutputStream out = Files.newOutputStream(emlFile.toPath()); - InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out)) { - inflaterOutputStream.write(data); - } catch (Exception e) { - log.error("Decoded the Base64 eml file[{}] error: {}", emlFile.getAbsolutePath(), e.getMessage()); - } - } + emlFile = new File(rootPath+emlPath+File.separator+fileName); + // Thread.sleep(6000l); + // try(FileOutputStream outputStream = new FileOutputStream(emlFile)) { + // message.writeTo(outputStream); + // } catch (IOException e) { + // throw new RuntimeException(e); + // } } catch (MessagingException | IOException e) { // 下载邮件失败 抛出自定义邮件下载异常 status = EmailLogManager.STATUS_ERROR; String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); log.error(errorMsg); throw new DownloadEmailException(errorMsg); - }catch (Exception e) { - log.error("The email download failed: {}", e.getMessage()); - }finally { + } catch (Exception e) { + log.error("",e); + } finally { EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); @@ -617,6 +706,9 @@ public class EmailServiceManager { return emlFile; } + public void a(AtomicReference outputStream, Message message) throws MessagingException, IOException { + message.writeTo(outputStream.get()); + } /** * 删除邮件 * @param message @@ -630,11 +722,12 @@ public class EmailServiceManager { subject = MimeUtility.decodeText(message.getSubject()); receivedDate = message.getReceivedDate(); message.setFlag(Flags.Flag.DELETED,true); -// log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); + // log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); } catch (MessagingException | UnsupportedEncodingException e) { status = EmailLogManager.STATUS_ERROR; log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage()); e.printStackTrace(); + log.error(e.getMessage(), e); }finally { EmailLogEvent removeEvent = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.DELETEID,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS")); EmailLogManager.getInstance().offer(Thread.currentThread().getId(),removeEvent); @@ -656,6 +749,7 @@ public class EmailServiceManager { if(null != store){ store.close(); } + log.info(Thread.currentThread().getName() + ",EmailServiceManage资源关闭完成."); // for(String messageId : messageIds){ // String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; // redisUtil.del(key); @@ -663,6 +757,7 @@ public class EmailServiceManager { } catch (MessagingException e) { log.error("Email closure failed, email address is: {}, reason is: {}",email.getUsername(),e.getMessage()); e.printStackTrace(); + log.error(e.getMessage(), e); } } @@ -676,7 +771,7 @@ public class EmailServiceManager { try { String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0; -// exist = redisUtil.hasKey(key); + // exist = redisUtil.hasKey(key); if(numberKey >= taskProperties.getForceDeletedNumber()){ exist = true; log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java index 0e16b41e..c5c85095 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java @@ -281,39 +281,74 @@ public class FTPUtil { /** * 写入文件,若文件或文件目录不存在则自行创建 * @param filePath 文件路径 - * @param fileName 文件名称 * @param inputStream 文件输入流 * @return 返回值true/false */ - public synchronized boolean saveFile(String filePath,String fileName,InputStream inputStream){ - final FTPClient ftpClient = this.LoginFTP(); - try{ - final boolean flag = this.checkDirectory(ftpClient,filePath); - if(flag){ - ftpClient.setFileType(FTP.BINARY_FILE_TYPE); - String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1); - final boolean result = ftpClient.storeFile(encodedName, inputStream); - return result; + public synchronized boolean saveFile(String filePath, InputStream inputStream){ + //声明目标文件 + File targetFile = new File(filePath); + //创建输出流 + FileOutputStream outputStream = null; + try { + //获取父级路径 + File directory = targetFile.getParentFile(); + //判断父级路径是否存在 + if (!directory.exists()) { + directory.mkdirs(); } - }catch (IOException e){ - log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); - e.printStackTrace(); - return false; - }finally { - if(null != inputStream){ - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } + // 创建输出流对象并写入数据到文件 + outputStream = new FileOutputStream(targetFile); + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, length); } + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + // 关闭输入流和输出流 try { - ftpClient.disconnect(); + if (Objects.nonNull(inputStream)) { + inputStream.close(); + } + if (Objects.nonNull(outputStream)) { + outputStream.close(); + } } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e); } } - return false; + return true; +// final FTPClient ftpClient = this.LoginFTP(); +// try{ +// final boolean flag = this.checkDirectory(ftpClient,filePath); +// if(flag){ +// ftpClient.setFileType(FTP.BINARY_FILE_TYPE); +// String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1); +// final boolean result = ftpClient.storeFile(encodedName, inputStream); +// return result; +// } +// }catch (IOException e){ +// log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); +// e.printStackTrace(); +// return false; +// }finally { +// if(null != inputStream){ +// try { +// inputStream.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// try { +// ftpClient.disconnect(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// return false; } /** @@ -458,65 +493,85 @@ public class FTPUtil { /* * 将源FTP路径的文件保存为指定路径的临时文件 * */ - public File downloadFile(String fromPath, String toPath) { - FTPClient ftpClient = null; - InputStream inputStream = null; - // 声明一个临时文件 - File tempFile = null; - try { - ftpClient = LoginFTP(); - // 切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - inputStream = ftpClient.retrieveFileStream(fromPath); - if (Objects.nonNull(inputStream)) { - tempFile = File.createTempFile(toPath, null); - // 将FTP文件的输入流复制给临时文件 - FileUtils.copyInputStreamToFile(inputStream, tempFile); - } - return tempFile; - } catch (IOException e) { - e.printStackTrace(); - return null; - } finally { - try { - if (ObjectUtil.isNotNull(ftpClient)) - ftpClient.disconnect(); - if (ObjectUtil.isNotNull(inputStream)) - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } + public File downloadFile(String fromPath) { + //获取路径下的文件信息 + File tempFile = new File(fromPath); + //判断文件是否存在 + if (!tempFile.exists()) { + tempFile = null; } + return tempFile; +// FTPClient ftpClient = null; +// InputStream inputStream = null; +// // 声明一个临时文件 +// File tempFile = null; +// try { +// //连接ftp +// ftpClient = LoginFTP(); +// // 切换被动模式 +// ftpClient.enterLocalPassiveMode(); +// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); +// // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 +// ftpClient.setControlEncoding("UTF-8"); +// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); +// inputStream = ftpClient.retrieveFileStream(fromPath); +// if (Objects.nonNull(inputStream)) { +// tempFile = File.createTempFile(toPath, null); +// // 将FTP文件的输入流复制给临时文件 +// FileUtils.copyInputStreamToFile(inputStream, tempFile); +// } +// return tempFile; +// } catch (IOException e) { +// e.printStackTrace(); +// return null; +// } finally { +// try { +// if (ObjectUtil.isNotNull(ftpClient)) +// ftpClient.disconnect(); +// if (ObjectUtil.isNotNull(inputStream)) +// inputStream.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } } /* * 将源FTP路径的文件转换为文件流 * */ public InputStream downloadFileStream(String fromPath) { - FTPClient ftpClient = null; + //获取路径下的文件信息 + File tempFile = new File(fromPath); + InputStream inputStream = null; try { - ftpClient = LoginFTP(); - // 切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - return ftpClient.retrieveFileStream(fromPath); - } catch (IOException e) { - e.printStackTrace(); - return null; - } finally { - try { - if (ObjectUtil.isNotNull(ftpClient)) - ftpClient.disconnect(); - } catch (IOException e) { - e.printStackTrace(); + //判断文件是否存在 + if (tempFile.exists()) { + inputStream = new FileInputStream(tempFile); } + return inputStream; + } catch (FileNotFoundException e) { + throw new RuntimeException(e); } +// FTPClient ftpClient = null; +// try { +// ftpClient = LoginFTP(); +// // 切换被动模式 +// ftpClient.enterLocalPassiveMode(); +// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); +// // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 +// ftpClient.setControlEncoding("UTF-8"); +// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); +// return ftpClient.retrieveFileStream(fromPath); +// } catch (IOException e) { +// e.printStackTrace(); +// return null; +// } finally { +// try { +// if (ObjectUtil.isNotNull(ftpClient)) +// ftpClient.disconnect(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SystemType.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SystemType.java index 9bd0b84e..e3e78b9e 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SystemType.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/SystemType.java @@ -15,9 +15,13 @@ public enum SystemType { */ GAMMA("G"), /** - * 自建台站 + * 自建台站 β-γ */ - SELFSTATION("C"); + SELFSTATION("C"), + /** + * 海水系统 γ + */ + WATER("W"); private String type; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/CalculateConcController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/CalculateConcController.java deleted file mode 100644 index 0c6cafba..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/CalculateConcController.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.jeecg.modules.controller; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.jeecg.modules.service.CalculateConcService; -import org.jeecg.modules.service.IAlarmAnalysisNuclideParamService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Api(value = "定时计算核素浓度" ,tags="定时计算核素浓度") -@RestController -@RequestMapping("calculateConc") -public class CalculateConcController { - - @Autowired - private CalculateConcService calculateConcService; - - @GetMapping("caclAndSave") - @ApiOperation(value = "计算并保存核素浓度",notes = "计算并保存核素浓度") - public void caclAndSave(){ - calculateConcService.calcAndSave(); - } - -} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java index 576588e2..7bf3492c 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java @@ -18,10 +18,8 @@ import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.enums.SampleType; -import org.jeecg.common.util.DataTool; -import org.jeecg.common.util.RedisStreamUtil; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.common.util.TemplateUtil; +import org.jeecg.common.util.*; +import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory; import org.jeecg.modules.base.dto.NuclideInfo; import org.jeecg.modules.base.dto.Info; import org.jeecg.modules.base.entity.postgre.AlarmAnalysisLog; @@ -45,6 +43,7 @@ import static org.jeecg.modules.base.enums.Template.ANALYSIS_NUCLIDE; import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -80,7 +79,7 @@ public class AnalysisConsumer implements StreamListener conditions = ListUtil.toList(conditionStr.split(COMMA)); List firstDetected = new ArrayList<>(); // 首次发现 List moreThanAvg = new ArrayList<>(); // 超浓度均值 List meanwhile = new ArrayList<>(); // 同时出现两种及以上核素 for (String con : conditions) { Condition condition = Condition.valueOf1(con); - if (ObjectUtil.isNotNull(condition)){ - switch (condition){ - case FIRST_FOUND: // 首次发现该元素 - firstDetected = firstDetected(betaOrGamma, datasource, nuclideNames); - break; - case ABOVE_AVERAGE: // 元素浓度高于均值 - moreThanAvg = moreThanAvg(datasource,nuclidesCross); - break; - case MEANWHILE: // 同时出现两种及以上核素 - if (CollUtil.isNotEmpty(nuclideNames) && nuclideNames.size() >= 2) - meanwhile.addAll(nuclideNames); - break; - default: - break; - } + if (ObjectUtil.isNull(condition)) continue; + switch (condition){ + case FIRST_FOUND: // 首次发现该元素 + firstDetected = firstDetected(betaOrGamma, datasource, nuclideNames); + break; + case ABOVE_AVERAGE: // 元素浓度高于均值 + moreThanAvg = moreThanAvg(datasource, stationId, collDate, nuclidesCross); + break; + case MEANWHILE: // 同时出现两种及以上核素 + if (CollUtil.isNotEmpty(nuclideNames) && nuclideNames.size() >= 2) + meanwhile.addAll(nuclideNames); + break; + default: + break; } } // 构建预警信息 @@ -224,12 +228,12 @@ public class AnalysisConsumer implements StreamListener moreThanAvg(String dataSourceType, - Map nuclidesCross){ + private List moreThanAvg(String dataSourceType, String stationId, + LocalDate collDate, Map nuclidesCross){ List nuclideInfos = new ArrayList<>(); Set nuclideNames = nuclidesCross.keySet(); Map nuclideAvgs = nuclideAvgService - .list(nuclideNames, dataSourceType).stream() + .list(nuclideNames, dataSourceType, stationId, collDate).stream() .collect(Collectors.toMap(AlarmAnalysisNuclideAvg::getNuclide, AlarmAnalysisNuclideAvg::getVal)); for (Map.Entry nuclide : nuclidesCross.entrySet()) { @@ -249,25 +253,26 @@ public class AnalysisConsumer implements StreamListener readA1 = StreamMessageListenerContainer + /* 1.需要手动确认消费消息 */ + // 1.1 使用 register 方式 + StreamMessageListenerContainer.ConsumerStreamReadRequest readRequest = StreamMessageListenerContainer .StreamReadRequest - .builder(StreamOffset.create(warnKey, ReadOffset.lastConsumed())) - .consumer(Consumer.from(groupWarnA, consumerWarnA1)) + .builder(StreamOffset.create(analysisKey, ReadOffset.lastConsumed())) + .consumer(Consumer.from(analysisGroup, analysisConsumer)) + // 手动确认消费了消息 默认为自动确认消息 .autoAcknowledge(false) - // 如果消费者发生了异常,是否禁止消费者消费 + // 如果消费者发生了异常 不禁止消费者消费 默认为禁止 .cancelOnError(throwable -> false) .build(); - ConsumeA1 consumeA1 = new ConsumeA1(groupWarnA, consumerWarnA1); - streamMessageListenerContainer.register(readA1, consumeA1);*/ - AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup,analysisConsumer); + AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup, analysisConsumer); + streamMessageListenerContainer.register(readRequest, analysis); + // 1.2 使用 receive 方式 + /*AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup, analysisConsumer); streamMessageListenerContainer.receive(Consumer.from(analysisGroup, analysisConsumer), - StreamOffset.create(analysisKey, ReadOffset.lastConsumed()), analysis); - // 创建消费组A中的消费者A2,自动ACK - /* ConsumeA2 consumeA2 = new ConsumeA2(consumerWarnA2); - streamMessageListenerContainer.receiveAutoAck(Consumer.from(groupWarnA, consumerWarnA2), - StreamOffset.create(warnKey, ReadOffset.lastConsumed()), consumeA2);*/ + StreamOffset.create(analysisKey, ReadOffset.lastConsumed()), analysis);*/ + /* 2.自动确认消费消息 */ + // 2.1 使用 receive 方式 + /*AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup,analysisConsumer); + streamMessageListenerContainer.receiveAutoAck(Consumer.from(analysisGroup, analysisConsumer), + StreamOffset.create(analysisKey, ReadOffset.lastConsumed()), analysis);*/ return streamMessageListenerContainer; } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java index 70199b04..a9afd7a9 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java @@ -6,12 +6,14 @@ import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.bizVo.NuclideAvgVo; +import java.time.LocalDate; import java.util.List; import java.util.Set; public interface IAlarmAnalysisNuclideAvgService extends IService { - List list(Set nuclideNames,String dataSourceType); + List list(Set nuclideNames, String dataSourceType, + String stationId, LocalDate collDate); Page findPage(NuclideAvgVo nuclideAvgVo); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java index 2659c56d..71d23713 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.Set; @@ -27,13 +28,15 @@ public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl list(Set nuclideNames,String dataSourceType) { - LocalDate dayAgo = LocalDate.now().minusDays(1); + public List list(Set nuclideNames, String dataSourceType, + String stationId, LocalDate collDate) { + LocalDate dayAgo = collDate.minusDays(1); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(AlarmAnalysisNuclideAvg::getDataSourceType,dataSourceType); - wrapper.eq(AlarmAnalysisNuclideAvg::getCaclDate,dayAgo); + wrapper.eq(AlarmAnalysisNuclideAvg::getStationId, stationId); + wrapper.eq(AlarmAnalysisNuclideAvg::getDataSourceType, dataSourceType); + wrapper.eq(AlarmAnalysisNuclideAvg::getCaclDate, dayAgo); wrapper.in(AlarmAnalysisNuclideAvg::getNuclide,nuclideNames); - return list(wrapper); + return this.list(wrapper); } @Override diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index 9460d44d..2574ec35 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -15,7 +15,6 @@ import org.jeecg.modules.spectrum.SpectrumServiceQuotes; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.io.*; import java.util.*; import java.util.concurrent.TimeUnit; @@ -120,6 +119,7 @@ public class AutoProcessManager{ TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { e.printStackTrace(); + log.error(e.getMessage(), e); } } } @@ -158,7 +158,7 @@ public class AutoProcessManager{ //如果这时邮箱线程里已有执行的线程则设置停止标记 if(emailExecThreadMap.containsKey(email.getId())){ EmailParsingActuator actuator = emailExecThreadMap.get(email.getId()); - actuator.setStop(true); + actuator.setThreadSleep(true); actuator.setStopTime(new Date()); } log.info("{}邮箱测试连接失败,emailMap删除此邮箱数据,emailExecThreadMap设置线程停止标记",email.getUsername()); @@ -169,6 +169,7 @@ public class AutoProcessManager{ //捕获异常不处理保障线程异常不退出 }catch (Exception e){ e.printStackTrace(); + log.error(e.getMessage(), e); } long end = System.currentTimeMillis(); long sleepTime = taskProperties.getMonitoringMailCommStatusCycle() - (end-start); @@ -178,6 +179,7 @@ public class AutoProcessManager{ TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { e.printStackTrace(); + log.error(e.getMessage(), e); } } } @@ -235,7 +237,7 @@ public class AutoProcessManager{ if(testFlag){ if (emailExecThreadMap.containsKey(databaseEmail.getId())) { EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId()); - actuator.setStop(false); + actuator.setThreadSleep(false); log.info("{}邮箱重新加入监测队列",databaseEmail.getUsername()); } else { databaseEmail.setNewEmailFlag(true); @@ -251,6 +253,7 @@ public class AutoProcessManager{ //捕获异常不处理保障线程异常不退出 }catch (Exception e){ e.printStackTrace(); + log.error(e.getMessage(), e); } long end = System.currentTimeMillis(); long sleepTime = taskProperties.getMonitoringMailDataCycle() - (end-start); @@ -260,6 +263,7 @@ public class AutoProcessManager{ TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { e.printStackTrace(); + log.error(e.getMessage(), e); } } } @@ -304,6 +308,7 @@ public class AutoProcessManager{ } }catch (Exception e){ e.printStackTrace(); + log.error(e.getMessage(), e); }finally { if(emailExecThread.getState() != State.TERMINATED && emailExecThread.isStop()){ final long nowTime = System.currentTimeMillis(); @@ -325,6 +330,7 @@ public class AutoProcessManager{ TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { e.printStackTrace(); + log.error(e.getMessage(), e); } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 67983395..93ec8fa4 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -17,10 +17,7 @@ import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.concurrent.*; /** @@ -39,6 +36,8 @@ public class EmailParsingActuator extends Thread{ @Setter @Getter private boolean isStop; @Setter @Getter + private boolean threadSleep; + @Setter @Getter private Date stopTime; public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes, @@ -65,8 +64,17 @@ public class EmailParsingActuator extends Thread{ @Override public void run() { for(;;){ + String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); + if (threadSleep) { + log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is sleep!"); + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + log.error("Thread sleep error"); + } + continue; + } if (isStop) { - String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is Stop!"); closeResource(); return; @@ -78,10 +86,14 @@ public class EmailParsingActuator extends Thread{ List messageIds = new ArrayList<>(); try { Message[] messages = emailServiceManager.receiveMail(); + log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), ArrayUtils.isEmpty(messages) ? 0 : messages.length); if(ArrayUtils.isNotEmpty(messages)){ - log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), messages.length); //检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除 for(int i=messages.length-1;i>=0;i--){ + if (null == messages[i].getHeader("Message-ID")) { + messages = ArrayUtils.remove(messages, i); + continue; + } if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); final boolean exist = emailServiceManager.check(messages[i],messageId); @@ -103,11 +115,14 @@ public class EmailParsingActuator extends Thread{ poolExecutor.execute(spectrumParsingActuator); } taskLatch.await(); + log.info("EmailParsingActuator本次{}封邮件处理完成", messages.length); } } - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (MessagingException e) { + } catch (Exception e) { + log.error("EmailParsingActuator has exception: {}", e.getMessage()); + log.info("Mail-Parsing线程池资源关闭..."); + closeResource(); + log.error(e.getMessage(), e); throw new RuntimeException(e); } finally { //清除本批次邮件日志缓存 @@ -128,6 +143,8 @@ public class EmailParsingActuator extends Thread{ TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { e.printStackTrace(); + log.error(e.getMessage(), e); + throw new RuntimeException(); } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java index 5a2d3d6a..b5b77ac7 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java @@ -84,7 +84,8 @@ public class GardsSampleDataServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(GardsSampleData::getInputFileName,inputFileName); final GardsSampleData sampleData = this.getOne(queryWrapper); - if(Objects.nonNull(sampleData) && !SampleStatus.COMPLETE.getValue().equals(sampleData.getStatus())){ + if(Objects.nonNull(sampleData) && !SampleStatus.COMPLETE.getValue().equals(sampleData.getStatus()) + && !SampleStatus.INTERACTIVE.getValue().equals(sampleData.getStatus())){ this.baseMapper.updateStatus(status,inputFileName); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java index 0e062852..d824459e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java @@ -17,7 +17,10 @@ import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.eneity.event.SpectrumLog; import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.enums.SpectrumSource; -import org.jeecg.modules.exception.*; +import org.jeecg.modules.exception.AnalySpectrumException; +import org.jeecg.modules.exception.AnalyseException; +import org.jeecg.modules.exception.FileRepeatException; +import org.jeecg.modules.exception.HeaderBlockException; import org.jeecg.modules.file.FileOperation; import java.io.File; import java.io.FileNotFoundException; @@ -313,7 +316,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { ex.printStackTrace(); } } else if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource) && (e instanceof FileRepeatException)){ - this.spectrumFile.delete(); + //this.spectrumFile.delete(); // TODO 删除原始谱文件 } else if (SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)) { try { if (isDateFormatErr) { diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index a88f07ad..5548ba1e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -97,9 +97,6 @@ public class SpectrumParsingActuator implements Runnable{ String emlName = subject+ StringConstant.UNDER_LINE+ receiveDate; String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; // spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime); - //判断当前key的下载次数是否超过限制次数 - spectrumServiceQuotes.getRedisUtil().incr(key, 1L); - spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime); //线程开始初始化时,初始本线程负责的能谱日志事件 SpectrumLogManager.mailSpectrumLogManager.offer(Thread.currentThread().getId(),null); @@ -144,7 +141,10 @@ public class SpectrumParsingActuator implements Runnable{ log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); } emailServiceManager.removeMail(message,batchesCounter); - }else { + } else { + //判断当前key的下载次数是否超过限制次数 + spectrumServiceQuotes.getRedisUtil().incr(key, 1L); + spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime); // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError if (Objects.nonNull(emlFile) && emlFile.exists()){ moveEmail(emlFile, key); diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java index 3da16c3f..97b7889c 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java @@ -70,9 +70,9 @@ public class GammaFileUtil extends AbstractLogOrReport { //如果功能是人工交互模块则从ftp获取文件内容 File file = null; if (sysSource.equals("BetaGamma")) { - file = ftpUtil.downloadFile(fromPath, "betaGamma"); + file = ftpUtil.downloadFile(fromPath); if (Objects.isNull(file)) { - result.error500("ftp file can't find"); + result.error500("file can't find"); return false; } } else if (sysSource.equals("AUTO")) {//如果是自动处理则从本地文件中获取文件内容 @@ -265,7 +265,7 @@ public class GammaFileUtil extends AbstractLogOrReport { try { String lcFileName = prefixName+"_"+subFileName + ".lc"; String fromPathLc = pathName + StringPool.SLASH + lcFileName; - lcFile = ftpUtil.downloadFile(fromPathLc, "betaGamma"); + lcFile = ftpUtil.downloadFile(fromPathLc); if (Objects.nonNull(lcFile)) { List readLinesLc = FileUtils.readLines(lcFile, "UTF-8"); //得到行数据处理后的数据结果 @@ -275,7 +275,7 @@ public class GammaFileUtil extends AbstractLogOrReport { } String scacFileName = prefixName+"_"+subFileName + ".scac"; String fromPathScac = pathName + StringPool.SLASH + scacFileName; - scacFile = ftpUtil.downloadFile(fromPathScac, "betaGamma"); + scacFile = ftpUtil.downloadFile(fromPathScac); if (Objects.nonNull(scacFile)) { List readLinesScac = FileUtils.readLines(scacFile, "UTF-8"); //得到行数据处理后的数据结果 @@ -298,10 +298,6 @@ public class GammaFileUtil extends AbstractLogOrReport { try { if (ObjectUtil.isNotNull(inputStreamBase)) inputStreamBase.close(); - if (ObjectUtil.isNotNull(lcFile)) - lcFile.delete(); - if (ObjectUtil.isNotNull(scacFile)) - scacFile.delete(); } catch (IOException e) { e.printStackTrace(); } @@ -3234,8 +3230,10 @@ public class GammaFileUtil extends AbstractLogOrReport { File sampleTmp = null; try { sampleTmp = new File(fileAnlyse.getTmpFilePath()); - if (Objects.nonNull(sampleTmp)) { - bRet = ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath.substring(0, middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH)), middleData.analyses_save_filePath.substring(middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH)+1), new FileInputStream(sampleTmp)); + //sample文件的存储路径 + String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath; + if (Objects.nonNull(sampleTmp) && !saveSamplePath.equals(fileAnlyse.getTmpFilePath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { + bRet = ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); } } catch (FileNotFoundException e) { throw new RuntimeException(e); @@ -4369,7 +4367,7 @@ public class GammaFileUtil extends AbstractLogOrReport { public File analyzeFile(String path, String fileName) { path = path.replace("\\", "/"); String fromPath = path + StringPool.SLASH + fileName; - return ftpUtil.downloadFile(fromPath, "betaGamma"); + return ftpUtil.downloadFile(fromPath); } public List readLine(String filePath) { diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java index bf783238..9b2ff809 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java @@ -2,7 +2,9 @@ package org.jeecg.modules.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.jeecg.common.api.vo.Result; import org.jeecg.common.util.FTPUtil; +import org.jeecg.modules.base.bizVo.FileVo; import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.service.ILogManageService; @@ -20,31 +22,24 @@ import java.util.List; @Api(value = "日志管理", tags = "日志管理") public class LogManageController { - @Autowired - private FTPUtil ftpUtil; @Autowired private ILogManageService logManageService; @GetMapping("findFtpFolders") @ApiOperation(value = "查询日志文件夹树形结构", notes = "查询日志文件夹树形结构") public List findFtpFolders(String workPath) { - return logManageService.findFtpFolders(workPath); + return logManageService.fileTree(workPath); } - /** - * 查询目录下文件内容 - * @param path - * @return - */ @GetMapping("findFiles") @ApiOperation(value = "查询目录下文件内容", notes = "查询目录下文件内容") - public List findFiles(String path) { - return logManageService.findFiles(path); + public Result findFiles(String path, FileVo fileVo) { + return logManageService.findFiles(path, fileVo); } @PostMapping("downloadFile") @ApiOperation(value = "ftp文件下载", notes = "ftp文件下载") - public void downloadFile(String localPath, String fileName, HttpServletResponse response) { - ftpUtil.downloadFTPFile(localPath, response); + public void downloadFile(String localPath, HttpServletResponse response) { + logManageService.downloadFile(localPath, response); } } diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java index bab2dce0..5a073fc1 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java @@ -1,24 +1,24 @@ package org.jeecg.modules.service; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.bizVo.FileVo; import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.LogManage; +import javax.servlet.http.HttpServletResponse; import java.util.List; public interface ILogManageService { /** * 查询日志文件夹树形结构 - * @param workPath - * @return */ - List findFtpFolders(String workPath); + List fileTree(String workPath); /** * 查询目录下文件内容 - * @param path - * @return */ - List findFiles(String path); + Result findFiles(String path, FileVo fileVo); + void downloadFile(String localPath, HttpServletResponse response); } diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java index 3138b956..33fc1c18 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java @@ -1,192 +1,159 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.Prompt; +import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.FTPUtil; +import org.jeecg.common.util.ExportUtil; +import org.jeecg.common.util.PageUtil; +import org.jeecg.modules.base.bizVo.FileVo; import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.service.ILogManageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.*; +import java.util.stream.Collectors; -@Service("logManageService") +@Slf4j +@Service public class LogManageServiceImpl implements ILogManageService { @Autowired - private FTPUtil ftpUtil; + private SpectrumPathProperties spectrumPath; @Override - public List findFtpFolders(String workPath) { + public List fileTree(String workPath) { List result = new ArrayList<>(); - FTPClient ftpClient = ftpUtil.LoginFTP(); - if(Objects.isNull(ftpClient)){ - throw new RuntimeException("ftp connection failed!"); + workPath = spectrumPath.getRootPath() + StringPool.SLASH + workPath; + List files = ListUtil.toList(FileUtil.ls(workPath)); + if (CollUtil.isEmpty(files)) return result; + int num = 1; + for (File file : files) { + LogManage logManage = new LogManage(); + logManage.setName(file.getName()); + logManage.setOrderNum(num++); + logManage.setPath(workPath + StringPool.SLASH + file.getName()); + List children = this.getChildren(logManage); + logManage.setHashChild(CollUtil.isNotEmpty(children)); + logManage.setChildren(children); + result.add(logManage); } - try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - //切换工作文件路径 - workPath = ftpUtil.getFtpRootPath()+StringPool.SLASH+workPath; - ftpClient.changeWorkingDirectory(workPath); - List ftpFiles = Arrays.asList(ftpClient.listDirectories()); - if (CollectionUtils.isNotEmpty(ftpFiles)){ - int num =1; - for (FTPFile ftpFile:ftpFiles) { - LogManage logManage = new LogManage(); - logManage.setName(ftpFile.getName()); - logManage.setOrderNum(num); - logManage.setParentNum(0); - logManage.setPath(workPath + StringPool.SLASH + ftpFile.getName()); - result.add(logManage); - num++; - } - } - if (CollectionUtils.isNotEmpty(result)){ - List list = new LinkedList<>(); - for (LogManage logManage:result) { - list = this.findDirectory(ftpClient, list, logManage.getOrderNum(), workPath + StringPool.SLASH + logManage.getName() , logManage.getName()); - ftpClient.changeToParentDirectory(); - } - result.addAll(list); - } - - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - try { - if (ftpClient != null){ - ftpClient.disconnect(); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - result = this.LogManageTree(result); return result; } @Override - public List findFiles(String path) { - List result = new ArrayList<>(); - FTPClient ftpClient = ftpUtil.LoginFTP(); - if (Objects.isNull(ftpClient)){ - throw new RuntimeException("ftp connection failed!"); + public Result findFiles(String path, FileVo fileVo) { + String name = fileVo.getName(); + Integer pageNo = fileVo.getPageNo(); + Integer pageSize = fileVo.getPageSize(); + Page page = new Page<>(pageNo, pageSize); + List files = CollUtil.toList(FileUtil.ls(path)); + // 文件名过滤 + if (StrUtil.isNotBlank(name)) + files = files.stream().filter(file -> StrUtil.containsIgnoreCase(file.getName(), name)) + .collect(Collectors.toList()); + page.setTotal(files.size()); + // 分页 + files = PageUtil.page(pageNo, pageSize, files); + List records = new ArrayList<>(); + for (File file : files) { + if (FileUtil.isDirectory(file)) continue; + FileInfo fileInfo = new FileInfo(); + fileInfo.setFileName(file.getName()); + fileInfo.setFilePath(path + StringPool.SLASH + file.getName()); + fileInfo.setFileSize(FileUtil.readableFileSize(file)); + fileInfo.setFileDate(DateUtil.formatDateTime(FileUtil.lastModifiedTime(file))); + records.add(fileInfo); } + page.setRecords(records); + return Result.OK(page); + } + + @Override + public void downloadFile(String localPath, HttpServletResponse response) { + OutputStream outputStream = null; + InputStream inputStream = null; try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - //切换工作文件路径 - ftpClient.changeWorkingDirectory(path); - List ftpFiles = Arrays.asList(ftpClient.listFiles()); - if (CollectionUtils.isNotEmpty(ftpFiles)){ - for (FTPFile ftpFile:ftpFiles) { - if (ftpFile.isFile()){ - FileInfo fileInfo = new FileInfo(); - fileInfo.setFileName(ftpFile.getName()); - fileInfo.setFilePath(path + StringPool.SLASH + ftpFile.getName()); - fileInfo.setFileSize(String.format("%.2f", Double.valueOf(Double.valueOf(ftpFile.getSize())/1024)) + "KB"); - fileInfo.setFileDate(DateUtils.formatDate(ftpFile.getTimestamp(),"yyyy-MM-dd")); - result.add(fileInfo); - } - } + // 如果是目录 则直接退出方法 + if (FileUtil.isDirectory(localPath)) return; + + // 判断是否存在此文件 + if (!FileUtil.exist(localPath)) return; + + // 获取文件名 + String fileName = FileUtil.getName(localPath); + + inputStream = FileUtil.getInputStream(localPath); + outputStream = ExportUtil.stream(response, fileName); + + // 缓冲区大小 + byte[] buffer = new byte[4096]; + int bytesRead; + + // 将文件输出流写入到输出流中 + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); } } catch (IOException e) { - throw new RuntimeException(e); + log.error("文件{}下载失败 :{}", localPath, e.getMessage()); } finally { try { - if (ftpClient != null){ - ftpClient.disconnect(); - } + if (ObjectUtil.isNotNull(inputStream))inputStream.close(); + if (ObjectUtil.isNotNull(outputStream))outputStream.close(); } catch (IOException e) { - throw new RuntimeException(e); + e.printStackTrace(); } } - return result; } /** - * 遍历查询当前路径下的文件夹信息 - * @param ftpClient - * @param list - * @param filePath 以"/"开始和结束 - * @return + * 获取当前目录节点所有子孙节点Tree */ - public List findDirectory(FTPClient ftpClient, List list, Integer parentNum, String filePath, String fileName){ - try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.changeWorkingDirectory(fileName); - List ftpFiles = Arrays.asList(ftpClient.listDirectories()); - if (CollectionUtils.isNotEmpty(ftpFiles)){ - int num = 1; - for (FTPFile file : ftpFiles) { - if (file.isDirectory()) { - LogManage logManage = new LogManage(); - logManage.setName(file.getName()); - logManage.setOrderNum(parentNum*10+num); - logManage.setParentNum(parentNum); - logManage.setPath(filePath + StringPool.SLASH + file.getName()); - list.add(logManage); - // 需要加此判断。否则,ftp默认将‘项目文件所在目录之下的目录(./)’与‘项目文件所在目录向上一级目录下的目录(../)’都纳入递归,这样下去就陷入一个死循环了。需将其过滤掉。 - if (!".".equals(file.getName()) && !"..".equals(file.getName())) { - findDirectory(ftpClient, list, parentNum*10+num, filePath + StringPool.SLASH + file.getName(), file.getName()); - ftpClient.changeToParentDirectory(); - } - num++; - } - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - return list; - } - - /** - * 将当前的文件夹转换成树形结构 - * @param logManages - * @return - */ - public List LogManageTree(List logManages){ - if (logManages == null) { - return null; - } + private List getChildren(LogManage parent){ List result = new LinkedList<>(); - Integer TOP_NODE_ID = 0; - logManages.forEach(logManage -> { - Integer pid = logManage.getParentNum(); - if (pid == null || TOP_NODE_ID.equals(pid)) { - result.add(logManage); - return; - } - for (LogManage manage : logManages) { - Integer id = manage.getOrderNum(); - if (id != null && id.equals(pid)) { - if (manage.getChildren() == null) { - manage.initChildren(); - } - logManage.setHashParent(true); - manage.getChildren().add(logManage); - manage.setHashChild(true); - return; - } - } - }); + String parentPath = parent.getPath(); + // 如果是文件 则直接返回空集合 + if (FileUtil.isFile(parentPath)) return result; + List files = ListUtil.toList(FileUtil.ls(parentPath)); + // 如果当前目录不存在子文件 则返回空集合 + if (CollUtil.isEmpty(files)) return result; + int parentOrderNum = parent.getOrderNum(); + int num = parentOrderNum * 10 + 1; + for (File file : files) { + // 过滤掉文件 只收集目录 + if (FileUtil.isFile(file)) continue; + LogManage logManage = new LogManage(); + logManage.setName(file.getName()); + logManage.setOrderNum(num++); + logManage.setHashParent(true); + logManage.setParentNum(parentOrderNum); + logManage.setPath(parentPath + StringPool.SLASH + file.getName()); + List children = getChildren(logManage); + logManage.setHashChild(CollUtil.isNotEmpty(children)); + logManage.setChildren(children); + result.add(logManage); + } return result; } - } 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 94876f3e..4f7d35cb 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 @@ -817,7 +817,7 @@ public class PHDFileUtil extends AbstractLogOrReport { File file = null; try { String fromPath = filePath + StringPool.SLASH + sampleFileName; - file = ftpUtil.downloadFile(fromPath, "betaGamma"); + file = ftpUtil.downloadFile(fromPath); //加载sampleFile内容 EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); //获取所需要的数据 @@ -841,9 +841,6 @@ public class PHDFileUtil extends AbstractLogOrReport { }catch (Exception e){ e.printStackTrace(); return map; - }finally { - if (ObjectUtil.isNotNull(file)) - file.delete(); } } @@ -852,7 +849,7 @@ public class PHDFileUtil extends AbstractLogOrReport { File file = null; try { String fromPath = filePath + StringPool.SLASH + fileName; - file = ftpUtil.downloadFile(fromPath, "betaGamma"); + file = ftpUtil.downloadFile(fromPath); EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); String systemType = sourceData.system_type; String dataType = sourceData.data_type; @@ -886,9 +883,6 @@ public class PHDFileUtil extends AbstractLogOrReport { }catch (Exception e){ e.printStackTrace(); return path.toString(); - }finally { - if (ObjectUtil.isNotNull(file)) - file.delete(); } } @@ -1120,9 +1114,6 @@ public class PHDFileUtil extends AbstractLogOrReport { if (Objects.nonNull(inputStream)){ inputStream.close(); } - if (Objects.nonNull(file)) { - file.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/BetaDataFile.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/BetaDataFile.java index 92a31639..2de9f6e2 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/BetaDataFile.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/BetaDataFile.java @@ -41,6 +41,8 @@ public class BetaDataFile implements Serializable { private String stationId; + private String detectorId; + private boolean bProcessed; private boolean saveAnalysisResult; diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java index 761ca62a..42f90b0b 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java @@ -180,7 +180,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi return result; } // 切割数据库存储的文件路径获取路径信息 - String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); + String pathName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); // 切割数据库存储的文件路径获取文件名称 String fileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH) + 1); // 声明phd实体类 @@ -194,6 +194,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (!flag) { return result; } + if (Objects.nonNull(phd) && !phd.isValid()) { + result.error500("This Spectrum is invalid! it's counts are all zero"); + return result; + } // 加载phd数据所需的lc,scac,baseline数据 if (dbName.equals("auto")) { gammaFileUtil.SetBaseInfo(phd, "RNAUTO"); @@ -598,7 +602,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi Map map = new HashMap<>(); Cache phdCache = localCache.getPHDCache(); // 上传文件路径 - String path = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String path = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; // 获取当前角色的颜色配置 Map colorMap = sysUserColorService.initColor(userName); PHDFile phd = phdCache.getIfPresent(fileName + StringPool.DASH + userName); @@ -609,6 +613,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (!bRet) { return result; } + if (Objects.nonNull(phd) && !phd.isValid()) { + result.error500("This Spectrum is invalid! it's counts are all zero"); + return result; + } if (!redisUtil.hasKey(userName+StringPool.DASH+phd.getHeader().getSystem_type()) || !redisUtil.hasKey(userName+StringPool.DASH+phd.getHeader().getSystem_type()+"-list")) { //读取缓存的全部核素信息 Map allNuclideMap = (Map) redisUtil.get("AllNuclideMap"); @@ -671,12 +679,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi String key = fileName + StrUtil.DASHED + username; Cache phdCache = localCache.getPHDCache(); PHDFile phdFile = phdCache.getIfPresent(key); - if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) { - File file = new File(phdFile.getTmpFilePath()); - if (Objects.nonNull(file)) { - file.delete(); - } - } // 删除指定key的Cache localCache.deletePHDCache(key); } @@ -743,8 +745,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.error500("The comparison file path does not exist"); return result; } - compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath; - File compareFile = ftpUtil.downloadFile(compareFilePath, "betaGamma"); + compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath; + File compareFile = ftpUtil.downloadFile(compareFilePath); if (Objects.isNull(compareFile)) { result.error500("The comparison file path does not exist"); return result; @@ -756,7 +758,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(chartDataList); } - compareFile.delete(); return result; } @@ -776,9 +777,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi long m_nCount = phd.getSpec().getNum_g_channel(); List vEnergy = phd.getVEnergy(); //加载compare文件 - String compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; String fromPath = compareFilePath + StringPool.SLASH + compareFileName; - File compareFile = ftpUtil.downloadFile(fromPath, "betaGamma"); + File compareFile = ftpUtil.downloadFile(fromPath); if (Objects.nonNull(compareFile)) { // 获取Compare数据 List m_vecCompare = gammaFileUtil.loadCompareData(compareFile, userName, m_nCount, result); @@ -787,7 +788,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(chartDataList); } - compareFile.delete(); } return result; } @@ -827,8 +827,8 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.error500("The comparison file path does not exist"); return result; } - stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath; - File stripFile = ftpUtil.downloadFile(stripFilePath, "betaGamma"); + stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath; + File stripFile = ftpUtil.downloadFile(stripFilePath); if (Objects.isNull(stripFile)) { result.error500("The comparison file path does not exist"); return result; @@ -843,7 +843,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(stripMap); } - stripFile.delete(); return result; } @@ -877,9 +876,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi m_vCount.add(0L); } //加载strip文件 - String stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; String fromPath = stripFilePath + StringPool.SLASH + stripFileName; - File stripFile = ftpUtil.downloadFile(fromPath, "betaGamma"); + File stripFile = ftpUtil.downloadFile(fromPath); if (Objects.nonNull(stripFile)) { // 获取Compare数据 List m_vecCompare = gammaFileUtil.loadCompareData(stripFile, userName, m_nCount, result); @@ -891,7 +890,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(stripMap); } - stripFile.delete(); } return result; } @@ -1312,7 +1310,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi HashMap map = new HashMap<>(); // 根据boolean 决定是否保留本次数据 如果保留则不需要操作vPeak 并重新拟合线 if (accept) { - Map nuclideLinesMap = (Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); + Map nuclideLinesMap = phd.getPhdNuclideMap();//(Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); if (flag.equalsIgnoreCase("insert")) {// 如果传递的flag标识 是 Insert则进行峰值的插入 //重新赋值index for (int k=0; k peakNuclides = phd.getVPeak().get(curRow).nuclides; + if (peakNuclides.indexOf(nuclideName) < 0 ) { + peakNuclides.add(nuclideName); + } // 查询当前用户所关心的核素名称 Map mapNucLines = (Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); //用户当前缓存的核素信息 @@ -1714,8 +1715,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi } t_idx++; } + //重新计算核素的MDA值 gammaFileUtil.CalcNuclideMDA(phd, it_line, nuclideName, vPeakIdx); map.put("identify", list_identify); + //格式化核素表单内容 List vPeak = gammaFileUtil.InitPeakTable(phd.getVPeak()); map.put("table", vPeak); //如果当前缓存的谱核素信息不包含当前核素 @@ -3021,9 +3024,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (Objects.nonNull(inputStream)) { inputStream.close(); } - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } @@ -3295,9 +3295,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (Objects.nonNull(inputStream)) { inputStream.close(); } - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } @@ -3591,9 +3588,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (Objects.nonNull(inputStream)) { inputStream.close(); } - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } @@ -3956,7 +3950,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (StringUtils.isBlank(reportPath)) { throw new RuntimeException("The automatic handler generated report does not exist!"); } - String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; + String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; InputStream inputStream = null; ServletOutputStream outputStream = null; try { @@ -3990,7 +3984,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi public void exportARR(Integer sampleId, HttpServletResponse response) { // 获取自动处理生成的报告地址 String reportPath = spectrumAnalysisMapper.viewARR(sampleId); - String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; + String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; InputStream inputStream = null; ServletOutputStream outputStream = null; try { @@ -4590,7 +4584,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (StringUtils.isBlank(logPath)) { throw new RuntimeException("The log generated by the automatic processor does not exist!"); } - String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath; + String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath; InputStream inputStream = null; ServletOutputStream outputStream = null; try { @@ -4805,47 +4799,40 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi phd.setStatus("R"); //分析成功后存储日志文件和报告文件 String rootPath = spectrumPathProperties.getRootPath(); +// { +// File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath); +// try { +// FileInputStream in = new FileInputStream(baselineFile); +// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_baseline_absolute_filePath, in); +// } catch (FileNotFoundException e) { +// throw new RuntimeException(e); +// } +// } +// { +// File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath); +// try { +// FileInputStream in = new FileInputStream(lcFile); +// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_lc_absolute_filePath, in); +// } catch (FileNotFoundException e) { +// throw new RuntimeException(e); +// } +// } +// { +// File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath); +// try { +// FileInputStream in = new FileInputStream(scacFile); +// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_scac_absolute_filePath, in); +// } catch (FileNotFoundException e) { +// throw new RuntimeException(e); +// } +// } { - String baselinePathName = ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath.substring(0, middleData.analyses_baseline_absolute_filePath.lastIndexOf(StringPool.SLASH)); - String baselineFileName = middleData.analyses_baseline_absolute_filePath.substring(middleData.analyses_baseline_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1); - File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath); - try { - FileInputStream in = new FileInputStream(baselineFile); - ftpUtil.saveFile(baselinePathName, baselineFileName, in); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - { - String lcPathName = ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath.substring(0, middleData.analyses_lc_absolute_filePath.lastIndexOf(StringPool.SLASH)); - String lcFileName = middleData.analyses_lc_absolute_filePath.substring(middleData.analyses_lc_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1); - File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath); - try { - FileInputStream in = new FileInputStream(lcFile); - ftpUtil.saveFile(lcPathName, lcFileName, in); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - { - String scacPathName = ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath.substring(0, middleData.analyses_scac_absolute_filePath.lastIndexOf(StringPool.SLASH)); - String scacFileName = middleData.analyses_scac_absolute_filePath.substring(middleData.analyses_scac_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1); - File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath); - try { - FileInputStream in = new FileInputStream(scacFile); - ftpUtil.saveFile(scacPathName, scacFileName, in); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - { - String logPathName = middleData.analyses_absolute_LogPath.substring(0, middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)); String logFileName = middleData.analyses_absolute_LogPath.substring(middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1); File logFile = new File(logFileName); try { FileUtil.writeString(gammaFileUtil.GetLogContent(middleData), logFile, "UTF-8"); FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(logPathName, logFileName, in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { @@ -4853,13 +4840,12 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi } } { - String rptPathName = middleData.analyses_absolute_ReportPath.substring(0, middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)); String rptFileName = middleData.analyses_absolute_ReportPath.substring(middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt"; File rptFile = new File(rptFileName); try { FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(rptPathName, rptFileName, in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_ReportPath+".txt", in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { 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 51df6917..4ae9e817 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 @@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.cache.Cache; import com.google.common.collect.Maps; +import io.swagger.models.auth.In; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.shiro.SecurityUtils; @@ -43,6 +44,7 @@ import org.jeecg.modules.native_jni.struct.BgAnalyseResult; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.TemplateEngine; @@ -299,7 +301,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements Result result = new Result(); List> resultList = new LinkedList<>(); String userName = JwtUtil.getUserNameByToken(request); - String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH +userName; + String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH +userName; String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.PHD"; Pattern regexPattern = Pattern.compile(sampleRx); String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.\\d+\\.PHD"; @@ -497,9 +499,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setSampleId(String.valueOf(sampleId)); //判断sample信息是否存在 if (Objects.nonNull(sample)) { - betaDataFile.setSampleFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath()); + betaDataFile.setSampleFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath()); betaDataFile.setSampleFileName(sampleFileName); - sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName(), "betaGamma"); + sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName()); if (Objects.nonNull(sampleTmp)) { //sample临时文件路径存储 betaDataFile.setSampleTmpPath(sampleTmp.getAbsolutePath()); @@ -534,9 +536,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //判断gas信息是否存在 if (Objects.nonNull(gasBg)) { - betaDataFile.setGasFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath()); + betaDataFile.setGasFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath()); betaDataFile.setGasFileName(gasFileName); - gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName(), "betaGamma"); + gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName()); if (Objects.nonNull(gasTmp)) { //存储gas临时文件路径 betaDataFile.setGasTmpPath(gasTmp.getAbsolutePath()); @@ -571,9 +573,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //判断det信息是否存在 if (Objects.nonNull(detBg)) { - betaDataFile.setDetFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath()); + betaDataFile.setDetFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath()); betaDataFile.setDetFileName(detFileName); - detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName(), "betaGamma"); + detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName()); if (Objects.nonNull(detTmp)) { //存储det临时文件路径 betaDataFile.setDetTmpPath(detTmp.getAbsolutePath()); @@ -608,9 +610,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //判断qc信息是否存在 if (Objects.nonNull(qc)) { - betaDataFile.setQcFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath); + betaDataFile.setQcFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath); betaDataFile.setQcFileName(qcFileName); - qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName(), "betaGamma"); + qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName()); if (Objects.nonNull(qcTmp)) { betaDataFile.setQcTmpPath(qcTmp.getAbsolutePath()); EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(qcTmp.getAbsolutePath()); @@ -622,6 +624,13 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //更新缓存数据对应的缓存数据 phdFileUtil.createBgCalPara(betaDataFile, gammaCalibrationSpectrumList, betaCalibrationSpectrumList, gammaCalibrationPairsList, betaCalibrationPairsList); + //第一次加载时初始化数据库数据 + betaDataFile.setGammaCalibrationSpectrumEList(gammaCalibrationSpectrumList); + betaDataFile.setBetaCalibrationSpectrumEList(betaCalibrationSpectrumList); + betaDataFile.setRoiChannelsSpectrumList(roiChannelsSpectrumList); + betaDataFile.setRoiResultsSpectrumList(roiResultsSpectrumList); + betaDataFile.setGammaCalibrationPairsList(gammaCalibrationPairsList); + betaDataFile.setBetaCalibrationPairsList(betaCalibrationPairsList); } else { xeResultsSpectrumList = betaDataFile.getXeResultsSpectrumList(); sampleMap = loadData("sample", betaDataFile); @@ -656,12 +665,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements xeData.setConcErr(Double.valueOf(NumberFormatUtil.numberSixLen(String.valueOf(xeData.getConcErr())))); } } - betaDataFile.setGammaCalibrationSpectrumEList(gammaCalibrationSpectrumList); - betaDataFile.setBetaCalibrationSpectrumEList(betaCalibrationSpectrumList); - betaDataFile.setRoiChannelsSpectrumList(roiChannelsSpectrumList); - betaDataFile.setRoiResultsSpectrumList(roiResultsSpectrumList); - betaDataFile.setGammaCalibrationPairsList(gammaCalibrationPairsList); - betaDataFile.setBetaCalibrationPairsList(betaCalibrationPairsList); betaDataFile.setXeResultsSpectrumList(xeResultsSpectrumList); betaDataFile.setSaveAnalysisResult(true); resultMap.put("XeData", phdFileUtil.viewXeData(xeResultsSpectrumList)); @@ -687,7 +690,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements //获取用户名 String userName = JwtUtil.getUserNameByToken(request); //上传文件路径 - String path = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String path = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; Map resultMap = new HashMap<>(); Map sampleMap = new HashMap<>(); Map gasBgMap = new HashMap<>(); @@ -799,7 +802,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements File file = null; try { //根据完整的文件路径 获取临时文件 - file = ftpUtil.downloadFile(filePathName, "betaGamma"); + file = ftpUtil.downloadFile(filePathName); if (Objects.nonNull(file)) { if (type.equalsIgnoreCase("sample")) { betaDataFile.setSampleTmpPath(file.getAbsolutePath()); @@ -896,26 +899,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements String betaKey = sampleFileName + "-" + userName; Cache cache = betaCache.getBetaCache(); BetaDataFile betaDataFile = cache.getIfPresent(betaKey); - String sampleTmpPath = betaDataFile.getSampleTmpPath(); - if (StringUtils.isNotBlank(sampleTmpPath)) { - File file = new File(sampleTmpPath); - file.delete(); - } - String gasTmpPath = betaDataFile.getGasTmpPath(); - if (StringUtils.isNotBlank(gasTmpPath)) { - File file = new File(gasTmpPath); - file.delete(); - } - String detTmpPath = betaDataFile.getDetTmpPath(); - if (StringUtils.isNotBlank(detTmpPath)) { - File file = new File(detTmpPath); - file.delete(); - } - String qcTmpPath = betaDataFile.getQcTmpPath(); - if (StringUtils.isNotBlank(qcTmpPath)) { - File file = new File(qcTmpPath); - file.delete(); - } betaCache.deleteBetaCache(betaKey); } @@ -964,7 +947,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements InputStream inputStream = null; ServletOutputStream outputStream = null; try { - inputStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"); + inputStream = ftpUtil.downloadFileStream(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"); if (Objects.nonNull(inputStream)){ outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; @@ -3514,6 +3497,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } betaDataFile.setBProcessed(false); betaDataFile.setSaveAnalysisResult(false); + betaDataFile.setXeResultsSpectrumList(Collections.EMPTY_LIST); xeMap.put("XeData", Collections.EMPTY_LIST); xeMap.put("bProcessed", false); xeMap.put("savedAnalysisResult", false); @@ -3539,10 +3523,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements List betaList = new LinkedList<>(); List betaFittingPara = new LinkedList<>(); List betaFittingParaToUi = new LinkedList<>(); + List> betaNewEnergyListNow = new LinkedList<>(); List gammaList = new LinkedList<>(); List gammaFittingPara = new LinkedList<>(); List gammaFittingParaToUi = new LinkedList<>(); - //根据sample文件名称获取当前文件的缓存信息 + List> gammaNewEnergyListNow = new LinkedList<>(); + //根据sample文件名称获取当前文件的缓存信息 BetaDataFile sampleBetaData = cache.getIfPresent(sampleFileName + "-" + userName); //存储重新分析字段的实体类 SpectrumGroup spectrum_group = new SpectrumGroup(); @@ -3557,15 +3543,16 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setBetaFittingPara(betaDataFile.getBetaFittingParaNow()); betaDataFile.setBetaFittingParaToUi(betaDataFile.getBetaFittingParaToUiNow()); betaDataFile.setBetaNewEnergyList(betaDataFile.getBetaNewEnergyListNow()); - //将当前文件用到的计算数据同步到需要计算的文件缓存 - sampleBetaData.setBetaList(betaList); - sampleBetaData.setBetaFittingPara(betaFittingPara); - sampleBetaData.setBetaFittingParaToUi(betaFittingParaToUi); - sampleBetaData.setBetaNewEnergyList(betaDataFile.getBetaNewEnergyListNow()); //将新的数组封装到各自的数组中 betaList = betaDataFile.getBetaList(); betaFittingPara = betaDataFile.getBetaFittingPara(); betaFittingParaToUi = betaDataFile.getBetaFittingParaToUi(); + betaNewEnergyListNow = betaDataFile.getBetaNewEnergyListNow(); + //将当前文件用到的计算数据同步到需要计算的文件缓存 + sampleBetaData.setBetaList(betaList); + sampleBetaData.setBetaFittingPara(betaFittingPara); + sampleBetaData.setBetaFittingParaToUi(betaFittingParaToUi); + sampleBetaData.setBetaNewEnergyList(betaNewEnergyListNow); } List beCal = new LinkedList<>(); beCal.add(Double.valueOf(betaFittingParaToUi.get(0))); @@ -3614,15 +3601,16 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setGammaFittingPara(betaDataFile.getGammaFittingParaNow()); betaDataFile.setGammaFittingParaToUi(betaDataFile.getGammaFittingParaToUiNow()); betaDataFile.setGammaNewEnergyList(betaDataFile.getGammaNewEnergyListNow()); - //将当前文件用到的计算数据同步到需要计算的文件缓存 - sampleBetaData.setGammaList(gammaList); - sampleBetaData.setGammaFittingPara(gammaFittingPara); - sampleBetaData.setGammaFittingParaToUi(gammaFittingParaToUi); - sampleBetaData.setGammaNewEnergyList(betaDataFile.getGammaNewEnergyListNow()); //将新的数组封装到各自的数组中 gammaList = betaDataFile.getGammaList(); gammaFittingPara = betaDataFile.getGammaFittingPara(); gammaFittingParaToUi = betaDataFile.getGammaFittingParaToUi(); + gammaNewEnergyListNow = betaDataFile.getGammaNewEnergyListNow(); + //将当前文件用到的计算数据同步到需要计算的文件缓存 + sampleBetaData.setGammaList(gammaList); + sampleBetaData.setGammaFittingPara(gammaFittingPara); + sampleBetaData.setGammaFittingParaToUi(gammaFittingParaToUi); + sampleBetaData.setGammaNewEnergyList(gammaNewEnergyListNow); } List geCal = new LinkedList<>(); geCal.add(Double.valueOf(gammaFittingParaToUi.get(0))); @@ -3752,6 +3740,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } sampleBetaData.setBProcessed(false); sampleBetaData.setSaveAnalysisResult(false); + sampleBetaData.setXeResultsSpectrumList(Collections.EMPTY_LIST); xeMap.put("XeData", Collections.EMPTY_LIST); xeMap.put("bProcessed", false); xeMap.put("savedAnalysisResult", false); @@ -3882,6 +3871,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements map.put("XeData", Collections.EMPTY_LIST); betaDataFile.setBProcessed(false); betaDataFile.setSaveAnalysisResult(false); + betaDataFile.setXeResultsSpectrumList(Collections.EMPTY_LIST); map.put("bProcessed", false); map.put("savedAnalysisResult", false); } @@ -4007,6 +3997,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements map.put("XeData", Collections.EMPTY_LIST); betaDataFile.setBProcessed(false); betaDataFile.setSaveAnalysisResult(false); + betaDataFile.setXeResultsSpectrumList(Collections.EMPTY_LIST); map.put("bProcessed", false); map.put("savedAnalysisResult", false); mapList.put(sampleFileName, map); @@ -4018,7 +4009,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements e.printStackTrace(); } result.setSuccess(true); - result.setResult(mapList.get(currentFileName)); + result.setResult(mapList); return result; } @@ -4031,7 +4022,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements InputStream inputStream = null; ServletOutputStream outputStream = null; try { - inputStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath); + inputStream = ftpUtil.downloadFileStream(spectrumPathProperties.getRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath); if (Objects.nonNull(inputStream)){ outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; @@ -4310,55 +4301,68 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //上传本次文件到ftp人工交互存储路径下 try { - if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath())) { - File sampleTmp = new File(betaDataFile.getSampleTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName.substring(0, sampleFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getSampleFileName(), new FileInputStream(sampleTmp)); + if (StringUtils.isNotBlank(sampleFilePathName)) { + //sample文件的saveFile存储路径 + String saveSamplePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { + File sampleTmp = new File(betaDataFile.getSampleTmpPath()); + ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); + } } - if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath())) { - File gasTmp = new File(betaDataFile.getGasTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName.substring(0, gasFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getGasFileName(), new FileInputStream(gasTmp)); + if (StringUtils.isNotBlank(gasFilePathName)) { + //gas文件的saveFile存储路径 + String saveGasPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { + File gasTmp = new File(betaDataFile.getGasTmpPath()); + ftpUtil.saveFile(saveGasPath, new FileInputStream(gasTmp)); + } } - if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath())) { - File detTmp = new File(betaDataFile.getDetTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName.substring(0, detFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getDetFileName(), new FileInputStream(detTmp)); + if (StringUtils.isNotBlank(detFilePathName)) { + //det文件的saveFile存储路径 + String saveDetPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { + File detTmp = new File(betaDataFile.getDetTmpPath()); + ftpUtil.saveFile(saveDetPath, new FileInputStream(detTmp)); + } } - if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath())) { - File qcTmp = new File(betaDataFile.getQcTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName.substring(0, qcFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getQcFileName(), new FileInputStream(qcTmp)); + if (StringUtils.isNotBlank(qcFilePathName)) { + //qc文件的saveFile存储路径 + String saveQcPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { + File qcTmp = new File(betaDataFile.getQcTmpPath()); + ftpUtil.saveFile(saveQcPath, new FileInputStream(qcTmp)); + } } //分析成功后存储日志文件和报告文件 { - String logPathName = analyses_absolute_LogPath.substring(0, analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)); - String logFileName = analyses_absolute_LogPath.substring(analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1); + String logFileName = betaDataFile.getSampleFileName().replace("PHD", "log"); //获取日志的文件存放路径 String logFilePath = parameterProperties.getLogFilePath() + File.separator + DateUtils.formatDate(new Date(), "yyyy-MM-dd"); - String localLogName = betaDataFile.getSampleFileName().replace("PHD", "log"); //判断文件路径是否存在 File logPath = new File(logFilePath); if (!logPath.exists()) { logPath.mkdirs(); } - File logFile = new File(logFilePath + File.separator +localLogName); + File logFile = new File(logFilePath + File.separator +logFileName); try { //判断日志文件是否存在 如果不存在创建一个空的文件 上传到ftp if (!logFile.exists()) { FileUtil.writeString("", logFile, "UTF-8"); } FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(logPathName, logFileName, in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } { String rptContent = phdFileUtil.OutPutRnRpt(betaDataFile); - String rptPathName = analyses_absolute_ReportPath.substring(0, analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)); String rptFileName = analyses_absolute_ReportPath.substring(analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt"; File rptFile = new File(rptFileName); try { FileUtil.writeString(rptContent, rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(rptPathName, rptFileName, in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_ReportPath+".txt", in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { @@ -4433,6 +4437,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements String error = "get station_id or detect_id error"; return false; } + betaDataFile.setDetectorId(detectorId.toString()); //新增Gards_Sample_Data表数据 sampleDataSpectrumService.saveSampleData(sourceData, stationId, detectorId, filePathName, readLines); //获取sampleId @@ -5805,13 +5810,13 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements xeDataList = getXeDataList(xeResultsSpectrumList); } for (GardsXeResults xeData :xeDataList) { - if (xeData.getNuclideName().equals(XeNuclideName.XE_131m)) { + if (xeData.getNuclideName().equals(XeNuclideName.XE_131m.getType())) { xeData.setNidFlag(anlyseResultIn.getXe131mFlag()); - } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133)) { + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133.getType())) { xeData.setNidFlag(anlyseResultIn.getXe133Flag()); - } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133m)) { + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133m.getType())) { xeData.setNidFlag(anlyseResultIn.getXe133mFlag()); - } else if (xeData.getNuclideName().equals(XeNuclideName.XE_135)) { + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_135.getType())) { xeData.setNidFlag(anlyseResultIn.getXe135Flag()); } } @@ -5843,10 +5848,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements public List getXeDataList(List xeResultsSpectrumList) { List xeDataList = new LinkedList<>(); - for (GardsXeResultsSpectrum xeResultsSpectrum:xeResultsSpectrumList) { - GardsXeResults xeResults = new GardsXeResults(); - BeanUtil.copyProperties(xeResultsSpectrum, xeResults); - xeDataList.add(xeResults); + if (CollectionUtils.isNotEmpty(xeResultsSpectrumList)) { + for (GardsXeResultsSpectrum xeResultsSpectrum:xeResultsSpectrumList) { + GardsXeResults xeResults = new GardsXeResults(); + BeanUtil.copyProperties(xeResultsSpectrum, xeResults); + xeDataList.add(xeResults); + } } return xeDataList; } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java index 0d8b0123..f758432a 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java @@ -53,31 +53,49 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { @Override public Result upload(MultipartFile file) { + //压缩包文件名称 String filename = file.getOriginalFilename(); + //判断是否是压缩包文件 boolean isZip = filename.endsWith(FileTypeEnum.zip.getType()); - if (!isZip) return Result.error(Prompt.FILE_TYPE_ERR); + //如果不是压缩包文件 返回错误提示信息 + if (!isZip) { + return Result.error(Prompt.FILE_TYPE_ERR); + } + //获取登陆用户名 LoginUser user = (LoginUser)SecurityUtils.getSubject().getPrincipal(); String username = user.getUsername(); - FTPClient ftpClient = null; +// FTPClient ftpClient = null; + //获取文件输出流 FileOutputStream fos = null; + //获取压缩包文件输入流 ZipInputStream zipInputStream = null; String slash = SymbolConstant.SINGLE_SLASH; //上传文件夹路径 - String filePath = spectrumPathProperties.getUploadPath() + slash + username; + String filePath = spectrumPathProperties.getRootPath() + slash + spectrumPathProperties.getUploadPath() + slash + username; //本地临时文件夹路径 String tempFilePath = System.getProperty("java.io.tmpdir") + username + slash; + //文件名称集合 List fileNames = new ArrayList<>(); + //文件集合 List fileList = new ArrayList<>(); + //正则表达式 String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_(S|G|D|Q)_(FULL_|PREL_)\\d+\\.PHD"; Pattern regexPattern = Pattern.compile(sampleRx); String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_(S|G|D|Q)_(FULL_|PREL_)\\d+\\.\\d+\\.PHD"; Pattern regexPattern1 = Pattern.compile(sampleRx1); try{ + //创建本地临时文件夹 File tempDir = new File(tempFilePath); - if (!tempDir.exists()) tempDir.mkdir(); + //判断本地临时文件夹是否存在 + if (!tempDir.exists()) { + tempDir.mkdir(); + } + //创建输入流 zipInputStream = new ZipInputStream(file.getInputStream()); ZipEntry entry; + //遍历获取压缩包内文件 while (ObjectUtil.isNotNull(entry = zipInputStream.getNextEntry())) { + //文件名称 String fileName = entry.getName(); fileNames.add(fileName); File oneFile = new File(tempFilePath + fileName); @@ -89,46 +107,61 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { } fileList.add(oneFile); } - if (CollUtil.isEmpty(fileList)) + //判断文件集合是否为空 + if (CollUtil.isEmpty(fileList)) { return Result.error(Prompt.FILE_IS_EMPTY); - ftpClient = ftpUtil.LoginFTP(); - if (ObjectUtil.isNull(ftpClient)) - return Result.error(Prompt.FTP_ERR); - // 如果指定目录不存在,逐级创建目录 - boolean created = FTPUtil.createDirs(ftpClient, filePath); - if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath); + } +// //登陆ftp +// ftpClient = ftpUtil.LoginFTP(); +// if (ObjectUtil.isNull(ftpClient)) { +// return Result.error(Prompt.FTP_ERR); +// } +// // 如果指定目录不存在,逐级创建目录 +// boolean created = FTPUtil.createDirs(ftpClient, filePath); +// if (!created) { +// return Result.error(Prompt.DIR_CREATE_FAIL + filePath); +// } // 上传所有文件 List failList = new ArrayList<>(); for (File oneFile : fileList) { String fileName = oneFile.getName(); // 判断能谱文件名称是否符合规则,不符合则进行重命名 if (!regexPattern.matcher(fileName).find() && !regexPattern1.matcher(fileName).find()) { + //分析文件 EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile); + //获取文件后缀 String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time)); + //获取文件名称 fileName = nameStandUtil.GetFileNameFromDateTime(struct.measurement_id, suffix); } String fullFilePath = filePath + slash + fileName; FileInputStream local = new FileInputStream(oneFile); - boolean success = ftpClient.storeFile(fileName, local); - if (!success) failList.add(fullFilePath); + boolean success = ftpUtil.saveFile(fullFilePath, local); + if (!success) { + failList.add(fullFilePath); + } } - if (CollUtil.isNotEmpty(failList)) + if (CollUtil.isNotEmpty(failList)) { return Result.error(Prompt.UPLOAD_ERR, failList); + } return Result.OK(Prompt.UPLOAD_SUCC); } catch (IOException e) { e.printStackTrace(); return Result.error(Prompt.UPLOAD_ERR); }finally { try { - if (ObjectUtil.isNotNull(zipInputStream)) + if (ObjectUtil.isNotNull(zipInputStream)) { zipInputStream.close(); - if (ObjectUtil.isNotNull(fos)) + } + if (ObjectUtil.isNotNull(fos)) { fos.close(); - if (ObjectUtil.isNotNull(ftpClient)) - if (ftpClient.isConnected()){ - ftpClient.logout(); - ftpClient.disconnect(); - } + } +// if (ObjectUtil.isNotNull(ftpClient)) { +// if (ftpClient.isConnected()){ +// ftpClient.logout(); +// ftpClient.disconnect(); +// } +// } } catch (IOException e) { e.printStackTrace(); } @@ -143,7 +176,7 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { String username = user.getUsername(); String slash = SymbolConstant.SINGLE_SLASH; String comma = SymbolConstant.COMMA; - String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + slash + username; + String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + slash + username; FTPClient ftpClient = null; List fileDtos = new ArrayList<>(); Page page = new Page<>(pageNo, pageSize); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java index 9f8ad726..8f8e5e73 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/AbnormalAlarmClient.java @@ -30,14 +30,6 @@ public interface AbnormalAlarmClient { @PostMapping("/alarmLog/create") Result create(@RequestBody AlarmLog alarmLog); - /* CalculateConcController下相关接口 */ - @GetMapping("/calculateConc/caclAndSave") - boolean calculateConc(); - - /* AlarmAnalysisNuclideParamController下相关接口 */ - @GetMapping("/nuclideParam/refresh") - boolean refreshParam(); - /* SysDatabaseController下相关接口 */ @GetMapping("/sysDatabase/getNameById") String getDatabaseName(@RequestParam String id); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/controller/TestController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/controller/TestController.java deleted file mode 100644 index c350e0a8..00000000 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/controller/TestController.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.jeecg.modules.quartz.controller; - -import cn.hutool.core.map.MapUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.SecurityUtils; -import org.jeecg.common.api.vo.Result; -import org.jeecg.common.constant.CommonConstant; -import org.jeecg.common.constant.Prompt; -import org.jeecg.common.constant.SymbolConstant; -import org.jeecg.common.system.query.QueryGenerator; -import org.jeecg.common.system.vo.LoginUser; -import org.jeecg.common.util.ImportExcelUtil; -import org.jeecg.common.util.RedisStreamUtil; -import org.jeecg.modules.base.dto.Info; -import org.jeecg.modules.quartz.entity.QuartzJob; -import org.jeecg.modules.quartz.service.IQuartzJobService; -import org.jeecgframework.poi.excel.ExcelImportUtil; -import org.jeecgframework.poi.excel.def.NormalExcelConstants; -import org.jeecgframework.poi.excel.entity.ExportParams; -import org.jeecgframework.poi.excel.entity.ImportParams; -import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -@RestController -@RequestMapping("sys/testana") -@Slf4j -@Api(tags = "定时任务接口") -public class TestController { - - @Autowired - private RedisStreamUtil redisStreamUtil; - - @GetMapping("test") - public void test(){ - Info info = new Info(); - info.setStationId("205"); - info.setSampleId("425496"); - info.setBetaOrGamma("Gamma"); - info.setFullOrPrel("FULL"); - info.setDatasource("1"); - info.setSampleName("CAX05_001-20230624_0220_Q_FULL_299.3.PHD"); - info.setCollectionDate(LocalDateTime.now()); - Map nuclides = MapUtil.newHashMap(); - nuclides.put("Be7","1000000"); - nuclides.put("sss","1000000"); - nuclides.put("Tl208","10"); - info.setNuclides(nuclides); - redisStreamUtil.pushAnalysis(info); - } -} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java deleted file mode 100644 index b0352d0e..00000000 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NuclideParamJob.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.jeecg.modules.quartz.job; - -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.config.mqtoken.UserTokenContext; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.common.util.TokenUtils; -import org.jeecg.modules.feignclient.AbnormalAlarmClient; -import org.quartz.*; - - -/** - * 此处的同步是指:当定时任务的执行时间大于任务的时间 - * 间隔时会等待第一个任务执行完成才会走第二个任务 - */ - -/** - * 定时更新核素浓度计算参数 - */ -@Slf4j -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class NuclideParamJob implements Job { - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - try { - UserTokenContext.setToken(TokenUtils.getTempToken()); - AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); - alarmClient.refreshParam(); - }catch (Exception e){ - log.error("定时任务[NuclideParamJob]执行异常: {}", e.getMessage()); - }finally { - UserTokenContext.remove(); - } - } -} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java deleted file mode 100644 index 126c51a5..00000000 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/NucliedAvgJob.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.jeecg.modules.quartz.job; - -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.config.mqtoken.UserTokenContext; -import org.jeecg.common.constant.DateConstant; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.common.util.TokenUtils; -import org.jeecg.modules.feignclient.AbnormalAlarmClient; -import org.quartz.*; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -/** - * 此处的同步是指:当定时任务的执行时间大于任务的时间 - * 间隔时会等待第一个任务执行完成才会走第二个任务 - */ - -/** - * 定时计算核素浓度均值 - */ -@Slf4j -@DisallowConcurrentExecution -@PersistJobDataAfterExecution -public class NucliedAvgJob implements Job { - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - try { - UserTokenContext.setToken(TokenUtils.getTempToken()); - AbnormalAlarmClient alarmClient = SpringContextUtils.getBean(AbnormalAlarmClient.class); - alarmClient.calculateConc(); - log.info(log()); - }catch (Exception e){ - log.error("定时任务[NucliedAvgJob]执行异常: {}", e.getMessage()); - }finally { - UserTokenContext.remove(); - } - } - - private String log(){ - String now = LocalDateTime.now() - .format(DateTimeFormatter.ofPattern(DateConstant.DATE_TIME)); - return "计算核素浓度均值的定时任务成功执行, " + - "任务执行类: org.jeecg.modules.quartz.job.NucliedAvgJob, " + - "任务执行时间: " + now; - } -} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java index aa69b370..19e064d4 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java @@ -246,7 +246,7 @@ public class LoginController { return Result.error("Token无效!"); } } - + /** * 获取访问量 * @return diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java index 22984ab2..71e490fc 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java @@ -1,8 +1,10 @@ package org.jeecg.modules.system.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.dynamic.datasource.annotation.DS; @@ -13,6 +15,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.toolkit.SqlRunner; +import com.google.common.io.Files; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.vo.Result; @@ -47,9 +50,6 @@ public class GardsSampleDataServiceImpl extends ServiceImpl failList = new ArrayList<>(); - for (String path:needDel) { - boolean success = ftpUtil.removeFiles(path); - if (!success) { - failList.add(path); - } + // 删除本地文件 + List fails = new ArrayList<>(); + for (String path : needDel) { + boolean success = FileUtil.del(path); + if (!success) fails.add(path); } - if (CollUtil.isNotEmpty(failList)) - return Result.error("Data clearing is complete, but file clearing fails!", failList); + if (CollUtil.isNotEmpty(fails)) + return Result.error("Data clearing is complete, but file clearing fails!", fails); return Result.OK("Data and file cleanup complete!"); }catch (Exception e){ transactionManager.rollback(txStatus); @@ -215,27 +213,25 @@ public class GardsSampleDataServiceImpl extends ServiceImpl fileList = new ArrayList<>(); List AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId); - if (CollectionUtils.isNotEmpty(AnalysesDtoList)) { - for (AnalysesDto AnalysesDto:AnalysesDtoList) { - String baselinePath = AnalysesDto.getBaselinePath(); - if (StrUtil.isNotBlank(baselinePath)) { - fileList.add(savePath + baselinePath); - } - String lcPath = AnalysesDto.getLcPath(); - if (StrUtil.isNotBlank(lcPath)) { - fileList.add(savePath + lcPath); - } - String scacPath = AnalysesDto.getScacPath(); - if (StrUtil.isNotBlank(scacPath)) { - fileList.add(savePath + scacPath); - } - if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) { - fileList.add(logPath + AnalysesDto.getLogPath()); - } - String reportPath = AnalysesDto.getReportPath(); - if (StrUtil.isNotBlank(reportPath)) { - fileList.add(savePath + reportPath + FileTypeEnum.txt.getType()); - } + for (AnalysesDto AnalysesDto:AnalysesDtoList) { + String baselinePath = AnalysesDto.getBaselinePath(); + if (StrUtil.isNotBlank(baselinePath)) { + fileList.add(savePath + baselinePath); + } + String lcPath = AnalysesDto.getLcPath(); + if (StrUtil.isNotBlank(lcPath)) { + fileList.add(savePath + lcPath); + } + String scacPath = AnalysesDto.getScacPath(); + if (StrUtil.isNotBlank(scacPath)) { + fileList.add(savePath + scacPath); + } + if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) { + fileList.add(logPath + AnalysesDto.getLogPath()); + } + String reportPath = AnalysesDto.getReportPath(); + if (StrUtil.isNotBlank(reportPath)) { + fileList.add(savePath + reportPath + FileTypeEnum.txt.getType()); } } return fileList; diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java index 5e8e8c85..dd776e78 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java @@ -34,7 +34,7 @@ public class ReadLineUtil { File file = null; try { filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath; - file = ftpUtil.downloadFile(filePath, "betaGamma"); + file = ftpUtil.downloadFile(filePath); //判断文件路径是否为空 if (Objects.nonNull(file)){ List allLines = FileUtils.readLines(file, encoding); @@ -52,10 +52,6 @@ public class ReadLineUtil { } } catch (IOException e) { throw new RuntimeException(e); - } finally { - if (Objects.nonNull(file)) { - file.delete(); - } } return Collections.emptyMap(); } diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java index c64a1e1b..6f3eb318 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java @@ -133,7 +133,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl 0); + } + System.exit(exitCode); + } + + // ConfigurableApplicationContext application = SpringApplication.run(JeecgAbnormalAlarmApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); diff --git a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java index 853ac505..f1883692 100644 --- a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java +++ b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java @@ -53,7 +53,19 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im } public static void main(String[] args) throws UnknownHostException { - ConfigurableApplicationContext application = SpringApplication.run(JeecgAutoProcessApplication.class, args); + int exitCode = 1; + ConfigurableApplicationContext application = null; + try { + application = SpringApplication.run(JeecgAutoProcessApplication.class, args); + } catch (Exception e) { + if (null != application) { + application.close(); + exitCode = SpringApplication.exit(application, () -> 0); + } + System.exit(exitCode); + } + + // ConfigurableApplicationContext application = SpringApplication.run(JeecgAutoProcessApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); diff --git a/jeecg-server-cloud/armd-log-manage-start/src/main/java/org/jeecg/JeecgLogManageApplication.java b/jeecg-server-cloud/armd-log-manage-start/src/main/java/org/jeecg/JeecgLogManageApplication.java index a4a117ed..61c29aac 100644 --- a/jeecg-server-cloud/armd-log-manage-start/src/main/java/org/jeecg/JeecgLogManageApplication.java +++ b/jeecg-server-cloud/armd-log-manage-start/src/main/java/org/jeecg/JeecgLogManageApplication.java @@ -27,7 +27,19 @@ public class JeecgLogManageApplication extends SpringBootServletInitializer impl } public static void main(String[] args) throws UnknownHostException { - ConfigurableApplicationContext application = SpringApplication.run(JeecgLogManageApplication.class, args); + int exitCode = 1; + ConfigurableApplicationContext application = null; + try { + application = SpringApplication.run(JeecgLogManageApplication.class, args); + } catch (Exception e) { + if (null != application) { + application.close(); + exitCode = SpringApplication.exit(application, () -> 0); + } + System.exit(exitCode); + } + + // ConfigurableApplicationContext application = SpringApplication.run(JeecgLogManageApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); diff --git a/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml b/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml index a6d71a86..4ba3ba15 100644 --- a/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml +++ b/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml @@ -15,4 +15,5 @@ spring: config: import: - optional:nacos:armd.yaml - - optional:nacos:armd-@profile.name@.yaml \ No newline at end of file + - optional:nacos:armd-@profile.name@.yaml + - optional:nacos:armd-analysis-@profile.name@.yaml \ No newline at end of file diff --git a/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java b/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java index 175576c4..b56896b1 100644 --- a/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java +++ b/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java @@ -1,5 +1,6 @@ package org.jeecg; +import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.cache.BetaCache; import org.jeecg.common.cache.LocalCache; @@ -10,6 +11,7 @@ import org.jeecg.modules.service.IDataService; import org.jeecg.modules.service.IGammaService; import org.jeecg.modules.service.IGardsNuclCoincidenceSumSpectrumService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -43,6 +45,9 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ @Autowired private IDataService dataService; + @Value("${isOpen}") + private Boolean isOpen; + @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { @@ -50,7 +55,19 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ } public static void main(String[] args) throws UnknownHostException { - ConfigurableApplicationContext application = SpringApplication.run(JeecgSpectrumAnalysisApplication.class, args); + int exitCode = 1; + ConfigurableApplicationContext application = null; + try { + application = SpringApplication.run(JeecgSpectrumAnalysisApplication.class, args); + } catch (Exception e) { + if (null != application) { + application.close(); + exitCode = SpringApplication.exit(application, () -> 0); + } + System.exit(exitCode); + } + + // ConfigurableApplicationContext application = SpringApplication.run(JeecgSpectrumAnalysisApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); @@ -82,6 +99,7 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ gammaService.readMDCParameter(); nuclLibService.getNuclideMap(); nuclCoincidenceSumSpectrumService.getNuclCoincidenceMap(); - dataService.viewStations(); + if (ObjectUtil.isNotNull(isOpen) && isOpen) + dataService.viewStations(); } } \ No newline at end of file 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 8c3db501..e44e7459 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 @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.service.ISysUserFocusStationService; import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.ExitCodeGenerator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; @@ -35,7 +36,19 @@ public class JeecgStationOperationApplication extends SpringBootServletInitializ } public static void main(String[] args) throws UnknownHostException { - ConfigurableApplicationContext application = SpringApplication.run(JeecgStationOperationApplication.class, args); + int exitCode = 1; + ConfigurableApplicationContext application = null; + try { + application = SpringApplication.run(JeecgStationOperationApplication.class, args); + } catch (Exception e) { + if (null != application) { + application.close(); + exitCode = SpringApplication.exit(application, () -> 0); + } + System.exit(exitCode); + } + + //ConfigurableApplicationContext application = SpringApplication.run(JeecgStationOperationApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); diff --git a/jeecg-server-cloud/armd-system-cloud-start/src/main/java/org/jeecg/JeecgSystemCloudApplication.java b/jeecg-server-cloud/armd-system-cloud-start/src/main/java/org/jeecg/JeecgSystemCloudApplication.java index ea5070ee..c270153a 100644 --- a/jeecg-server-cloud/armd-system-cloud-start/src/main/java/org/jeecg/JeecgSystemCloudApplication.java +++ b/jeecg-server-cloud/armd-system-cloud-start/src/main/java/org/jeecg/JeecgSystemCloudApplication.java @@ -52,7 +52,18 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im } public static void main(String[] args) throws UnknownHostException { - ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemCloudApplication.class, args); + int exitCode = 1; + ConfigurableApplicationContext application = null; + try { + application = SpringApplication.run(JeecgSystemCloudApplication.class, args); + } catch (Exception e) { + if (null != application) { + application.close(); + exitCode = SpringApplication.exit(application, () -> 0); + } + System.exit(exitCode); + } + // ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemCloudApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); diff --git a/jeecg-server-cloud/armd-web-statistics-start/src/main/java/org/jeecg/JeecgWebStatisticsApplication.java b/jeecg-server-cloud/armd-web-statistics-start/src/main/java/org/jeecg/JeecgWebStatisticsApplication.java index 2c0c4f34..f227a7c5 100644 --- a/jeecg-server-cloud/armd-web-statistics-start/src/main/java/org/jeecg/JeecgWebStatisticsApplication.java +++ b/jeecg-server-cloud/armd-web-statistics-start/src/main/java/org/jeecg/JeecgWebStatisticsApplication.java @@ -26,7 +26,19 @@ public class JeecgWebStatisticsApplication extends SpringBootServletInitializer } public static void main(String[] args) throws UnknownHostException { - ConfigurableApplicationContext application = SpringApplication.run(JeecgWebStatisticsApplication.class, args); + int exitCode = 1; + ConfigurableApplicationContext application = null; + try { + application = SpringApplication.run(JeecgWebStatisticsApplication.class, args); + } catch (Exception e) { + if (null != application) { + application.close(); + exitCode = SpringApplication.exit(application, () -> 0); + } + System.exit(exitCode); + } + + // ConfigurableApplicationContext application = SpringApplication.run(JeecgWebStatisticsApplication.class, args); Environment env = application.getEnvironment(); String ip = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port");