diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 24f3f3f5..d465b421 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -121,7 +121,7 @@ public class EmailServiceManager { store.connect(); store.id(iam); //获取收件箱 - folder = store.getFolder("INBOX"); + folder = store.getFolder("INBOX");//INBOX folder.open(Folder.READ_WRITE); //如果邮箱邮件数量 > 0 final int messageCount = folder.getMessageCount(); diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/DetectorIdFormat.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/DetectorIdFormat.java new file mode 100644 index 00000000..4bbd6814 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/DetectorIdFormat.java @@ -0,0 +1,48 @@ +package org.jeecg.common.properties; + +import io.swagger.models.auth.In; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; +import org.jeecg.common.constant.StringConstant; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import java.util.Map; + +@Data +@Component +@ConfigurationProperties(prefix = "detectorstype") +public class DetectorIdFormat { + + private Map suffixMap; + + /** + * 格式化探测器编码解析为探测器id + * @return + */ + public Integer formatDetectorCodeToId(String detectorCode){ + if(!detectorCode.contains(StringConstant.UNDER_LINE)){ + throw new RuntimeException("The "+detectorCode+" detector code is illegal"); + } + //举例:FRP28_007 + final String[] arr = detectorCode.split(StringConstant.UNDER_LINE); + final String prefix = arr[0]; + final String suffix = arr[1]; + //格式化前缀 + String prefixFormatResult = null; + for(int i=prefix.length()-1;i>=0;i--){ + final String letter = String.valueOf(prefix.charAt(i)); + if(StringUtils.isAlpha(letter)){ + final String mapVal = suffixMap.getOrDefault(letter, "-1"); + final String prefixNumber = prefix.substring(i + 1); + prefixFormatResult = mapVal + prefixNumber; + break; + } + } + //格式化后缀 + final Integer suffixVal = Integer.valueOf(suffix); + final String suffixFormatResult = suffixVal>=10?String.valueOf(suffixVal):"0"+suffixVal; + //得到最终探测器id值 + Integer detectorId = Integer.valueOf(prefixFormatResult + suffixFormatResult); + return detectorId; + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java index 08670ca5..d64cdbd0 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java @@ -51,6 +51,11 @@ public class TaskProperties implements Serializable { */ private Integer undealDirReceiveNum; + /** + * undeal目录文件分析周期 + */ + private Integer undealFileTimeOut; + /** * filesource目录文件获取周期 */ diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java index aba5f03f..3da43cd0 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RedisStreamUtil.java @@ -161,6 +161,15 @@ public class RedisStreamUtil { return redisTemplate.opsForStream().delete(streamKey, recordIds); } + /** + * 根据记录id删除n个消息记录 + * + * @param streamKey + */ + public boolean del(String streamKey){ + return redisTemplate.delete(streamKey); + } + /** * 添加Map消息 * diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DetectorsStatus.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DetectorsStatus.java new file mode 100644 index 00000000..e5b9c45f --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DetectorsStatus.java @@ -0,0 +1,26 @@ +package org.jeecg.modules.base.enums; + +/** + * 探测器运行状态 + */ +public enum DetectorsStatus { + + /** + * 未运行 + */ + UNOPERATING("Unoperating"), + /** + * 在运行 + */ + OPERATING("Operating"); + + private String status; + + DetectorsStatus(String type) { + this.status = type; + } + + public String getStatus(){ + return this.status; + } +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java b/jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java new file mode 100644 index 00000000..513e0b0a --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/common/util/LogFileUtil.java @@ -0,0 +1,64 @@ +package org.jeecg.common.util; + +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.properties.TaskProperties; +import org.jeecg.modules.exception.StationNotFoundException; +import org.jeecg.modules.spectrum.SpectrumServiceQuotes; +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.util.Date; +import java.util.Objects; + +@Component +public class LogFileUtil { + + /** + * 任务属性 + */ + @Autowired + private TaskProperties taskProperties; + /** + * 相关Spring组件引用 + */ + @Autowired + private SpectrumPathProperties spectrumPathProperties; + + + public void errorLog(String spectrumFileName, String warning, Exception e) { + String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + 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); + } + } + } + +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java index 833e0269..6d0ddaec 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/FileSourceHandleManager.java @@ -1,9 +1,12 @@ 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.modules.exception.StationNotFoundException; import org.jeecg.modules.service.BlockConstant; import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.spectrum.AbstractSpectrumHandler; @@ -13,7 +16,13 @@ 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.*; /** @@ -137,6 +146,15 @@ public class FileSourceHandleManager{ 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(); + } + spectrumServiceQuotes.getLogFileUtil().errorLog(spectrumFile.getName(), warning, e); + log.error("Parsing the {} file of the filesource directory failed.The reason is {}",spectrumFile.getName(),e.getMessage()); e.printStackTrace(); }finally { diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java index 3549492e..ea867546 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/UndealHandleManager.java @@ -1,19 +1,32 @@ 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.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.*; /** @@ -122,24 +135,45 @@ public class UndealHandleManager{ @Override public void run() { + long currentMillis = System.currentTimeMillis(); + long createMillis = currentMillis; + //判断redis是否包含文件名称 key + if (spectrumServiceQuotes.getRedisStreamUtil().hasKey(spectrumFile.getName())) { + createMillis = (long) spectrumServiceQuotes.getRedisStreamUtil().get(spectrumFile.getName()); + } else { + spectrumServiceQuotes.getRedisStreamUtil().set(spectrumFile.getName(), currentMillis); + } try { //获取文件内容 final String fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8"); //解析文件 AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(fileContent,spectrumServiceQuotes); + spectrumHandler.init(fileContent,spectrumServiceQuotes,true); 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(); + } + spectrumServiceQuotes.getLogFileUtil().errorLog(spectrumFile.getName(), warning, e); log.error("The {} file of the undeal directory fails to be parsed again.The reason is {}",spectrumFile.getName(),e.getMessage()); e.printStackTrace(); }finally { this.taskLatch.countDown(); - //解析成功或者失败都会删除源文件 - spectrumFile.delete(); + //满足undeal文件处理周期时长会删除源文件 + if ((currentMillis - createMillis) >= taskProperties.getUndealFileTimeOut()) { + spectrumServiceQuotes.getRedisStreamUtil().del(spectrumFile.getName()); + //解析成功或者失败都会删除源文件 + spectrumFile.delete(); + } } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/StationNotFoundException.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/StationNotFoundException.java new file mode 100644 index 00000000..ffa9707b --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/StationNotFoundException.java @@ -0,0 +1,9 @@ +package org.jeecg.modules.exception; + +public class StationNotFoundException extends Exception { + + public StationNotFoundException(String message) { + super(message); + } + +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java index 04b852f1..4205782d 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/file/FileOperation.java @@ -117,7 +117,7 @@ public class FileOperation { * @throws IOException */ public static void moveFile(File srcFile,String destDir,boolean isOverride) throws IOException { - FileUtil.move(srcFile,new File(destDir),true); + FileUtil.move(srcFile,new File(destDir),isOverride); } /** @@ -128,7 +128,7 @@ public class FileOperation { * @throws IOException */ public static void copyFile(File srcFile,String destDir,boolean isOverride) throws IOException { - FileUtil.copy(srcFile,new File(destDir),true); + FileUtil.copy(srcFile,new File(destDir),isOverride); } /** diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/GardsSampleDataMapper.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/GardsSampleDataMapper.java index d63a1c0a..67fc201d 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/GardsSampleDataMapper.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/GardsSampleDataMapper.java @@ -13,8 +13,8 @@ public interface GardsSampleDataMapper extends BaseMapper { @Select(value = "select " + "gsd.SAMPLE_ID as sampleId,gsd.input_file_name as inputFileName " + "from ORIGINAL.GARDS_SAMPLE_AUX gsa inner join ORIGINAL.GARDS_SAMPLE_DATA gsd on gsa.sample_id = gsd.sample_id " + - "where gsa.measurement_id = #{measurementId} and gsd.data_type=#{dataType}") - public List getSampleIdAndInputFileName(@Param("measurementId") String measurementId, @Param("dataType") String dataType); + "where gsa.measurement_id = #{measurementId} and gsd.SAMPLE_TYPE = #{systemType} and gsd.data_type=#{dataType} and TRIM(gsd.SITE_DET_CODE) = #{detectorId}") + public List getSampleIdAndInputFileName(@Param("measurementId") String measurementId, @Param("dataType") String dataType, @Param("systemType") String systemType, String detectorId); @Update(value = "UPDATE ORIGINAL.GARDS_SAMPLE_DATA SET STATUS=#{status} WHERE INPUT_FILE_NAME=#{inputFileName}") public int updateStatus(@Param("status") String status,@Param("inputFileName") String inputFileName); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsDetectorsService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsDetectorsService.java new file mode 100644 index 00000000..b62d69b6 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsDetectorsService.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.base.entity.configuration.GardsDetectors; + +/** + * 探测器服务 + */ +public interface GardsDetectorsService extends IService { + + /** + * 校验探测器是否存在,不存在则创建 + * @param detectorCode + */ + GardsDetectors check(String detectorCode); +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsSampleDataService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsSampleDataService.java index 8fc6d37d..65083a27 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsSampleDataService.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsSampleDataService.java @@ -25,7 +25,7 @@ public interface GardsSampleDataService extends IService { * @param dataType * @return */ - public GardsSampleData getSampleIdAndInputFileName(String measurementId,String dataType); + public GardsSampleData getSampleIdAndInputFileName(String measurementId,String dataType, String systemType); /** * 修改能谱处理状态 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java new file mode 100644 index 00000000..f462b7e0 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/GardsStationsService.java @@ -0,0 +1,17 @@ +package org.jeecg.modules.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.base.entity.configuration.GardsStations; +import org.jeecg.modules.exception.StationNotFoundException; + +/** + * 台站服务 + */ +public interface GardsStationsService extends IService { + + /** + * 校验台站编码是否存在 + * @return + */ + GardsStations check(String site_code) throws StationNotFoundException; +} 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 9595be0c..aed8319b 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 @@ -10,8 +10,8 @@ import org.jeecg.modules.base.entity.configuration.GardsStations; import org.jeecg.modules.base.entity.original.GardsAlertData; import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.mapper.GardsAlertDataMapper; -import org.jeecg.modules.mapper.GardsStationsMapper; import org.jeecg.modules.native_jni.struct.AlertSpectrumStruct; +import org.jeecg.modules.service.GardsStationsService; import org.jeecg.modules.service.IAlertSpectrumService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,7 +25,7 @@ import org.springframework.util.Assert; @RequiredArgsConstructor public class AlertSpectrumServiceImpl extends ServiceImpl implements IAlertSpectrumService { - private final GardsStationsMapper gardsStationsMapper; + private final GardsStationsService stationsService; /** * 保存报警谱信息 @@ -38,14 +38,11 @@ public class AlertSpectrumServiceImpl extends ServiceImpl gardsStationsQuery = new LambdaQueryWrapper<>(); - gardsStationsQuery.select(GardsStations::getStationId); - gardsStationsQuery.eq(GardsStations::getStationCode,struct.station_code); - final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery); - Assert.notNull(stations,"此台站代码:"+struct.station_code+"所属台站不存在"); + //校验台站是否存在,不存在则报异常 + final GardsStations station = stationsService.check(struct.station_code); GardsAlertData alertData = new GardsAlertData(); - alertData.setStationId(stations.getStationId()); + alertData.setStationId(station.getStationId()); alertData.setStationCode(struct.station_code); alertData.setTime(DateUtils.parseDate(struct.date+" "+struct.time)); alertData.setAlertType(struct.alert_type); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsDetectorsServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsDetectorsServiceImpl.java new file mode 100644 index 00000000..b88bb174 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsDetectorsServiceImpl.java @@ -0,0 +1,46 @@ +package org.jeecg.modules.service.impl; + +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 org.jeecg.common.properties.DetectorIdFormat; +import org.jeecg.modules.base.entity.configuration.GardsDetectors; +import org.jeecg.modules.base.enums.DetectorsStatus; +import org.jeecg.modules.mapper.GardsDetectorsMapper; +import org.jeecg.modules.service.GardsDetectorsService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.Date; +import java.util.Objects; + +@DS("ora") +@Service +@RequiredArgsConstructor +public class GardsDetectorsServiceImpl extends ServiceImpl implements GardsDetectorsService { + + private final DetectorIdFormat format; + + /** + * 校验探测器是否存在,不存在则创建 + * @param detectorCode + */ + @Transactional + @Override + public GardsDetectors check(String detectorCode) { + LambdaQueryWrapper detectorsQuery = new LambdaQueryWrapper<>(); + detectorsQuery.select(GardsDetectors::getDetectorId); + detectorsQuery.eq(GardsDetectors::getDetectorCode,detectorCode); + final GardsDetectors query = this.baseMapper.selectOne(detectorsQuery); + if(Objects.isNull(query)){ + GardsDetectors detector = new GardsDetectors(); + detector.setDetectorId(format.formatDetectorCodeToId(detectorCode)); + detector.setDetectorCode(detectorCode); + detector.setStatus(DetectorsStatus.OPERATING.getStatus()); + detector.setModdate(new Date()); + this.baseMapper.insert(detector); + return detector; + } + return query; + } +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java index c47689a5..fbe35204 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java @@ -61,8 +61,9 @@ public class GardsSampleDataServiceImpl extends ServiceImpl sampleDatas = this.baseMapper.getSampleIdAndInputFileName(measurementId, dataType); + public GardsSampleData getSampleIdAndInputFileName(String measurementId, String dataType, String systemType) { + String detectorId = measurementId.substring(0, 8); + final List sampleDatas = this.baseMapper.getSampleIdAndInputFileName(measurementId, dataType, systemType, detectorId); if(!CollectionUtils.isEmpty(sampleDatas)){ //如果查询出多条则需要根据inputFileName字段降序排序后返回第一个 final List sortResult = sampleDatas.stream().sorted(Comparator.comparing(GardsSampleData::getInputFileName).reversed()).collect(Collectors.toList()); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java new file mode 100644 index 00000000..9d786aac --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java @@ -0,0 +1,38 @@ +package org.jeecg.modules.service.impl; + +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 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; + +@DS("ora") +@Service +@RequiredArgsConstructor +public class GardsStationsServiceImpl extends ServiceImpl implements GardsStationsService { + + /** + * 校验台站编码是否存在 + * + * @param site_code + * @return + */ + @Override + public GardsStations check(String site_code) throws StationNotFoundException { + LambdaQueryWrapper 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"); + } + return station; + } +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java index 3696307d..01b09677 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/MetSpectrumServiceImpl.java @@ -12,6 +12,7 @@ import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.mapper.GardsMetDataMapper; import org.jeecg.modules.mapper.GardsStationsMapper; import org.jeecg.modules.native_jni.struct.MetSpectrumStruct; +import org.jeecg.modules.service.GardsStationsService; import org.jeecg.modules.service.IMetSpectrumService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,7 +30,7 @@ import java.util.List; @RequiredArgsConstructor public class MetSpectrumServiceImpl extends ServiceImpl implements IMetSpectrumService { - private final GardsStationsMapper gardsStationsMapper; + private final GardsStationsService stationsService; /** * 保存气象谱数据 @@ -43,16 +44,13 @@ public class MetSpectrumServiceImpl extends ServiceImpl create(MetSpectrumStruct struct,String fileName) throws Exception{ Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空"); - LambdaQueryWrapper gardsStationsQuery = new LambdaQueryWrapper<>(); - gardsStationsQuery.select(GardsStations::getStationId); - gardsStationsQuery.eq(GardsStations::getStationCode,struct.station_code); - final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery); - Assert.notNull(stations,"此台站代码:"+struct.station_code+"所属台站不存在"); + //校验台站是否存在,不存在则报异常 + final GardsStations station = stationsService.check(struct.station_code); List list = Lists.newArrayList(); if(struct.record_count > 0){ for(int i=0;i implements ISOHSpectrumService { - private final GardsStationsMapper gardsStationsMapper; - private final GardsDetectorsMapper gardsDetectorsMapper; + private final GardsStationsService stationsService; + private final GardsDetectorsService detectorsService; /** * 保存健康谱数据 @@ -47,29 +46,23 @@ public class SOHSpectrumServiceImpl extends ServiceImpl gardsStationsQuery = new LambdaQueryWrapper<>(); - gardsStationsQuery.select(GardsStations::getStationId); - gardsStationsQuery.eq(GardsStations::getStationCode,struct.station_code); - final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery); - Assert.notNull(stations,"此台站代码:"+struct.station_code+"所属台站不存在"); + //校验台站是否存在,不存在则报异常 + final GardsStations station = stationsService.check(struct.station_code); + //校验探测器是否存在,不存在则创建 + final GardsDetectors detector = detectorsService.check(struct.detector_code); - LambdaQueryWrapper gardsGardsDetectorsQuery = new LambdaQueryWrapper<>(); - gardsGardsDetectorsQuery.select(GardsDetectors::getDetectorId); - gardsGardsDetectorsQuery.eq(GardsDetectors::getDetectorCode,struct.detector_code); - final GardsDetectors gardsDetectors = gardsDetectorsMapper.selectOne(gardsGardsDetectorsQuery); - Assert.notNull(gardsDetectors,"此探测器代码:"+struct.detector_code+"所属探测器不存在"); List list = Lists.newArrayList(); if(struct.af_record_count > 0){ for(int i=0;i gardsStationsQuery = new LambdaQueryWrapper<>(); - gardsStationsQuery.select(GardsStations::getStationId); - gardsStationsQuery.eq(GardsStations::getStationCode,struct.site_code); - final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery); - Assert.notNull(stations,"此台站代码:"+struct.site_code+"所属台站不存在"); - - LambdaQueryWrapper gardsGardsDetectorsQuery = new LambdaQueryWrapper<>(); - gardsGardsDetectorsQuery.select(GardsDetectors::getDetectorId); - gardsGardsDetectorsQuery.eq(GardsDetectors::getDetectorCode,struct.detector_code); - final GardsDetectors gardsDetectors = gardsDetectorsMapper.selectOne(gardsGardsDetectorsQuery); - Assert.notNull(gardsDetectors,"此探测器代码:"+struct.detector_code+"所属探测器不存在"); + 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 GardsDetectors detector = detectorsService.check(struct.detector_code); GardsSampleData gardsSampleData = new GardsSampleData(); gardsSampleData.setSiteDetCode(struct.detector_code); // gardsSampleData.setSampleId();//数据库自增 - gardsSampleData.setStationId(stations.getStationId()); - gardsSampleData.setDetectorId(gardsDetectors.getDetectorId()); + gardsSampleData.setStationId(station.getStationId()); + gardsSampleData.setDetectorId(detector.getDetectorId()); gardsSampleData.setInputFileName(fileName); gardsSampleData.setSampleType(struct.system_type); gardsSampleData.setDataType(String.valueOf(struct.data_type.charAt(0))); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java index d9c55f63..f9daa734 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java @@ -8,7 +8,6 @@ import org.apache.logging.log4j.util.Strings; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.modules.base.entity.original.GardsSampleData; -import org.jeecg.modules.base.enums.DataType; import org.jeecg.modules.base.enums.SampleStatus; import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.exception.AcquisitionBlockException; @@ -21,8 +20,6 @@ import org.jeecg.modules.service.ISpectrumBlockService; import org.springframework.boot.system.ApplicationHome; import org.springframework.transaction.TransactionStatus; import java.io.*; -import java.math.BigDecimal; -import java.math.RoundingMode; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -132,45 +129,13 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa newFileName.append(StringUtils.replace(this.sourceData.acquisition_start_date,StringConstant.SLASH,"")); newFileName.append(StringConstant.UNDER_LINE); newFileName.append(StringUtils.replace(this.sourceData.acquisition_start_time.substring(0,this.sourceData.acquisition_start_time.lastIndexOf(":")),":","")); - newFileName.append(StringConstant.UNDER_LINE); - newFileName.append(this.sourceData.data_type.charAt(0)); - newFileName.append(StringConstant.UNDER_LINE); - newFileName.append(this.sourceData.spectrum_quantity); - newFileName.append(StringConstant.UNDER_LINE); - newFileName.append(handleLiveTime()); - newFileName.append(super.currDataType.getSuffix()); + newFileName.append(super.spectrumServiceQuotes.getNameStandUtil().GetSuffix(super.currDataType.getType(),this.sourceData.spectrum_quantity,String.valueOf(this.sourceData.acquisition_live_time))); if(!super.spectrumFile.exists()){ throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist"); } super.spectrumFile = FileUtil.rename(super.spectrumFile, newFileName.toString(), true); } - /** - * 处理acquisition_live_time字段 - * @return - */ - private String handleLiveTime(){ - BigDecimal bg = new BigDecimal(this.sourceData.acquisition_live_time); - //将acquisition_live_time保留一位小数 如果保留一位小数后小数点后的值是0则四舍五入保留整数,否则按正常条件四舍五入保留小数位 - String scale = bg.setScale(1, RoundingMode.HALF_UP).toPlainString(); - if(DataType.SAMPLEPHD.getType().equals(super.currDataType.getType()) || DataType.GASBKPHD.getType().equals(super.currDataType.getType())){ - if (scale.indexOf(".0") > 0) { - bg = bg.setScale(0, RoundingMode.HALF_UP); - } else { - bg = bg.setScale(1, RoundingMode.HALF_UP); - } - }else if(DataType.DETBKPHD.getType().equals(super.currDataType.getType())){ - bg = bg.setScale(0, RoundingMode.HALF_UP); - }else if(DataType.QCPHD.getType().equals(super.currDataType.getType())){ - if (scale.indexOf(".0") > 0) { - bg = bg.setScale(0, RoundingMode.HALF_UP); - } else { - bg = bg.setScale(2, RoundingMode.HALF_UP); - } - } - return bg.toPlainString(); - } - /** * 读取邮件内容#开头的标签 * @throws Exception @@ -190,37 +155,39 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa */ @Override protected void handlerOriginalData() throws Exception { - this.startIntoDatabaseTime = new Date(); - //如果数据已经存储,不在重复存储 - final GardsSampleData query = spectrumServiceQuotes.getSampleDataService().findByInputFileName(super.spectrumFileRelativePath); - if(Objects.nonNull(query)){ - this.sampleData = query; - this.endIntoDatabaseTime = new Date(); - //设置文件重复标记为true - this.parsingProcessLog.setFileRepeat(true); - throw new FileRepeatException("file repeat"); - } - DataSourceSwitcher.switchToOracle(); - final TransactionStatus transactionStatus = spectrumServiceQuotes.getTransactionManager().getTransaction(spectrumServiceQuotes.getTransactionDefinition()); - try{ - //存储基础数据 - this.sampleData = spectrumServiceQuotes.getSpectrumBaseBlockService().create(this.sourceData,super.spectrumFileRelativePath,status); - //存储其他块数据 - for(String labels : spectrumFileLabels){ - final ISpectrumBlockService spectrumBlockService = spectrumServiceQuotes.getSpectrumBlockService().get(labels); - if(Objects.nonNull(spectrumBlockService)){ - spectrumBlockService.create(sourceData,this.sampleData); - } + synchronized (spectrumServiceQuotes.getOriginalLibraryLock()){ + this.startIntoDatabaseTime = new Date(); + //如果数据已经存储,不在重复存储 + final GardsSampleData query = spectrumServiceQuotes.getSampleDataService().findByInputFileName(super.spectrumFileRelativePath); + if(Objects.nonNull(query)){ + this.sampleData = query; + this.endIntoDatabaseTime = new Date(); + //设置文件重复标记为true + this.parsingProcessLog.setFileRepeat(true); + throw new FileRepeatException("file repeat"); + } + DataSourceSwitcher.switchToOracle(); + final TransactionStatus transactionStatus = spectrumServiceQuotes.getTransactionManager().getTransaction(spectrumServiceQuotes.getTransactionDefinition()); + try{ + //存储基础数据 + this.sampleData = spectrumServiceQuotes.getSpectrumBaseBlockService().create(this.sourceData,super.spectrumFileRelativePath,status); + //存储其他块数据 + for(String labels : spectrumFileLabels){ + final ISpectrumBlockService spectrumBlockService = spectrumServiceQuotes.getSpectrumBlockService().get(labels); + if(Objects.nonNull(spectrumBlockService)){ + spectrumBlockService.create(sourceData,this.sampleData); + } + } + //提交事务 + this.spectrumServiceQuotes.getTransactionManager().commit(transactionStatus); + }catch (Exception e){ + //回滚事务 + spectrumServiceQuotes.getTransactionManager().rollback(transactionStatus); + throw e; + }finally { + this.endIntoDatabaseTime = new Date(); + DataSourceSwitcher.clearDataSource(); } - //提交事务 - this.spectrumServiceQuotes.getTransactionManager().commit(transactionStatus); - this.endIntoDatabaseTime = new Date(); - }catch (Exception e){ - //回滚事务 - spectrumServiceQuotes.getTransactionManager().rollback(transactionStatus); - throw e; - }finally { - DataSourceSwitcher.clearDataSource(); } } @@ -228,7 +195,10 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa * 修改解析状态 */ protected void updateStatus(){ - this.spectrumServiceQuotes.getSampleDataService().updateStatus(this.status,this.sampleData.getInputFileName()); + //这里要加非空判断,若台站或探测器不存在,这时所有数据还都没有入库sampleData还为null,不需要修改状态 + if(Objects.nonNull(this.sampleData)){ + this.spectrumServiceQuotes.getSampleDataService().updateStatus(this.status,this.sampleData.getInputFileName()); + } } /** diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java index 10c379e9..c485d87a 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java @@ -13,6 +13,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; import java.util.Objects; +import java.util.UUID; /** * 能谱处理模版 @@ -43,6 +44,10 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { * 能谱文件保存相对路径 */ protected String spectrumFileRelativePath; + /** + * 是否来自于undel目录 + */ + protected boolean fromUndel = false; /** * 保存当前能谱文件有哪些#开头的标签 @@ -57,15 +62,25 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { this.spectrumServiceQuotes = spectrumServiceQuotes; } + /** + * 初始化参数 + */ + public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,boolean fromUndel) throws Exception{ + this.mailContent = mailContent; + this.spectrumServiceQuotes = spectrumServiceQuotes; + this.fromUndel = fromUndel; + } + /** * 初始化参数 */ protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File spectrumFile,DataType currDataType, - String mailContent){ + String mailContent,boolean fromUndel){ this.spectrumServiceQuotes = spectrumServiceQuotes; this.spectrumFile = spectrumFile; this.currDataType = currDataType; this.mailContent = mailContent; + this.fromUndel = fromUndel; this.setChina(); } @@ -96,7 +111,8 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { finalPath.append(fileSavePath); finalPath.append(File.separator); finalPath.append(this.spectrumFile.getName()); - FileOperation.copyFile(this.spectrumFile,finalPath.toString(),true); + FileOperation.moveFile(this.spectrumFile,finalPath.toString(),true); + this.spectrumFile = new File(finalPath.toString()); //设置能谱文件保存相对路径(包含文件名称) this.spectrumFileRelativePath = fileSavePath+File.separator+this.spectrumFile.getName(); } @@ -143,7 +159,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { StringBuilder localPath = new StringBuilder(); localPath.append(this.spectrumServiceQuotes.getTaskProperties().getTemporaryStoragePath()); localPath.append(File.separator); - localPath.append(System.currentTimeMillis()+StringConstant.UNDER_LINE+RandomUtils.nextInt()); + localPath.append(UUID.randomUUID()); localPath.append(value.getSuffix()); this.spectrumFile = FileUtil.writeString(this.mailContent, localPath.toString(), "UTF-8"); // 能谱数据类型如果是 SPHDP 或者 SPHDF 统一改为 SAMPLEPHD @@ -168,14 +184,34 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { * @throws FileNotFoundException */ protected void handleParseingFailFile() throws FileNotFoundException { - try { - //解析失败会把文件移动到undeal目录 - final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); - final String undealPath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath(); - final String finalPath = rootPath+File.separator+undealPath; - FileOperation.copyFile(spectrumFile,finalPath,true); - } catch (IOException ex) { - ex.printStackTrace(); + if(!fromUndel){ + try { + //解析失败会把文件移动到undeal目录 + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String undealPath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath(); + final String finalPath = rootPath+File.separator+undealPath; + FileOperation.copyFile(spectrumFile,finalPath,true); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + /** + * 若文件件来自于undel并且解析成功后则需要把undel目录里文件删除 + */ + protected void deleteIfFromUndelFile(){ + if(fromUndel){ + StringBuilder undealFilePath = new StringBuilder(); + undealFilePath.append(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()); + undealFilePath.append(File.separator); + undealFilePath.append(spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath()); + undealFilePath.append(File.separator); + undealFilePath.append(this.spectrumFile.getName()); + File undelFile = new File(undealFilePath.toString()); + if(undelFile.exists()){ + undelFile.delete(); + } } } 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 398e4420..712e3acd 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 @@ -47,7 +47,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{ protected void setChina() { AbstractSpectrumHandler spectrumHandler = new HealthStatusSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, - super.currDataType,super.mailContent); + super.currDataType,super.mailContent,super.fromUndel); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -70,8 +70,8 @@ public class AlertSpectrum extends AbstractSpectrumHandler{ super.saveFileToSavefile(); //结构体数据入库 this.handlerOriginalData(); - //删除本地临时文件 - super.deleteLocalTemporaryFile(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); }catch (Exception e){ throw e; }finally { 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 e0309048..56f86467 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 @@ -16,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.currDataType,super.mailContent,super.fromUndel); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -45,6 +45,8 @@ public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); }catch (Exception e){ //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); @@ -57,8 +59,6 @@ public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { if(Objects.nonNull(this.parsingProcessLog)){ this.parsingProcessLog.handleLog(); } - //删除本地临时文件 - super.deleteLocalTemporaryFile(); } }else{ super.next.handler(); 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 fa8f2d51..19e8506f 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 @@ -18,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.currDataType,super.mailContent,super.fromUndel); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -47,6 +47,8 @@ public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); }catch (Exception e){ //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); @@ -59,8 +61,6 @@ public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { if(Objects.nonNull(this.parsingProcessLog)){ this.parsingProcessLog.handleLog(); } - //删除本地临时文件 - super.deleteLocalTemporaryFile(); } }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 8a67f5d8..fb554287 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 @@ -67,10 +67,10 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{ super.saveFileToSavefile(); //结构体数据入库 this.handlerOriginalData(); - //删除本地临时文件 - super.deleteLocalTemporaryFile(); //把流程日志保存到日志目录 this.saveLogToLogDir(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); } } 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 f1c2f9d6..b243a61a 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 @@ -43,7 +43,7 @@ public class MetSpectrum extends AbstractSpectrumHandler{ protected void setChina() { AbstractSpectrumHandler spectrumHandler = new AlertSpectrum(); spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile, - super.currDataType,super.mailContent); + super.currDataType,super.mailContent,super.fromUndel); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -62,10 +62,10 @@ public class MetSpectrum extends AbstractSpectrumHandler{ super.saveFileToSavefile(); //结构体数据入库 this.handlerOriginalData(); - //删除本地临时文件 - super.deleteLocalTemporaryFile(); //把流程日志保存到日志目录 this.saveLogToLogDir(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); }else{ super.next.handler(); } 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 85b826d0..ef489640 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 @@ -16,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.currDataType,super.mailContent,super.fromUndel); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -46,6 +46,8 @@ public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); }catch (Exception e){ //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); @@ -58,8 +60,6 @@ public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { if(Objects.nonNull(this.parsingProcessLog)){ this.parsingProcessLog.handleLog(); } - //删除本地临时文件 - super.deleteLocalTemporaryFile(); } }else{ super.next.handler(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java index dc3c632c..5ac1056b 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java @@ -64,7 +64,7 @@ public class Sample_B_Analysis implements BlockConstant { /** * sample谱PHD文件临时路径 */ - private String sampleTempFilePath; + private String sampleFileFinalPath; /** * det谱PHD文件临时路径 */ @@ -129,7 +129,7 @@ public class Sample_B_Analysis implements BlockConstant { public Sample_B_Analysis(AbstractS_D_Q_G_SpectrumHandler spectrumHandler){ this.sampleData = spectrumHandler.sampleData; - this.sampleTempFilePath = spectrumHandler.spectrumFile.getAbsolutePath(); + this.sampleFileFinalPath = spectrumHandler.spectrumFile.getAbsolutePath(); this.spectrumServiceQuotes = spectrumHandler.spectrumServiceQuotes; this.sampleStruct = spectrumHandler.sourceData; this.parsingProcessLog = spectrumHandler.parsingProcessLog; @@ -181,8 +181,8 @@ public class Sample_B_Analysis implements BlockConstant { */ private void queryPHDFile() throws FileNotExistException { //查询det和gas能谱文 - this.detSampleData = spectrumServiceQuotes.getSampleDataService().getSampleIdAndInputFileName(this.sampleStruct.detector_bk_measurement_id, DataTypeAbbr.DETBKPHD.getType()); - this.gasSampleData = spectrumServiceQuotes.getSampleDataService().getSampleIdAndInputFileName(this.sampleStruct.gas_bk_measurement_id, DataTypeAbbr.GASBKPHD.getType()); + this.detSampleData = spectrumServiceQuotes.getSampleDataService().getSampleIdAndInputFileName(this.sampleStruct.detector_bk_measurement_id, DataTypeAbbr.DETBKPHD.getType(), this.sampleStruct.system_type); + this.gasSampleData = spectrumServiceQuotes.getSampleDataService().getSampleIdAndInputFileName(this.sampleStruct.gas_bk_measurement_id, DataTypeAbbr.GASBKPHD.getType(), this.sampleStruct.system_type); //如果找不到sample、det、gas谱文件数据则解析失败修改记录状态 if(StringUtils.isEmpty(this.sampleData.getInputFileName()) || Objects.isNull(this.detSampleData) || StringUtils.isEmpty(this.detSampleData.getInputFileName()) || Objects.isNull(this.gasSampleData) || StringUtils.isEmpty(this.gasSampleData.getInputFileName())){ @@ -217,10 +217,10 @@ public class Sample_B_Analysis implements BlockConstant { * 调用dll库的分析B谱结果 */ private void autoAnalyse() throws BAnalyseException, FileNotExistException { - BgAnalyseResult analyseResult = EnergySpectrumHandler.bgAnalyse(this.sampleTempFilePath,this.gasFileFinalPath,this.detFileFinalPath); + BgAnalyseResult analyseResult = EnergySpectrumHandler.bgAnalyse(this.sampleFileFinalPath,this.gasFileFinalPath,this.detFileFinalPath); System.out.println(analyseResult); if(Objects.isNull(analyseResult) || !analyseResult.analyse_flag){ - throw new BAnalyseException("THE PHD file cannot be parsed:"+this.sampleTempFilePath+","+this.gasFileFinalPath+","+this.detFileFinalPath); + throw new BAnalyseException("THE PHD file cannot be parsed:"+this.sampleFileFinalPath+","+this.gasFileFinalPath+","+this.detFileFinalPath); } this.analyseResult = analyseResult; } @@ -232,14 +232,26 @@ public class Sample_B_Analysis implements BlockConstant { private void getPHDFile() throws IOException, FileNotExistException { boolean flag = false; //gas谱PHD文件本地路径 - this.gasFileFinalPath = this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+File.separator+this.spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath()+File.separator+gasSampleData.getInputFileName(); + StringBuilder gasFileFinalPath = new StringBuilder(); + gasFileFinalPath.append(this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()); + gasFileFinalPath.append(File.separator); + gasFileFinalPath.append(this.spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath()); + gasFileFinalPath.append(File.separator); + gasFileFinalPath.append(gasSampleData.getInputFileName()); + this.gasFileFinalPath = gasFileFinalPath.toString(); File gasFile = new File(this.gasFileFinalPath); if(!gasFile.exists()){ flag = true; } //det谱PHD文件本地路径 - this.detFileFinalPath = this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()+File.separator+this.spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath()+File.separator+detSampleData.getInputFileName(); + StringBuilder detFileFinalPath = new StringBuilder(); + detFileFinalPath.append(this.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()); + detFileFinalPath.append(File.separator); + detFileFinalPath.append(this.spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath()); + detFileFinalPath.append(File.separator); + detFileFinalPath.append(detSampleData.getInputFileName()); + this.detFileFinalPath = detFileFinalPath.toString(); File detFile = new File(this.detFileFinalPath); if(!detFile.exists()){ flag = true; @@ -263,7 +275,7 @@ public class Sample_B_Analysis implements BlockConstant { //如果数据已经存储,不在重复存储 final Integer idAnalysis = spectrumServiceQuotes.getAnalysesService().getIdAnalysis(this.sampleData.getSampleId()); if(Objects.nonNull(idAnalysis)){ - log.warn("{} file analysis data has been stored",new File(this.sampleTempFilePath).getName()); + log.warn("{} file analysis data has been stored",new File(this.sampleFileFinalPath).getName()); return; } DataSourceSwitcher.switchToOracle(); 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 7c555044..d4e4f086 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 @@ -17,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.currDataType,super.mailContent,super.fromUndel); spectrumHandler.setPrevious(this); super.setNext(spectrumHandler); } @@ -49,6 +49,8 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { //修改状态为解析完成 super.status = SampleStatus.COMPLETE.getValue(); super.updateStatus(); + //若本次文件来自于undel目录,解析成功则删除 + deleteIfFromUndelFile(); }catch (Exception e){ //修改状态为解析失败 super.status = SampleStatus.FAIL.getValue(); @@ -61,8 +63,6 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { if(Objects.nonNull(this.parsingProcessLog)){ this.parsingProcessLog.handleLog(); } - //删除本地临时文件 - super.deleteLocalTemporaryFile(); } }else{ super.next.handler(); 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 e4b5f0f8..b43e6df9 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 @@ -2,10 +2,9 @@ package org.jeecg.modules.spectrum; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.jeecg.common.properties.ParameterProperties; -import org.jeecg.common.properties.SoftwareProperties; -import org.jeecg.common.properties.SpectrumPathProperties; -import org.jeecg.common.properties.TaskProperties; +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; import org.jeecg.modules.service.*; @@ -76,4 +75,13 @@ public class SpectrumServiceQuotes { private final ResourceLoader resourceLoader; + private final NameStandUtil nameStandUtil; + + private final LogFileUtil logFileUtil; + + /** + * 原始库插入数据锁 + */ + private final Object originalLibraryLock = new Object(); + }