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<GardsNuclLibDto> halfLife(List<String> nuclideNames);
List<String> allName(); List<String> allName();
List<GardsNuclLib> getNucliLib();
} }

View File

@ -17,7 +17,13 @@
</if> </if>
</where> </where>
</select> </select>
<select id="allName" resultType="java.lang.String"> <select id="allName" resultType="java.lang.String">
SELECT NAME FROM CONFIGURATION.GARDS_NUCL_LIB SELECT NAME FROM CONFIGURATION.GARDS_NUCL_LIB
</select> </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> </mapper>

View File

@ -11,4 +11,6 @@ public interface IGardsNuclLibService extends IService<GardsNuclLib> {
Map<String,Double> halfLife(List<String> nuclideNames); Map<String,Double> halfLife(List<String> nuclideNames);
List<String> allName(); 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.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS; 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.dto.GardsNuclLibDto;
import org.jeecg.modules.base.entity.configuration.GardsNuclLib; import org.jeecg.modules.base.entity.configuration.GardsNuclLib;
import org.jeecg.modules.mapper.GardsNuclLibMapper; import org.jeecg.modules.mapper.GardsNuclLibMapper;
import org.jeecg.modules.service.IGardsNuclLibService; import org.jeecg.modules.service.IGardsNuclLibService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@DS("ora") @DS("ora")
public class GardsNuclLibServiceImpl extends ServiceImpl<GardsNuclLibMapper, GardsNuclLib> implements IGardsNuclLibService { public class GardsNuclLibServiceImpl extends ServiceImpl<GardsNuclLibMapper, GardsNuclLib> implements IGardsNuclLibService {
@Autowired
private RedisUtil redisUtil;
@Override @Override
public Map<String, Double> halfLife(List<String> nuclideNames) { public Map<String, Double> halfLife(List<String> nuclideNames) {
Map<String, Double> halfLife = MapUtil.newHashMap(); Map<String, Double> halfLife = MapUtil.newHashMap();
@ -38,4 +45,11 @@ public class GardsNuclLibServiceImpl extends ServiceImpl<GardsNuclLibMapper, Gar
return baseMapper.allName().stream().filter(StrUtil::isNotBlank) return baseMapper.allName().stream().filter(StrUtil::isNotBlank)
.collect(Collectors.toList()); .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); result.setResult(chartDataList);
} }
compareFile.delete(); compareFile.delete();
} else {
result.error500("比较文件不存在!");
return result;
} }
return result; return result;
} }
@ -1062,6 +1065,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.setResult(stripMap); result.setResult(stripMap);
} }
stripFile.delete(); stripFile.delete();
} else {
result.error500("比较文件不存在!");
return result;
} }
return result; return result;
} }
@ -2105,7 +2111,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (CollectionUtils.isNotEmpty(nuclideList)) { if (CollectionUtils.isNotEmpty(nuclideList)) {
map.put("list", nuclideList); map.put("list", nuclideList);
String name = nuclideList.get(0); String name = nuclideList.get(0);
InitTable(name, map, phd, colorMap); InitTable(name, map, phd, colorMap, nuclideMap);
} else { } else {
map.put("list", nuclideList); map.put("list", nuclideList);
map.put("chart", new LinkedList<>()); map.put("chart", new LinkedList<>());
@ -2130,67 +2136,68 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
// return nuclideList; // 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); InitNuclideInfo(name, map);
long span = phd.getSpec().getG_energy_span(); long span = phd.getSpec().getG_energy_span();
List<GardsNuclLinesLib> nuclideTableList = spectrumAnalysisMapper.getNuclideTable(name, span);
if (CollectionUtils.isNotEmpty(nuclideTableList)) { //判断缓存的核素信息是否为空
nuclideTableList.stream().forEach(item-> { if (CollectionUtils.isNotEmpty(nuclideMap)) {
if (Objects.nonNull(item.getEnergy())) { //获取当前核素名称的核素集合
item.setEnergy(Double.valueOf(String.format("%.3f", item.getEnergy()))); NuclideLines lines = nuclideMap.get(name);
} else { List<GardsNuclLinesLib> nuclideTableList = new LinkedList<>();//spectrumAnalysisMapper.getNuclideTable(name, span);
item.setEnergy(Double.valueOf(String.format("%.3f", 0.0))); 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()))); if (CollectionUtils.isNotEmpty(nuclideTableList)) {
} else { nuclideTableList = nuclideTableList.stream().sorted(Comparator.comparing(GardsNuclLinesLib::getYield)).collect(Collectors.toList());
item.setEnergyUncert(Double.valueOf(String.format("%.3f", 0.0))); nuclideTableList.stream().max(Comparator.comparing(GardsNuclLinesLib::getYield)).get().setKeyFlag(1);
} map.put("table", nuclideTableList);
if (Objects.nonNull(item.getYield())) { gammaFileUtil.InitChart(nuclideTableList, phd, map, colorMap);
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);
} }
} }
public void InitNuclideInfo(String name, Map<String, Object> map) { public void InitNuclideInfo(String name, Map<String, Object> map) {
map.put("name", name); map.put("name", name);
Map<String, GardsNuclLib> nuclLibs = (Map<String, GardsNuclLib>) redisUtil.get("nuclLibs");
GardsNuclLib nuclideInfo = spectrumAnalysisMapper.getNuclideInfo(name); if (CollectionUtils.isNotEmpty(nuclLibs)) {
if (Objects.nonNull(nuclideInfo)) { GardsNuclLib nuclideInfo = nuclLibs.get(name);
map.put("lines", nuclideInfo.getNumLines()); if (Objects.nonNull(nuclideInfo)) {
if (Objects.isNull(nuclideInfo.getHalflife())) { map.put("lines", nuclideInfo.getNumLines());
map.put("halfLife", ""); if (Objects.isNull(nuclideInfo.getHalflife())) {
} else { map.put("halfLife", "");
String units = "D"; } else {
double halflife = nuclideInfo.getHalflife().doubleValue(); String units = "D";
if (halflife >= 1000) { double halflife = nuclideInfo.getHalflife().doubleValue();
halflife = halflife / 365.25; if (halflife >= 1000) {
units = "A"; halflife = halflife / 365.25;
} else if (halflife < 0.1 && halflife >= 1.0 / 1440) { units = "A";
halflife = halflife * 1440; } else if (halflife < 0.1 && halflife >= 1.0 / 1440) {
units = "M"; halflife = halflife * 1440;
} else if (halflife <= 1.0 / 1440 && halflife > 0) { units = "M";
halflife = halflife * 86400; } else if (halflife <= 1.0 / 1440 && halflife > 0) {
units = "S"; 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; return result;
} }
Map<String, String> colorMap = sysUserColorService.initColor(userName); 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.setSuccess(true);
result.setResult(map); result.setResult(map);
return result; return result;
@ -2255,7 +2264,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (CollectionUtils.isNotEmpty(nuclideList)) { if (CollectionUtils.isNotEmpty(nuclideList)) {
map.put("list", nuclideList); map.put("list", nuclideList);
String name = nuclideList.get(0); String name = nuclideList.get(0);
InitTable(name, map, phd, colorMap); InitTable(name, map, phd, colorMap, nuclideMap);
} else { } else {
map.put("list", nuclideList); map.put("list", nuclideList);
map.put("chart", new LinkedList<>()); 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.base.BaseMap;
import org.jeecg.common.constant.GlobalConstants; import org.jeecg.common.constant.GlobalConstants;
import org.jeecg.common.util.oConvertUtils; 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.IGardsDetectorsService;
import org.jeecg.modules.system.service.IGardsNuclearfacilityService; import org.jeecg.modules.system.service.IGardsNuclearfacilityService;
import org.jeecg.modules.system.service.IGardsStationsService; import org.jeecg.modules.system.service.IGardsStationsService;
@ -42,6 +43,8 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
private IGardsDetectorsService gardsDetectorsService; private IGardsDetectorsService gardsDetectorsService;
@Autowired @Autowired
private IGardsNuclearfacilityService gardsNuclearfacilityService; private IGardsNuclearfacilityService gardsNuclearfacilityService;
@Autowired
private IGardsNuclLibService gardsNuclLibService;
@Override @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
@ -81,5 +84,7 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
gardsDetectorsService.findDetectors(); gardsDetectorsService.findDetectors();
//触发缓存一下核设施信息 //触发缓存一下核设施信息
gardsNuclearfacilityService.findNuclearFacility(); gardsNuclearfacilityService.findNuclearFacility();
//触发缓存一下核素信息
gardsNuclLibService.getNucliLib();
} }
} }