system启动时增加核素相关缓存信息

人工交互分析gamma部分NuclLib Review接口慢问题修改
This commit is contained in:
qiaoqinzheng 2023-12-12 16:01:09 +08:00
parent a74736e2eb
commit 5290d50b65
6 changed files with 93 additions and 55 deletions

View File

@ -12,4 +12,6 @@ public interface GardsNuclLibMapper extends BaseMapper<GardsNuclLib> {
List<GardsNuclLibDto> halfLife(List<String> nuclideNames);
List<String> allName();
List<GardsNuclLib> getNucliLib();
}

View File

@ -17,7 +17,13 @@
</if>
</where>
</select>
<select id="allName" resultType="java.lang.String">
SELECT NAME FROM CONFIGURATION.GARDS_NUCL_LIB
</select>
<select id="getNucliLib" resultType="org.jeecg.modules.base.entity.configuration.GardsNuclLib">
select a.NAME, a.num_lines, a.halflife, a.halflife_err from CONFIGURATION.GARDS_NUCL_LIB a
</select>
</mapper>

View File

@ -11,4 +11,6 @@ public interface IGardsNuclLibService extends IService<GardsNuclLib> {
Map<String,Double> halfLife(List<String> nuclideNames);
List<String> allName();
void getNucliLib();
}

View File

@ -5,22 +5,29 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.dto.GardsNuclLibDto;
import org.jeecg.modules.base.entity.configuration.GardsNuclLib;
import org.jeecg.modules.mapper.GardsNuclLibMapper;
import org.jeecg.modules.service.IGardsNuclLibService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@DS("ora")
public class GardsNuclLibServiceImpl extends ServiceImpl<GardsNuclLibMapper, GardsNuclLib> implements IGardsNuclLibService {
@Autowired
private RedisUtil redisUtil;
@Override
public Map<String, Double> halfLife(List<String> nuclideNames) {
Map<String, Double> halfLife = MapUtil.newHashMap();
@ -38,4 +45,11 @@ public class GardsNuclLibServiceImpl extends ServiceImpl<GardsNuclLibMapper, Gar
return baseMapper.allName().stream().filter(StrUtil::isNotBlank)
.collect(Collectors.toList());
}
@Override
public void getNucliLib() {
List<GardsNuclLib> gardsNuclLibs = this.baseMapper.getNucliLib();
Map<String, GardsNuclLib> nuclLibMap = gardsNuclLibs.stream().collect(Collectors.toMap(GardsNuclLib::getName, Function.identity()));
redisUtil.set("nuclLibs", nuclLibMap);
}
}

View File

@ -977,6 +977,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setResult(chartDataList);
}
compareFile.delete();
} else {
result.error500("比较文件不存在!");
return result;
}
return result;
}
@ -1062,6 +1065,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setResult(stripMap);
}
stripFile.delete();
} else {
result.error500("比较文件不存在!");
return result;
}
return result;
}
@ -2105,7 +2111,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (CollectionUtils.isNotEmpty(nuclideList)) {
map.put("list", nuclideList);
String name = nuclideList.get(0);
InitTable(name, map, phd, colorMap);
InitTable(name, map, phd, colorMap, nuclideMap);
} else {
map.put("list", nuclideList);
map.put("chart", new LinkedList<>());
@ -2130,67 +2136,68 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
// return nuclideList;
// }
public void InitTable(String name, Map<String, Object> map, PHDFile phd, Map<String, String> colorMap) {
public void InitTable(String name, Map<String, Object> map, PHDFile phd, Map<String, String> colorMap, Map<String, NuclideLines> nuclideMap) {
InitNuclideInfo(name, map);
long span = phd.getSpec().getG_energy_span();
List<GardsNuclLinesLib> nuclideTableList = spectrumAnalysisMapper.getNuclideTable(name, span);
if (CollectionUtils.isNotEmpty(nuclideTableList)) {
nuclideTableList.stream().forEach(item-> {
if (Objects.nonNull(item.getEnergy())) {
item.setEnergy(Double.valueOf(String.format("%.3f", item.getEnergy())));
} else {
item.setEnergy(Double.valueOf(String.format("%.3f", 0.0)));
//判断缓存的核素信息是否为空
if (CollectionUtils.isNotEmpty(nuclideMap)) {
//获取当前核素名称的核素集合
NuclideLines lines = nuclideMap.get(name);
List<GardsNuclLinesLib> nuclideTableList = new LinkedList<>();//spectrumAnalysisMapper.getNuclideTable(name, span);
for (int i=0; i<lines.fullNames.size(); i++) {
Double energy = lines.venergy.get(i);
if (Objects.nonNull(energy)) {
if (lines.venergy.get(i) >= 30 && lines.venergy.get(i) <= span) {
GardsNuclLinesLib nuclLinesLib = new GardsNuclLinesLib();
nuclLinesLib.setFullName(lines.fullNames.get(i));
nuclLinesLib.setEnergy(Double.valueOf(String.format("%.3f", lines.venergy.get(i))));
nuclLinesLib.setEnergyUncert(Objects.nonNull(lines.vuncertE.get(i))?Double.valueOf(String.format("%.3f", lines.vuncertE.get(i))):0.0);
nuclLinesLib.setYield(Objects.nonNull(lines.vyield.get(i))?Double.valueOf(String.format("%.3f", lines.vyield.get(i)*100)):0.0);
nuclLinesLib.setYieldUncert(Objects.nonNull(lines.vuncertY.get(i))?Double.valueOf(String.format("%.3f", lines.vuncertY.get(i))):0.0);
nuclideTableList.add(nuclLinesLib);
}
}
if (Objects.nonNull(item.getEnergyUncert())) {
item.setEnergyUncert(Double.valueOf(String.format("%.3f", item.getEnergyUncert())));
} else {
item.setEnergyUncert(Double.valueOf(String.format("%.3f", 0.0)));
}
if (Objects.nonNull(item.getYield())) {
item.setYield(Double.valueOf(String.format("%.3f", item.getYield())));
} else {
item.setYield(Double.valueOf(String.format("%.3f", 0.0)));
}
if (Objects.nonNull(item.getYieldUncert())) {
item.setYieldUncert(Double.valueOf(String.format("%.3f", item.getYieldUncert())));
} else {
item.setYieldUncert(Double.valueOf(String.format("%.3f", 0.0)));
}
});
nuclideTableList.stream().max(Comparator.comparing(GardsNuclLinesLib::getYield)).get().setKeyFlag(1);
map.put("table", nuclideTableList);
gammaFileUtil.InitChart(nuclideTableList, phd, map, colorMap);
}
if (CollectionUtils.isNotEmpty(nuclideTableList)) {
nuclideTableList = nuclideTableList.stream().sorted(Comparator.comparing(GardsNuclLinesLib::getYield)).collect(Collectors.toList());
nuclideTableList.stream().max(Comparator.comparing(GardsNuclLinesLib::getYield)).get().setKeyFlag(1);
map.put("table", nuclideTableList);
gammaFileUtil.InitChart(nuclideTableList, phd, map, colorMap);
}
}
}
public void InitNuclideInfo(String name, Map<String, Object> map) {
map.put("name", name);
GardsNuclLib nuclideInfo = spectrumAnalysisMapper.getNuclideInfo(name);
if (Objects.nonNull(nuclideInfo)) {
map.put("lines", nuclideInfo.getNumLines());
if (Objects.isNull(nuclideInfo.getHalflife())) {
map.put("halfLife", "");
} else {
String units = "D";
double halflife = nuclideInfo.getHalflife().doubleValue();
if (halflife >= 1000) {
halflife = halflife / 365.25;
units = "A";
} else if (halflife < 0.1 && halflife >= 1.0 / 1440) {
halflife = halflife * 1440;
units = "M";
} else if (halflife <= 1.0 / 1440 && halflife > 0) {
halflife = halflife * 86400;
units = "S";
Map<String, GardsNuclLib> nuclLibs = (Map<String, GardsNuclLib>) redisUtil.get("nuclLibs");
if (CollectionUtils.isNotEmpty(nuclLibs)) {
GardsNuclLib nuclideInfo = nuclLibs.get(name);
if (Objects.nonNull(nuclideInfo)) {
map.put("lines", nuclideInfo.getNumLines());
if (Objects.isNull(nuclideInfo.getHalflife())) {
map.put("halfLife", "");
} else {
String units = "D";
double halflife = nuclideInfo.getHalflife().doubleValue();
if (halflife >= 1000) {
halflife = halflife / 365.25;
units = "A";
} else if (halflife < 0.1 && halflife >= 1.0 / 1440) {
halflife = halflife * 1440;
units = "M";
} else if (halflife <= 1.0 / 1440 && halflife > 0) {
halflife = halflife * 86400;
units = "S";
}
halflife = halflife + 0.0001;
map.put("halfLife", String.format("%.3f", halflife) + units);
}
if (Objects.isNull(nuclideInfo.getHalflifeErr())) {
map.put("halfLifeErr", "");
} else {
map.put("halfLifeErr", String.format("%.3f", nuclideInfo.getHalflifeErr().doubleValue()) + "%");
}
halflife = halflife + 0.0001;
map.put("halfLife", String.format("%.3f", halflife) + units);
}
if (Objects.isNull(nuclideInfo.getHalflifeErr())) {
map.put("halfLifeErr", "");
} else {
map.put("halfLifeErr", String.format("%.3f", nuclideInfo.getHalflifeErr().doubleValue()) + "%");
}
}
}
@ -2207,7 +2214,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
return result;
}
Map<String, String> colorMap = sysUserColorService.initColor(userName);
InitTable(nuclideName, map, phd, colorMap);
//获取缓存的核素信息
Map<String, NuclideLines> nuclideMap = (Map<String, NuclideLines>) redisUtil.get(userName+"-"+phd.getHeader().getSystem_type());
InitTable(nuclideName, map, phd, colorMap, nuclideMap);
result.setSuccess(true);
result.setResult(map);
return result;
@ -2255,7 +2264,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (CollectionUtils.isNotEmpty(nuclideList)) {
map.put("list", nuclideList);
String name = nuclideList.get(0);
InitTable(name, map, phd, colorMap);
InitTable(name, map, phd, colorMap, nuclideMap);
} else {
map.put("list", nuclideList);
map.put("chart", new LinkedList<>());

View File

@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.base.BaseMap;
import org.jeecg.common.constant.GlobalConstants;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.service.IGardsNuclLibService;
import org.jeecg.modules.system.service.IGardsDetectorsService;
import org.jeecg.modules.system.service.IGardsNuclearfacilityService;
import org.jeecg.modules.system.service.IGardsStationsService;
@ -42,6 +43,8 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
private IGardsDetectorsService gardsDetectorsService;
@Autowired
private IGardsNuclearfacilityService gardsNuclearfacilityService;
@Autowired
private IGardsNuclLibService gardsNuclLibService;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
@ -81,5 +84,7 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
gardsDetectorsService.findDetectors();
//触发缓存一下核设施信息
gardsNuclearfacilityService.findNuclearFacility();
//触发缓存一下核素信息
gardsNuclLibService.getNucliLib();
}
}