fix:1.修改文件命名格式2.添加探测器若不存在则新增业务
This commit is contained in:
parent
27dea46773
commit
6d67e30906
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.jeecg.modules.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.base.entity.configuration.GardsStations;
|
||||
|
||||
/**
|
||||
* 台站服务
|
||||
*/
|
||||
public interface GardsStationsService extends IService<GardsStations> {
|
||||
|
||||
/**
|
||||
* 校验台站编码是否存在
|
||||
* @return
|
||||
*/
|
||||
GardsStations check(String site_code);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
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.mapper.GardsStationsMapper;
|
||||
import org.jeecg.modules.service.GardsStationsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@DS("ora")
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, GardsStations> implements GardsStationsService {
|
||||
|
||||
/**
|
||||
* 校验台站编码是否存在
|
||||
*
|
||||
* @param site_code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GardsStations check(String site_code) {
|
||||
LambdaQueryWrapper<GardsStations> gardsStationsQuery = new LambdaQueryWrapper<>();
|
||||
gardsStationsQuery.select(GardsStations::getStationId);
|
||||
gardsStationsQuery.eq(GardsStations::getStationCode,site_code);
|
||||
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
|
||||
Assert.notNull(station,"The station to which this "+site_code+" station code belongs does not exist");
|
||||
return station;
|
||||
}
|
||||
}
|
|
@ -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)));
|
||||
|
|
|
@ -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,38 @@ 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;
|
||||
//设置文件重复标记为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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,8 @@ 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.NameStandUtil;
|
||||
import org.jeecg.common.util.RedisStreamUtil;
|
||||
import org.jeecg.modules.datasource.OraDataSourceProperties;
|
||||
import org.jeecg.modules.service.*;
|
||||
|
@ -76,4 +74,11 @@ public class SpectrumServiceQuotes {
|
|||
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
private final NameStandUtil nameStandUtil;
|
||||
|
||||
/**
|
||||
* 原始库插入数据锁
|
||||
*/
|
||||
private final Object originalLibraryLock = new Object();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user