diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsAlertData.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsAlertData.java index e37e7553..c6b4bd04 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsAlertData.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsAlertData.java @@ -1,12 +1,13 @@ package org.jeecg.modules.base.entity.original; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import org.jeecgframework.poi.excel.annotation.Excel; import org.springframework.format.annotation.DateTimeFormat; - import java.io.Serializable; import java.util.Date; @@ -21,7 +22,7 @@ public class GardsAlertData implements Serializable { @TableField(value = "STATION_CODE") private String stationCode; - @TableField(value = "ALERT_ID") + @TableId(value = "ALERT_ID",type = IdType.AUTO) private Integer alertId; @TableField(value = "TIME") diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsMetData.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsMetData.java index 4a79b8ec..18db6daf 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsMetData.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsMetData.java @@ -1,6 +1,8 @@ package org.jeecg.modules.base.entity.original; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @@ -29,7 +31,7 @@ public class GardsMetData implements Serializable { /** * 气象数据id */ - @TableField(value = "MET_ID") + @TableId(value = "MET_ID",type = IdType.AUTO) private Integer metId; /** diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsSohData.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsSohData.java index b0c93f2d..c5747b8d 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsSohData.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/original/GardsSohData.java @@ -1,12 +1,13 @@ package org.jeecg.modules.base.entity.original; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import org.jeecgframework.poi.excel.annotation.Excel; import org.springframework.format.annotation.DateTimeFormat; - import java.io.Serializable; import java.util.Date; @@ -30,7 +31,7 @@ public class GardsSohData implements Serializable { /** * 报警ID号 */ - @TableField(value = "SOH_ID") + @TableId(value = "SOH_ID",type = IdType.AUTO) @Excel(name = "SID",orderNum = "5") private Integer sohId; 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 55bf9cbf..143d5624 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 @@ -2,8 +2,6 @@ package org.jeecg.modules; import org.apache.commons.lang3.ArrayUtils; import org.jeecg.common.email.EmailServiceManager; -import org.jeecg.common.properties.SpectrumPathProperties; -import org.jeecg.common.util.FTPUtil; import org.jeecg.common.properties.TaskProperties; import org.jeecg.modules.email.EmailProperties; import org.jeecg.modules.spectrum.EmailCounter; @@ -30,6 +28,7 @@ public class EmailParsingActuator extends Thread{ this.spectrumServiceQuotes = spectrumServiceQuotes; this.taskProperties = spectrumServiceQuotes.getTaskProperties(); this.emailCounter = emailCounter; + //获取机器可用核心数 int systemCores = Runtime.getRuntime().availableProcessors(); int maximumPoolSize = taskProperties.getReceiveNum() > systemCores?taskProperties.getReceiveNum():systemCores; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/datasource/OraDataSourceProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/datasource/OraDataSourceProperties.java new file mode 100644 index 00000000..8bc65ce2 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/datasource/OraDataSourceProperties.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.datasource; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Data +@Component +@ConfigurationProperties(prefix = "spring.datasource.dynamic.datasource.ora") +public class OraDataSourceProperties { + + private String url; + + private String username; +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPProperties.java new file mode 100644 index 00000000..258b1833 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPProperties.java @@ -0,0 +1,25 @@ +package org.jeecg.modules.ftp; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Data +@Component +@ConfigurationProperties(prefix = "ftp") +public class FTPProperties { + + private String host; + + private Integer port; + + private String userName; + + private String password; + + private String encoding; + + private String ftpRootPath; + + +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java new file mode 100644 index 00000000..97faf647 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ftp/FTPUtils.java @@ -0,0 +1,246 @@ +package org.jeecg.modules.ftp; + +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPFile; +import org.apache.commons.net.ftp.FTPReply; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class FTPUtils { + + private String encoding; + + private String ftpRootPath; + + private FTPClient client; + + public FTPUtils(String host, Integer port, String userName, String password, String encoding,String ftpRootPath){ + this.encoding = encoding; + this.ftpRootPath = ftpRootPath; + try{ + //声明FTP客户端 + client = new FTPClient(); + //连接 + client.connect(host, port); + //登录 + client.login(userName, password); + // 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单 + client.enterLocalPassiveMode(); + //判断是否连接成功 + int reply = client.getReplyCode(); + if (!FTPReply.isPositiveCompletion(reply)) { + client.disconnect(); + } + }catch (IOException e){ + log.error("FTP服务连接失败,原因:{}",e.getMessage()); + e.printStackTrace(); + } + } + + /** + * 下载ftp服务文件 + * @param localPath + * @param fileName + * @param response + */ + public void downloadFTPFile(String localPath, String fileName, HttpServletResponse response) { + InputStream in = null; + ServletOutputStream out = null; + //传输模式 + try { + List paths = Arrays.asList(localPath.split("/")); + if (CollectionUtils.isNotEmpty(paths)){ + for (String workPath:paths) { + //切换工作文件路径 + client.changeWorkingDirectory(workPath); + } + } + client.enterLocalPassiveMode(); + client.setFileType(FTPClient.BINARY_FILE_TYPE); + // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 + client.setControlEncoding(encoding); + client.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); + List ftpFiles = Arrays.asList(client.listFiles()); + if (CollectionUtils.isNotEmpty(ftpFiles)){ + for (FTPFile ftpFile:ftpFiles) { + if (ftpFile.getName().equals(fileName)){ + in = client.retrieveFileStream(new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1)); + } + } + } + //重置响应信息 + response.reset(); + //设置响应类型 + response.setContentType("application/download"); + //解决中文不能生成文件 + response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(fileName,"UTF-8")); + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); + //获取输出流 + out = response.getOutputStream(); + //声明一个长度参数 + int len; + //声明字节数组 + byte[] bytes = new byte[1024]; + //判断如果输入流的字节长度不等于-1,进行字节数组内容的读取 + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + out.flush(); + if (out != null) { + out.close(); + } + if (in != null) { + in.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + /** + * 检查目录是否存在,不存在则创建,支持递归创建 + * @param path 目录路径 + * @return 返回值true/false + * @throws IOException + */ + private boolean checkDirectory(String path){ + try{ + final boolean changeFlag = client.changeWorkingDirectory(ftpRootPath); + if(!changeFlag){ + log.error("{},根目录切换失败",ftpRootPath); + return false; + } + String[] directories = path.split("/"); + for(String directory : directories){ + if(StringUtils.isEmpty(directory)){ + continue; + } + if(!client.changeWorkingDirectory(directory)){ + if(!client.makeDirectory(directory)){ + log.error("{},目录创建失败",directory); + return false; + } + if(!client.changeWorkingDirectory(directory)){ + log.error("{},目录切换失败",directory); + return false; + } + } + } + return true; + }catch (IOException e){ + log.error("检查目录失败,原因:{}",e.getMessage()); + e.printStackTrace(); + } + return true; + } + + /** + * 写入文件,若文件或文件目录不存在则自行创建 + * @param filePath 文件路径 + * @param fileName 文件名称 + * @param inputStream 文件输入流 + * @return 返回值true/false + */ + public boolean saveFile(String filePath,String fileName,InputStream inputStream){ + try{ + final boolean flag = this.checkDirectory(filePath); + if(flag){ + client.setFileType(FTP.BINARY_FILE_TYPE); + String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1); + return client.storeFile(encodedName, inputStream); + } + }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(); + } + } + } + return false; + } + + /** + * 删除文件 + * @param filePath 文件路径 + * @param fileName 文件名称 + * @return 返回值true/false + */ + public boolean removeFile(String filePath,String fileName){ + try { + final String rootPath = client.printWorkingDirectory(); + final boolean changeFlag = client.changeWorkingDirectory(rootPath); + if(!changeFlag){ + log.error("{},根目录切换失败",rootPath); + return false; + } + String[] directories = filePath.split("/"); + for(String directory : directories){ + if(StringUtils.isEmpty(directory)){ + continue; + } + if(!client.changeWorkingDirectory(directory)){ + log.error("此文件目录不存在:{}",filePath); + return false; + } + } + boolean result = client.deleteFile(new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1)); + if(!result){ + log.error("此文件不存在:{}",filePath+"/"+fileName); + } + return result; + } catch (IOException e) { + log.error("{}文件删除失败,原因为:{}",filePath,e.getMessage()); + e.printStackTrace(); + return false; + } + } + + /** + * 获取FTP服务根目录(绝对路径) + * @return + */ + public String getRootPath(){ + try { + final String rootPath = client.printWorkingDirectory(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 关闭ftp客户端连接 + * @throws IOException + */ + public void close(){ + try{ + if (client != null){ + client.disconnect(); + } + }catch (IOException e){ + e.printStackTrace(); + } + } +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java index 391c6057..0bd0b2b7 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/native_jni/struct/EnergySpectrumStruct.java @@ -1,6 +1,7 @@ package org.jeecg.modules.native_jni.struct; import java.util.List; +import java.util.Objects; /** * 能谱结构体字段信息 @@ -550,10 +551,4 @@ public class EnergySpectrumStruct { ", t_record_count=" + t_record_count + '}'; } - - public static void main(String[] args) { - EnergySpectrumStruct s = new EnergySpectrumStruct(); - System.out.println(s); - System.out.println(s.gas_bk_measurement_id); - } } \ No newline at end of file diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IAlertSpectrumService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IAlertSpectrumService.java index 5f21c43a..2a362c9b 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IAlertSpectrumService.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IAlertSpectrumService.java @@ -14,5 +14,5 @@ public interface IAlertSpectrumService extends IService { * @param struct * @param fileName */ - public void create(AlertSpectrumStruct struct,String fileName) throws Exception; + public GardsAlertData create(AlertSpectrumStruct struct,String fileName) throws Exception; } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IMetSpectrumService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IMetSpectrumService.java index 8176ea71..a28d2c4a 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IMetSpectrumService.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/IMetSpectrumService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.original.GardsMetData; import org.jeecg.modules.native_jni.struct.MetSpectrumStruct; +import java.util.List; + /** * 处理气象谱 */ @@ -13,7 +15,8 @@ public interface IMetSpectrumService extends IService { * 保存气象谱数据 * @param struct * @param fileName + * @return * @throws Exception */ - public void create(MetSpectrumStruct struct,String fileName) throws Exception; + public List create(MetSpectrumStruct struct, String fileName) throws Exception; } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISOHSpectrumService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISOHSpectrumService.java index 8539705d..394517a5 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISOHSpectrumService.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISOHSpectrumService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.original.GardsSohData; import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct; +import java.util.List; + /** * 健康谱数据处理 */ @@ -13,7 +15,8 @@ public interface ISOHSpectrumService extends IService { * 保存健康谱数据 * @param struct * @param fileName + * @return * @throws Exception */ - public void create(SOHSpectrumStruct struct,String fileName) throws Exception; + public List create(SOHSpectrumStruct struct, String fileName) throws Exception; } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java index 63be0c09..10ac3480 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/AlertSpectrumServiceImpl.java @@ -33,7 +33,7 @@ public class AlertSpectrumServiceImpl extends ServiceImpl gardsStationsQuery = new LambdaQueryWrapper<>(); @@ -50,5 +50,6 @@ public class AlertSpectrumServiceImpl extends ServiceImpl create(MetSpectrumStruct struct,String fileName) throws Exception{ Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空"); LambdaQueryWrapper gardsStationsQuery = new LambdaQueryWrapper<>(); @@ -46,9 +47,8 @@ public class MetSpectrumServiceImpl extends ServiceImpl list = Lists.newArrayList(); if(struct.record_count > 0){ - List list = Lists.newArrayList(); for(int i=0;i{ + this.save(metData); + }); } } + return list; } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SOHSpectrumServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SOHSpectrumServiceImpl.java index d4f0e67e..3698b531 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SOHSpectrumServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SOHSpectrumServiceImpl.java @@ -37,11 +37,12 @@ public class SOHSpectrumServiceImpl extends ServiceImpl create(SOHSpectrumStruct struct,String fileName) throws Exception{ Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空"); Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空"); @@ -72,8 +73,11 @@ public class SOHSpectrumServiceImpl extends ServiceImpl{ + this.save(sohData); + }); } } + return list; } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java index 11a9fa29..61600d6d 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java @@ -1,19 +1,24 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; -import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.base.entity.original.GardsAlertData; import org.jeecg.modules.emuns.DataType; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.AlertSpectrumStruct; + +import java.io.ByteArrayInputStream; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; +import java.util.Date; +import java.util.Objects; /** * 警告谱处理 */ -@Slf4j public class AlertSpectrum extends SpectrumHandler{ /** @@ -21,6 +26,16 @@ public class AlertSpectrum extends SpectrumHandler{ */ private AlertSpectrumStruct sourceData = null; + private GardsAlertData alertData; + /** + * 开始存库时间 + */ + private Date startIntoDatabaseTime = null; + /** + * 结束存库时间 + */ + private Date endIntoDatabaseTime = null; + /** * 设置过滤链路 */ @@ -28,7 +43,7 @@ public class AlertSpectrum extends SpectrumHandler{ protected void setChina() { SpectrumHandler spectrumHandler = new HealthStatusSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.message,super.emailProperties); + super.currDataType,super.message,super.emailProperties,super.ftpUtil); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -42,9 +57,8 @@ public class AlertSpectrum extends SpectrumHandler{ DataType.ALERT_TEMP.getType().equals(super.currDataType.getType()) || DataType.ALERT_SYSTEM.getType().equals(super.currDataType.getType()) || DataType.ALERT_UPS.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 this.parseingEmail(); //保存PHD文件到ftp @@ -55,6 +69,8 @@ public class AlertSpectrum extends SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + this.saveLogToFtp(); }else{ super.next.handler(); } @@ -74,6 +90,9 @@ public class AlertSpectrum extends SpectrumHandler{ @Override protected void parseingEmail() { final AlertSpectrumStruct sourceData = EnergySpectrumHandler.getAlertSourceData(mailFile.getAbsolutePath()); + if(Objects.isNull(sourceData)){ + throw new RuntimeException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + } this.sourceData = sourceData; } @@ -83,6 +102,20 @@ public class AlertSpectrum extends SpectrumHandler{ @Override protected void saveFileToFtp() throws Exception { this.updateSpectrumFileName(); + //获取文件保存路径 + String fileSavePath = this.getFileSavePath(); + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + fileSavePath = properties.getRootPath()+"/"+fileSavePath; + super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); + //设置FTP文件保存路径 + super.ftpSavePath = fileSavePath+"/"+this.mailFile.getName(); + } + + /** + * 获取文件保存路径 + * @return + */ + private String getFileSavePath(){ //处理此文件需要保存到ftp服务的路径 final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); @@ -93,10 +126,7 @@ public class AlertSpectrum extends SpectrumHandler{ ftpPath.append(year); ftpPath.append("/"); ftpPath.append(month>=10?month:"0"+month); - super.spectrumServiceQuotes.getFtpUtil().saveFile(properties.getRootPath()+"/"+ftpPath.toString(),this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = ftpPath+"/"+this.mailFile.getName(); -// FileUtil.appendString(super.ftpSavePath+System.lineSeparator(),"C:\\Users\\86187\\Desktop\\engine\\sampleId.txt", "UTF-8"); + return ftpPath.toString(); } /** @@ -121,6 +151,27 @@ public class AlertSpectrum extends SpectrumHandler{ */ @Override protected void handlerOriginalData() throws Exception { - spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData,super.ftpSavePath); + this.startIntoDatabaseTime = new Date(); + this.alertData = spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.ftpSavePath); + this.endIntoDatabaseTime = new Date(); + } + + /** + * 把流程日志写入ftp日志文件 + */ + @Override + protected void saveLogToFtp() { + //组装日志文件内容 + 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("\n\n"); + logContent.append("ALERT ID: ").append(this.alertData.getAlertId()).append(" StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append("/").append(super.ftpSavePath); + logContent.append("\n\n"); + logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); + //保存日志文件到ftp + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + final String ftpPath = properties.getLogPath()+"/"+this.getFileSavePath(); + final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),".log"); + super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java index 77aa6c78..ce48be7f 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/DetbkphdSpectrum.java @@ -1,12 +1,10 @@ package org.jeecg.modules.spectrum; -import lombok.extern.slf4j.Slf4j; import org.jeecg.modules.emuns.DataType; /** * 探测器本地谱处理 */ -@Slf4j public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ /** @@ -16,7 +14,7 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ protected void setChina() { SpectrumHandler spectrumHandler = new QcphdSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.message,super.emailProperties); + super.currDataType,super.message,super.emailProperties,super.ftpUtil); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -27,9 +25,8 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ @Override protected void handler() throws Exception { if(DataType.DETBKPHD.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 super.parseingEmail(); //读取邮件内容标签 @@ -42,6 +39,8 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + super.saveLogToFtp(); }else{ super.next.handler(); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/EmailCounter.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/EmailCounter.java index a6b1e62a..3d35d351 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/EmailCounter.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/EmailCounter.java @@ -17,7 +17,7 @@ public class EmailCounter { public int getCurrValue(){ synchronized (lock){ final int currValue = emlCounter.getAndIncrement(); - if(currValue >= 10){ + if(currValue >= 10000){ emlCounter.set(0); } return currValue; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java index 2da4da8f..7354d29c 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GasbkphdSpectrum.java @@ -16,7 +16,7 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ protected void setChina() { SpectrumHandler spectrumHandler = new MetSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.message,super.emailProperties); + super.currDataType,super.message,super.emailProperties,super.ftpUtil); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -27,9 +27,8 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ @Override protected void handler() throws Exception { if(DataType.GASBKPHD.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 super.parseingEmail(); //读取邮件内容标签 @@ -42,6 +41,8 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + super.saveLogToFtp(); }else{ super.next.handler(); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java index 640f7c2f..46a95d5c 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java @@ -1,25 +1,42 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; -import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.base.entity.original.GardsSohData; import org.jeecg.modules.emuns.DataType; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct; +import org.springframework.util.CollectionUtils; + +import java.io.ByteArrayInputStream; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; +import java.util.Date; +import java.util.List; +import java.util.Objects; /** * 健康状态谱处理 */ -@Slf4j public class HealthStatusSpectrum extends SpectrumHandler{ /** * 解析后的数据 */ private SOHSpectrumStruct sourceData = null; + /** + * 开始存库时间 + */ + private Date startIntoDatabaseTime = null; + /** + * 结束存库时间 + */ + private Date endIntoDatabaseTime = null; + + private List sohDatas; /** * 设置过滤链路 @@ -35,9 +52,8 @@ public class HealthStatusSpectrum extends SpectrumHandler{ @Override protected void handler() throws Exception { if(DataType.SOH.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 this.parseingEmail(); //保存PHD文件到ftp @@ -48,6 +64,8 @@ public class HealthStatusSpectrum extends SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + this.saveLogToFtp(); } } @@ -65,6 +83,9 @@ public class HealthStatusSpectrum extends SpectrumHandler{ @Override protected void parseingEmail() { final SOHSpectrumStruct sourceData = EnergySpectrumHandler.getSOHSourceData(mailFile.getAbsolutePath()); + if(Objects.isNull(sourceData)){ + throw new RuntimeException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + } this.sourceData = sourceData; } @@ -74,6 +95,20 @@ public class HealthStatusSpectrum extends SpectrumHandler{ @Override protected void saveFileToFtp() throws Exception { this.updateSpectrumFileName(); + //获取文件保存路径 + String fileSavePath = this.getFileSavePath(); + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + fileSavePath = properties.getRootPath()+"/"+fileSavePath; + super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); + //设置FTP文件保存路径 + super.ftpSavePath = fileSavePath+"/"+this.mailFile.getName(); + } + + /** + * 获取文件保存路径 + * @return + */ + private String getFileSavePath(){ //处理此文件需要保存到ftp服务的路径 final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); @@ -84,10 +119,7 @@ public class HealthStatusSpectrum extends SpectrumHandler{ ftpPath.append(year); ftpPath.append("/"); ftpPath.append(month>=10?month:"0"+month); - super.spectrumServiceQuotes.getFtpUtil().saveFile(properties.getRootPath()+"/"+ftpPath.toString(),this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = ftpPath+"/"+this.mailFile.getName(); -// FileUtil.appendString(super.ftpSavePath+System.lineSeparator(),"C:\\Users\\86187\\Desktop\\engine\\sampleId.txt", "UTF-8"); + return ftpPath.toString(); } /** @@ -112,6 +144,32 @@ public class HealthStatusSpectrum extends SpectrumHandler{ */ @Override protected void handlerOriginalData() throws Exception { - spectrumServiceQuotes.getSohSpectrumService().create(this.sourceData,super.ftpSavePath); + this.startIntoDatabaseTime = new Date(); + this.sohDatas = spectrumServiceQuotes.getSohSpectrumService().create(this.sourceData, super.ftpSavePath); + this.endIntoDatabaseTime = new Date(); + } + + /** + * 把流程日志写入ftp日志文件 + */ + @Override + protected void saveLogToFtp() { + //获取健康谱记录ID范围 + String sohIdRange = ""; + if(!CollectionUtils.isEmpty(this.sohDatas)){ + sohIdRange = this.sohDatas.get(0).getSohId()+"-"+this.sohDatas.get(this.sohDatas.size()-1).getSohId(); + } + //组装日志文件内容 + 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("\n\n"); + logContent.append("SOH ID: ").append(sohIdRange).append(" StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append("/").append(super.ftpSavePath); + logContent.append("\n\n"); + logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); + //保存日志文件到ftp + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + final String ftpPath = properties.getLogPath()+"/"+this.getFileSavePath(); + final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),".log"); + super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java index a065fbb1..afb8fdc3 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java @@ -1,25 +1,42 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; -import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.base.entity.original.GardsMetData; import org.jeecg.modules.emuns.DataType; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.MetSpectrumStruct; +import org.springframework.util.CollectionUtils; + +import java.io.ByteArrayInputStream; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; +import java.util.Date; +import java.util.List; +import java.util.Objects; /** * 气象谱处理 */ -@Slf4j public class MetSpectrum extends SpectrumHandler{ /** * 解析后的数据 */ private MetSpectrumStruct sourceData = null; + /** + * 开始存库时间 + */ + private Date startIntoDatabaseTime = null; + /** + * 结束存库时间 + */ + private Date endIntoDatabaseTime = null; + + private List metDatas; /** * 设置过滤链路 @@ -28,7 +45,7 @@ public class MetSpectrum extends SpectrumHandler{ protected void setChina() { SpectrumHandler spectrumHandler = new AlertSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.message,super.emailProperties); + super.currDataType,super.message,super.emailProperties,super.ftpUtil); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -39,9 +56,8 @@ public class MetSpectrum extends SpectrumHandler{ @Override protected void handler() throws Exception { if(DataType.MET.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 this.parseingEmail(); //保存PHD文件到ftp @@ -52,6 +68,8 @@ public class MetSpectrum extends SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + this.saveLogToFtp(); }else{ super.next.handler(); } @@ -71,6 +89,9 @@ public class MetSpectrum extends SpectrumHandler{ @Override protected void parseingEmail() { final MetSpectrumStruct sourceData = EnergySpectrumHandler.getMetSourceData(mailFile.getAbsolutePath()); + if(Objects.isNull(sourceData)){ + throw new RuntimeException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + } this.sourceData = sourceData; } @@ -80,6 +101,20 @@ public class MetSpectrum extends SpectrumHandler{ @Override protected void saveFileToFtp() throws Exception { this.updateSpectrumFileName(); + //获取文件保存路径 + String fileSavePath = this.getFileSavePath(); + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + fileSavePath = properties.getRootPath()+"/"+fileSavePath; + super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); + //设置FTP文件保存路径 + super.ftpSavePath = fileSavePath+"/"+this.mailFile.getName(); + } + + /** + * 获取文件保存路径 + * @return + */ + private String getFileSavePath(){ //处理此文件需要保存到ftp服务的路径 final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); @@ -90,10 +125,7 @@ public class MetSpectrum extends SpectrumHandler{ ftpPath.append(year); ftpPath.append("/"); ftpPath.append(month>=10?month:"0"+month); - super.spectrumServiceQuotes.getFtpUtil().saveFile(properties.getRootPath()+"/"+ftpPath.toString(),this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = ftpPath+"/"+this.mailFile.getName(); - FileUtil.appendString(super.ftpSavePath+System.lineSeparator(),"C:\\Users\\86187\\Desktop\\engine\\sampleId.txt", "UTF-8"); + return ftpPath.toString(); } /** @@ -118,6 +150,32 @@ public class MetSpectrum extends SpectrumHandler{ */ @Override protected void handlerOriginalData() throws Exception { + this.startIntoDatabaseTime = new Date(); spectrumServiceQuotes.getMetSpectrumService().create(this.sourceData,super.ftpSavePath); + this.endIntoDatabaseTime = new Date(); + } + + /** + * 把流程日志写入ftp日志文件 + */ + @Override + protected void saveLogToFtp() { + //获取气象记录ID范围 + String metIdRange = ""; + if(!CollectionUtils.isEmpty(this.metDatas)){ + metIdRange = this.metDatas.get(0).getMetId()+"-"+this.metDatas.get(this.metDatas.size()-1).getMetId(); + } + //组装日志文件内容 + 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("\n\n"); + logContent.append("Met ID: ").append(metIdRange).append(" StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append("/").append(super.ftpSavePath); + logContent.append("\n\n"); + logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); + //保存日志文件到ftp + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + final String ftpPath = properties.getLogPath()+"/"+this.getFileSavePath(); + final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),".log"); + super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java index ebcc31c9..c51361a9 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/QcphdSpectrum.java @@ -6,7 +6,6 @@ import org.jeecg.modules.emuns.DataType; /** * QC谱处理 */ -@Slf4j public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{ /** @@ -16,7 +15,7 @@ public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{ protected void setChina() { SpectrumHandler spectrumHandler = new GasbkphdSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.message,super.emailProperties); + super.currDataType,super.message,super.emailProperties,super.ftpUtil); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -28,9 +27,8 @@ public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{ protected void handler() throws Exception { //判断当前邮件内容是否是QC谱 if(DataType.QCPHD.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 super.parseingEmail(); //读取邮件内容标签 @@ -43,6 +41,8 @@ public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + super.saveLogToFtp(); }else{ super.next.handler(); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java index c5035d0d..7de54040 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/S_D_Q_G_SpectrumHandler.java @@ -1,19 +1,26 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.util.Strings; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.ISpectrumBlockService; +import org.springframework.boot.system.ApplicationHome; import org.springframework.transaction.TransactionStatus; -import java.io.FileInputStream; + +import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDate; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -26,6 +33,18 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ * 解析后的数据 */ protected EnergySpectrumStruct sourceData = null; + /** + * 开始存库时间 + */ + private Date startIntoDatabaseTime = null; + /** + * 结束存库时间 + */ + private Date endIntoDatabaseTime = null; + /** + * 基础数据 + */ + private GardsSampleData sampleData; /** * 调用dll解析邮件 @@ -33,6 +52,9 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ @Override protected void parseingEmail() { final EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(mailFile.getAbsolutePath()); + if(Objects.isNull(sourceData)){ + throw new RuntimeException("THE PHDFile has some blocks can't be read:"+this.mailFile.getAbsolutePath()); + } this.sourceData = sourceData; } @@ -43,6 +65,20 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ protected void saveFileToFtp() throws Exception { //修改能谱文件名称 this.updateSpectrumFileName(); + //获取文件保存路径 + String fileSavePath = this.getFileSavePath(); + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + fileSavePath = properties.getRootPath()+"/"+fileSavePath; + super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile)); + //设置FTP文件保存路径 + super.ftpSavePath = fileSavePath+"/"+this.mailFile.getName(); + } + + /** + * 获取文件保存路径 + * @return + */ + private String getFileSavePath(){ //处理此文件需要保存到ftp服务的路径 final int year = LocalDate.now().getYear(); final int month = LocalDate.now().getMonth().getValue(); @@ -55,10 +91,7 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ ftpPath.append(year); ftpPath.append("/"); ftpPath.append(month>=10?month:"0"+month); - this.spectrumServiceQuotes.getFtpUtil().saveFile(properties.getRootPath()+"/"+ftpPath.toString(),this.mailFile.getName(),new FileInputStream(this.mailFile)); - //设置FTP文件保存路径 - super.ftpSavePath = ftpPath+"/"+this.mailFile.getName(); -// FileUtil.appendString(super.ftpSavePath+System.lineSeparator(),"C:\\Users\\86187\\Desktop\\engine\\sampleId.txt", "UTF-8"); + return ftpPath.toString(); } /** @@ -102,20 +135,22 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ */ @Override protected void handlerOriginalData() throws Exception { + this.startIntoDatabaseTime = new Date(); DataSourceSwitcher.switchToOracle(); final TransactionStatus transactionStatus = spectrumServiceQuotes.getTransactionManager().getTransaction(spectrumServiceQuotes.getTransactionDefinition()); try{ //存储基础数据 - final GardsSampleData sampleData = spectrumServiceQuotes.getSpectrumBaseBlockService().create(this.sourceData,super.ftpSavePath); + this.sampleData = spectrumServiceQuotes.getSpectrumBaseBlockService().create(this.sourceData,super.ftpSavePath); //存储其他块数据 for(String labels : spectrumFileLabels){ final ISpectrumBlockService spectrumBlockService = spectrumServiceQuotes.getSpectrumBlockService().get(labels); if(Objects.nonNull(spectrumBlockService)){ - spectrumBlockService.create(sourceData,sampleData); + spectrumBlockService.create(sourceData,this.sampleData); } } //提交事务 spectrumServiceQuotes.getTransactionManager().commit(transactionStatus); + this.endIntoDatabaseTime = new Date(); }catch (Exception e){ //回滚事务 spectrumServiceQuotes.getTransactionManager().rollback(transactionStatus); @@ -124,4 +159,73 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{ DataSourceSwitcher.clearDataSource(); } } + + /** + * 把流程日志写入ftp日志文件 + * @throws Exception + */ + @Override + protected void saveLogToFtp() throws FileNotFoundException { + //获取数据源属性 + final String oraUsername = spectrumServiceQuotes.getOraDataSourceProperties().getUsername(); + final String oraUrl = spectrumServiceQuotes.getOraDataSourceProperties().getUrl(); + //组装日志文件内容 + 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("\n\n"); + logContent.append("ApplicationPath:").append(this.getProjectAbsolutePath()).append(",").append("ApplicationName:").append(this.getProjectName()).append(",started by RNAUTO at ").append(this.startIntoDatabaseTime); + logContent.append("\n\n"); + logContent.append("Successfully connected to database,source:").append(oraUrl.substring(oraUrl.lastIndexOf(":")+1)).append(",user=").append(oraUsername); + logContent.append("\n\n"); + logContent.append("SourceFile:").append(super.mailFile.getAbsolutePath()); + logContent.append("\n"); + logContent.append("StandardFile:").append(spectrumServiceQuotes.getFtpProperties().getFtpRootPath()).append("/").append(super.ftpSavePath); + logContent.append("\n\n"); + logContent.append("Detector ID:").append(this.sampleData.getDetectorId()); + logContent.append("\n"); + logContent.append("Station ID:").append(this.sampleData.getStationId()); + logContent.append("\n"); + logContent.append("Sample ID:").append(this.sampleData.getSampleId()); + logContent.append("\n\n"); + logContent.append("Instance status successfully set to:").append(this.sampleData.getStatus()).append("....."); + logContent.append("\n\n"); + logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------"); + //保存日志文件到ftp + final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties(); + final String ftpPath = properties.getLogPath()+"/"+this.getFileSavePath(); + final String fileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),".log"); + super.ftpUtil.saveFile(ftpPath,fileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8))); + } + + /** + * 获取项目绝对路径 + * @return + */ + private String getProjectAbsolutePath(){ + ApplicationHome applicationHome = new ApplicationHome(); + return applicationHome.getDir().getAbsolutePath(); + } + + /** + * 获取项目名称 + * @return + */ + private String getProjectName(){ + ApplicationHome applicationHome = new ApplicationHome(); + File[] files = applicationHome.getDir().listFiles(new FileFilter() { + @Override + public boolean accept(File file) { + if(file.getName().endsWith(".jar")) { + return true; + } + return false; + } + }); + if(ArrayUtils.isNotEmpty(files)){ + String fileName = files[0].getName(); + fileName = fileName.substring(0,fileName.lastIndexOf(".")); + return fileName; + } + return Strings.EMPTY; + } } \ No newline at end of file diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java index 7595284a..7f98af6f 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java @@ -1,12 +1,10 @@ package org.jeecg.modules.spectrum; -import lombok.extern.slf4j.Slf4j; import org.jeecg.modules.emuns.DataType; /** * 样品谱处理 */ -@Slf4j public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ /** @@ -16,7 +14,7 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ protected void setChina() { SpectrumHandler spectrumHandler = new DetbkphdSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile, - super.currDataType,super.message,super.emailProperties); + super.currDataType,super.message,super.emailProperties,super.ftpUtil); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -27,9 +25,8 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ @Override protected void handler() throws Exception { if(DataType.SAMPLEPHD.getType().equals(super.currDataType.getType())){ - log.info("----------------------------------"); - log.info(super.currDataType.getType()); - log.info("----------------------------------"); + //打印当前处理的能谱类型 + super.printCurrDataType(); //解析邮件内容 super.parseingEmail(); //读取邮件内容标签 @@ -42,6 +39,8 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{ super.saveEmailLog(); //删除本地临时文件 super.deleteLocalTemporaryFile(); + //把流程日志写入ftp日志文件 + super.saveLogToFtp(); }else{ super.next.handler(); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java index 18525198..9cf54469 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumHandler.java @@ -2,16 +2,20 @@ 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.modules.email.EmailProperties; import org.jeecg.modules.emuns.DataType; +import org.jeecg.modules.ftp.FTPUtils; import javax.mail.Message; import java.io.File; +import java.io.FileNotFoundException; import java.util.List; import java.util.Objects; /** * 能谱处理模版 */ +@Slf4j public abstract class SpectrumHandler extends Chain{ private final static String DATA_TYPE_PREFIX = "DATA_TYPE "; @@ -27,6 +31,10 @@ public abstract class SpectrumHandler extends Chain{ * 处理能谱数据相关Service引用 */ protected SpectrumServiceQuotes spectrumServiceQuotes; + /** + * ftp工具 + */ + protected FTPUtils ftpUtil; /** * 当前解析的邮件内容文本 */ @@ -52,22 +60,26 @@ public abstract class SpectrumHandler extends Chain{ /** * 初始化参数 */ - protected void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,Message message,EmailProperties emailProperties) throws Exception{ + protected void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,Message message, + EmailProperties emailProperties,FTPUtils ftpUtil) throws Exception{ this.mailContent = mailContent; this.spectrumServiceQuotes = spectrumServiceQuotes; this.message = message; this.emailProperties = emailProperties; + this.ftpUtil = ftpUtil; } /** * 初始化参数 */ - protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File mailFile,DataType currDataType,Message message,EmailProperties emailProperties){ + protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File mailFile,DataType currDataType, + Message message,EmailProperties emailProperties,FTPUtils ftpUtil){ this.spectrumServiceQuotes = spectrumServiceQuotes; this.mailFile = mailFile; this.currDataType = currDataType; this.message = message; this.emailProperties = emailProperties; + this.ftpUtil = ftpUtil; this.setChina(); } @@ -101,6 +113,17 @@ public abstract class SpectrumHandler extends Chain{ */ protected abstract void handlerOriginalData() throws Exception; + protected void printCurrDataType(){ + log.info("----------------------------------"); + log.info(this.currDataType.getType()); + log.info("----------------------------------"); + } + + /** + * 把流程日志写入ftp日志文件 + */ + protected abstract void saveLogToFtp() throws FileNotFoundException; + /** * 把邮件内容存储到本地 */ 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 aa4a9ac2..dd5af9a2 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 @@ -1,22 +1,18 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.email.EmailServiceManager; import org.jeecg.common.properties.SpectrumPathProperties; -import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.FTPUtil; -import org.jeecg.modules.email.EmailLogProperties; import org.jeecg.modules.email.EmailProperties; +import org.jeecg.modules.ftp.FTPProperties; +import org.jeecg.modules.ftp.FTPUtils; -import javax.mail.Address; import javax.mail.Message; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeUtility; -import java.io.File; import java.util.Date; import java.util.concurrent.CountDownLatch; @@ -67,12 +63,10 @@ public class SpectrumParsingActuator implements Runnable{ /** * ftp工具 */ - private FTPUtil ftpUtil; + private FTPUtils ftpUtil; - public void init(Message message, EmailProperties emailProperties, - EmailServiceManager emailServiceManager, - CountDownLatch taskLatch,SpectrumServiceQuotes spectrumServiceQuotes, - EmailCounter emailCounter){ + public void init(Message message, EmailProperties emailProperties,EmailServiceManager emailServiceManager, + CountDownLatch taskLatch, SpectrumServiceQuotes spectrumServiceQuotes,EmailCounter emailCounter){ this.message = message; this.emailProperties = emailProperties; this.emailServiceManager = emailServiceManager; @@ -80,25 +74,31 @@ public class SpectrumParsingActuator implements Runnable{ this.spectrumServiceQuotes = spectrumServiceQuotes; this.spectrumPathProperties = spectrumServiceQuotes.getSpectrumPathProperties(); this.emailCounter = emailCounter; - this.ftpUtil = spectrumServiceQuotes.getFtpUtil(); + //初始化FTP客户端对象 + final FTPProperties ftpProperties = spectrumServiceQuotes.getFtpProperties(); + ftpUtil = new FTPUtils(ftpProperties.getHost(),ftpProperties.getPort(),ftpProperties.getUserName(), + ftpProperties.getPassword(),ftpProperties.getEncoding(),ftpProperties.getFtpRootPath()); } @Override public void run() { String subject = null; StringBuilder mailContent = null; + String sendTime = null; + String receiveTime = null; try { 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"); System.out.println(subject); mailContent = new StringBuilder(); emailServiceManager.getMailContent(message,mailContent); -// mailContent = new StringBuilder(FileUtil.readUtf8String("E:\\file\\AUX04_RMSSOH-20230601_021743.soh")); //所有邮件都需以.eml格式存储到ftp eml文件夹中 downloadEmailToFtp(); //判断是否是IMS2.0协议文件 if(checkMailContent(mailContent,subject)){ SpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,message,emailProperties); + spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,message,emailProperties,ftpUtil); final boolean matchResult = spectrumHandler.saveEmailToLocal(); if(matchResult){ spectrumHandler.handler(); @@ -109,11 +109,12 @@ public class SpectrumParsingActuator implements Runnable{ //删除邮箱中已处理过的邮件 emailServiceManager.removeMail(message); } catch (Exception e) { - System.out.println(mailContent.toString()); - log.error("邮件解析失败,邮件主题为:{},失败原因为:{}",subject,e.getMessage()); + log.error(mailContent.toString()); + log.error("邮件解析失败,邮件主题为:{},发送时间为:{},接收时间为:{},失败原因为:{}",subject,sendTime,receiveTime,e.getMessage()); e.printStackTrace(); }finally { this.taskLatch.countDown(); + ftpUtil.close(); } } @@ -176,8 +177,6 @@ public class SpectrumParsingActuator implements Runnable{ fileName.append("_"); fileName.append(emailCounter.getCurrValue()); fileName.append(SAVE_EML_SUFFIX); -// final File file = new File("E:\\file\\" + fileName.toString()); -// FileUtil.writeFromStream(message.getInputStream(),file); ftpUtil.saveFile(spectrumPathProperties.getEmlPath(),fileName.toString(),message.getInputStream()); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java index dcdafb1e..f907e193 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumServiceQuotes.java @@ -4,7 +4,8 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; -import org.jeecg.common.util.FTPUtil; +import org.jeecg.modules.datasource.OraDataSourceProperties; +import org.jeecg.modules.ftp.FTPProperties; import org.jeecg.modules.service.*; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; @@ -29,7 +30,7 @@ public class SpectrumServiceQuotes { private final TaskProperties taskProperties; - private final FTPUtil ftpUtil; + private final FTPProperties ftpProperties; private final SpectrumPathProperties spectrumPathProperties; @@ -41,4 +42,6 @@ public class SpectrumServiceQuotes { private final ISysMailLogService mailLogService; + private final OraDataSourceProperties oraDataSourceProperties; + } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/StructInsertInput.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/StructInsertInput.java new file mode 100644 index 00000000..4d26353b --- /dev/null +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/StructInsertInput.java @@ -0,0 +1,62 @@ +package org.jeecg.modules.entity.vo; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class StructInsertInput implements Serializable { + + //-----------------input:------------------ + List peakCentroid; + + List fwhmc; + + List tail; + + List tailAlpha; + + List upperTail; + + List upperTailAlpha; + + List area; + + List stepRatio; + + List usedEnerPara; + + List usedResoPara; + + List usedEffiPara; + + long num_g_channel; + + long begin_channel; + + List XCtrl; + + List YCtrl; + + List YSlope; + + int rg_low; + + int rg_high; + + List para_tail; + + List para_tailAlpha; + + List para_tailRight; + + List para_tailRightAlpha; + + List para_stepRatio; + + int curChan; + + List vCount; + +} diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/StructInsertOutput.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/StructInsertOutput.java new file mode 100644 index 00000000..f1bb26cb --- /dev/null +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/entity/vo/StructInsertOutput.java @@ -0,0 +1,34 @@ +package org.jeecg.modules.entity.vo; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class StructInsertOutput implements Serializable { + + //-----------------output:------------------ + List energy; + + List sensitivity; + + List fwhm; + + List efficiency; + + List BWWidthChan; + + List recoilBetaChan; + + List recoilDeltaChan; + + List vIdx; + + List vLeft; + + List vRight; + + List vCentroid; + +} diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java index 6be425bf..296e7ce9 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java @@ -1,6 +1,8 @@ package org.jeecg.modules.native_jni; import org.jeecg.modules.entity.vo.PeakInfo; +import org.jeecg.modules.entity.vo.StructInsertInput; +import org.jeecg.modules.entity.vo.StructInsertOutput; import org.jeecg.modules.native_jni.struct.CalValuesOut; import java.util.List; @@ -13,6 +15,14 @@ public class CalValuesHandler { public static native CalValuesOut calDerivEval(List channel, List para); + public static native double calDerivaOut(double Chan, List p); + public static native List interp1(PeakInfo peak, List t_base, List regChan); + public static native StructInsertOutput insertPeaks(StructInsertInput structInsertInput); + + public static native List calFitPara(String type, int funcId, List x, List y, List err); + + public static native List ComputePeakRange(int m_nCount, List vCentroid, List vFwhmCh, List vTail, List vUpperTail); + }