修改 不修改内容时保存到数据提示错误

This commit is contained in:
duwenyuan 2025-12-17 13:31:40 +08:00
parent 5cb0ca72a5
commit 8bac595897

View File

@ -1155,6 +1155,23 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
selfStationUtil.createGamma(path, selfStationData.getSampleFileName(), struct, sampleData);
}
public void updateROI(List<ROIParam> roiParams, SelfStationData selfStationData, PHDFile phdFile) {
EnergySpectrumStruct struct = selfStationData.getSampleStruct();
LinkedList<Integer> roiBBoundaryStart = Lists.newLinkedList();
LinkedList<Integer> roiBBoundaryStop = Lists.newLinkedList();
for (ROIParam roiParam : roiParams) {
roiBBoundaryStart.add(roiParam.getRoiNum() - 1, roiParam.getStartChannel());
roiBBoundaryStop.add(roiParam.getRoiNum() - 1, roiParam.getEndChannel());
}
// 根据ROI卡Gamma能谱数据
selfStationUtil.getGammaByROI("sample", roiBBoundaryStart, roiBBoundaryStop, selfStationData);
SelfStationVueData sampleData = selfStationData.getSampleVueData();
String path = StrUtil.subBefore(selfStationData.getSampleTmpPath(), StringPool.SLASH, true);
// 生成gamma数据
selfStationUtil.createGamma(path, selfStationData.getSampleFileName(), struct, sampleData, phdFile);
}
@Override
public Result updateROI(List<ROIParam> roiParams, String sampleFileName, String dataType, HttpServletRequest request) {
Result result = new Result();
@ -2194,6 +2211,25 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
map.put("max", max);
map.put("gammaSpectrum", seriseDataList);
//存储新的表单能量值
List<TableWidget> tableWidgets = new LinkedList();
List<SeriseData> newSeriseDataList = new LinkedList<>();
for (int i = 0; i < betaDataFile.getGammaList().size(); i++) {
//表单数据信息
TableWidget tableWidget = new TableWidget();
tableWidget.setRowCount(i + 1);
tableWidget.setChannel(betaDataFile.getGammaList().get(i).getX());
tableWidget.setEnergy(betaDataFile.getGammaList().get(i).getY());
tableWidgets.add(tableWidget);
//折线图位置信息
SeriseData seriseData = new SeriseData();
seriseData.setX(betaDataFile.getGammaList().get(i).getX());
seriseData.setY(betaDataFile.getGammaList().get(i).getY());
newSeriseDataList.add(seriseData);
}
map.put("tableWidgets", tableWidgets);
map.put("newScatterSeriesData", newSeriseDataList);
//判断人工交互的道值与能量对应参数数组是否为空
if (Objects.nonNull(betaDataFile.getBgPara()) && CollectionUtils.isNotEmpty(betaDataFile.getGammaList())) {
//存储计算参数道值
@ -2207,13 +2243,13 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
//存储新的线点能量值
List<SeriseData> newLineSeries = new LinkedList<>();
//存储新的表单能量值
List<TableWidget> tableWidgets = new LinkedList();
//List<TableWidget> tableWidgets = new LinkedList();
//存储新的公式参数C TO E
List<String> newFittingParaStr = new LinkedList<>();
//存储新的公式参数E TO C
List<String> newFittingParaToUiStr = new LinkedList<>();
//记录点值数组
List<SeriseData> newSeriseDataList = new LinkedList<>();
//List<SeriseData> newSeriseDataList = new LinkedList<>();
//遍历临时点数组 将点位的横坐标以及纵坐标封装到对应的数组
for (int i = 0; i < betaDataFile.getGammaList().size(); i++) {
xs.add(betaDataFile.getGammaList().get(i).getX());
@ -2592,70 +2628,37 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
if (StrUtil.isNotBlank(roiParams)) {
roiParamList = JSONArray.parseArray(roiParams, ROIParam.class);
this.updateROI(roiParamList, selfStationData);
// mapEnerKD; // 能量刻度 newEner=当前修改的刻度名称
selfStationData.getSampleVueData().getROIOnePHDFile().setNewEner(tempROIOnePHDFile.getNewEner());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapEnerKD(tempROIOnePHDFile.getMapEnerKD());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapEnerPara(tempROIOnePHDFile.getMapEnerPara());
selfStationData.getSampleVueData().getROITwoPHDFile().setNewEner(tempROIOnePHDFile.getNewEner());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapEnerKD(tempROIOnePHDFile.getMapEnerKD());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapEnerPara(tempROIOnePHDFile.getMapEnerPara());
selfStationData.getSampleVueData().getROIThreePHDFile().setNewEner(tempROIOnePHDFile.getNewEner());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapEnerKD(tempROIOnePHDFile.getMapEnerKD());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapEnerPara(tempROIOnePHDFile.getMapEnerPara());
selfStationData.getSampleVueData().getROIFourPHDFile().setNewEner(tempROIOnePHDFile.getNewEner());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapEnerKD(tempROIOnePHDFile.getMapEnerKD());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapEnerPara(tempROIOnePHDFile.getMapEnerPara());
// MapResoKD; // 分辨率刻度 newReso=当前修改的刻度名称
selfStationData.getSampleVueData().getROIOnePHDFile().setNewReso(tempROIOnePHDFile.getNewReso());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapResoKD(tempROIOnePHDFile.getMapResoKD());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapResoPara(tempROIOnePHDFile.getMapResoPara());
selfStationData.getSampleVueData().getROITwoPHDFile().setNewReso(tempROIOnePHDFile.getNewReso());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapResoKD(tempROIOnePHDFile.getMapResoKD());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapResoPara(tempROIOnePHDFile.getMapResoPara());
selfStationData.getSampleVueData().getROIThreePHDFile().setNewReso(tempROIOnePHDFile.getNewReso());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapResoKD(tempROIOnePHDFile.getMapResoKD());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapResoPara(tempROIOnePHDFile.getMapResoPara());
selfStationData.getSampleVueData().getROIFourPHDFile().setNewReso(tempROIOnePHDFile.getNewReso());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapResoKD(tempROIOnePHDFile.getMapResoKD());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapResoPara(tempROIOnePHDFile.getMapResoPara());
//
// MapEffiKD; // 效率刻度 NewEffi=当前修改的刻度名称
selfStationData.getSampleVueData().getROIOnePHDFile().setNewEffi(tempROIOnePHDFile.getNewEffi());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapEffiKD(tempROIOnePHDFile.getMapEffiKD());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapEffiPara(tempROIOnePHDFile.getMapEffiPara());
selfStationData.getSampleVueData().getROITwoPHDFile().setNewEffi(tempROIOnePHDFile.getNewEffi());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapEffiKD(tempROIOnePHDFile.getMapEffiKD());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapEffiPara(tempROIOnePHDFile.getMapEffiPara());
selfStationData.getSampleVueData().getROIThreePHDFile().setNewEffi(tempROIOnePHDFile.getNewEffi());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapEffiKD(tempROIOnePHDFile.getMapEffiKD());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapEffiPara(tempROIOnePHDFile.getMapEffiPara());
selfStationData.getSampleVueData().getROIFourPHDFile().setNewEffi(tempROIOnePHDFile.getNewEffi());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapEffiKD(tempROIOnePHDFile.getMapEffiKD());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapEffiPara(tempROIOnePHDFile.getMapEffiPara());
//
// MapTotEKD; // 总效率刻度 NewTotE=当前修改的刻度名称
selfStationData.getSampleVueData().getROIOnePHDFile().setNewTotE(tempROIOnePHDFile.getNewTotE());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapTotEKD(tempROIOnePHDFile.getMapTotEKD());
selfStationData.getSampleVueData().getROIOnePHDFile().setMapTotEPara(tempROIOnePHDFile.getMapTotEPara());
selfStationData.getSampleVueData().getROITwoPHDFile().setNewTotE(tempROIOnePHDFile.getNewTotE());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapTotEKD(tempROIOnePHDFile.getMapTotEKD());
selfStationData.getSampleVueData().getROITwoPHDFile().setMapTotEPara(tempROIOnePHDFile.getMapTotEPara());
selfStationData.getSampleVueData().getROIThreePHDFile().setNewTotE(tempROIOnePHDFile.getNewTotE());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapTotEKD(tempROIOnePHDFile.getMapTotEKD());
selfStationData.getSampleVueData().getROIThreePHDFile().setMapTotEPara(tempROIOnePHDFile.getMapTotEPara());
selfStationData.getSampleVueData().getROIFourPHDFile().setNewTotE(tempROIOnePHDFile.getNewTotE());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapTotEKD(tempROIOnePHDFile.getMapTotEKD());
selfStationData.getSampleVueData().getROIFourPHDFile().setMapTotEPara(tempROIOnePHDFile.getMapTotEPara());
PHDFile[] phdList = new PHDFile[]{
selfStationData.getSampleVueData().getROIOnePHDFile(),
selfStationData.getSampleVueData().getROITwoPHDFile(),
selfStationData.getSampleVueData().getROIThreePHDFile(),
selfStationData.getSampleVueData().getROIFourPHDFile(),
};
for (PHDFile phd : phdList) {
// mapEnerKD; // 能量刻度 newEner=当前修改的刻度名称
phd.setNewEner(tempROIOnePHDFile.getNewEner());
phd.setMapEnerKD(tempROIOnePHDFile.getMapEnerKD());
phd.setMapEnerPara(tempROIOnePHDFile.getMapEnerPara());
phd.setNewEner(tempROIOnePHDFile.getNewEner());
// MapResoKD; // 分辨率刻度 newReso=当前修改的刻度名称
phd.setNewReso(tempROIOnePHDFile.getNewReso());
phd.setMapResoKD(tempROIOnePHDFile.getMapResoKD());
phd.setMapResoPara(tempROIOnePHDFile.getMapResoPara());
// MapEffiKD; // 效率刻度 NewEffi=当前修改的刻度名称
phd.setNewEffi(tempROIOnePHDFile.getNewEffi());
phd.setMapEffiKD(tempROIOnePHDFile.getMapEffiKD());
phd.setMapEffiPara(tempROIOnePHDFile.getMapEffiPara());
// MapEffiKD; // 效率刻度 NewEffi=当前修改的刻度名称
phd.setNewTotE(tempROIOnePHDFile.getNewTotE());
phd.setMapTotEKD(tempROIOnePHDFile.getMapTotEKD());
phd.setMapTotEPara(tempROIOnePHDFile.getMapTotEPara());
}
}
BetaDataFile betaDataFile = selfStationData.getBetaDataFile();
// Gamma文件内容转换为PHD实体
SelfStationVueData sampleVueData = selfStationData.getSampleVueData();
PHDFile phdOne = sampleVueData.getROIOnePHDFile();
@ -2778,6 +2781,237 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
return result;
}
public Result Reprocessing1(String fileName, String processKey, String roiParams, HttpServletRequest request) {
//region 设置局部变量
Result result = new Result();
String userName = JwtUtil.getUserNameByToken(request);
// 获取当前角色的颜色配置
Map<String, String> colorMap = sysUserColorService.initColor(userName);
//获取自建台站缓存信息
Cache<String, SelfStationData> selfCache = selfStationCache.getSelfCache();
SelfStationData selfStationData = selfCache.getIfPresent(fileName + StringPool.DASH + userName);
if (Objects.isNull(selfStationData)) {
result.error500("Please select the parse file first");
return result;
}
BetaDataFile betaDataFile = selfStationData.getBetaDataFile();
EnergySpectrumStruct struct = selfStationData.getSampleStruct();
SelfStationVueData sampleVueData = selfStationData.getSampleVueData();
PHDFile phdOne = sampleVueData.getROIOnePHDFile();
PHDFile phdTwo = sampleVueData.getROITwoPHDFile();
PHDFile phdThree = sampleVueData.getROIThreePHDFile();
PHDFile phdFour = sampleVueData.getROIFourPHDFile();
//endregion
AnalyseData analyseData = (AnalyseData)redisUtil.get("analyseData");
//region 判断是否对beta页面进行过分析
if (analyseData.isBetaEnergyValid()) {
//如果进行过分析 则将当前beta用于分析的新的数据 赋值到最终使用的数组
if (Objects.nonNull(betaDataFile)) {
//重新分析时将当前的数组封装给到最终记录结果的数组中
betaDataFile.setBetaList(betaDataFile.getBetaListNow());
betaDataFile.setBetaFittingPara(betaDataFile.getBetaFittingParaNow());
betaDataFile.setBetaFittingParaToUi(betaDataFile.getBetaFittingParaToUiNow());
betaDataFile.setBetaNewEnergyList(betaDataFile.getBetaNewEnergyListNow());
}
// 接收算法计算得到的公式的数据
List<Double> fittingParas = betaDataFile.getBetaFittingParaNow().stream()
.map(Double::parseDouble)
.collect(Collectors.toList());
}
//endregion
//region 更新ROI
PHDFile tempROIOnePHDFile = new PHDFile();
tempROIOnePHDFile = selfStationData.getSampleVueData().getROIOnePHDFile();
List<ROIParam> roiParamList = null;
if (StrUtil.isNotBlank(roiParams)) {
roiParamList = JSONArray.parseArray(roiParams, ROIParam.class);
this.updateROI(roiParamList, selfStationData);
PHDFile[] phdList = new PHDFile[]{
selfStationData.getSampleVueData().getROIOnePHDFile(),
selfStationData.getSampleVueData().getROITwoPHDFile(),
selfStationData.getSampleVueData().getROIThreePHDFile(),
selfStationData.getSampleVueData().getROIFourPHDFile(),
};
for (PHDFile phd : phdList) {
// mapEnerKD; // 能量刻度 newEner=当前修改的刻度名称
phd.setNewEner(tempROIOnePHDFile.getNewEner());
phd.setMapEnerKD(tempROIOnePHDFile.getMapEnerKD());
phd.setMapEnerPara(tempROIOnePHDFile.getMapEnerPara());
phd.setNewEner(tempROIOnePHDFile.getNewEner());
// MapResoKD; // 分辨率刻度 newReso=当前修改的刻度名称
phd.setNewReso(tempROIOnePHDFile.getNewReso());
phd.setMapResoKD(tempROIOnePHDFile.getMapResoKD());
phd.setMapResoPara(tempROIOnePHDFile.getMapResoPara());
// MapEffiKD; // 效率刻度 NewEffi=当前修改的刻度名称
phd.setNewEffi(tempROIOnePHDFile.getNewEffi());
phd.setMapEffiKD(tempROIOnePHDFile.getMapEffiKD());
phd.setMapEffiPara(tempROIOnePHDFile.getMapEffiPara());
// MapEffiKD; // 效率刻度 NewEffi=当前修改的刻度名称
phd.setNewTotE(tempROIOnePHDFile.getNewTotE());
phd.setMapTotEKD(tempROIOnePHDFile.getMapTotEKD());
phd.setMapTotEPara(tempROIOnePHDFile.getMapTotEPara());
}
}
//endregion
//region 判断是否对gamma页面进行过分析
if (analyseData.isGammaEnergyValid()) {
//如果缓存数据不为空 且对gamma进行了计算 将当前gamma的计算结果赋值到最终的结果数组 进行新的分析使用
if (Objects.nonNull(betaDataFile)) {
betaDataFile.setGammaList(betaDataFile.getGammaListNow());
betaDataFile.setGammaFittingPara(betaDataFile.getGammaFittingParaNow());
betaDataFile.setGammaFittingParaToUi(betaDataFile.getGammaFittingParaToUiNow());
betaDataFile.setGammaNewEnergyList(betaDataFile.getGammaNewEnergyListNow());
// 接收算法计算得到的公式的数据
List<Double> fittingParas = betaDataFile.getGammaFittingParaNow().stream()
.map(Double::parseDouble)
.collect(Collectors.toList());
List<Double> newEnergyList = EnergySpectrumHandler.GetFileFittingData(struct.g_centroid_channel, fittingParas);
this.updateGammaEnergy(newEnergyList, phdOne, phdTwo, phdThree, phdFour);
}
}
//endregion
Map<String, NuclideLines> nuclideLinesMap = (Map<String, NuclideLines>) redisUtil.get(userName + StringPool.DASH + phdOne.getHeader().getSystem_type() + "-self");
Map<String, Object> resultMap = new HashMap<>();
try {
//region 修改ROI 重新分析gamma
boolean bROI1 = selfStationUtil.checkROIRenew(sampleVueData, SelfStationConstant.ROI1);
boolean bROI2 = selfStationUtil.checkROIRenew(sampleVueData, SelfStationConstant.ROI2);
boolean bROI3 = selfStationUtil.checkROIRenew(sampleVueData, SelfStationConstant.ROI3);
boolean bROI4 = selfStationUtil.checkROIRenew(sampleVueData, SelfStationConstant.ROI4);
int flag = gammaFileUtil.AnalyseData(phdOne);
// 如果参数没有修改且没有修改任何ROI则不允许分析
if (flag == 0 && !bROI1 && !bROI2 && !bROI3 && !bROI4) {
String warning = "The spectrum needn't Analyed. Maybe:\n" +
"1. It has already Analyed.\n" +
"2. You didn't change any setting or calibration.";
result.error500(StrUtil.replace(warning, "%s", "ROI"));
return result;
}
// 如果参数修改 或者 修改某个ROI 只重新分析某个gamma
if (flag != 0 || bROI1) {
resultMap.put(SelfStationConstant.ROI1, this.gammaAnalyse(processKey, phdOne, nuclideLinesMap, colorMap, flag));
}
if (flag != 0 || bROI2) {
resultMap.put(SelfStationConstant.ROI2, this.gammaAnalyse(processKey, phdTwo, nuclideLinesMap, colorMap, flag));
}
if (flag != 0 || bROI3) {
resultMap.put(SelfStationConstant.ROI3, this.gammaAnalyse(processKey, phdThree, nuclideLinesMap, colorMap, flag));
}
if (flag != 0 || bROI4) {
resultMap.put(SelfStationConstant.ROI4, this.gammaAnalyse(processKey, phdFour, nuclideLinesMap, colorMap, flag));
}
//endregion
//region 用于下次分析判断是否更新
sampleVueData.setUsedROIOneBetaStart(sampleVueData.getROIOneBetaStart());
sampleVueData.setUsedROIOneBetaStop(sampleVueData.getROIOneBetaStop());
sampleVueData.setUsedROITwoBetaStart(sampleVueData.getROITwoBetaStart());
sampleVueData.setUsedROITwoBetaStop(sampleVueData.getROITwoBetaStop());
sampleVueData.setUsedROIThreeBetaStart(sampleVueData.getROIThreeBetaStart());
sampleVueData.setUsedROIThreeBetaStop(sampleVueData.getROIThreeBetaStop());
sampleVueData.setUsedROIFourBetaStart(sampleVueData.getROIFourBetaStart());
sampleVueData.setUsedROIFourBetaStop(sampleVueData.getROIFourBetaStop());
sampleVueData.setUsedEner(phdOne.getUsedEner());
sampleVueData.setUsedEnerKD(phdOne.getUsedEnerKD());
sampleVueData.setUsedEffiKD(phdOne.getUsedEffiKD());
sampleVueData.setUsedResoKD(phdOne.getUsedResoKD());
sampleVueData.setMapEnerKD(phdOne.getMapEnerKD());
sampleVueData.setMapResoKD(phdOne.getMapResoKD());
sampleVueData.setMapEffiKD(phdOne.getMapEffiKD());
sampleVueData.setUsedEnerPara(phdOne.getUsedEnerPara());
sampleVueData.setUsedEffiPara(phdOne.getUsedEffiPara());
sampleVueData.setUsedResoPara(phdOne.getUsedResoPara());
sampleVueData.setMapEnerPara(phdOne.getMapEnerPara());
sampleVueData.setMapResoPara(phdOne.getMapResoPara());
sampleVueData.setMapEffiPara(phdOne.getMapEffiPara());
//endregion
//region 执行Beta分析获取Xe结果
SelfStationVueData sampleData = selfStationData.getSampleVueData();
// 获取自建台站参数
SelfParameter selfParameter = (SelfParameter) redisUtil.get(RedisConstant.SELF_PARAMETER);
HashMap<String, NuclideLine> nuclideMap = selfParameter.getNuclideMap();
// 执行Beta分析
List<GardsXeResultsSpectrum> betaResult = SelfBaseUtil.betaAnalyse(nuclideMap, struct.POI_G_y1,
struct.POI_G_y2, selfStationData.getSampleTmpPath(), sampleData.getROIOnePHDFile(), sampleData.getROITwoPHDFile(),
sampleData.getROIThreePHDFile(), sampleData.getROIFourPHDFile());
resultMap.put("XeData", betaResult);
List<GardsXeResults> xeResults = Lists.newArrayList(betaResult);
betaDataFile.setXeDataList(xeResults);
betaDataFile.setXeResultsSpectrumList(betaResult);
betaDataFile.setRoiResultsSpectrumList(SelfBaseUtil.getRoiResult(betaResult));
//endregion
//region 获取gammaEnergyDatabetaEnergyData
//横坐标 beta-gamma
long bChannels = struct.b_channels;
//纵坐标 gamma
long gChannels = struct.g_channels;
//调用算法 传入道值和道值对应的能量 得到计算gamma能量公式的参数
String currentText = phdOne.getUsedEner();
List<Double> m_vCurCentroid = phdOne.getMapEnerKD().get(currentText).getCentroid_channel();
List<Double> m_vCurEnergy = phdOne.getMapEnerKD().get(currentText).getG_energy();
List<Double> gammaParam = EnergySpectrumHandler.GetFileFittingPara(m_vCurCentroid, m_vCurEnergy);
//存储需要计算gamma能量的道值
List<Double> gchannels = new ArrayList<>();
for (int i = 0; i < gChannels; i++) {
gchannels.add(Double.valueOf(i));
}
//调用算法 传递gamma参与计算的道值以及计算公式参数 得到各道值对应的能量
List<Double> gammaEnergyList = EnergySpectrumHandler.GetFileFittingData(gchannels, gammaParam);
//将gamma能量折线图进行赋值返回
resultMap.put("gammaEnergyData", gammaEnergyList);
//调用算法 传入道值和道值对应的能量 得到计算beta能量公式的参数
// todo beta canshu xuyao tiaozheng
List<Double> betaParam = EnergySpectrumHandler.GetFileFittingPara(struct.b_channel, struct.b_electron_energy);
List<Double> bchannels = new ArrayList<>();
for (int i = 0; i < bChannels; i++) {
bchannels.add(Double.valueOf(i));
}
//传入道值和计算公式的参数计算出各道值对应的beta能量
List<Double> betaEnergyList = EnergySpectrumHandler.GetFileFittingData(bchannels, betaParam);
//将beta能量折线图进行赋值返回
resultMap.put("betaEnergyData", betaEnergyList);
//endregion
result.setSuccess(true);
result.setResult(resultMap);
selfStationData.setBAnalyed(true);
} catch (RuntimeException e) {
Log.error("analyse error", e);
result.error500(StrUtil.replace(e.getMessage(), "%s", "ROI"));
} catch (Exception e) {
Log.error("analyse error", e);
result.error500("analyse error!");
}
return result;
}
@Override
public Result InteractiveTool(Integer sampleId, String fileName, int gammaROINum, HttpServletRequest request) {
Result result = new Result();
@ -4106,11 +4340,24 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
return result;
}
//@Override
public Result ReAnalyse1(AnalyseData analyseData, HttpServletRequest request) {
Result result = new Result();
//声明接收当前分析后的返回结果的map
Map<String, Object> map = new HashMap<>();
redisUtil.set("analyseData", analyseData);
result.setSuccess(true);
result.setResult(map);
return result;
}
private Map<String, Object> BetaGammaAnalyzeCurrentProcess(AnalyseData analyseData, String userName, SelfStationData selfStationData) {
//声明一个map 缓存xeData计算后的结果
Map<String, Object> resultMap = new HashMap<>();
try {
//analyseData.setGammaEnergyValid(false);
BetaDataFile betaDataFile = selfStationData.getBetaDataFile();
EnergySpectrumStruct struct = selfStationData.getSampleStruct();
SelfStationVueData sampleVueData = selfStationData.getSampleVueData();
@ -5468,38 +5715,103 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
result.error500("Please select the parse file first");
return result;
}
EnergySpectrumStruct struct = selfStationData.getSampleStruct();
SelfStationVueData sampleVueData = selfStationData.getSampleVueData();
//region 获取 gamma
PHDFile phdFile = sampleVueData.getROIOnePHDFile();
long bChannels = struct.b_channels;
List<Double> betaParam = EnergySpectrumHandler.GetFileFittingPara(struct.b_channel, struct.b_electron_energy);
List<Double> bchannels = new ArrayList<>();
for (int i = 0; i < bChannels; i++) {
bchannels.add(Double.valueOf(i));
}
//传入道值和计算公式的参数计算出各道值对应的beta能量
List<Double> betaEnergyList = EnergySpectrumHandler.GetFileFittingData(bchannels, betaParam);
List<Double> POI_B_x1 = new ArrayList<>();
List<Double> POI_B_x2 = new ArrayList<>();
for (int r = 0; r < selfStationData.getRoiBBoundaryStart().size(); r++) {
int startChannel = selfStationData.getRoiBBoundaryStart().get(r);
int endChannel = selfStationData.getRoiBBoundaryStop().get(r);
POI_B_x1.add(betaEnergyList.get(startChannel));
POI_B_x2.add(betaEnergyList.get(endChannel));
}
Map<String, List<String>> blockUpdates = new HashMap<>();
List<String> newRoiData = format(struct.ROI_number, POI_B_x1, POI_B_x2, struct.POI_G_y1, struct.POI_G_y2);
blockUpdates.put(SampleFileHeader.ROILIMITS.getMessage(), newRoiData);
if (Objects.nonNull(phdFile.getUsedEnerKD())) {
List<String> newEnergy = format(phdFile.getUsedEnerKD().getG_energy(), phdFile.getUsedEnerKD().getCentroid_channel(), phdFile.getUsedEnerKD().getUncertainty());
blockUpdates.put(SampleFileHeader.GENERGY.getMessage(), newEnergy);
}
if (Objects.nonNull(phdFile.getUsedResoKD())) {
List<String> newResolution = format(phdFile.getUsedResoKD().getG_energy(), phdFile.getUsedResoKD().getFWHM(), phdFile.getUsedResoKD().getUncertainty());
blockUpdates.put(SampleFileHeader.GRESOLUTION.getMessage(), newResolution);
}
if (Objects.nonNull(phdFile.getUsedEffiKD())) {
List<String> newEfficiency = format(phdFile.getUsedEffiKD().getG_energy(), phdFile.getUsedEffiKD().getEfficiency(), phdFile.getUsedEffiKD().getUncertainty());
blockUpdates.put(SampleFileHeader.GEFFICIENCY.getMessage(), newEfficiency);
}
//endregion
//region 获取 bate
BetaDataFile betaDataFile = selfStationData.getBetaDataFile();
betaDataFile.getBetaList();
betaDataFile.getBetaFittingPara();
betaDataFile.getBetaFittingParaToUi();
List<SeriseData> newEneryList = betaDataFile.getBetaListNow();
List<String> bates = new ArrayList<>();
for (int i = 0; i < newEneryList.size(); i++) {
bates = formatBEnergyData(newEneryList, struct.b_decay_mode, struct.b_uncertainty);
}
blockUpdates.put(SampleFileHeader.BENERGY.getMessage(), bates);
//endregion
Map<String, List<String>> map = new HashMap<>();
if (FileUtil.exist(selfStationData.getSampleTmpPath())) {
List<String> lines = FileUtil.readUtf8Lines(selfStationData.getSampleTmpPath());
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("sample", lines);
}
if (FileUtil.exist(selfStationData.getDetTmpPath())) {
List<String> lines = FileUtil.readUtf8Lines(selfStationData.getDetTmpPath());
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("detBg", lines);
}
if (FileUtil.exist(selfStationData.getQcTmpPath())) {
List<String> lines = FileUtil.readUtf8Lines(selfStationData.getQcTmpPath());
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("qc", lines);
}
SelfStationVueData sampleVueData = selfStationData.getSampleVueData();
String tmpFilePath1 = sampleVueData.getROIOnePHDFile().getTmpFilePath();
if (FileUtil.exist(tmpFilePath1)) {
List<String> lines = FileUtil.readUtf8Lines(tmpFilePath1);
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("Gamma_ROI_1", lines);
}
String tmpFilePath2 = sampleVueData.getROITwoPHDFile().getTmpFilePath();
if (FileUtil.exist(tmpFilePath2)) {
List<String> lines = FileUtil.readUtf8Lines(tmpFilePath2);
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("Gamma_ROI_2", lines);
}
String tmpFilePath3 = sampleVueData.getROIThreePHDFile().getTmpFilePath();
if (FileUtil.exist(tmpFilePath3)) {
List<String> lines = FileUtil.readUtf8Lines(tmpFilePath3);
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("Gamma_ROI_3", lines);
}
String tmpFilePath4 = sampleVueData.getROIFourPHDFile().getTmpFilePath();
if (FileUtil.exist(tmpFilePath4)) {
List<String> lines = FileUtil.readUtf8Lines(tmpFilePath4);
lines = updateMultipleBlocks(lines, blockUpdates);
map.put("Gamma_ROI_4", lines);
}
result.setSuccess(true);
@ -5507,6 +5819,298 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
return result;
}
/**
* 格式化ROI数据并返回格式化后的字符串
*
* @param ROI_number ROI编号列表
* @param aList 第一列数据列表
* @param bList 第二列数据列表
* @param cList 第三列数据列表
* @param dList 第四列数据列表
* @return 格式化后的字符串每行包含编号和4个对齐的数值
*/
private static List<String> format(List<String> ROI_number, List<Double> aList,
List<Double> bList, List<Double> cList,
List<Double> dList) {
// 创建数字格式化器保留6位小数
DecimalFormat decimalFormat = new DecimalFormat("0.000000");
// 用于存储最终结果的StringBuilder
List<String> result = new ArrayList<>();
// 遍历每一行数据
for (int i = 0; i < ROI_number.size(); i++) {
// 获取当前行的各个值
String number = ROI_number.get(i); // ROI编号
String a = decimalFormat.format(aList.get(i)); // 格式化第一列
String b = decimalFormat.format(bList.get(i)); // 格式化第二列
String c = decimalFormat.format(cList.get(i)); // 格式化第三列
String d = decimalFormat.format(dList.get(i)); // 格式化第四列
// 计算每列需要填充的空格数保证每列宽度为17字符
int padA = Math.max(0, 17 - a.length()); // 第一列填充空格数
int padB = Math.max(0, 17 - b.length()); // 第二列填充空格数
int padC = Math.max(0, 17 - c.length()); // 第三列填充空格数
int padD = Math.max(0, 17 - d.length()); // 第四列填充空格数
// 构建当前行的字符串
StringBuilder line = new StringBuilder();
line.append(number).append(" "); // 添加编号和两个空格
// 添加第一列右对齐
line.append(a).append(spaces(padA));
// 添加第二列右对齐
line.append(b).append(spaces(padB));
// 添加第三列右对齐
line.append(c).append(spaces(padC));
// 添加第四列右对齐和换行符
line.append(d);
// 将当前行添加到结果中
result.add(line.toString());
}
// 返回最终格式化结果
return result;
}
private static List<String> format(List<Double> aList,
List<Double> bList, List<Double> cList) {
// 创建数字格式化器保留6位小数
DecimalFormat decimalFormat = new DecimalFormat("0.000000");
// 用于存储最终结果的StringBuilder
List<String> result = new ArrayList<>();
// 遍历每一行数据
for (int i = 0; i < aList.size(); i++) {
// 获取当前行的各个值
String a = decimalFormat.format(aList.get(i)); // 格式化第一列
String b = decimalFormat.format(bList.get(i)); // 格式化第二列
String c = decimalFormat.format(cList.get(i)); // 格式化第三列
// 计算每列需要填充的空格数保证每列宽度为17字符
int padA = Math.max(0, 17 - a.length()); // 第一列填充空格数
int padB = Math.max(0, 17 - b.length()); // 第二列填充空格数
int padC = Math.max(0, 17 - c.length()); // 第三列填充空格数
// 构建当前行的字符串
StringBuilder line = new StringBuilder();
// 添加第一列右对齐
line.append(a).append(spaces(padA));
// 添加第二列右对齐
line.append(b).append(spaces(padB));
// 添加第三列右对齐
line.append(c).append(spaces(padC));
// 将当前行添加到结果中
result.add(line.toString());
}
// 返回最终格式化结果
return result;
}
// b_Energy数据格式化
/**
* 格式化b_Energy数据块支持动态集合大小
*
* @param energyList 能量值列表
* @param categories 类别列表可空可不足
* @param uncertainties 不确定度列表可空可不足
* @return 格式化后的行列表
*/
private List<String> formatBEnergyData(List<SeriseData> energyList,
List<String> categories,
List<Double> uncertainties) {
// 1. 基础校验
if (energyList == null) {
log.error("energyList不能为null");
}
if (categories == null) categories = Collections.emptyList();
if (uncertainties == null) uncertainties = Collections.emptyList();
List<String> result = new ArrayList<>(energyList.size());
for (int i = 0; i < energyList.size(); i++) {
SeriseData data = energyList.get(i);
if (data == null) {
log.warn("第{}行energyData为null已跳过", i);
continue;
}
// 2. 动态获取category不足时用默认值
String category = (i < categories.size()) ?
categories.get(i) : "C"; // 默认值"C"
// 3. 动态获取uncertainty不足时用默认值
double uncertainty = (i < uncertainties.size()) ?
uncertainties.get(i) : 0.005000; // 默认值0.005000
try {
String line = String.format("%-15.6f %-2s %-15.6f %-15.6f",
data.getX(),
category,
data.getY(),
uncertainty);
result.add(line);
} catch (Exception e) {
log.error("第{}行格式化失败: x={} y={} category={} uncertainty={}",
i, data.getX(), data.getY(), category, uncertainty, e);
}
}
// 4. 结果校验
if (result.isEmpty()) {
log.warn("所有数据行均处理失败,请检查输入");
}
return result;
}
private List<String> formatBEnergyData(double[] energies, String[] categories, double[] cValues, double[] uncertainties) {
// 参数校验
if (energies == null || categories == null || cValues == null || uncertainties == null) {
return Collections.emptyList();
}
// 获取最小长度防止数组越界
int minLength = Math.min(Math.min(energies.length, categories.length),
Math.min(cValues.length, uncertainties.length));
List<String> result = new ArrayList<>(minLength);
for (int i = 0; i < minLength; i++) {
// 严格保持原始格式61.599998 C 20.000000 0.005000
String line = String.format("%-15.6f%-2s%-15.6f%-15.6f",
energies[i],
categories[i],
cValues[i],
uncertainties[i]);
result.add(line);
}
return result;
}
/**
* 生成指定数量的空格字符串
*
* @param count 需要的空格数量
* @return 由空格组成的字符串
*/
private static String spaces(int count) {
StringBuilder sb = new StringBuilder();
// 循环添加指定数量的空格
for (int i = 0; i < count; i++) {
sb.append(" ");
}
return sb.toString();
}
/**
* 通用方法更新文本行列表中指定块的数据
*
* @param lines 原始文本行列表
* @param blockMarker 块标记"#ROI_Limits"
* @param newData 新的数据行列表
* @return 更新后的文本行列表
*/
public static List<String> updateBlockData(List<String> lines, String blockMarker, List<String> newData) {
List<String> updatedLines = new ArrayList<>();
int blockStart = -1;
int blockEnd = -1;
boolean inBlock = false;
// 查找块的位置
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i).trim();
if (line.equals(blockMarker)) {
blockStart = i;
inBlock = true;
continue;
}
// 查找块结束位置下一个标记或列表末尾
if (inBlock && line.startsWith("#")) {
blockEnd = i;
inBlock = false;
}
}
// 如果没找到结束标记设置到列表末尾
if (inBlock) {
blockEnd = lines.size();
}
// 验证块标记是否存在
if (blockStart == -1) {
throw new IllegalArgumentException("未找到块标记: " + blockMarker);
}
// 构建更新后的内容
// 1. 添加块之前的内容
updatedLines.addAll(lines.subList(0, blockStart + 1));
// 2. 添加新数据
updatedLines.addAll(newData);
// 3. 添加块之后的内容
if (blockEnd != -1 && blockEnd < lines.size()) {
updatedLines.addAll(lines.subList(blockEnd, lines.size()));
}
return updatedLines;
}
private static List<String> updateMultipleBlocks(List<String> lines, Map<String, List<String>> blockUpdates) {
List<String> result = new ArrayList<>(lines.size());
String currentBlock = null;
for (String line : lines) {
String trimmed = line.trim();
if (trimmed.startsWith("#")) {
// 遇到块标记
currentBlock = trimmed;
result.add(line); // 添加块标记行
// 如果是目标块跳过原始数据准备添加新数据
if (blockUpdates.containsKey(currentBlock)) {
// 立即添加新数据
result.addAll(blockUpdates.get(currentBlock));
}
} else if (currentBlock != null && blockUpdates.containsKey(currentBlock)) {
// 目标块的原始数据行跳过不添加
continue;
} else {
// 非目标块的数据行正常添加
result.add(line);
}
}
// 验证所有目标块是否都处理了
for (String marker : blockUpdates.keySet()) {
if (!result.contains(marker)) {
}
}
return result;
}
@Override
@Transactional
public Result saveToDB(String fileName, String comment, HttpServletRequest request) {
@ -5808,7 +6412,7 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
// 存储报告文件
{
String rptContent = SelfBaseUtil.getReport(sampleId, sampleStruct, qcStruct,
betaDataFile.getXeResultsSpectrumList());
betaDataFile.getXeResultsSpectrumList(),betaDataFile.getRoiResultsSpectrumList());
String rptFileName = reportPath.substring(reportPath.lastIndexOf(StringPool.SLASH) + 1) + ".txt";
File rptFile = new File(rptFileName);
try {