Merge remote-tracking branch 'origin/station' into station

# Conflicts:
#	jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java
This commit is contained in:
nieziyan 2023-11-24 17:25:16 +08:00
commit 8044187299
33 changed files with 900 additions and 517 deletions

View File

@ -0,0 +1,103 @@
package org.jeecg.common.email;
import lombok.Data;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import java.util.Date;
/**
* 邮件日志事件
*/
@Data
public class EmailLogEvent {
/**
* 区分日志生成是getEmail还是sendEmail的日志
*/
private String gsType;
/**
* 邮件配置对象
*/
private SysEmail email;
/**
* 状态
*/
private String state;
/**
* 当前位于邮箱流程的位置
*/
private String logProcess;
/**
* 邮件主题
*/
private String subject;
/**
* 接收时间
*/
private Date recieveTime;
/**
* 能谱文件名称
*/
private String emlPath;
/**
* PHD文件临时存储路径
*/
private String phdMailLoadPath;
/**
*
* 日志时间
*/
private Date logTime;
public EmailLogEvent(){
}
public EmailLogEvent(String gsType, SysEmail email, String state, String logProcess) {
this.gsType = gsType;
this.email = email;
this.state = state;
this.logProcess = logProcess;
this.logTime = new Date();
}
public EmailLogEvent(String gsType,String logProcess) {
this.gsType = gsType;
this.logProcess = logProcess;
this.logTime = new Date();
}
public EmailLogEvent(String gsType,String state, String logProcess) {
this.gsType = gsType;
this.state = state;
this.logProcess = logProcess;
this.logTime = new Date();
}
public EmailLogEvent(String gsType,String state, String logProcess,String phdMailLoadPath) {
this.gsType = gsType;
this.state = state;
this.logProcess = logProcess;
this.phdMailLoadPath = phdMailLoadPath;
this.logTime = new Date();
}
public EmailLogEvent(String gsType,String state, String logProcess,String subject,Date recieveTime,String emlPath) {
this.gsType = gsType;
this.state = state;
this.logProcess = logProcess;
this.subject = subject;
this.recieveTime = recieveTime;
this.emlPath = emlPath;
this.logTime = new Date();
}
public EmailLogEvent(String gsType,String state, String logProcess,String subject,Date recieveTime) {
this.gsType = gsType;
this.state = state;
this.logProcess = logProcess;
this.subject = subject;
this.recieveTime = recieveTime;
this.logTime = new Date();
}
}

View File

@ -0,0 +1,368 @@
package org.jeecg.common.email;
import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.Setter;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import java.io.File;
import java.time.LocalDateTime;
import java.util.*;
/**
* 邮件过程日志
*/
public class EmailLogManager {
public static final String GS_TYPE_GET = "GET";
public static final String GS_TYPE_SEND = "SEND";
public static final String CONNECT = "CONNECT";
public static final String GETALLID = "GETALLID";
public static final String GETIDHEADER = "GETIDHEADER";
public static final String GETIDBODY = "GETIDBODY";
public static final String GETIDEML = "GETIDEML";
public static final String DELETEID = "DELETEID";
public static final String EXPUNGE = "EXPUNGE";
public static final String DONE = "DONE";
public static final String STATUS_SUCCESS = " SUCCESS";
public static final String STATUS_ERROR = " ERROR";
private static final String FIXED_FILE_NAME = "Mail";
private static final String FIXED_FILE_SUFFIX = ".log";
private static final String LOG_SUFFIX = ".....";
/**
* 邮箱连接全局日志事件
*/
@Setter
private EmailLogEvent connectLogEvent = null;
/**
* 邮件同步全局日志事件
*/
@Setter
private EmailLogEvent getAllIdLogEvent = null;
/**
* 完成解析邮件流程的线程id集合
*/
private LinkedList<Long> completeThreadIds = new LinkedList<>();
/**
* 线程邮件日志队列
*/
private LinkedHashMap<Long,LinkedList<EmailLogEvent>> queue = new LinkedHashMap<>();
private SpectrumPathProperties spectrumPathProperties;
private static EmailLogManager emailLogManager = null;
public static EmailLogManager getInstance(){
return emailLogManager;
}
public EmailLogManager(SpectrumPathProperties spectrumPathProperties) {
this.spectrumPathProperties = spectrumPathProperties;
EmailLogExecThread logExecThread = new EmailLogExecThread();
logExecThread.setName("email-get-exec-thread");
logExecThread.start();
}
/**
* 初始化
* @param spectrumPathProperties
*/
public static void init(SpectrumPathProperties spectrumPathProperties){
emailLogManager = new EmailLogManager(spectrumPathProperties);
}
/**
* 追加日志事件
* @param event
*/
public void offer(Long threadId,EmailLogEvent event){
synchronized (completeThreadIds){
if(queue.containsKey(threadId)){
queue.get(threadId).offer(event);
if(EmailLogManager.DONE.equals(event.getLogProcess())){
completeThreadIds.offer(threadId);
completeThreadIds.notify();
}
}else{
LinkedList<EmailLogEvent> logEventList = new LinkedList<>();
logEventList.offer(event);
queue.put(threadId,logEventList);
}
}
}
/**
* 获取日志事件
* @return
* @throws InterruptedException
*/
public LinkedList<EmailLogEvent> take(Long threadId) throws InterruptedException {
synchronized (completeThreadIds){
final LinkedList<EmailLogEvent> logEventList = queue.remove(threadId);
return logEventList;
}
}
/**
* 获取解析邮件完成的线程id
* @return
* @throws InterruptedException
*/
public Long getCompleteThreadId() throws InterruptedException {
synchronized (completeThreadIds){
if(completeThreadIds.isEmpty()){
completeThreadIds.wait();
return null;
}
final Long threadId = completeThreadIds.removeFirst();
return threadId;
}
}
/**
* 邮件日志执行线程
*/
private class EmailLogExecThread extends Thread{
@Override
public void run() {
for(;;){
try {
final Long threadId = EmailLogManager.getInstance().getCompleteThreadId();
if(Objects.nonNull(threadId)){
final LinkedList<EmailLogEvent> logEventList = EmailLogManager.getInstance().take(threadId);
if(Objects.nonNull(getAllIdLogEvent)){
logEventList.addFirst(getAllIdLogEvent);
}
if(Objects.nonNull(connectLogEvent)){
logEventList.addFirst(connectLogEvent);
}
List<String> logContentList = new ArrayList<>();
logEventList.forEach(logEvent->{
final String logContent = getLogContent(logEvent);
logContentList.add(logContent);
});
writeLog(GS_TYPE_GET,logContentList);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/**
* 获取日志内容
* @param event
*/
private String getLogContent(EmailLogEvent event) {
String logContent = "";
switch (event.getLogProcess()) {
case CONNECT:
logContent = this.getConnectLog(event);
break;
case GETALLID:
logContent = this.getGetAllIdLog(event);
break;
case GETIDHEADER:
logContent = this.getIdHeaderLog(event);
break;
case GETIDBODY:
logContent = this.getIdBodyLog(event);
break;
case GETIDEML:
logContent = this.getIdEmlLog(event);
break;
case DELETEID:
logContent = this.getDeleteLog(event);
break;
case EXPUNGE:
logContent = this.getExpungeLog(event);
break;
case DONE:
logContent = this.getDoneLog(event);
break;
default:
break;
}
return logContent;
}
/**
* 获取连接日志
* @param event
* @return
*/
private String getConnectLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Connect Server:");
logContent.append(event.getEmail().getEmailServerAddress());
logContent.append(" Port:");
logContent.append(event.getEmail().getPort());
logContent.append(event.getState());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 获取邮件同步日志
* @param event
* @return
*/
private String getGetAllIdLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Get All FileName ");
logContent.append(event.getState());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 获取获取邮件主题日志
* @param event
* @return
*/
private String getIdHeaderLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Get FileNameHeader ");
logContent.append(event.getState());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 获取邮件内容日志
* @param event
* @return
*/
private String getIdBodyLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Get File ");
logContent.append(event.getPhdMailLoadPath());
logContent.append(event.getState());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 下载邮件日志
* @param event
* @return
*/
private String getIdEmlLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Get File subject:");
logContent.append(event.getSubject());
logContent.append(" recieve datetime:");
logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS"));
logContent.append(event.getState());
logContent.append(" EmlFile ");
logContent.append(event.getEmlPath());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 下载邮件日志
* @param event
* @return
*/
private String getDeleteLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Delete File subject:");
logContent.append(event.getSubject());
logContent.append(" recieve datetime:");
logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS"));
logContent.append(event.getState());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 下载邮件日志
* @param event
* @return
*/
private String getExpungeLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Expunge File subject:");
logContent.append(event.getSubject());
logContent.append(" recieve datetime:");
logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS"));
logContent.append(event.getState());
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 完成日志
* @param event
* @return
*/
private String getDoneLog(EmailLogEvent event){
StringBuilder logContent = new StringBuilder();
logContent.append(DateUtils.formatDate(event.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
logContent.append(" Done");
logContent.append(LOG_SUFFIX);
logContent.append(System.lineSeparator());
logContent.append(System.lineSeparator());
return logContent.toString();
}
/**
* 把日志写入文件
*/
private void writeLog(String gsType, List<String> logContentList){
LocalDateTime now = LocalDateTime.now();
StringBuilder logFilePath = new StringBuilder();
logFilePath.append(spectrumPathProperties.getRootPath());
logFilePath.append(File.separator);
logFilePath.append(spectrumPathProperties.getLogPath());
logFilePath.append(File.separator);
logFilePath.append(FIXED_FILE_NAME);
logFilePath.append(File.separator);
logFilePath.append(gsType);
logFilePath.append(File.separator);
logFilePath.append(now.getYear());
logFilePath.append(File.separator);
logFilePath.append(now.getMonthValue());
logFilePath.append(File.separator);
logFilePath.append(now.getYear());
logFilePath.append(StringConstant.DASH);
logFilePath.append(now.getMonthValue());
logFilePath.append(StringConstant.DASH);
logFilePath.append(now.getDayOfMonth());
logFilePath.append(StringConstant.UNDER_LINE);
logFilePath.append(FIXED_FILE_NAME);
logFilePath.append(FIXED_FILE_SUFFIX);
FileUtil.appendLines(logContentList,logFilePath.toString(),"UTF-8");
}
}

View File

@ -1,25 +1,22 @@
package org.jeecg.common.email;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.sun.mail.imap.IMAPStore;
import com.sun.mail.smtp.SMTPAddressFailedException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.email.emuns.MailContentType;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
@ -38,6 +35,11 @@ import java.util.stream.Collectors;
@Slf4j
public class EmailServiceManager {
/**
* 存储到eml目录的Email文件后缀
*/
private final static String SAVE_EML_SUFFIX = ".eml";
private SysEmail email;
private SpectrumPathProperties spectrumPathProperties;
/**
@ -105,63 +107,77 @@ public class EmailServiceManager {
/**
* 接收邮件
*/
public Message[] receiveMail() throws MessagingException {
//配置邮件服务属性
Properties props = new Properties();
props.put("mail.store.protocol","imap");
props.put("mail.imap.host",email.getEmailServerAddress());
props.put("mail.imap.port",email.getPort());
//获取邮件回话
final Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(email.getUsername(), email.getPassword());
}
});
Map<String, String> iam = new HashMap<>();
iam.put("name", "myname");
iam.put("version", "1.0.0");
iam.put("vendor", "myclient");
iam.put("support-email", "testmail@test.com");
//获取smtp协议的存储对象
store = (IMAPStore) session.getStore();
//连接
store.connect();
store.id(iam);
//获取收件箱
folder = store.getFolder("INBOX");//INBOX
folder.open(Folder.READ_WRITE);
//如果邮箱邮件数量 > 0
final int messageCount = folder.getMessageCount();
if(messageCount > 0){
Message[] messages = null;
if(Objects.isNull(this.systemStartupTime)){
int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount;
//邮箱邮件下标是从1开始的
return folder.getMessages(1,finalNum);
}
SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime);
messages = folder.search(searchTerm);
Arrays.sort(messages, (o1, o2) -> {
try {
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
} catch (MessagingException e) {
e.printStackTrace();
public Message[] receiveMail() {
String status = EmailLogManager.STATUS_SUCCESS;
try{
//配置邮件服务属性
Properties props = new Properties();
props.put("mail.store.protocol","imap");
props.put("mail.imap.host",email.getEmailServerAddress());
props.put("mail.imap.port",email.getPort());
//获取邮件回话
final Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(email.getUsername(), email.getPassword());
}
return 0;
});
if(this.receiveNum >= messages.length){
return messages;
}else{
return Arrays.copyOfRange(messages,0,this.receiveNum-1);
Map<String, String> iam = new HashMap<>();
iam.put("name", "myname");
iam.put("version", "1.0.0");
iam.put("vendor", "myclient");
iam.put("support-email", "testmail@test.com");
//获取smtp协议的存储对象
store = (IMAPStore) session.getStore();
//连接
store.connect();
store.id(iam);
//获取收件箱
folder = store.getFolder("INBOX");//INBOX
folder.open(Folder.READ_WRITE);
//如果邮箱邮件数量 > 0
final int messageCount = folder.getMessageCount();
if(messageCount > 0){
Message[] messages = null;
if(Objects.isNull(this.systemStartupTime)){
int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount;
//邮箱邮件下标是从1开始的
return folder.getMessages(1,finalNum);
}
SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime);
messages = folder.search(searchTerm);
Arrays.sort(messages, (o1, o2) -> {
try {
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
} catch (MessagingException e) {
e.printStackTrace();
}
return 0;
});
if(this.receiveNum >= messages.length){
return messages;
}else{
return Arrays.copyOfRange(messages,0,this.receiveNum-1);
}
}
}catch (MessagingException 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 {
EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT);
EmailLogManager.getInstance().setConnectLogEvent(connectEvent);
//GetAllId C++原业务是把远程邮箱邮件同步到C++本次java编写没有这一步所以和Connect绑定若Connect成功则GetAllId成功
EmailLogEvent getAllEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETALLID);
EmailLogManager.getInstance().setGetAllIdLogEvent(getAllEvent);
}
return null;
}
/*
* 测试收件邮箱账号是否可以正常使用
* */
* 测试收件邮箱账号是否可以正常使用
* */
public boolean canReceive(){
Integer port = email.getPort();
String username = email.getUsername();
@ -174,6 +190,7 @@ public class EmailServiceManager {
props.put("mail.imap.port", port);
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
@ -233,8 +250,10 @@ public class EmailServiceManager {
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
@ -394,6 +413,28 @@ public class EmailServiceManager {
}
}
/**
* 获取邮件主题
* @param message
* @return
*/
public String getMailSubject(@NotNull Message message) throws MessagingException {
String subject = "";
String status = EmailLogManager.STATUS_SUCCESS;
try {
subject = MimeUtility.decodeText(message.getSubject());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (MessagingException e) {
status = EmailLogManager.STATUS_ERROR;
throw e;
}finally {
EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDHEADER);
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
}
return subject;
}
/**
* 获取邮件内容
* @param part
@ -402,24 +443,14 @@ public class EmailServiceManager {
* @throws IOException
*/
public void getMailContent(@NotNull Part part, StringBuilder content) throws MessagingException, IOException {
try {
if(part.isMimeType(MailContentType.PLAIN.getContentType())){
content.append(part.getContent());
}else if(part.isMimeType("multipart/*")){
Multipart multipart = (Multipart) part.getContent();
for(int i=0;i<multipart.getCount();i++) {
final Part bodyPart = multipart.getBodyPart(i);
getMailContent(bodyPart,content);
}
if(part.isMimeType(MailContentType.PLAIN.getContentType())){
content.append(part.getContent());
}else if(part.isMimeType("multipart/*")){
Multipart multipart = (Multipart) part.getContent();
for(int i=0;i<multipart.getCount();i++) {
final Part bodyPart = multipart.getBodyPart(i);
getMailContent(bodyPart,content);
}
} catch (MessagingException e) {
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(),"Get", null, "Error", "GETALLID", "", "");
throw e;
} catch (IOException e) {
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(),"Get", null, "Error", "GETALLID", "", "");
throw e;
}
}
@ -462,20 +493,79 @@ public class EmailServiceManager {
return filePathList;
}
/**
* 把邮件下载到eml目录
* 格式为发件人_主题_年月日_时分秒毫秒_计数0-10000
* 当计数大于10000后从0开始服务重启后也从0开始
*/
public void downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter) throws MessagingException, IOException {
String subject = "";
File emlFile = null;
String status = EmailLogManager.STATUS_SUCCESS;
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,"");
}
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(emailCounter);
fileName.append(SAVE_EML_SUFFIX);
final String rootPath = spectrumPathProperties.getRootPath();
final String emlPath = spectrumPathProperties.getEmlPath();
emlFile = new File(rootPath+File.separator+emlPath+File.separator+fileName);
message.writeTo(new FileOutputStream(emlFile));
} catch (MessagingException | IOException e) {
//下载邮件失败
status = EmailLogManager.STATUS_ERROR;
log.error("The email download failed, the subject of the email is {}, the reason is {}.",subject,e.getMessage());
throw e;
}finally {
EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,message.getReceivedDate(),
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
}
}
/**
* 删除邮件
* @param message
* @throws MessagingException
*/
public void removeMail(@NotNull Message message) throws MessagingException {
synchronized (this){
try {
message.setFlag(Flags.Flag.DELETED,true);
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(), "Get", null, "Successful", "DELETEID", message.getSubject(), "");
} catch (MessagingException e) {
LogFileUtil.emailLog(spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath(), "Get", null, "Error", "DELETEID", message.getSubject(), "");
throw e;
}
public void removeMail(@NotNull Message message){
String status = EmailLogManager.STATUS_SUCCESS;
String subject = "";
Date receivedDate = null;
try {
subject = MimeUtility.decodeText(message.getSubject());
receivedDate = message.getReceivedDate();
message.setFlag(Flags.Flag.DELETED,true);
} 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();
}finally {
EmailLogEvent removeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.DELETEID,subject,receivedDate);
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),removeEvent);
//这里删除和彻底删除一起写入日志java和C++处理有差异java是在连接关闭时彻底删除的
EmailLogEvent expungeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.EXPUNGE,subject,receivedDate);
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),expungeEvent);
}
}

View File

@ -1,124 +0,0 @@
package org.jeecg.common.util;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;
@Component
public class LogFileUtil {
public static void errorLog(String logHeadPath, String spectrumFileName, String warning) {
String logFilePath = logHeadPath + File.separator + "Error";
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdir();
}
String logFileName = logFilePath + File.separator + spectrumFileName.replace("PHD", "log");
File logFile = new File(logFileName);
StringBuffer out = new StringBuffer();
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
out.append(nowDate+ StringPool.SPACE + "Data Anlyse Error:");
out.append(warning);
out.append(System.lineSeparator());
out.append(System.lineSeparator());
out.append(System.lineSeparator());
FileWriter writer = null;
try {
writer = new FileWriter(logFile, true);
writer.write(out.toString());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (Objects.nonNull(writer)) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
/**
* GSType 区分日志生成是getEmail还是sendEmail的日志 warning是日志内容 state是状态 成功失败 logProccess是当前位于邮箱流程的位置
* @param GSType
* @param email
* @param state
* @param logProcess
*/
public static void emailLog(String logHeadPath, String GSType, SysEmail email, String state, String logProcess, String subjectName, String fileName) {
String warning = "";
switch (logProcess) {
case "CONNECT":
warning="Connect Server:"+email.getEmailServerAddress()+" Port:"+email.getPort()+" "+state+".....";
break;
case "GETALLID":
warning="Get All FileName "+state+".....";
break;
case "GETIDHEADER":
warning="Get FileNameHeader "+state+".....";
break;
case "GETIDBODY":
warning="Get File "+fileName+" FileNameBody "+state+".....";
break;
case "GETIDATTACH":
warning="Get File "+subjectName+" AttachFile "+fileName+" "+state+".....";
break;
case "GETIDEML":
warning="Get File "+subjectName+" EmlFile .....";
break;
case "DELETEID":
warning="Delete File "+subjectName+" "+state+".....";
break;
case "EXPUNGE":
warning="Expunge File "+subjectName+" "+state+".....";
break;
case "DONE":
warning="Done";
break;
default:
break;
}
LocalDateTime now = LocalDateTime.now();
String logFilePath = logHeadPath + File.separator + "Mail" + File.separator + GSType + File.separator + now.getYear() + File.separator + now.getMonthValue();
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdirs();
}
String logFileName = logFilePath + File.separator + now.getYear() + StringPool.DASH + now.getMonthValue() + StringPool.DASH + now.getDayOfMonth() + StringPool.UNDERSCORE + "Mail.log";
File logFile = new File(logFileName);
StringBuffer out = new StringBuffer();
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
out.append(nowDate+ StringPool.SPACE);
out.append(warning);
out.append(System.lineSeparator());
out.append(System.lineSeparator());
out.append(System.lineSeparator());
FileWriter writer = null;
try {
writer = new FileWriter(logFile, true);
writer.write(out.toString());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (Objects.nonNull(writer)) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}

View File

@ -1,18 +1,15 @@
package org.jeecg.modules;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.apache.commons.lang3.ArrayUtils;
import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.spectrum.EmailCounter;
import org.jeecg.modules.spectrum.SpectrumParsingActuator;
import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import javax.mail.Message;
import javax.mail.MessagingException;
import java.io.File;
import java.util.Date;
import java.util.concurrent.*;
@ -53,8 +50,6 @@ public class EmailParsingActuator extends Thread{
emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(),this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties());
try {
final Message[] messages = emailServiceManager.receiveMail();
//连接成功写入日志内容
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Successful", "CONNECT", "", "");
if(ArrayUtils.isNotEmpty(messages)){
CountDownLatch taskLatch = new CountDownLatch(messages.length);
for(Message message : messages){
@ -65,10 +60,12 @@ public class EmailParsingActuator extends Thread{
}
taskLatch.await();
}
}catch (MessagingException | InterruptedException e) {
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Error", "CONNECT", "", "");
}catch (InterruptedException e) {
e.printStackTrace();
}finally {
//每批次连接关闭后清空邮箱全局日志
EmailLogManager.getInstance().setConnectLogEvent(null);
EmailLogManager.getInstance().setGetAllIdLogEvent(null);
//关闭资源
emailServiceManager.close();
}

View File

@ -1,13 +1,10 @@
package org.jeecg.modules;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.exception.StationNotFoundException;
import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.service.BlockConstant;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.spectrum.AbstractSpectrumHandler;
@ -17,13 +14,7 @@ import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.*;
/**
@ -141,21 +132,13 @@ public class FileSourceHandleManager{
fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
//解析文件
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName);
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName,SpectrumSource.FROM_FILE_SOURCE.getSourceType());
final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){
//开始解析
spectrumHandler.handler();
}
}catch (Exception e){
//生成日志
String warning = "";
if (e.getClass().equals(StationNotFoundException.class)) {
warning = e.getMessage()+StringPool.SPACE+"timeout:0,waittime:"+taskProperties.getUndealFileTimeOut();
} else {
warning = e.getMessage();
}
LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
log.error("Parsing the {} file of the filesource directory failed.The reason is {}",spectrumFile.getName(),e.getMessage());
e.printStackTrace();
}finally {

View File

@ -1,32 +1,20 @@
package org.jeecg.modules;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.exception.StationNotFoundException;
import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.service.BlockConstant;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.spectrum.AbstractSpectrumHandler;
import org.jeecg.modules.spectrum.SamplephdSpectrum;
import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.*;
/**
@ -149,22 +137,13 @@ public class UndealHandleManager{
final String fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
//解析文件
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName,true);
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName,SpectrumSource.FORM_FILE_UNDEL.getSourceType());
final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){
//开始解析
spectrumHandler.handler();
}
}catch (Exception e){
//生成日志
long millis = currentMillis - createMillis;
String warning = "";
if (e.getClass().equals(StationNotFoundException.class)) {
warning = e.getMessage()+StringPool.SPACE+"timeout:"+(long) Math.floor(millis/1000)+",waittime:"+taskProperties.getUndealFileTimeOut();
} else {
warning = e.getMessage();
}
LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
log.error("The {} file of the undeal directory fails to be parsed again.The reason is {}",spectrumFile.getName(),e.getMessage());
e.printStackTrace();
}finally {

View File

@ -0,0 +1,24 @@
package org.jeecg.modules.eneity.event;
import lombok.Data;
/**
* 邮件解析过程错误日志
*/
@Data
public class ErrorEvent {
/**
* 能谱文件名称
*/
private String spectrumFileName;
/**
* 错误内容
*/
private String errorContent;
public ErrorEvent(String spectrumFileName, String errorContent) {
this.spectrumFileName = spectrumFileName;
this.errorContent = errorContent;
}
}

View File

@ -0,0 +1,30 @@
package org.jeecg.modules.enums;
/**
* 能谱来源类型枚举
*/
public enum SpectrumSource {
/**
* 能谱来源于邮箱
*/
FORM_EMAIL_SERVICE(0),
/**
* 能谱来源于filesource目录
*/
FROM_FILE_SOURCE(1),
/**
* 能谱来源于undel目录
*/
FORM_FILE_UNDEL(2);
private Integer sourceType;
SpectrumSource(int sourceType) {
this.sourceType = sourceType;
}
public Integer getSourceType(){
return this.sourceType;
}
}

View File

@ -4,72 +4,53 @@
<select id="countParsingMailRecords" resultType="org.jeecg.modules.eneity.vo.DBInfoCount">
select
r.stationName as stationName,
r.dataType as dataType,
r.originalDataNumber as originalDataNumber,
r.anlyseDataNumber as anlyseDataNumber
from (
select
substr(t.site_det_code,1,5) as stationName,
t.data_type as dataType,
(
1+
(select count(*) from original.GARDS_ROI_LIMITS grl where grl.sample_id = t.sample_id)+
(select count(*) from original.GARDS_SAMPLE_AUX gsa where gsa.sample_id = t.sample_id)+
(select count(*) from original.GARDS_SAMPLE_CERT gsc where gsc.sample_id = t.sample_id)+
(select count(*) from original.GARDS_SAMPLE_CERT_LINE gscl where gscl.sample_id = t.sample_id)+
(select count(*) from original.GARDS_SAMPLE_DESCRIPTION gsd where gsd.sample_id = t.sample_id)+
(select count(*) from original.GARDS_SAMPLE_RATIOS gsr where gsr.sample_id = t.sample_id)+
(select count(*) from original.GARDS_SPECTRUM gs where gs.sample_id = t.sample_id)+
(select count(*) from original.GARDS_TOTAL_EFFICIENCY_PAIRS gtep where gtep.sample_id = t.sample_id)+
(select count(*) from original.GARDS_HISTOGRAM gh where gh.sample_id = t.sample_id)+
(select count(*) from original.GARDS_CALIBRATION_PAIRS_ORIG gcp where gcp.sample_id = t.sample_id)+
(select count(*) from original.GARDS_BG_EFFICIENCY_PAIRS gbep where gbep.sample_id = t.sample_id)
) as originalDataNumber,
(
(select count(*) from rnauto.GARDS_ANALYSES ga where ga.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_CALIBRATION gc where gc.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_CALIBRATION_PAIRS gcp where gcp.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_NUCL_IDED gn where gn.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_NUCL_LINES_IDED gnli where gnli.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_ROI_CHANNELS grc where grc.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_ROI_RESULTS grr where grr.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_XE_RESULTS gxr where gxr.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_PEAKS gp where gp.sample_id = t.sample_id)+
(select count(*) from rnauto.GARDS_QC_CHECK gqc where gqc.sample_id = t.sample_id)
) as anlyseDataNumber,
t.moddate
from original.GARDS_SAMPLE_DATA t
where t.moddate between #{beginDate} and #{endDate}
union all
select
min(t.station_code) as stationName,
'MET' as dataType,
count(*) as originalDataNumber,
0 as anlyseDataNumber,
min(t.moddate) as moddate
from original.GARDS_MET_DATA t
where t.moddate between #{beginDate} and #{endDate}
group by t.input_file_name
union all
select
min(t.station_code) as stationName,
'SOH' as dataType,
count(*) as originalDataNumber,
0 as anlyseDataNumber,
min(t.moddate) as moddate
from original.GARDS_SOH_DATA t
where t.moddate between #{beginDate} and #{endDate}
group by t.input_file_name
union all
select
t.station_code as stationName,
'ALERT' as dataType,
1 as originalDataNumber,
0 as anlyseDataNumber,
t.time as moddate
from original.GARDS_ALERT_DATA t
where t.time between #{beginDate} and #{endDate}
) r order by r.moddate asc
f.station_name as stationName,
f.data_type as dataType,
f.original_data_number as originalDataNumber,
f.anlyse_data_number as anlyseDataNumber
from(
select
r.station_name,
r.data_type,
sum(r.original_data_number) as original_data_number,
sum(r.anlyse_data_number) as anlyse_data_number
from(
select
substr(t.site_det_code,1,5) as station_name,
t.data_type,
1 as original_data_number,
nvl2((select t.sample_id from rnauto.GARDS_ANALYSES ga where ga.sample_id = t.sample_id),1,0) as anlyse_data_number
from original.GARDS_SAMPLE_DATA t
where t.moddate between #{beginDate} and #{endDate}
) r
group by r.station_name,r.data_type
union all
select
t.station_code as station_name,
'MET' as data_type,
count(*) as original_data_number,
0 as anlyse_data_number
from original.GARDS_MET_DATA t
where t.moddate between #{beginDate} and #{endDate}
group by t.station_code
union all
select
t.station_code as station_name,
'SOH' as data_type,
count(*) as original_data_number,
0 as anlyse_data_number
from original.GARDS_SOH_DATA t
where t.moddate between #{beginDate} and #{endDate}
group by t.station_code
union all
select
t.station_code as station_name,
'ALERT' as data_type,
count(*) as original_data_number,
0 as anlyseDataNumber
from original.GARDS_ALERT_DATA t
where t.time between #{beginDate} and #{endDate}
group by t.station_code
) f order by f.station_name,f.data_type asc
</select>
</mapper>

View File

@ -11,7 +11,10 @@ public interface GardsStationsService extends IService<GardsStations> {
/**
* 校验台站编码是否存在
* @param site_code
* @param fileName
* @return
* @throws StationNotFoundException
*/
GardsStations check(String site_code) throws StationNotFoundException;
GardsStations check(String site_code,String fileName) throws StationNotFoundException;
}

View File

@ -39,7 +39,7 @@ public class AlertSpectrumServiceImpl extends ServiceImpl<GardsAlertDataMapper,
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
//校验台站是否存在不存在则报异常
final GardsStations station = stationsService.check(struct.station_code);
final GardsStations station = stationsService.check(struct.station_code,fileName);
GardsAlertData alertData = new GardsAlertData();
alertData.setStationId(station.getStationId());

View File

@ -4,34 +4,47 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.exception.StationNotFoundException;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.service.GardsStationsService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.Objects;
@Slf4j
@DS("ora")
@Service
@RequiredArgsConstructor
public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, GardsStations> implements GardsStationsService {
private final TaskProperties taskProperties;
private SpectrumPathProperties spectrumPathProperties;
/**
* 校验台站编码是否存在
*
* @param site_code
* @param fileName
* @return
* @throws StationNotFoundException
*/
@Override
public GardsStations check(String site_code) throws StationNotFoundException {
public GardsStations check(String site_code,String fileName) throws StationNotFoundException {
LambdaQueryWrapper<GardsStations> gardsStationsQuery = new LambdaQueryWrapper<>();
gardsStationsQuery.select(GardsStations::getStationId);
gardsStationsQuery.eq(GardsStations::getStationCode,site_code);
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
if (Objects.isNull(station)) {
throw new StationNotFoundException("station_code:"+site_code+"=0");
StringBuilder logContent = new StringBuilder();
logContent.append("station_code:"+site_code+"=0");
logContent.append(StringConstant.SPACE);
logContent.append(taskProperties.getUndealFileTimeOut());
log.error("This station does not exist, the number is {}.",site_code);
// LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
throw new StationNotFoundException("This station does not exist, the number is "+site_code+".");
}
return station;
}

View File

@ -45,7 +45,7 @@ public class MetSpectrumServiceImpl extends ServiceImpl<GardsMetDataMapper, Gard
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
//校验台站是否存在不存在则报异常
final GardsStations station = stationsService.check(struct.station_code);
final GardsStations station = stationsService.check(struct.station_code,fileName);
List<GardsMetData> list = Lists.newArrayList();
if(struct.record_count > 0){
for(int i=0;i<struct.record_count;i++){

View File

@ -47,7 +47,7 @@ public class SOHSpectrumServiceImpl extends ServiceImpl<GardsSohDataMapper, Gard
Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空");
//校验台站是否存在不存在则报异常
final GardsStations station = stationsService.check(struct.station_code);
final GardsStations station = stationsService.check(struct.station_code,fileName);
//校验探测器是否存在不存在则创建
final GardsDetectors detector = detectorsService.check(struct.detector_code);

View File

@ -59,7 +59,7 @@ public class SpectrumBaseBlockServiceImpl implements ISpectrumBaseBlockService {
Assert.notNull(struct.site_code,"The station code in this parsing structure is empty");
Assert.notNull(struct.detector_code,"The detector code in the parsing structure is empty");
//校验台站是否存在不存在则报异常
final GardsStations station = stationsService.check(struct.site_code);
final GardsStations station = stationsService.check(struct.site_code,fileName);
//校验探测器是否存在不存在则创建
final GardsDetectors detector = detectorsService.check(struct.detector_code);

View File

@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.config.datasource.DataSourceSwitcher;
@ -76,10 +75,8 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
if(this.mailContent.indexOf("#Header") == -1){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Error", "GETIDHEADER", "", "");
throw new HeaderBlockException("header data error");
}
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Successful", "GETIDHEADER", "", "");
}
/**
@ -100,10 +97,8 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
if(Objects.isNull(sourceData) || StringUtils.isBlank(sourceData.data_type)){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Error", "GETIDBODY", "", "");
throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath());
}
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Successful", "GETIDBODY", "", "");
this.sourceData = sourceData;
}

View File

@ -3,14 +3,18 @@ package org.jeecg.modules.spectrum;
import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.email.EmailLogEvent;
import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.file.FileOperation;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
/**
@ -43,9 +47,9 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
*/
protected String spectrumFileRelativePath;
/**
* 是否来自于undel目录
* 能谱来源0-邮箱1-filesource2-undel
*/
protected boolean fromUndel = false;
protected Integer spectrumSource;
/**
* 返回调用方filesourceundelSpectrumParsingActuator的文件名称
*/
@ -67,23 +71,23 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
/**
* 初始化参数
*/
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,StringBuilder returnFileName,boolean fromUndel) throws Exception{
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,StringBuilder returnFileName,Integer spectrumSource) throws Exception{
this.mailContent = mailContent;
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.returnFileName = returnFileName;
this.fromUndel = fromUndel;
this.spectrumSource = spectrumSource;
}
/**
* 初始化参数
*/
protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File spectrumFile,DataType currDataType,
String mailContent,boolean fromUndel,StringBuilder returnFileName){
String mailContent,Integer spectrumSource,StringBuilder returnFileName){
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.spectrumFile = spectrumFile;
this.currDataType = currDataType;
this.mailContent = mailContent;
this.fromUndel = fromUndel;
this.spectrumSource = spectrumSource;
this.returnFileName = returnFileName;
this.setChina();
}
@ -156,29 +160,42 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
*/
public boolean saveEmailToLocal(){
boolean flag = false;
final DataType[] values = DataType.values();
for(DataType value : values){
// 判断能谱数据类型是否正确
if(this.mailContent.contains(DATA_TYPE_PREFIX + value.getType())){
StringBuilder localPath = new StringBuilder();
localPath.append(this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath());
localPath.append(File.separator);
localPath.append(UUID.randomUUID());
localPath.append(value.getSuffix());
this.spectrumFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8");
// 能谱数据类型如果是 SPHDP 或者 SPHDF 统一改为 SAMPLEPHD
if (value.equals(DataType.SPHDP) || value.equals(DataType.SPHDF)) {
this.currDataType = DataType.SAMPLEPHD;
} else {
this.currDataType = value;
String status = EmailLogManager.STATUS_SUCCESS;
try{
final DataType[] values = DataType.values();
for(DataType value : values){
// 判断能谱数据类型是否正确
if(this.mailContent.contains(DATA_TYPE_PREFIX + value.getType())){
StringBuilder localPath = new StringBuilder();
localPath.append(this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath());
localPath.append(File.separator);
localPath.append(UUID.randomUUID());
localPath.append(value.getSuffix());
this.spectrumFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8");
// 能谱数据类型如果是 SPHDP 或者 SPHDF 统一改为 SAMPLEPHD
if (value.equals(DataType.SPHDP) || value.equals(DataType.SPHDF)) {
this.currDataType = DataType.SAMPLEPHD;
} else {
this.currDataType = value;
}
flag = true;
break;
}
flag = true;
break;
}
}
//如果匹配成功则设置过滤链路
if(flag){
this.setChina();
//如果匹配成功则设置过滤链路
if(flag){
this.setChina();
}
}catch (Exception e){
status = EmailLogManager.STATUS_ERROR;
log.error("Failed to get email content. The filename is {},because {}.",this.mailContent,e.getMessage());
e.printStackTrace();
}finally {
if(SpectrumSource.FORM_EMAIL_SERVICE.getSourceType().equals(spectrumSource)){
EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDBODY,
Objects.isNull(this.spectrumFile)?" ":this.spectrumFile.getAbsolutePath());
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
}
}
return flag;
}
@ -188,7 +205,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
* @throws FileNotFoundException
*/
protected void handleParseingFailFile(Exception e) throws FileNotFoundException {
if(!fromUndel && !(e instanceof FileRepeatException)){
if(!SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)){
try {
//解析失败会把文件移动到undeal目录
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
@ -205,7 +222,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
* 若文件件来自于undel并且解析成功后则需要把undel目录里文件删除
*/
protected void deleteIfFromUndelFile(){
if(fromUndel){
if(SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource)){
StringBuilder undealFilePath = new StringBuilder();
undealFilePath.append(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath());
undealFilePath.append(File.separator);

View File

@ -49,7 +49,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new HealthStatusSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -174,7 +174,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
StringBuilder logContent = new StringBuilder();
logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("ALERT ID: ").append(this.alertData.getAlertId()).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath);
logContent.append("ALERT ID: ").append(this.alertData.getAlertId()).append(" StandardFile:").append(super.spectrumFile.getAbsolutePath());
logContent.append(System.lineSeparator()).append(System.lineSeparator());
String handleFlag = "Successfully";

View File

@ -2,8 +2,6 @@ package org.jeecg.modules.spectrum;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -18,7 +16,7 @@ public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new QcphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}

View File

@ -3,8 +3,6 @@ package org.jeecg.modules.spectrum;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -20,7 +18,7 @@ public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new MetSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}

View File

@ -162,7 +162,7 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
StringBuilder logContent = new StringBuilder();
logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("SOH ID: ").append(sohIdRange).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath);
logContent.append("SOH ID: ").append(sohIdRange).append(" StandardFile:").append(super.spectrumFile.getAbsolutePath());
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");

View File

@ -44,7 +44,7 @@ public class MetSpectrum extends AbstractSpectrumHandler{
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new AlertSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -156,7 +156,7 @@ public class MetSpectrum extends AbstractSpectrumHandler{
StringBuilder logContent = new StringBuilder();
logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("Met ID: ").append(metIdRange).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath);
logContent.append("Met ID: ").append(metIdRange).append(" StandardFile:").append(super.spectrumFile.getAbsolutePath());
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");

View File

@ -94,16 +94,16 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{
final String oraUsername = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUsername();
final String oraUrl = spectrumHandler.spectrumServiceQuotes.getOraDataSourceProperties().getUrl();
final String startIntoDatabaseTime = DateUtils.formatDate(spectrumHandler.startIntoDatabaseTime, "yyyy-MM-dd HH:mm:ss");
final String standardFile = spectrumHandler.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + StringConstant.SLASH + spectrumHandler.spectrumFileRelativePath;
final String sourceFile = spectrumHandler.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()+File.separator+spectrumHandler.spectrumFile.getName();
storageLog.append(titleFormat(WRITE_INTO_START,26, StringConstant.DASH,startIntoDatabaseTime,StringConstant.DASH));
storageLog.append(System.lineSeparator()).append(System.lineSeparator());
storageLog.append(rowFormat(APPLICATION_PATH,spectrumHandler.getProjectAbsolutePath(),spectrumHandler.getProjectName(),startIntoDatabaseTime));
storageLog.append(System.lineSeparator()).append(System.lineSeparator());
storageLog.append(rowFormat(DATABASE_CONNECTED,oraUrl.substring(oraUrl.lastIndexOf(":")+1),oraUsername));
storageLog.append(System.lineSeparator()).append(System.lineSeparator());
storageLog.append(rowFormat(SOURCE_FILE,spectrumHandler.spectrumFile.getAbsolutePath()));
storageLog.append(rowFormat(SOURCE_FILE,sourceFile));
storageLog.append(System.lineSeparator());
storageLog.append(rowFormat(STANDARD_FILE,standardFile));
storageLog.append(rowFormat(STANDARD_FILE,spectrumHandler.spectrumFile.getAbsolutePath()));
storageLog.append(System.lineSeparator()).append(System.lineSeparator());
if(fileRepeat){
this.endOfFileRepeat();

View File

@ -2,8 +2,6 @@ package org.jeecg.modules.spectrum;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -18,7 +16,7 @@ public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new GasbkphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}

View File

@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.NumberFormatUtil;
import org.jeecg.modules.base.dto.Info;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.base.entity.rnauto.GardsAnalyses;
@ -459,7 +460,7 @@ public class Sample_B_Analysis implements BlockConstant {
reportContent.append(System.lineSeparator());
reportContent.append(super.rowFormat(collectionStop,StringConstant.SPACE,sampleStruct.collection_stop_date+StringConstant.SPACE+sampleStruct.collection_stop_time));
reportContent.append(System.lineSeparator());
reportContent.append(super.rowFormat(collectionTime,StringConstant.SPACE,String.valueOf((sampleData.getCollectStart().getTime()-sampleData.getCollectStop().getTime())/1000)));
reportContent.append(super.rowFormat(collectionTime,StringConstant.SPACE,String.valueOf((sampleData.getCollectStop().getTime()-sampleData.getCollectStart().getTime())/1000)));
reportContent.append(System.lineSeparator());
reportContent.append(super.rowFormat(airVolume,StringConstant.SPACE,String.valueOf(sampleStruct.air_volume)));
reportContent.append(System.lineSeparator());
@ -662,9 +663,9 @@ public class Sample_B_Analysis implements BlockConstant {
String rowValue = " %-50s %-51s %-21s %s";
List<String> roi = analyseResult.ROI.stream().map(Object::toString).collect(Collectors.toList());
List<String> s_roi_cts = analyseResult.s_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList());
List<String> g_roi_cts = analyseResult.g_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList());
List<String> d_roi_cts = analyseResult.d_roi_cts.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList());
List<String> s_roi_cts = analyseResult.s_roi_cts.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList());
List<String> g_roi_cts = analyseResult.g_roi_cts.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList());
List<String> d_roi_cts = analyseResult.d_roi_cts.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList());
reportContent.append(grossCountsBlock);
reportContent.append(System.lineSeparator());
@ -693,14 +694,14 @@ public class Sample_B_Analysis implements BlockConstant {
List<Double> roi_net_count_err = analyseResult.ROI_net_coutns_err;
//此参数需第一位补0
analyseResult.LC_CTS.add(0,0D);
List<String> lc = analyseResult.LC_CTS.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList());
List<String> lc = analyseResult.LC_CTS.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList());
reportContent.append(netCountsBlock);
reportContent.append(System.lineSeparator());
reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE));
reportContent.append(System.lineSeparator());
for (int i=0;i<roi.size();i++){
String netCount = super.formatToStr5(roi_net_count.get(i))+arithmetic_flag+super.formatToStr5(roi_net_count_err.get(i));
String netCount = NumberFormatUtil.numberFormat(String.valueOf(roi_net_count.get(i)))+arithmetic_flag+NumberFormatUtil.numberFormat(String.valueOf(roi_net_count_err.get(i)));
reportContent.append(super.rowFormat(rowValue,String.valueOf(roi.get(i)),netCount,lc.get(i)));
if(i==roi.size()-1){
reportContent.append(System.lineSeparator()).append(System.lineSeparator());
@ -723,15 +724,15 @@ public class Sample_B_Analysis implements BlockConstant {
List<Double> conErr = analyseResult.ROI_con_uncer_err;
analyseResult.LC.add(0,0.0D);
analyseResult.MDC.add(0,0.0D);
List<String> lc = analyseResult.LC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList());
List<String> mdc = analyseResult.MDC.stream().map(v->super.formatToStr5(v)).collect(Collectors.toList());
List<String> lc = analyseResult.LC.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList());
List<String> mdc = analyseResult.MDC.stream().map(v->NumberFormatUtil.numberFormat(String.valueOf(v))).collect(Collectors.toList());
reportContent.append(grossCountsBlock);
reportContent.append(System.lineSeparator());
reportContent.append(super.rowFormat(rowTitle,StringConstant.SPACE,StringConstant.SPACE,StringConstant.SPACE));
reportContent.append(System.lineSeparator());
for (int i=0;i<roi.size();i++){
String conc = super.formatToStr5(con.get(i))+arithmetic_flag+super.formatToStr5(conErr.get(i));
String conc = NumberFormatUtil.numberFormat(String.valueOf(con.get(i)))+arithmetic_flag+NumberFormatUtil.numberFormat(String.valueOf(conErr.get(i)));
reportContent.append(super.rowFormat(rowValue,roi.get(i),conc,lc.get(i),mdc.get(i)));
if(i==roi.size()-1){
reportContent.append(System.lineSeparator()).append(System.lineSeparator());
@ -751,20 +752,20 @@ public class Sample_B_Analysis implements BlockConstant {
String[] nuclideName = {XE_135,XE_131m,XE_133m,XE_133};
String xe_135_conc = super.formatToStr5(analyseResult.Xe135_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe135_uncer);
String xe_131m_conc = super.formatToStr5(analyseResult.Xe131m_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe131m_uncer);
String xe_133m_conc = super.formatToStr5(analyseResult.Xe133m_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe133m_uncer);
String xe_133_conc = super.formatToStr5(analyseResult.Xe133_con) + arithmetic_flag + super.formatToStr5(analyseResult.Xe133_uncer);
String xe_135_conc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe135_con)) + arithmetic_flag + NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe135_uncer));
String xe_131m_conc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe131m_con)) + arithmetic_flag + NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe131m_uncer));
String xe_133m_conc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe133m_con)) + arithmetic_flag + NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe133m_uncer));
String xe_133_conc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe133_con)) + arithmetic_flag + NumberFormatUtil.numberFormat(String.valueOf(analyseResult.Xe133_uncer));
String xe_135_uncertainty = super.formatToStr5(analyseResult.LC_Xe135);
String xe_131m_uncertainty = super.formatToStr5(analyseResult.LC_Xe131m);
String xe_133m_uncertainty = super.formatToStr5(analyseResult.LC_Xe133m);
String xe_133_uncertainty = super.formatToStr5(analyseResult.LC_Xe133);
String xe_135_uncertainty = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.LC_Xe135));
String xe_131m_uncertainty = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.LC_Xe131m));
String xe_133m_uncertainty = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.LC_Xe133m));
String xe_133_uncertainty = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.LC_Xe133));
String xe_135_mdc = super.formatToStr5(analyseResult.MDC_Xe135);
String xe_131m_mdc = super.formatToStr5(analyseResult.MDC_Xe131m);
String xe_133m_mdc = super.formatToStr5(analyseResult.MDC_Xe133m);
String xe_133_mdc = super.formatToStr5(analyseResult.MDC_Xe133);
String xe_135_mdc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.MDC_Xe135));
String xe_131m_mdc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.MDC_Xe131m));
String xe_133m_mdc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.MDC_Xe133m));
String xe_133_mdc = NumberFormatUtil.numberFormat(String.valueOf(analyseResult.MDC_Xe133));
String xe_135_nid_flag = analyseResult.Xe135_con>analyseResult.MDC_Xe135?"1":"0";
String xe_131m_nid_flag = analyseResult.Xe131m_con>analyseResult.MDC_Xe131m?"1":"0";

View File

@ -111,6 +111,7 @@ public class Sample_G_Analysis {
public void analysis() throws GAnalyseException{
log.info("Gamma自动处理分析--Start");
PHDFile phdFile = new PHDFile();
try {
/* 准备Gamma分析需要的数据 */
GStoreMiddleProcessData middleData = new GStoreMiddleProcessData();
@ -120,7 +121,6 @@ public class Sample_G_Analysis {
GammaFileUtil gammaFileUtil = ApplicationContextUtil.getContext().getBean(GammaFileUtil.class);
parameterProperties = ApplicationContextUtil.getContext().getBean(ParameterProperties.class);
PHDFile phdFile = new PHDFile();
phdFile.setXmlFilePath(parameterProperties.getFilePath());
// 解析PHD文件
spectrumPathProperties = SpringContextUtils.getBean(SpectrumPathProperties.class);
@ -173,8 +173,14 @@ public class Sample_G_Analysis {
e.printStackTrace();
log.error("Sample_G_Analysis", e);
throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
}finally {
} finally {
//删除临时文件
if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) {
File tmpFile = new File(phdFile.getTmpFilePath());
if (Objects.nonNull(tmpFile)) {
tmpFile.delete();
}
}
}
log.info("Gamma自动处理分析--End");
}

View File

@ -3,8 +3,6 @@ package org.jeecg.modules.spectrum;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.base.enums.SystemType;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -19,7 +17,7 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new DetbkphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
super.currDataType,super.mailContent,super.spectrumSource,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}

View File

@ -1,23 +1,13 @@
package org.jeecg.modules.spectrum;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.email.EmailLogEvent;
import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.exception.StationNotFoundException;
import org.jeecg.modules.enums.SpectrumSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
/**
@ -31,10 +21,7 @@ public class SpectrumParsingActuator implements Runnable{
private final static String EMAIL_BEGIN = "BEGIN IMS2.0";
private final static String MSG_TYPE = "MSG_TYPE DATA";
private final static String EMAIL_STOP = "STOP";
/**
* 存储到eml目录的Email文件后缀
*/
private final static String SAVE_EML_SUFFIX = ".eml";
/**
* 邮件对象
@ -56,10 +43,6 @@ public class SpectrumParsingActuator implements Runnable{
* 相关Spring组件引用
*/
private SpectrumServiceQuotes spectrumServiceQuotes;
/**
* 邮件保存路径相关属性
*/
private SpectrumPathProperties spectrumPathProperties;
/**
* 邮件计数器
*/
@ -73,36 +56,29 @@ public class SpectrumParsingActuator implements Runnable{
this.emailServiceManager = emailServiceManager;
this.taskLatch = taskLatch;
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.spectrumPathProperties = spectrumServiceQuotes.getSpectrumPathProperties();
this.emailCounter = emailCounter;
}
@Override
public void run() {
String subject = null;
StringBuilder mailContent = null;
String sendTime = null;
String receiveTime = null;
StringBuilder finalFileName = new StringBuilder();
try {
//获取邮件主题
subject = emailServiceManager.getMailSubject(message);
//获取邮件内容
StringBuilder mailContent = new StringBuilder();
emailServiceManager.getMailContent(message,mailContent);
//所有邮件都需以.eml格式存储到eml文件夹中
downloadEmailToEmlDir();
emailServiceManager.downloadEmailToEmlDir(message,emailCounter.getCurrValue());
//保存邮件日志到PG数据库
this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties);
subject = MimeUtility.decodeText(message.getSubject());
sendTime = DateUtils.formatDate(message.getSentDate(),"yyyy-MM-dd HH:mm:ss");
receiveTime = DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss");
mailContent = new StringBuilder();
emailServiceManager.getMailContent(message,mailContent);
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Successful", "GETALLID", "", "");
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Successful", "GETIDEML", subject, "");
//判断是否是IMS2.0协议文件
if(checkMailContent(mailContent,subject)){
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,finalFileName);
spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FROM_FILE_SOURCE.getSourceType());
final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){
//开始解析
@ -112,25 +88,12 @@ public class SpectrumParsingActuator implements Runnable{
}
}
} catch (Exception e) {
//生成日志
String warning = "";
if (e.getClass().equals(StationNotFoundException.class)) {
warning = e.getMessage()+ StringPool.SPACE+"timeout:0,waittime:"+spectrumServiceQuotes.getTaskProperties().getUndealFileTimeOut();
} else {
warning = e.getMessage();
}
LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
log.error("This email failed to parse. The email subject is: {}, sent on: {}, received on: {}, and the reason for the failure is: {}",subject,sendTime,receiveTime,e.getMessage());
e.printStackTrace();
}finally {
emailServiceManager.removeMail(message);
EmailLogEvent expungeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,EmailLogManager.DONE);
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),expungeEvent);
this.taskLatch.countDown();
//删除邮箱中已处理过的邮件
try {
emailServiceManager.removeMail(message);
} catch (MessagingException e) {
e.printStackTrace();
}
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), "Get", null, "Successful", "DONE", "", "");
}
}
@ -164,50 +127,4 @@ public class SpectrumParsingActuator implements Runnable{
return false;
}
/**
* 把邮件下载到eml目录
* 格式为发件人_主题_年月日_时分秒毫秒_计数0-10000
* 当计数大于10000后从0开始服务重启后也从0开始
*/
private void downloadEmailToEmlDir() throws Exception{
try {
//获取发件人
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
final String from = address.substring(0,address.indexOf(StringConstant.AT));
//获取主题
String 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,"");
}
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(emailCounter.getCurrValue());
fileName.append(SAVE_EML_SUFFIX);
final String rootPath = spectrumPathProperties.getRootPath();
final String emlPath = spectrumPathProperties.getEmlPath();
final File file = new File(rootPath+File.separator+emlPath+File.separator+fileName);
if(!file.exists()){
file.setWritable(true);
file.setReadable(true);
file.createNewFile();
}
message.writeTo(new FileOutputStream(file));
} catch (Exception e) {
//读取文件内容成功后写入日志
LogFileUtil.emailLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(),"Get", emailProperties, "Error", "GETIDEML", message.getSubject(), "");
throw e;
}
}
}

View File

@ -3,7 +3,6 @@ package org.jeecg.modules.spectrum;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jeecg.common.properties.*;
import org.jeecg.common.util.LogFileUtil;
import org.jeecg.common.util.NameStandUtil;
import org.jeecg.common.util.RedisStreamUtil;
import org.jeecg.modules.datasource.OraDataSourceProperties;
@ -78,8 +77,6 @@ public class SpectrumServiceQuotes {
private final NameStandUtil nameStandUtil;
private final LogFileUtil logFileUtil;
private final ApplicationContext applicationContext;
/**

View File

@ -887,7 +887,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
PHDFile phdFile = phdCache.getIfPresent(key);
if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) {
File file = new File(phdFile.getTmpFilePath());
file.delete();
if (Objects.nonNull(file)) {
file.delete();
}
}
// 删除指定key的Cache
localCache.deletePHDCache(key);
@ -4951,7 +4953,14 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
String date = phd.getAcq().getAcquisition_start_date().replace("/", "");
String time = phd.getAcq().getAcquisition_start_time().replace(":", "").substring(0, 4);
String dataType = phd.getMsgInfo().getData_type().substring(0, 1);
String phdFileName = String.format("%s-%s_%s_%s.PHD", detectorCode, date, time, dataType);
String spectrumQuantity = phd.getHeader().getSpectrum_quantity();
double acquisitionLiveTime = phd.getAcq().getAcquisition_live_time();
DecimalFormat df = new DecimalFormat("#.##########");
//AUX09_003-20151226_1855 _S_FULL_40184.8.PHD
//将acquisition_live_time保留六位有效数字 如果保留一位小数后小数点后的值是0则四舍五入保留整数否则按正常条件四舍五入保留小数位
String numberCal = NumberFormatUtil.numberCal(String.valueOf(acquisitionLiveTime));
numberCal = df.format(Double.valueOf(numberCal));
String phdFileName = String.format("%s-%s_%s_%s_%s_%s.PHD", detectorCode, date, time, dataType, spectrumQuantity, numberCal);
String spectrum = gammaFileUtil.makeUpSpectrum(phd);
// 导出数据内容到txt文本
OutputStream fos = null;

View File

@ -4,9 +4,9 @@ import cn.hutool.core.io.FileUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.*;
import org.jeecg.modules.email.EmailReceivePolicy;
@ -76,9 +76,11 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
}
//校验临时存储目录是否存在不存在则创建
checkTempStorageDirectory();
//初始化邮箱邮件声明周期日志
EmailLogManager.init(spectrumPathProperties);
//校验存储目录是否存在不存在则创建存在无操作
checkStorageDirectory();
// autoProcessManager.start(systemStartupTime);
autoProcessManager.start(systemStartupTime);
undealHandleManager.start();
fileSourceHandleManager.start();
// 删除过期的文件

View File

@ -15,6 +15,6 @@ spring:
config:
import:
- optional:nacos:armd.yaml
- optional:nacos:armd-@profile.name@.yaml
- optional:nacos:armd-@profile.name@-pbl.yaml
- optional:nacos:armd-analysis-@profile.name@.yaml