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

This commit is contained in:
nieziyan 2023-10-25 17:18:35 +08:00
commit 89c5377c09
32 changed files with 511 additions and 175 deletions

View File

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

View File

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

View File

@ -51,6 +51,11 @@ public class TaskProperties implements Serializable {
*/
private Integer undealDirReceiveNum;
/**
* undeal目录文件分析周期
*/
private Integer undealFileTimeOut;
/**
* filesource目录文件获取周期
*/

View File

@ -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消息
*

View File

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

View File

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

View File

@ -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 {

View File

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

View File

@ -0,0 +1,9 @@
package org.jeecg.modules.exception;
public class StationNotFoundException extends Exception {
public StationNotFoundException(String message) {
super(message);
}
}

View File

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

View File

@ -13,8 +13,8 @@ public interface GardsSampleDataMapper extends BaseMapper<GardsSampleData> {
@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<GardsSampleData> 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<GardsSampleData> 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);

View File

@ -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<GardsDetectors> {
/**
* 校验探测器是否存在不存在则创建
* @param detectorCode
*/
GardsDetectors check(String detectorCode);
}

View File

@ -25,7 +25,7 @@ public interface GardsSampleDataService extends IService<GardsSampleData> {
* @param dataType
* @return
*/
public GardsSampleData getSampleIdAndInputFileName(String measurementId,String dataType);
public GardsSampleData getSampleIdAndInputFileName(String measurementId,String dataType, String systemType);
/**
* 修改能谱处理状态

View File

@ -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<GardsStations> {
/**
* 校验台站编码是否存在
* @return
*/
GardsStations check(String site_code) throws StationNotFoundException;
}

View File

@ -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<GardsAlertDataMapper, GardsAlertData> implements IAlertSpectrumService {
private final GardsStationsMapper gardsStationsMapper;
private final GardsStationsService stationsService;
/**
* 保存报警谱信息
@ -38,14 +38,11 @@ public class AlertSpectrumServiceImpl extends ServiceImpl<GardsAlertDataMapper,
public GardsAlertData create(AlertSpectrumStruct struct, String fileName) throws Exception{
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
LambdaQueryWrapper<GardsStations> 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);

View File

@ -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<GardsDetectorsMapper, GardsDetectors> implements GardsDetectorsService {
private final DetectorIdFormat format;
/**
* 校验探测器是否存在不存在则创建
* @param detectorCode
*/
@Transactional
@Override
public GardsDetectors check(String detectorCode) {
LambdaQueryWrapper<GardsDetectors> 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;
}
}

View File

@ -61,8 +61,9 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
* @return
*/
@Override
public GardsSampleData getSampleIdAndInputFileName(String measurementId, String dataType) {
final List<GardsSampleData> sampleDatas = this.baseMapper.getSampleIdAndInputFileName(measurementId, dataType);
public GardsSampleData getSampleIdAndInputFileName(String measurementId, String dataType, String systemType) {
String detectorId = measurementId.substring(0, 8);
final List<GardsSampleData> sampleDatas = this.baseMapper.getSampleIdAndInputFileName(measurementId, dataType, systemType, detectorId);
if(!CollectionUtils.isEmpty(sampleDatas)){
//如果查询出多条则需要根据inputFileName字段降序排序后返回第一个
final List<GardsSampleData> sortResult = sampleDatas.stream().sorted(Comparator.comparing(GardsSampleData::getInputFileName).reversed()).collect(Collectors.toList());

View File

@ -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<GardsStationsMapper, GardsStations> implements GardsStationsService {
/**
* 校验台站编码是否存在
*
* @param site_code
* @return
*/
@Override
public GardsStations check(String site_code) throws StationNotFoundException {
LambdaQueryWrapper<GardsStations> gardsStationsQuery = new LambdaQueryWrapper<>();
gardsStationsQuery.select(GardsStations::getStationId);
gardsStationsQuery.eq(GardsStations::getStationCode,site_code);
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
if (Objects.isNull(station)) {
throw new StationNotFoundException("station_code:"+site_code+"=0");
}
return station;
}
}

View File

@ -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<GardsMetDataMapper, GardsMetData> implements IMetSpectrumService {
private final GardsStationsMapper gardsStationsMapper;
private final GardsStationsService stationsService;
/**
* 保存气象谱数据
@ -43,16 +44,13 @@ public class MetSpectrumServiceImpl extends ServiceImpl<GardsMetDataMapper, Gard
public List<GardsMetData> create(MetSpectrumStruct struct,String fileName) throws Exception{
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
LambdaQueryWrapper<GardsStations> 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<GardsMetData> list = Lists.newArrayList();
if(struct.record_count > 0){
for(int i=0;i<struct.record_count;i++){
GardsMetData metData = new GardsMetData();
metData.setStationId(stations.getStationId());
metData.setStationId(station.getStationId());
metData.setStationCode(struct.station_code);
metData.setStartTime(DateUtils.parseDate(struct.met_start_date.get(i)+" "+struct.met_start_time.get(i)));
metData.setEndTime(DateUtils.parseDate(struct.met_end_date.get(i)+" "+struct.met_end_time.get(i)));

View File

@ -10,16 +10,15 @@ import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsDetectorsMapper;
import org.jeecg.modules.mapper.GardsSohDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct;
import org.jeecg.modules.service.GardsDetectorsService;
import org.jeecg.modules.service.GardsStationsService;
import org.jeecg.modules.service.ISOHSpectrumService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
@ -31,8 +30,8 @@ import java.util.List;
@RequiredArgsConstructor
public class SOHSpectrumServiceImpl extends ServiceImpl<GardsSohDataMapper, GardsSohData> 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<GardsSohDataMapper, Gard
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空");
LambdaQueryWrapper<GardsStations> 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<GardsDetectors> 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<GardsSohData> list = Lists.newArrayList();
if(struct.af_record_count > 0){
for(int i=0;i<struct.af_record_count;i++){
GardsSohData sohData = new GardsSohData();
sohData.setStationId(stations.getStationId());
sohData.setStationId(station.getStationId());
sohData.setStationCode(struct.station_code);
sohData.setStartTime(DateUtils.parseDate(struct.af_start_date.get(i)+" "+struct.af_start_time.get(i)));
sohData.setTime(struct.af_interval_duration.get(i).doubleValue());
sohData.setAvgflowrate(struct.average_flow_rate.get(i));
sohData.setFlowratedev(struct.flow_rate_standard_deviation.get(i));
sohData.setInputFileName(FileOperation.separatorConvert(fileName));
sohData.setDetectorId(gardsDetectors.getDetectorId());
sohData.setDetectorId(detector.getDetectorId());
sohData.setModdate(new Date());
list.add(sohData);
}

View File

@ -1,6 +1,5 @@
package org.jeecg.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
@ -10,11 +9,11 @@ import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsSampleAux;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsDetectorsMapper;
import org.jeecg.modules.mapper.GardsSampleAuxMapper;
import org.jeecg.modules.mapper.GardsSampleDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
import org.jeecg.modules.service.GardsDetectorsService;
import org.jeecg.modules.service.GardsStationsService;
import org.jeecg.modules.service.ISpectrumBaseBlockService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
@ -28,10 +27,10 @@ import java.util.Objects;
@RequiredArgsConstructor
public class SpectrumBaseBlockServiceImpl implements ISpectrumBaseBlockService {
private final GardsStationsMapper gardsStationsMapper;
private final GardsDetectorsMapper gardsDetectorsMapper;
private final GardsStationsService stationsService;
private final GardsSampleDataMapper sampleDataMapper;
private final GardsSampleAuxMapper sampleAuxMapper;
private final GardsDetectorsService detectorsService;
/**
* 保存块数据
@ -57,26 +56,18 @@ public class SpectrumBaseBlockServiceImpl implements ISpectrumBaseBlockService {
* @throws Exception
*/
private GardsSampleData saveSampleData(EnergySpectrumStruct struct,String fileName,String status) throws Exception{
Assert.notNull(struct.site_code,"此次解析结构体中的台站“台站代码”为空");
Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空");
LambdaQueryWrapper<GardsStations> 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<GardsDetectors> 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)));

View File

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

View File

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

View File

@ -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 {

View File

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

View File

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

View File

@ -67,10 +67,10 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//删除本地临时文件
super.deleteLocalTemporaryFile();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}
}

View File

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

View File

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

View File

@ -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);
//如果找不到sampledetgas谱文件数据则解析失败修改记录状态
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();

View File

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

View File

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