diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/controller/imsDataMonitorController.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/controller/imsDataMonitorController.java index b241ce4..584fe8f 100644 --- a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/controller/imsDataMonitorController.java +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/controller/imsDataMonitorController.java @@ -9,6 +9,7 @@ import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.imsDataMonitor.entity.ProvisionData; import org.jeecg.imsDataMonitor.entity.StationInfo; import org.jeecg.imsDataMonitor.service.IMSDataMonitorService; +import org.jeecg.utils.EffConfigManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.GetMapping; @@ -35,21 +36,13 @@ public class imsDataMonitorController { /** * 获取Particulate 台站的有效率和提供率 * - * @param code 类型代码 - * @param startDate 开始日期 - * @param endDate 结束日期 * @return 返回 Result */ @AutoLog(value = "Particulate 台站的有效率") @GetMapping("getParticulate") - public Result getParticulate(@RequestParam(value = "code", required = false) String code, - @RequestParam(value = "startDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date startDate, - @RequestParam(value = "endDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date endDate) { -// List data = imsDataMonitorService.getParticulate(code, startDate, endDate); + public Result getParticulate() { + + List data = imsDataMonitorService.getParticulate(); // return Result.OK(data); //TODO 测试待删除 try (InputStream inputStream = imsDataMonitorController.class.getClassLoader() @@ -70,21 +63,12 @@ public class imsDataMonitorController { /** * Spalax 台站的有效率 * - * @param code - * @param startDate - * @param endDate * @return */ @AutoLog(value = "Spalax 台站的有效率") @GetMapping("getSpalax") - public Result getSpalax(@RequestParam(value = "code", required = false) String code, - @RequestParam(value = "startDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date startDate, - @RequestParam(value = "endDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date endDate) { -// List data = imsDataMonitorService.getSpalax(code, startDate, endDate); + public Result getSpalax() { + List data = imsDataMonitorService.getSpalax(); // return Result.OK(data); //TODO 测试待删除 try (InputStream inputStream = imsDataMonitorController.class.getClassLoader() @@ -106,21 +90,12 @@ public class imsDataMonitorController { /** * Sauna2 台站的有效率 * - * @param code - * @param startDate - * @param endDate * @return */ @AutoLog(value = "Sauna2 台站的有效率") @GetMapping("getSauna2") - public Result getSauna2(@RequestParam(value = "code", required = false) String code, - @RequestParam(value = "startDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date startDate, - @RequestParam(value = "endDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date endDate) { -// List data = imsDataMonitorService.getSauna2(code, startDate, endDate); + public Result getSauna2() { + List data = imsDataMonitorService.getSauna2(); // return Result.OK(data); //TODO 测试待删除 try (InputStream inputStream = imsDataMonitorController.class.getClassLoader() @@ -141,21 +116,12 @@ public class imsDataMonitorController { /** * Sauna3 台站的有效率 * - * @param code - * @param startDate - * @param endDate * @return */ @AutoLog(value = "Sauna3 台站的有效率") @GetMapping("getSauna3") - public Result getSauna3(@RequestParam(value = "code", required = false) String code, - @RequestParam(value = "startDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date startDate, - @RequestParam(value = "endDate", required = false) - @DateTimeFormat(pattern = "yyyy-MM-dd") - Date endDate) { -// List data = imsDataMonitorService.getSauna3(code, startDate, endDate); + public Result getSauna3() { + List data = imsDataMonitorService.getSauna3(); // return Result.OK(data); //TODO 测试待删除 try (InputStream inputStream = imsDataMonitorController.class.getClassLoader() diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/BaseParameter.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/BaseParameter.java new file mode 100644 index 0000000..6d16c9c --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/BaseParameter.java @@ -0,0 +1,26 @@ +package org.jeecg.imsDataMonitor.entity; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Data; + +@Data +public abstract class BaseParameter { + @JacksonXmlProperty(localName = "liveLow") + private double liveLow; + + @JacksonXmlProperty(localName = "liveHigh") + private double liveHigh; + + @JacksonXmlProperty(localName = "quantity") + private int quantity; + + @JacksonXmlProperty(localName = "collectLow") + private double collectLow; + + @JacksonXmlProperty(localName = "collectHigh") + private double collectHigh; + + @JacksonXmlProperty(localName = "number") + private int number; + +} diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Config.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Config.java new file mode 100644 index 0000000..a735cf8 --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Config.java @@ -0,0 +1,13 @@ +package org.jeecg.imsDataMonitor.entity; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import lombok.Data; + +@Data +@JacksonXmlRootElement(localName = "config") +public class Config { + @JacksonXmlProperty(localName = "phdf") + private Phdf phdf; + +} diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Particulate.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Particulate.java new file mode 100644 index 0000000..48b2fc7 --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Particulate.java @@ -0,0 +1,4 @@ +package org.jeecg.imsDataMonitor.entity; + +public class Particulate extends BaseParameter { +} diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Phdf.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Phdf.java new file mode 100644 index 0000000..4901939 --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Phdf.java @@ -0,0 +1,19 @@ +package org.jeecg.imsDataMonitor.entity; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Data; + +@Data +public class Phdf { + @JacksonXmlProperty(localName = "particulate") + private Particulate particulate; + + @JacksonXmlProperty(localName = "spalax") + private Spalax spalax; + + @JacksonXmlProperty(localName = "sauna2") + private Sauna sauna2; + + @JacksonXmlProperty(localName = "sauna3") + private Sauna sauna3; +} diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/PhdfProvisionEfficiency.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/PhdfProvisionEfficiency.java index c7daef8..b51bdf4 100644 --- a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/PhdfProvisionEfficiency.java +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/PhdfProvisionEfficiency.java @@ -7,27 +7,27 @@ import java.util.List; @Data public class PhdfProvisionEfficiency { //liveLow - private String liveLow; + private double liveLow; //liveHigh - private String liveHigh; + private double liveHigh; //quantity - private String quantity; + private double quantity; //collectLow - private String collectLow; + private double collectLow; //collectHigh - private String collectHigh; + private double collectHigh; //curDateTime private String curDateTime; //pretime private String pretime; //number - private String number; + private int number; private String nuclideName; - private String liveQc; - private String mdc; - private String xeVolume; + private double liveQc; + private double mdc; + private double xeVolume; //stationId private List stationId; } diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Sauna.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Sauna.java new file mode 100644 index 0000000..5383103 --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Sauna.java @@ -0,0 +1,19 @@ +package org.jeecg.imsDataMonitor.entity; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Data; + +@Data +public class Sauna extends BaseParameter { + @JacksonXmlProperty(localName = "xeVolume") + private double xeVolume; + + @JacksonXmlProperty(localName = "mdc") + private int mdc; + + @JacksonXmlProperty(localName = "nuclideName") + private String nuclideName; + + @JacksonXmlProperty(localName = "liveQc") + private int liveQc; +} diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Spalax.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Spalax.java new file mode 100644 index 0000000..795cd25 --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/entity/Spalax.java @@ -0,0 +1,10 @@ +package org.jeecg.imsDataMonitor.entity; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Data; + +@Data +public class Spalax extends BaseParameter { + @JacksonXmlProperty(localName = "liveqc") + private int liveqc; +} diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/IMSDataMonitorService.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/IMSDataMonitorService.java index 3761867..4b48f1d 100644 --- a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/IMSDataMonitorService.java +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/IMSDataMonitorService.java @@ -22,13 +22,13 @@ public interface IMSDataMonitorService { *获取Particulate类型的有效率数据 * @return Map> */ - List getParticulate(String code, Date startDate, Date endDate); + List getParticulate(); - List getSpalax(String code, Date startDate, Date endDate); + List getSpalax(); - List getSauna2(String code, Date startDate, Date endDate); + List getSauna2(); - List getSauna3(String code, Date startDate, Date endDate); + List getSauna3(); } diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/impl/IMSDataMonitorServiceImpl.java b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/impl/IMSDataMonitorServiceImpl.java index e9aaeff..8317a2d 100644 --- a/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/impl/IMSDataMonitorServiceImpl.java +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/imsDataMonitor/service/impl/IMSDataMonitorServiceImpl.java @@ -3,17 +3,18 @@ package org.jeecg.imsDataMonitor.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Param; import org.jeecg.common.util.DateUtils; -import org.jeecg.imsDataMonitor.entity.PhdfProvisionEfficiency; -import org.jeecg.imsDataMonitor.entity.ProvisionData; +import org.jeecg.imsDataMonitor.entity.*; import org.jeecg.imsDataMonitor.mapper.IMSDataMonitorMapper; import org.jeecg.imsDataMonitor.service.IMSDataMonitorService; import org.jeecg.modules.base.entity.configuration.GardsStations; import org.jeecg.modules.base.mapper.GardsStationsMapper; import org.jeecg.modules.base.mapper.StasStationSettingMapper; +import org.jeecg.utils.EffConfigManager; import org.jspecify.annotations.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -26,26 +27,35 @@ import java.util.stream.Collectors; @Slf4j @Service @DS("ora") +@RequiredArgsConstructor() public class IMSDataMonitorServiceImpl implements IMSDataMonitorService { @Autowired private IMSDataMonitorMapper imsDataMonitorMapper; @Autowired private StasStationSettingMapper settingMapper; + private final EffConfigManager configManager; + @Override public List getGardsStationList(String systemType) { return imsDataMonitorMapper.findStationList(systemType); } //region Particulate + + /** + * 获取获取Particulate类型的台站有效率 + *

时间范围默认当前时间往前一个月

+ * + * @return List + */ @Override - public List getParticulate(String code, Date startDate, Date endDate) { + public List getParticulate() { //获取Particulate类型的台站信息 List stations = imsDataMonitorMapper.findStationList("P"); - String[] times = getDataTime(startDate, endDate); + String[] times = getDataTime(); //有效率状态 return getStationDailyData(stations, times[0], times[1]); - } private List getStationDailyData(List stationList, @@ -55,26 +65,19 @@ public class IMSDataMonitorServiceImpl implements IMSDataMonitorService { return new ArrayList<>(); } - - String liveLow = "21.6"; - String liveHigh = "26.4"; - String quantity = "10800"; - String collectLow = "21.6"; - String collectHigh = "26.4"; - String number = "1"; + Particulate particulate = (Particulate) configManager.getParameter("particulate"); //每个台站一个月的有效率 - PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency(); List sts = stationList.stream() .map(GardsStations::getStationId) .collect(Collectors.toList()); efficiency.setStationId(sts); - efficiency.setNumber(number); - efficiency.setCollectHigh(collectHigh); - efficiency.setLiveHigh(liveHigh); - efficiency.setCollectLow(collectLow); - efficiency.setLiveLow(liveLow); - efficiency.setQuantity(quantity); + efficiency.setNumber(particulate.getNumber()); + efficiency.setCollectHigh(particulate.getCollectHigh()); + efficiency.setCollectLow(particulate.getCollectLow()); + efficiency.setLiveHigh(particulate.getLiveHigh()); + efficiency.setLiveLow(particulate.getLiveLow()); + efficiency.setQuantity(particulate.getQuantity()); efficiency.setCurDateTime(endTime); efficiency.setPretime(startTime); //查询数据库 获取台站有效率 @@ -85,9 +88,119 @@ public class IMSDataMonitorServiceImpl implements IMSDataMonitorService { } - private String[] getDataTime(Date startDate, Date endDate) { + //endregion - // 使用final确保不可变性,提供更好的线程安全性 + //region SPALAX + @Override + public List getSpalax() { + String actualCode = "SPALAX"; + //获取Particulate类型的台站信息 + List stations = imsDataMonitorMapper.findEfficStationList(actualCode); + String[] times = getDataTime(); + //有效率状态 + return getSpalaxStationDailyData(stations, times[0], times[1]); + } + + private List getSpalaxStationDailyData(List stationList, + String startTime, String endTime) { + + if (CollectionUtil.isEmpty(stationList)) { + return new ArrayList<>(); + } + //每个台站一个月的有效率 + Spalax spalax = (Spalax) configManager.getParameter("spalax"); + + PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency(); + List sts = stationList.stream() + .map(GardsStations::getStationId) + .collect(Collectors.toList()); + efficiency.setStationId(sts); + efficiency.setNumber(spalax.getNumber()); + efficiency.setCollectHigh(spalax.getCollectHigh()); + efficiency.setLiveHigh(spalax.getLiveHigh()); + efficiency.setCollectLow(spalax.getCollectLow()); + efficiency.setLiveLow(spalax.getLiveLow()); + efficiency.setQuantity(spalax.getQuantity()); + efficiency.setCurDateTime(endTime); + efficiency.setPretime(startTime); + efficiency.setLiveQc(spalax.getLiveqc()); + //查询数据库 获取台站有效率 + List rawDataList = + imsDataMonitorMapper.findPhdfSpalaxEfficiency(efficiency); + //dataMap.put(station.getStationCode(), rawDataList); + return rawDataList; + + } + + + //endregion + + //region SAUNA II + @Override + public List getSauna2() { + String actualCode = "SAUNA2"; + //获取Particulate类型的台站信息 + List stations = imsDataMonitorMapper.findEfficStationList(actualCode); + String[] times = getDataTime(); + //有效率状态 + return getSauna2StationDailyData(stations, times[0], times[1]); + } + + private List getSauna2StationDailyData(List stationList, + String startTime, String endTime) { + + if (CollectionUtil.isEmpty(stationList)) { + return new ArrayList<>(); + } + //每个台站一个月的有效率 + Sauna sauna2 = (Sauna) configManager.getParameter("sauna2"); + + PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency(); + List sts = stationList.stream() + .map(GardsStations::getStationId) + .collect(Collectors.toList()); + efficiency.setStationId(sts); + efficiency.setNumber(sauna2.getNumber()); + efficiency.setCollectHigh(sauna2.getCollectHigh()); + efficiency.setLiveHigh(sauna2.getLiveHigh()); + efficiency.setCollectLow(sauna2.getCollectLow()); + efficiency.setLiveLow(sauna2.getLiveLow()); + efficiency.setQuantity(sauna2.getQuantity()); + efficiency.setCurDateTime(endTime); + efficiency.setPretime(startTime); + efficiency.setNuclideName(sauna2.getNuclideName()); + efficiency.setMdc(sauna2.getMdc()); + efficiency.setLiveQc(sauna2.getLiveQc()); + efficiency.setXeVolume(sauna2.getXeVolume()); + //查询数据库 获取台站有效率 + List rawDataList = + imsDataMonitorMapper.findPhdfSauna2Efficiency(efficiency); + //dataMap.put(station.getStationCode(), rawDataList); + return rawDataList; + + } + //endregion + + //region SAUNA III + @Override + public List getSauna3() { + String actualCode = "SAUNA3"; + //获取Particulate类型的台站信息 + List stations = imsDataMonitorMapper.findEfficStationList(actualCode); + String[] times = getDataTime(); + //TODO 有效率状态 + return getSauna2StationDailyData(stations, times[0], times[1]); + } + //endregion + + /** + * 获取时间范围 默认30天 + * + * @return + */ + private String[] getDataTime() { + Date startDate = null, endDate = null; + //当前时间 final LocalDateTime currentTime = LocalDateTime.now(); // 计算默认时间范围 @@ -110,128 +223,4 @@ public class IMSDataMonitorServiceImpl implements IMSDataMonitorService { return new String[] {startTime, endTime}; } - - //endregion - - //region SPALAX - @Override - public List getSpalax(String code, Date startDate, Date endDate) { - String actualCode = (code == null || code.trim().isEmpty()) ? "SPALAX" : code; - //获取Particulate类型的台站信息 - List stations = imsDataMonitorMapper.findEfficStationList(actualCode); - String[] times = getDataTime(startDate, endDate); - //有效率状态 - return getSpalaxStationDailyData(stations, times[0], times[1]); - } - - private List getSpalaxStationDailyData(List stationList, - String startTime, String endTime) { - - if (CollectionUtil.isEmpty(stationList)) { - return new ArrayList<>(); - } - - - String liveLow = "10"; - String liveHigh = "11"; - String quantity = "10"; - String collectLow = "10.8"; - String collectHigh = "13.2"; - String number = "4"; - String liveqc = "240"; - //每个台站一个月的有效率 - - PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency(); - List sts = stationList.stream() - .map(GardsStations::getStationId) - .collect(Collectors.toList()); - efficiency.setStationId(sts); - efficiency.setNumber(number); - efficiency.setCollectHigh(collectHigh); - efficiency.setLiveHigh(liveHigh); - efficiency.setCollectLow(collectLow); - efficiency.setLiveLow(liveLow); - efficiency.setQuantity(quantity); - efficiency.setCurDateTime(endTime); - efficiency.setPretime(startTime); - efficiency.setLiveQc(liveqc); - //查询数据库 获取台站有效率 - List rawDataList = - imsDataMonitorMapper.findPhdfSpalaxEfficiency(efficiency); - //dataMap.put(station.getStationCode(), rawDataList); - return rawDataList; - - } - - - //endregion - - //region SAUNA II - @Override - public List getSauna2(String code, Date startDate, Date endDate) { - String actualCode = (code == null || code.trim().isEmpty()) ? "SAUNA2" : code; - //获取Particulate类型的台站信息 - List stations = imsDataMonitorMapper.findEfficStationList(actualCode); - String[] times = getDataTime(startDate, endDate); - //有效率状态 - return getSauna2StationDailyData(stations, times[0], times[1]); - } - - private List getSauna2StationDailyData(List stationList, - String startTime, String endTime) { - - if (CollectionUtil.isEmpty(stationList)) { - return new ArrayList<>(); - } - - - String collectLow = "5.4"; - String collectHigh = "6.6"; - String liveLow = "4.2"; - String liveHigh = "6.6"; - String quantity = "10"; - String xeVolume = "0.87"; - String mdc = "1"; - String nuclideName = "Xe133"; - String liveQc = "600"; - String number = "16"; - //每个台站一个月的有效率 - - PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency(); - List sts = stationList.stream() - .map(GardsStations::getStationId) - .collect(Collectors.toList()); - efficiency.setStationId(sts); - efficiency.setNumber(number); - efficiency.setCollectHigh(collectHigh); - efficiency.setLiveHigh(liveHigh); - efficiency.setCollectLow(collectLow); - efficiency.setLiveLow(liveLow); - efficiency.setQuantity(quantity); - efficiency.setCurDateTime(endTime); - efficiency.setPretime(startTime); - efficiency.setNuclideName(nuclideName); - efficiency.setMdc(mdc); - efficiency.setLiveQc(liveQc); - efficiency.setXeVolume(xeVolume); - //查询数据库 获取台站有效率 - List rawDataList = - imsDataMonitorMapper.findPhdfSauna2Efficiency(efficiency); - //dataMap.put(station.getStationCode(), rawDataList); - return rawDataList; - - } - //endregion - - //region SAUNA III - @Override - public List getSauna3(String code, Date startDate, Date endDate) { - String actualCode = (code == null || code.trim().isEmpty()) ? "SAUNA3" : code; - //获取Particulate类型的台站信息 - List stations = imsDataMonitorMapper.findEfficStationList(actualCode); - String[] times = getDataTime(startDate, endDate); - //有效率状态 - return getSauna2StationDailyData(stations, times[0], times[1]); - } - //endregion } diff --git a/jeecg-module-large-screen/src/main/java/org/jeecg/utils/EffConfigManager.java b/jeecg-module-large-screen/src/main/java/org/jeecg/utils/EffConfigManager.java new file mode 100644 index 0000000..1585f93 --- /dev/null +++ b/jeecg-module-large-screen/src/main/java/org/jeecg/utils/EffConfigManager.java @@ -0,0 +1,271 @@ +package org.jeecg.utils; + +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.imsDataMonitor.entity.*; +import org.springframework.stereotype.Component; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; + +import java.nio.file.InvalidPathException; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@Slf4j +@Component +public class EffConfigManager { + + // 私有构造方法 + private EffConfigManager() { + init(); + } + + private static EffConfigManager instance; + + //全局变量 + private Config config; + + // XML文件路径 + private String xmlFilePath = "compute_efficiency.xml"; + // 解析后的设备配置映射 + private Map parameterMap = new HashMap<>(); + // 配置状态 + private boolean initialized = false; + + /** + * 初始化配置 + * + *

使用默认配置文件路径("compute_efficiency.xml")

+ * + *

文件位置:类路径资源:classpath:config.xml

+ * + * @throws Exception + */ + public void init() { + try { + String filePath = this.getClass().getClassLoader().getResource(xmlFilePath).getPath(); + initializeCache(filePath); + this.initialized = true; + } catch (Exception e) { + log.error("参数初始化失败:" + e.getMessage()); + } + + } + + /** + * 初始化配置管理器(指定文件路径) + * + *

使用指定的XML文件路径初始化配置管理器。

+ * + *

文件格式要求:

+ *
    + *
  • 必须是有效的XML文件
  • + *
  • 必须符合预定义的XML Schema结构
  • + *
  • 编码推荐使用UTF-8
  • + *
  • 文件大小建议不超过10MB
  • + *
+ * + * @param filePath XML配置文件的完整路径或相对路径 + *

路径格式:

+ *
    + *
  • 绝对路径:/home/user/config.xml 或 C:\config\config.xml
  • + *
  • 相对路径:config.xml 或 ./config/config.xml
  • + *
  • 类路径资源:classpath:config.xml(暂不支持)
  • + *
+ * @throws IllegalArgumentException 如果文件路径为null、空字符串或无效路径 + * @throws java.nio.file.NoSuchFileException 如果指定的文件不存在 + * @throws java.nio.file.AccessDeniedException 如果没有文件读取权限 + * @throws com.fasterxml.jackson.core.JsonParseException 如果XML格式不正确 + * @throws com.fasterxml.jackson.databind.JsonMappingException 如果XML结构不匹配 + * @throws Exception 其他IO或解析异常 + * + *

示例:

+ *
+     *                                                             {@code
+     *                                                             // 使用绝对路径
+     *                                                             manager.init("/etc/app/config.xml");
+     *
+     *                                                             // 使用相对路径
+     *                                                             manager.init("conf/production.xml");
+     *
+     *                                                             // 从命令行参数获取路径
+     *                                                             if (args.length > 0) {
+     *                                                                 manager.init(args[0]);
+     *                                                             }
+     *                                                             }
+     *                                                             
+ */ + public void init(String filePath) throws Exception { + if (filePath == null || filePath.trim().isEmpty()) { + throw new IllegalArgumentException("文件路径不能为空"); + } + + try { + Paths.get(filePath); + } catch (InvalidPathException e) { + throw new IllegalArgumentException("无效的文件路径: " + filePath, e); + } + this.xmlFilePath = filePath; + initializeCache(filePath); + + this.initialized = true; + } + + // 获取单例实例 + public static synchronized EffConfigManager getInstance() { + if (instance == null) { + instance = new EffConfigManager(); + } + return instance; + } + + + /** + * 加载并解析XML配置文件 + * + *

内部方法,执行以下操作:

+ *
    + *
  1. 配置XmlMapper解析器
  2. + *
  3. 解析XML到Java对象
  4. + *
  5. 构建设备配置映射表
  6. + *
+ * + * @param xmlFilePath XML文件路径 + * @throws Exception 参考{@link #init(String)}的异常说明 + * @see #init(String) + */ + public void initializeCache(String xmlFilePath) throws Exception { + try { + File file = new File(xmlFilePath); + XmlMapper xmlMapper = new XmlMapper(); + config = xmlMapper.readValue(file, Config.class); + buildMap(); + + } catch (Exception e) { + System.out.println("错误:" + e.getMessage()); + } + } + + /** + * 构建配置映射表 + * + *

将解析后的配置对象转换为按名称索引的映射表,便于快速访问。

+ * + *

设备名称映射规则:

+ *
    + *
  • "particulate" → {@link Particulate} 对象
  • + *
  • "spalax" → {@link Spalax} 对象
  • + *
  • "sauna2" → {@link Sauna} 对象
  • + *
  • "sauna3" → {@link Sauna} 对象
  • + *
+ * + * @throws IllegalStateException 如果全局配置未初始化 + */ + private void buildMap() { + parameterMap.clear(); + if (config == null) { + throw new IllegalStateException("全局配置未初始化"); + } + if (config != null && config.getPhdf() != null) { + Phdf phdf = config.getPhdf(); + + if (phdf.getParticulate() != null) { + parameterMap.put("particulate", phdf.getParticulate()); + } + if (phdf.getSpalax() != null) { + parameterMap.put("spalax", phdf.getSpalax()); + } + if (phdf.getSauna2() != null) { + parameterMap.put("sauna2", phdf.getSauna2()); + } + if (phdf.getSauna3() != null) { + parameterMap.put("sauna3", phdf.getSauna3()); + } + } + } + + /** + * 获取全局配置对象 + */ + public Config getGlobalConfig() { + return config; + } + + /** + * 获取指定名称的配置 + * + *

根据名称返回对应的设备配置对象。

+ * + * @param parameterName 名称,支持以下值: + *
    + *
  • "particulate" - 颗粒物
  • + *
  • "spalax" -
  • + *
  • "sauna2" -
  • + *
  • "sauna3" -
  • + *
+ * @return 设备配置对象,如果名称不存在返回null + * @throws IllegalStateException 如果配置未初始化 + * + *

示例:

+ *
+     * {@code
+     * // 获取颗粒物设备配置
+     * BaseParameter particulate = manager.getDevice("particulate");
+     * if (particulate != null) {
+     *     double liveLow = particulate.getLiveLow();
+     *     // 处理配置...
+     * }
+     *
+     * // 获取氙气设备并转换类型
+     * Sauna sauna2 = (Sauna) manager.getDevice("sauna2");
+     * if (sauna2 != null) {
+     *     String nuclide = sauna2.getNuclideName();
+     * }
+     * }
+     * 
+ */ + public BaseParameter getParameter(String parameterName) { + return parameterMap.get(parameterName); + } + + /** + * 获取所有参数 + */ + public Map getAllDevices() { + return new HashMap<>(parameterMap); + } + + /** + * 重新加载配置 + */ + public void reload() throws Exception { + initializeCache(xmlFilePath); + } + + /** + * 重新加载配置(新文件) + */ + public void reload(String newFilePath) throws Exception { + this.xmlFilePath = newFilePath; + initializeCache(newFilePath); + } + + /** + * 检查配置是否已初始化 + * + * @return true如果配置已初始化,否则false + */ + public boolean isInitialized() { + return initialized && config != null; + } + +} diff --git a/jeecg-module-large-screen/src/main/resources/compute_efficiency.xml b/jeecg-module-large-screen/src/main/resources/compute_efficiency.xml new file mode 100644 index 0000000..128b198 --- /dev/null +++ b/jeecg-module-large-screen/src/main/resources/compute_efficiency.xml @@ -0,0 +1,46 @@ + + + + + 21.6 + 26.4 + 10800 + 21.6 + 26.4 + 1 + + + 10 + 11 + 10 + 10.8 + 13.2 + 4 + 240 + + + 5.4 + 6.6 + 4.2 + 6.6 + 10 + 0.87 + 1 + Xe133 + 600 + 16 + + + 5.4 + 6.6 + 4.2 + 6.6 + 10 + 0.87 + 1 + Xe133 + 600 + 16 + + + \ No newline at end of file