This commit is contained in:
panbaolin 2026-07-09 17:55:13 +08:00
commit 28c0ba277e
34 changed files with 1902 additions and 333 deletions

View File

@ -848,5 +848,10 @@ public class DateUtils extends PropertyEditorSupport {
return dateList;
}
public static Date addDays(Date date, int days) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, days);
return cal.getTime();
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 探测器模拟及联符合校正因子库数据
@ -89,4 +90,8 @@ public class GardsCorrectionFactor implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date moddate;
@TableField(exist = false)
private List<GardsCorrectionFactorDetail> details;
}

View File

@ -0,0 +1,67 @@
package org.jeecg.modules.base.entity.configuration;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 探测器模拟及联符合校正因子库数据---校正因子
*
*/
@Data
@TableName("CONFIGURATION.GARDS_CORRECTION_FACTOR_DETAIL")
public class GardsCorrectionFactorDetail {
/**
* 校正因子ID
*/
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
/**
* 台站ID
*/
@TableField(value = "STATION_ID")
private Integer stationId;
/**
* 探测器ID
*/
@TableField(value = "DETECTOR_ID")
private Integer detectorId;
/**
* 能量
*/
@Excel(name = "核素", width = 20, height = 20, orderNum = "1")
@TableField(value = "NUCLIDE_NAME")
private String nuclideName;
/**
* 能量
*/
@Excel(name = "能量", width = 20, height = 20, orderNum = "2")
@TableField(value = "ENERGY")
private Double energy;
/**
* 校正因子
*/
@Excel(name = "校正因子", width = 20, height = 20, orderNum = "3")
@TableField(value = "CORRECTION_FACTOR")
private Double correctionFactor;
/**
* 修改时间
*/
@TableField(value = "MODDATE", fill = FieldFill.INSERT_UPDATE)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date moddate;
}

View File

@ -0,0 +1,67 @@
package org.jeecg.modules.base.entity.configuration;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 探测器模拟及联符合校正因子库数据---效率
*
*/
@Data
@TableName("CONFIGURATION.GARDS_CORRECTION_FACTOR_EFF")
public class GardsCorrectionFactorEff {
/**
* 主键ID
*/
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
/**
* 台站ID
*/
@TableField(value = "STATION_ID")
private Integer stationId;
/**
* 探测器ID
*/
@TableField(value = "DETECTOR_ID")
private Integer detectorId;
/**
* 峰效率
*/
@Excel(name = "峰效率", width = 20, height = 20, orderNum = "1")
@TableField(value = "PEAK_EFFICIENCY")
private Double peakEfficiency;
/**
* 总效率
*/
@Excel(name = "总效率", width = 20, height = 20, orderNum = "2")
@TableField(value = "TOTAL_EFFICIENCY")
private Double totalEfficiency;
/**
* 能量
*/
@Excel(name = "能量", width = 20, height = 20, orderNum = "3")
@TableField(value = "ENERGY")
private Double energy;
/**
* 修改时间
*/
@TableField(value = "MODDATE", fill = FieldFill.INSERT_UPDATE)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date moddate;
}

View File

@ -0,0 +1,25 @@
package org.jeecg.modules.base.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorDetail;
import org.jeecg.modules.base.vo.GardsCorrectionFactorDetailVO;
import java.util.List;
import java.util.Map;
public interface GardsCorrectionFactorDetailMapper extends BaseMapper<GardsCorrectionFactorDetail> {
IPage<GardsCorrectionFactorDetailVO> selectCombinedPage(
Page<GardsCorrectionFactorDetailVO> page,@Param("stationCode")String stationCode,@Param("detectorCode") String detectorCode,@Param("nuclideName") String nuclideName);
List<GardsCorrectionFactorDetailVO> findList(@Param("stationCode")String stationCode,@Param("detectorCode") String detectorCode,@Param("nuclideName") String nuclideName);
List<Map<String, Object>>selectStations();
List<Map<String, Object>>selectdetectors();
}

View File

@ -0,0 +1,36 @@
package org.jeecg.modules.base.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorEff;
import org.jeecg.modules.base.vo.DetectorMapDTO;
import org.jeecg.modules.base.vo.DetectorOptionVO;
import org.jeecg.modules.base.vo.GardsCorrectionFactorEffVO;
import org.jeecg.modules.base.vo.StationOptionVO;
import java.util.List;
public interface GardsCorrectionFactorEffMapper extends BaseMapper<GardsCorrectionFactorEff> {
IPage<GardsCorrectionFactorEffVO> selectCombinedPage(
Page<GardsCorrectionFactorEffVO> page,
@Param("stationCode") String stationCode, @Param("detectorCode") String detectorCode);
List<GardsCorrectionFactorEffVO> selectVOList(@Param("stationCode") String stationCode,
@Param("detectorCode") String detectorCode);
@Select("SELECT DETECTOR_ID, DETECTOR_CODE, STATION_ID FROM CONFIGURATION.GARDS_DETECTORS")
List<DetectorMapDTO> queryAllDetectorRef();
// 获取所有站点
List<StationOptionVO> getStationOptions();
// 根据站点联动获取探测器
List<DetectorOptionVO> getDetectorOptions(@Param("stationId")Long stationId);
}

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.base.mapper.GardsCorrectionFactorDetailMapper">
<select id="selectCombinedPage" resultType="org.jeecg.modules.base.vo.GardsCorrectionFactorDetailVO">
SELECT
e.*,
f.DETECTOR_CODE,
f.STATION_CODE
FROM
CONFIGURATION.GARDS_CORRECTION_FACTOR_DETAIL e
INNER JOIN (
SELECT
d.DETECTOR_ID,
d.DETECTOR_CODE,
s.STATION_ID,
s.STATION_CODE
FROM
CONFIGURATION.GARDS_DETECTORS d
INNER JOIN CONFIGURATION.GARDS_STATIONS s ON d.STATION_ID = s.STATION_ID
) f ON e.STATION_ID = f.STATION_ID
AND e.DETECTOR_ID = f.DETECTOR_ID
<where>
<if test="stationCode != null and stationCode != ''">
AND f.STATION_CODE = #{stationCode}
</if>
<if test="detectorCode != null and detectorCode != ''">
AND f.DETECTOR_CODE = #{detectorCode}
</if>
<if test="nuclideName != null and nuclideName != ''">
AND e.NUCLIDE_NAME = #{nuclideName}
</if>
</where>
</select>
<select id="findList" resultType="org.jeecg.modules.base.vo.GardsCorrectionFactorDetailVO">
SELECT
e.*,
f.DETECTOR_CODE,
f.STATION_CODE
FROM
CONFIGURATION.GARDS_CORRECTION_FACTOR_DETAIL e
INNER JOIN (
SELECT
d.DETECTOR_ID,
d.DETECTOR_CODE,
s.STATION_ID,
s.STATION_CODE
FROM
CONFIGURATION.GARDS_DETECTORS d
INNER JOIN CONFIGURATION.GARDS_STATIONS s ON d.STATION_ID = s.STATION_ID
) f ON e.STATION_ID = f.STATION_ID
AND e.DETECTOR_ID = f.DETECTOR_ID
<where>
<if test="stationCode != null and stationCode != ''">
AND f.STATION_CODE = #{stationCode}
</if>
<if test="detectorCode != null and detectorCode != ''">
AND f.DETECTOR_CODE = #{detectorCode}
</if>
<if test="nuclideName != null and nuclideName != ''">
AND e.NUCLIDE_NAME LIKE CONCAT('%', #{nuclideName}, '%')
</if>
</where>
</select>
<select id="selectStations" resultType="java.util.HashMap">
SELECT DETECTOR_ID,
DETECTOR_CODE,
STATION_ID
FROM "CONFIGURATION"."GARDS_STATIONS"
WHERE STATION_ID IS NOT NULL
</select>
<select id="selectdetectors" resultType="java.util.HashMap">
SELECT
STATION_ID,
STATION_CODE
FROM
"CONFIGURATION"."GARDS_DETECTORS"
</select>
</mapper>

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.base.mapper.GardsCorrectionFactorEffMapper">
<select id="selectCombinedPage" resultType="org.jeecg.modules.base.vo.GardsCorrectionFactorEffVO">
SELECT
e.*,
f.DETECTOR_CODE,
f.STATION_CODE
FROM
CONFIGURATION.GARDS_CORRECTION_FACTOR_EFF e
INNER JOIN (
SELECT
d.DETECTOR_ID,
d.DETECTOR_CODE,
s.STATION_ID,
s.STATION_CODE
FROM
CONFIGURATION.GARDS_DETECTORS d
INNER JOIN CONFIGURATION.GARDS_STATIONS s
ON d.STATION_ID = s.STATION_ID
) f
ON e.STATION_ID = f.STATION_ID
AND e.DETECTOR_ID = f.DETECTOR_ID
<where>
<if test="stationCode != null and stationCode != ''">
AND f.STATION_CODE = #{stationCode}
</if>
<if test="detectorCode != null and detectorCode != ''">
AND f.DETECTOR_CODE = #{detectorCode}
</if>
</where>
</select>
<select id="selectVOList" resultType="org.jeecg.modules.base.vo.GardsCorrectionFactorEffVO">
SELECT
e.*,
f.DETECTOR_CODE,
f.STATION_CODE
FROM
CONFIGURATION.GARDS_CORRECTION_FACTOR_DETAIL e
INNER JOIN (
SELECT
d.DETECTOR_ID,
d.DETECTOR_CODE,
s.STATION_ID,
s.STATION_CODE
FROM
CONFIGURATION.GARDS_DETECTORS d
INNER JOIN CONFIGURATION.GARDS_STATIONS s
ON d.STATION_ID = s.STATION_ID
) f
ON e.STATION_ID = f.STATION_ID
AND e.DETECTOR_ID = f.DETECTOR_ID
<where>
<if test="stationCode != null and stationCode != ''">
AND f.STATION_CODE = #{stationCode}
</if>
<if test="detectorCode != null and detectorCode != ''">
AND f.DETECTOR_CODE = #{detectorCode}
</if>
</where>
</select>
<select id="getStationOptions" resultType="org.jeecg.modules.base.vo.StationOptionVO">
SELECT
STATION_ID as "stationId",
STATION_CODE as "stationCode"
FROM "CONFIGURATION"."GARDS_STATIONS"
WHERE STATUS = 'Operating'
ORDER BY STATION_CODE ASC
</select>
<select id="getDetectorOptions" resultType="org.jeecg.modules.base.vo.DetectorOptionVO">
SELECT
DETECTOR_ID as "detectorId",
DETECTOR_CODE as "detectorCode"
FROM "CONFIGURATION"."GARDS_DETECTORS"
WHERE STATION_ID = #{stationId}
ORDER BY DETECTOR_CODE ASC
</select>
</mapper>

View File

@ -0,0 +1,10 @@
package org.jeecg.modules.base.vo;
import lombok.Data;
@Data
public class DetectorMapDTO {
private Integer detectorId;
private String detectorCode;
private Integer stationId;
}

View File

@ -0,0 +1,14 @@
package org.jeecg.modules.base.vo;
import lombok.Data;
@Data
public class DetectorOptionVO {
private Long detectorId;
private String detectorCode;
public DetectorOptionVO(Long detectorId, String detectorCode) {
this.detectorId = detectorId;
this.detectorCode = detectorCode;
}
}

View File

@ -0,0 +1,18 @@
package org.jeecg.modules.base.vo;
import lombok.Data;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorDetail;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
import java.util.Date;
@Data
public class GardsCorrectionFactorDetailVO extends GardsCorrectionFactorDetail implements Serializable {
@Excel(name = "台站编码", orderNum = "0")
private String stationCode;
@Excel(name = "探测器编码", orderNum = "0")
private String detectorCode;
}

View File

@ -0,0 +1,16 @@
package org.jeecg.modules.base.vo;
import lombok.Data;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorEff;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
@Data
public class GardsCorrectionFactorEffVO extends GardsCorrectionFactorEff implements Serializable {
@Excel(name = "台站编码", orderNum = "0")
private String stationCode;
@Excel(name = "探测器编码", orderNum = "0")
private String detectorCode;
}

View File

@ -0,0 +1,14 @@
package org.jeecg.modules.base.vo;
import lombok.Data;
@Data
public class StationOptionVO {
private Long stationId;
private String stationCode;
public StationOptionVO(Long stationId, String stationCode) {
this.stationId = stationId;
this.stationCode = stationCode;
}
}

View File

@ -27,5 +27,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.15.2</version>
</dependency>
</dependencies>
</project>

View File

@ -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<ProvisionData> data = imsDataMonitorService.getParticulate(code, startDate, endDate);
public Result<?> getParticulate() {
List<ProvisionData> 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<ProvisionData> data = imsDataMonitorService.getSpalax(code, startDate, endDate);
public Result<?> getSpalax() {
List<ProvisionData> 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<ProvisionData> data = imsDataMonitorService.getSauna2(code, startDate, endDate);
public Result<?> getSauna2() {
List<ProvisionData> 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<ProvisionData> data = imsDataMonitorService.getSauna3(code, startDate, endDate);
public Result<?> getSauna3() {
List<ProvisionData> data = imsDataMonitorService.getSauna3();
// return Result.OK(data);
//TODO 测试待删除
try (InputStream inputStream = imsDataMonitorController.class.getClassLoader()

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,4 @@
package org.jeecg.imsDataMonitor.entity;
public class Particulate extends BaseParameter {
}

View File

@ -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;
}

View File

@ -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<Integer> stationId;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -22,13 +22,13 @@ public interface IMSDataMonitorService {
*获取Particulate类型的有效率数据
* @return Map<String, List<ProvisionData>>
*/
List<ProvisionData> getParticulate(String code, Date startDate, Date endDate);
List<ProvisionData> getParticulate();
List<ProvisionData> getSpalax(String code, Date startDate, Date endDate);
List<ProvisionData> getSpalax();
List<ProvisionData> getSauna2(String code, Date startDate, Date endDate);
List<ProvisionData> getSauna2();
List<ProvisionData> getSauna3(String code, Date startDate, Date endDate);
List<ProvisionData> getSauna3();
}

View File

@ -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<GardsStations> getGardsStationList(String systemType) {
return imsDataMonitorMapper.findStationList(systemType);
}
//region Particulate
/**
* 获取获取Particulate类型的台站有效率
* <p>时间范围默认当前时间往前一个月</p>
*
* @return List
*/
@Override
public List<ProvisionData> getParticulate(String code, Date startDate, Date endDate) {
public List<ProvisionData> getParticulate() {
//获取Particulate类型的台站信息
List<GardsStations> stations = imsDataMonitorMapper.findStationList("P");
String[] times = getDataTime(startDate, endDate);
String[] times = getDataTime();
//有效率状态
return getStationDailyData(stations, times[0], times[1]);
}
private List<ProvisionData> getStationDailyData(List<GardsStations> 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<Integer> 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<ProvisionData> getSpalax() {
String actualCode = "SPALAX";
//获取Particulate类型的台站信息
List<GardsStations> stations = imsDataMonitorMapper.findEfficStationList(actualCode);
String[] times = getDataTime();
//有效率状态
return getSpalaxStationDailyData(stations, times[0], times[1]);
}
private List<ProvisionData> getSpalaxStationDailyData(List<GardsStations> stationList,
String startTime, String endTime) {
if (CollectionUtil.isEmpty(stationList)) {
return new ArrayList<>();
}
//每个台站一个月的有效率
Spalax spalax = (Spalax) configManager.getParameter("spalax");
PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency();
List<Integer> 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<ProvisionData> rawDataList =
imsDataMonitorMapper.findPhdfSpalaxEfficiency(efficiency);
//dataMap.put(station.getStationCode(), rawDataList);
return rawDataList;
}
//endregion
//region SAUNA II
@Override
public List<ProvisionData> getSauna2() {
String actualCode = "SAUNA2";
//获取Particulate类型的台站信息
List<GardsStations> stations = imsDataMonitorMapper.findEfficStationList(actualCode);
String[] times = getDataTime();
//有效率状态
return getSauna2StationDailyData(stations, times[0], times[1]);
}
private List<ProvisionData> getSauna2StationDailyData(List<GardsStations> stationList,
String startTime, String endTime) {
if (CollectionUtil.isEmpty(stationList)) {
return new ArrayList<>();
}
//每个台站一个月的有效率
Sauna sauna2 = (Sauna) configManager.getParameter("sauna2");
PhdfProvisionEfficiency efficiency = new PhdfProvisionEfficiency();
List<Integer> 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<ProvisionData> rawDataList =
imsDataMonitorMapper.findPhdfSauna2Efficiency(efficiency);
//dataMap.put(station.getStationCode(), rawDataList);
return rawDataList;
}
//endregion
//region SAUNA III
@Override
public List<ProvisionData> getSauna3() {
String actualCode = "SAUNA3";
//获取Particulate类型的台站信息
List<GardsStations> 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<ProvisionData> getSpalax(String code, Date startDate, Date endDate) {
String actualCode = (code == null || code.trim().isEmpty()) ? "SPALAX" : code;
//获取Particulate类型的台站信息
List<GardsStations> stations = imsDataMonitorMapper.findEfficStationList(actualCode);
String[] times = getDataTime(startDate, endDate);
//有效率状态
return getSpalaxStationDailyData(stations, times[0], times[1]);
}
private List<ProvisionData> getSpalaxStationDailyData(List<GardsStations> 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<Integer> 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<ProvisionData> rawDataList =
imsDataMonitorMapper.findPhdfSpalaxEfficiency(efficiency);
//dataMap.put(station.getStationCode(), rawDataList);
return rawDataList;
}
//endregion
//region SAUNA II
@Override
public List<ProvisionData> getSauna2(String code, Date startDate, Date endDate) {
String actualCode = (code == null || code.trim().isEmpty()) ? "SAUNA2" : code;
//获取Particulate类型的台站信息
List<GardsStations> stations = imsDataMonitorMapper.findEfficStationList(actualCode);
String[] times = getDataTime(startDate, endDate);
//有效率状态
return getSauna2StationDailyData(stations, times[0], times[1]);
}
private List<ProvisionData> getSauna2StationDailyData(List<GardsStations> 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<Integer> 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<ProvisionData> rawDataList =
imsDataMonitorMapper.findPhdfSauna2Efficiency(efficiency);
//dataMap.put(station.getStationCode(), rawDataList);
return rawDataList;
}
//endregion
//region SAUNA III
@Override
public List<ProvisionData> getSauna3(String code, Date startDate, Date endDate) {
String actualCode = (code == null || code.trim().isEmpty()) ? "SAUNA3" : code;
//获取Particulate类型的台站信息
List<GardsStations> stations = imsDataMonitorMapper.findEfficStationList(actualCode);
String[] times = getDataTime(startDate, endDate);
//有效率状态
return getSauna2StationDailyData(stations, times[0], times[1]);
}
//endregion
}

View File

@ -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<String, BaseParameter> parameterMap = new HashMap<>();
// 配置状态
private boolean initialized = false;
/**
* 初始化配置
*
* <p>使用默认配置文件路径"compute_efficiency.xml"</p>
*
* <p><strong>文件位置</strong>类路径资源classpath:config.xml</p>
*
* @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());
}
}
/**
* 初始化配置管理器指定文件路径
*
* <p>使用指定的XML文件路径初始化配置管理器</p>
*
* <p><strong>文件格式要求</strong></p>
* <ul>
* <li>必须是有效的XML文件</li>
* <li>必须符合预定义的XML Schema结构</li>
* <li>编码推荐使用UTF-8</li>
* <li>文件大小建议不超过10MB</li>
* </ul>
*
* @param filePath XML配置文件的完整路径或相对路径
* <p><strong>路径格式</strong></p>
* <ul>
* <li>绝对路径/home/user/config.xml C:\config\config.xml</li>
* <li>相对路径config.xml ./config/config.xml</li>
* <li>类路径资源classpath:config.xml暂不支持</li>
* </ul>
* @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或解析异常
*
* <p><strong>示例</strong></p>
* <pre>
* {@code
* // 使用绝对路径
* manager.init("/etc/app/config.xml");
*
* // 使用相对路径
* manager.init("conf/production.xml");
*
* // 从命令行参数获取路径
* if (args.length > 0) {
* manager.init(args[0]);
* }
* }
* </pre>
*/
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配置文件
*
* <p>内部方法执行以下操作</p>
* <ol>
* <li>配置XmlMapper解析器</li>
* <li>解析XML到Java对象</li>
* <li>构建设备配置映射表</li>
* </ol>
*
* @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());
}
}
/**
* 构建配置映射表
*
* <p>将解析后的配置对象转换为按名称索引的映射表便于快速访问</p>
*
* <p><strong>设备名称映射规则</strong></p>
* <ul>
* <li>"particulate" {@link Particulate} 对象</li>
* <li>"spalax" {@link Spalax} 对象</li>
* <li>"sauna2" {@link Sauna} 对象</li>
* <li>"sauna3" {@link Sauna} 对象</li>
* </ul>
*
* @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;
}
/**
* 获取指定名称的配置
*
* <p>根据名称返回对应的设备配置对象</p>
*
* @param parameterName 名称支持以下值
* <ul>
* <li>"particulate" - 颗粒物</li>
* <li>"spalax" - </li>
* <li>"sauna2" - </li>
* <li>"sauna3" - </li>
* </ul>
* @return 设备配置对象如果名称不存在返回null
* @throws IllegalStateException 如果配置未初始化
*
* <p><strong>示例</strong></p>
* <pre>
* {@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();
* }
* }
* </pre>
*/
public BaseParameter getParameter(String parameterName) {
return parameterMap.get(parameterName);
}
/**
* 获取所有参数
*/
public Map<String, BaseParameter> 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;
}
}

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<phdf>
<particulate>
<liveLow>21.6</liveLow>
<liveHigh>26.4</liveHigh>
<quantity>10800</quantity>
<collectLow>21.6</collectLow>
<collectHigh>26.4</collectHigh>
<number>1</number>
</particulate>
<spalax>
<liveLow>10</liveLow>
<liveHigh>11</liveHigh>
<quantity>10</quantity>
<collectLow>10.8</collectLow>
<collectHigh>13.2</collectHigh>
<number>4</number>
<liveqc>240</liveqc>
</spalax>
<sauna2>
<collectLow>5.4</collectLow>
<collectHigh>6.6</collectHigh>
<liveLow>4.2</liveLow>
<liveHigh>6.6</liveHigh>
<quantity>10</quantity>
<xeVolume>0.87</xeVolume>
<mdc>1</mdc>
<nuclideName>Xe133</nuclideName>
<liveQc>600</liveQc>
<number>16</number>
</sauna2>
<sauna3>
<collectLow>5.4</collectLow>
<collectHigh>6.6</collectHigh>
<liveLow>4.2</liveLow>
<liveHigh>6.6</liveHigh>
<quantity>10</quantity>
<xeVolume>0.87</xeVolume>
<mdc>1</mdc>
<nuclideName>Xe133</nuclideName>
<liveQc>600</liveQc>
<number>16</number>
</sauna3>
</phdf>
</config>

View File

@ -23,5 +23,11 @@
<artifactId>jeecg-boot-base-core</artifactId>
<version>${jeecgboot.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,217 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorDetail;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorEff;
import org.jeecg.modules.base.vo.DetectorMapDTO;
import org.jeecg.modules.base.vo.GardsCorrectionFactorDetailVO;
import org.jeecg.modules.base.vo.GardsCorrectionFactorEffVO;
import org.jeecg.service.GardsCorrectionFactorDetailService;
import org.jeecg.service.GardsCorrectionFactorEffService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 级联符合校正因子库--校正因子
*/
@Slf4j
@RestController
@RequestMapping("/gardsCorrectionFactorDetail")
public class GardsCorrectionFactorDetailController {
final short titleHeight = 8;
@Autowired
private GardsCorrectionFactorDetailService detailService;
@Autowired
private GardsCorrectionFactorEffService effService;
/**
* 分页查询
*/
@GetMapping("/page")
@Operation(summary = "分页查询")
public Result<IPage<GardsCorrectionFactorDetailVO>> list(
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false)String stationCode,
@RequestParam(required = false)String detectorCode,
@RequestParam(required = false)String nuclideName) {
return Result.ok(
detailService.findPage(pageNum, size, stationCode, detectorCode, nuclideName));
}
/**
* 添加
*
* @param detail
* @return
*/
@PostMapping("/add")
@Operation(summary = "添加")
public Result<?> add(@RequestBody GardsCorrectionFactorDetail detail) {
return Result.ok(detailService.save(detail));
}
/**
* 更新
*
* @param detail
* @return
*/
@PutMapping("/update")
@Operation(summary = "更新")
public Result<?> update(@RequestBody GardsCorrectionFactorDetail detail) {
return Result.ok(detailService.updateById(detail));
}
/**
* 删除
*
* @param id
* @return
*/
@DeleteMapping("/delete")
@Operation(summary = "删除")
public Result<?> delete(@RequestParam(name = "id") Integer id) {
return Result.ok(detailService.removeById(id));
}
@AutoLog(value = "导出模版")
@Operation(summary = "导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("探测器模拟及联符合校正因子信息");
params.setFixedTitle(true);
params.setTitleHeight(titleHeight);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsCorrectionFactorDetailVO.class, new ArrayList<>())
.write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "导出校正因子Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String detectorCode,
@RequestParam(required = false) String nuclideName)
throws IOException {
ExportParams params = new ExportParams();
params.setTitle("探测器模拟及联符合校正因子信息");
params.setFixedTitle(true);
params.setTitleHeight(titleHeight);
params.setType(ExcelType.XSSF);
List<GardsCorrectionFactorDetailVO> list = detailService.findList(
stationCode, detectorCode, nuclideName);
ExcelExportUtil.exportExcel(params, GardsCorrectionFactorDetailVO.class, list)
.write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "导入GardsAccelerator数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsCorrectionFactorDetailVO> list =
ExcelImportUtil.importExcel(file.getInputStream(),
GardsCorrectionFactorDetailVO.class, params);
// 预加载映射关系 (Key: Code, Value: DTO)
// SQL: SELECT DETECTOR_ID, DETECTOR_CODE, STATION_ID FROM GARDS_DETECTORS
Map<String, DetectorMapDTO> refMap = effService.queryAllDetectorRef().stream()
.collect(Collectors.toMap(DetectorMapDTO::getDetectorCode, d -> d,
(k1, k2) -> k1));
// 转换GardsCorrectionFactorDetail并保存
List<GardsCorrectionFactorDetail> entityList = new ArrayList<>();
for (GardsCorrectionFactorDetailVO vo : list) {
if (StringUtils.isEmpty(vo.getDetectorCode())) {
continue;
}
// 根据 Excel 里的探测器代码获取数据库 ID
DetectorMapDTO ref = refMap.get(vo.getDetectorCode().trim());
if (ref == null) {
return Result.error(
"导入中止:系统中不存在探测器代码 [" + vo.getDetectorCode() + "]");
}
GardsCorrectionFactorDetail effEntity = new GardsCorrectionFactorDetail();
BeanUtils.copyProperties(vo, effEntity);
// 填充两个关联 ID
effEntity.setDetectorId(ref.getDetectorId());
effEntity.setStationId(ref.getStationId());
entityList.add(effEntity);
}
// 4. 批量保存数据到数据库
if (!CollectionUtils.isEmpty(entityList)) {
//detailService.saveBatch(entityList);
entityList.forEach(item -> detailService.save(item));
}
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,234 @@
package org.jeecg.controller;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorEff;
import org.jeecg.modules.base.vo.DetectorMapDTO;
import org.jeecg.modules.base.vo.DetectorOptionVO;
import org.jeecg.modules.base.vo.GardsCorrectionFactorEffVO;
import org.jeecg.modules.base.vo.StationOptionVO;
import org.jeecg.service.GardsCorrectionFactorEffService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 级联符合校正因子库--峰效率
*/
@Slf4j
@RestController
@RequestMapping("/gardsCorrectionFactorEff")
public class GardsCorrectionFactorEffController {
private final short titleHeight = 8;
@Autowired
private GardsCorrectionFactorEffService effService;
/**
* 分页查询
*/
@GetMapping("/page")
@Operation(summary = "分页查询")
public Result<?> list(@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String detectorCode) {
return Result.OK(effService.findPage(pageNum, size, stationCode, detectorCode));
}
/**
* 添加
*
* @param eff 实体
* @return Result
*/
@PostMapping("/add")
@Operation(summary = "添加")
public Result<?> add(@RequestBody GardsCorrectionFactorEff eff) {
return Result.OK(effService.add(eff));
}
/**
* 更新
*
* @param eff 实体
* @return Result
*/
@PutMapping("/update")
@Operation(summary = "更新")
public Result<?> update(@RequestBody GardsCorrectionFactorEff eff) {
return Result.OK(effService.update(eff));
}
/**
* 删除
*
* @param id 主键ID
* @return Result
*/
@DeleteMapping("/delete")
@Operation(summary = "删除")
public Result<?> delete(@RequestParam(name = "id") Integer id) {
effService.delete(id);
return Result.OK();
}
@AutoLog(value = "导出模版")
@Operation(summary = "导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("探测器模拟及联符合校正因子信息");
params.setFixedTitle(true);
params.setTitleHeight(titleHeight);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsCorrectionFactorEffVO.class, new ArrayList<>())
.write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "导出校正因子Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String detectorCode)
throws IOException {
ExportParams params = new ExportParams();
params.setTitle("探测器模拟及联符合校正因子效率信息");
params.setFixedTitle(true);
params.setTitleHeight(titleHeight);
params.setType(ExcelType.XSSF);
List<GardsCorrectionFactorEffVO> list = effService.selectVOList(
stationCode, detectorCode);
ExcelExportUtil.exportExcel(params, GardsCorrectionFactor.class, list)
.write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "导入GardsAccelerator数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 使用 AutoPoi 工具类解析 Excel
List<GardsCorrectionFactorEffVO> voList =
ExcelImportUtil.importExcel(file.getInputStream(),
GardsCorrectionFactorEffVO.class, params);
if (!CollectionUtils.isEmpty(voList)) {
// 预加载映射关系 (Key: Code, Value: DTO)
// SQL: SELECT DETECTOR_ID, DETECTOR_CODE, STATION_ID FROM GARDS_DETECTORS
Map<String, DetectorMapDTO> refMap = effService.queryAllDetectorRef().stream()
.collect(Collectors.toMap(DetectorMapDTO::getDetectorCode, d -> d,
(k1, k2) -> k1));
// 转换GardsCorrectionFactorEff并保存
List<GardsCorrectionFactorEff> entityList = new ArrayList<>();
for (GardsCorrectionFactorEffVO vo : voList) {
if (StringUtils.isEmpty(vo.getDetectorCode())) {
continue;
}
// 根据 Excel 里的探测器代码获取数据库 ID
DetectorMapDTO ref = refMap.get(vo.getDetectorCode().trim());
if (ref == null) {
return Result.error(
"导入中止:系统中不存在探测器代码 [" + vo.getDetectorCode() +
"]");
}
GardsCorrectionFactorEff effEntity = new GardsCorrectionFactorEff();
BeanUtils.copyProperties(vo, effEntity);
// 填充两个关联 ID
effEntity.setDetectorId(ref.getDetectorId());
effEntity.setStationId(ref.getStationId());
entityList.add(effEntity);
}
// 4. 批量保存数据到数据库
if (!CollectionUtils.isEmpty(entityList)) {
entityList.forEach(item -> effService.save(item));
//effService.saveBatch(entityList);
}
return Result.OK("文件导入成功!数据行数:" + entityList.size());
}
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
@AutoLog(value = "获取站点列表")
// 下拉框站点
@GetMapping("/stations")
public List<StationOptionVO> getStations() {
return effService.getStationOptions();
}
// 根据站点 ID 过滤探测器
@AutoLog(value = "获取探测器")
@GetMapping("/detectors")
public List<DetectorOptionVO> getDetectors(@RequestParam(value = "stationId",required = false) Long stationId) {
if (stationId == null) {
return Collections.emptyList();
}
return effService.getDetectorOptions(stationId);
}
}

View File

@ -0,0 +1,28 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorDetail;
import org.jeecg.modules.base.vo.GardsCorrectionFactorDetailVO;
import java.util.List;
import java.util.Map;
public interface GardsCorrectionFactorDetailService extends IService<GardsCorrectionFactorDetail> {
IPage<GardsCorrectionFactorDetailVO> findPage(Integer pageNum, Integer pageSize,
String stationCode, String detectorCode, String nuclideName);
List<GardsCorrectionFactorDetailVO> findList(String stationCode, String detectorCode, String nuclideName);
List<Map<String, Object>>selectStations();
List<Map<String, Object>>selectdetectors();
}

View File

@ -0,0 +1,59 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorEff;
import org.jeecg.modules.base.vo.*;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
public interface GardsCorrectionFactorEffService extends IService<GardsCorrectionFactorEff> {
IPage<GardsCorrectionFactorEffVO> findPage(Integer pageNum, Integer pageSize,
String stationCode, String detectorCode);
/**
* 添加
*/
boolean add(GardsCorrectionFactorEff entity);
/**
* 修改
*
* @param entity
* @return
*/
boolean update(GardsCorrectionFactorEff entity);
/**
* 删除
*
* @param id 主键ID
* @return
*/
boolean delete(Integer id);
/**
* 导出数据
*
* @param stationCode 台站编码
* @param detectorCode 探测器编码
* @return List<GardsCorrectionFactorEffVO>
*/
List<GardsCorrectionFactorEffVO> selectVOList(String stationCode, String detectorCode);
List<DetectorMapDTO> queryAllDetectorRef();
// 获取所有站点
List<StationOptionVO> getStationOptions();
// 根据站点联动获取探测器
List<DetectorOptionVO> getDetectorOptions(Long stationId);
}

View File

@ -0,0 +1,58 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorDetail;
import org.jeecg.modules.base.mapper.GardsCorrectionFactorDetailMapper;
import org.jeecg.modules.base.mapper.GardsCorrectionFactorMapper;
import org.jeecg.service.GardsCorrectionFactorDetailService;
import org.jeecg.modules.base.vo.GardsCorrectionFactorDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
@Service
@DS("ora")
public class GardsCorrectionFactorDetailServiceImpl
extends ServiceImpl<GardsCorrectionFactorDetailMapper, GardsCorrectionFactorDetail>
implements GardsCorrectionFactorDetailService {
@Autowired
private GardsCorrectionFactorMapper factorMapper;
@Override
public IPage<GardsCorrectionFactorDetailVO> findPage(Integer pageNum, Integer pageSize,
String stationCode, String detectorCode, String nuclideName) {
Page<GardsCorrectionFactorDetailVO> page = new Page<>(pageNum, pageSize);
// 对应界面顶部的搜索框逻辑
return baseMapper.selectCombinedPage(page, stationCode,detectorCode,nuclideName);
}
@Override
public List<GardsCorrectionFactorDetailVO> findList(String stationCode, String detectorCode, String nuclideName) {
return baseMapper.findList(stationCode,detectorCode,nuclideName);
}
@Override
public List<Map<String, Object>> selectStations() {
List<Map<String, Object>> stations= baseMapper.selectStations();
return stations;
}
@Override
public List<Map<String, Object>> selectdetectors() {
List<Map<String, Object>> detectors= baseMapper.selectdetectors();
return detectors;
}
}

View File

@ -0,0 +1,87 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorDetail;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactorEff;
import org.jeecg.modules.base.mapper.GardsCorrectionFactorEffMapper;
import org.jeecg.modules.base.vo.*;
import org.jeecg.service.GardsCorrectionFactorEffService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.stream.Collectors;
@Service
@DS("ora")
public class GardsCorrectionFactorEffServiceImpl
extends ServiceImpl<GardsCorrectionFactorEffMapper, GardsCorrectionFactorEff>
implements GardsCorrectionFactorEffService {
@Override
public IPage<GardsCorrectionFactorEffVO> findPage(Integer pageNum, Integer pageSize,
String stationCode, String detectorCode) {
Page<GardsCorrectionFactorEffVO> page = new Page<>(pageNum, pageSize);
return baseMapper.selectCombinedPage(page, stationCode, detectorCode);
}
// 增加 ()
@Transactional
public boolean add(GardsCorrectionFactorEff entity) {
return this.save(entity);
}
// 修改 ()
@Transactional
public boolean update(GardsCorrectionFactorEff entity) {
return this.updateById(entity);
}
// 删除 ()
@Transactional
public boolean delete(Integer id) {
return this.removeById(id);
}
/**
* 导出数据
* @param stationCode 台站编码
* @param detectorCode 探测器编码
* @return List<GardsCorrectionFactorEffVO>
*/
public List<GardsCorrectionFactorEffVO> selectVOList(String stationCode, String detectorCode) {
return baseMapper.selectVOList(stationCode, detectorCode);
}
@Override
public List<DetectorMapDTO> queryAllDetectorRef() {
return baseMapper.queryAllDetectorRef();
}
// 获取所有站点
public List<StationOptionVO> getStationOptions() {
return baseMapper.getStationOptions().stream()
.map(s -> new StationOptionVO(s.getStationId(), s.getStationCode()))
.collect(Collectors.toList());
}
// 根据站点联动获取探测器
public List<DetectorOptionVO> getDetectorOptions(Long stationId) {
return baseMapper.getDetectorOptions(stationId).stream()
.map(d -> new DetectorOptionVO(d.getDetectorId(), d.getDetectorCode()))
.collect(Collectors.toList());
}
}

View File

@ -33,82 +33,94 @@ public class HostMonitorServiceImpl implements HostMonitorService {
* 获取CPU信息
*/
@Override
public Map<String,Object> getCpuInfo(String ip,String conditions) {
Map<String,Object> result = new HashMap<>();
public Map<String, Object> getCpuInfo(String ip, String conditions) {
Map<String, Object> result = new HashMap<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
//查询CPU利用率
PrometheusHostQueryTypeEnum queryTypeEnum = PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
PrometheusHostQueryTypeEnum queryTypeEnum =
PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
String exprTime = queryTypeEnum.getExprTime();
String cpuQuery = "100 * (1 - avg(rate(node_cpu_seconds_total{mode=\"idle\", instance=\""+instance+"\"}["+exprTime+"])))";
String cpuQuery =
"100 * (1 - avg(rate(node_cpu_seconds_total{mode=\"idle\", instance=\"" +
instance + "\"}[" + exprTime + "])))";
PrometheusResponse response = webClient.get()
.uri(buildUri(url,cpuQuery))
.uri(buildUri(url, cpuQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(response) &&
if (Objects.nonNull(response) &&
Objects.nonNull(response.getData()) &&
CollUtil.isNotEmpty(response.getData().getResult())
) {
PrometheusResponse.Result cpuInfo = response.getData().getResult().get(0);
if(CollUtil.isNotEmpty(cpuInfo.getValue())) {
Date date = new Date(cpuInfo.getValue().get(0).longValue()*1000);
Double useRate = BigDecimal.valueOf(cpuInfo.getValue().get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
PrometheusResponse.Result cpuInfo = response.getData().getResult().get(0);
if (CollUtil.isNotEmpty(cpuInfo.getValue())) {
Date date = new Date(cpuInfo.getValue().get(0).longValue() * 1000);
Double useRate = BigDecimal.valueOf(cpuInfo.getValue().get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put("date", DateUtil.format(date, "MM/dd HH:mm:ss"));
result.put("usageRate", useRate);
}
}
}catch (Exception e){
log.error("获取CPU信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取CPU信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
return result;
}
/**
* 获取CPU信息列表
*/
@Override
public List<Map<String, Object>> getCpuInfoList(String ip,String conditions) {
List<Map<String, Object>> result = new ArrayList<>();
public List<Map<String, Object>> getCpuInfoList(String ip, String conditions) {
List<Map<String, Object>> result = new ArrayList<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
//查询CPU利用率
PrometheusHostQueryTypeEnum queryTypeEnum = PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
PrometheusHostQueryTypeEnum queryTypeEnum =
PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
long end = Instant.now().getEpochSecond();
long start = end - queryTypeEnum.getLastSecond();
String step = queryTypeEnum.getStep();
String exprTime = queryTypeEnum.getExprTime();
String cpuQuery = "100 * (1 - avg(rate(node_cpu_seconds_total{mode=\"idle\", instance=\""+instance+"\"}["+exprTime+"])))";
String cpuQuery =
"100 * (1 - avg(rate(node_cpu_seconds_total{mode=\"idle\", instance=\"" +
instance + "\"}[" + exprTime + "])))";
PrometheusResponse response = webClient.get()
.uri(buildUri(url,cpuQuery,start,end,step))
.uri(buildUri(url, cpuQuery, start, end, step))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(response) &&
if (Objects.nonNull(response) &&
Objects.nonNull(response.getData()) &&
CollUtil.isNotEmpty(response.getData().getResult())
) {
PrometheusResponse.Result cpuInfoList = response.getData().getResult().get(0);
if(CollUtil.isNotEmpty(cpuInfoList.getValues())) {
PrometheusResponse.Result cpuInfoList = response.getData().getResult().get(0);
if (CollUtil.isNotEmpty(cpuInfoList.getValues())) {
List<List<Double>> pointDatas = cpuInfoList.getValues();
for(List<Double> pointData : pointDatas) {
Map<String,Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue()*1000);
Double useRate = BigDecimal.valueOf(pointData.get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
for (List<Double> pointData : pointDatas) {
Map<String, Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue() * 1000);
Double useRate = BigDecimal.valueOf(pointData.get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
pointDataMap.put("date", DateUtil.format(date, "MM/dd HH:mm:ss"));
pointDataMap.put("usageRate", useRate);
result.add(pointDataMap);
}
}
}
}catch (Exception e){
log.error("获取CPU信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取CPU信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
}
@ -117,42 +129,45 @@ public class HostMonitorServiceImpl implements HostMonitorService {
* 获取CPU核心数
*/
@Override
public Map<String,Object> getCpuCoreInfo(String ip) {
Map<String,Object> result = new HashMap<>();
public Map<String, Object> getCpuCoreInfo(String ip) {
Map<String, Object> result = new HashMap<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
//查询CPU核数
String cpuCoreQuery = "count(count by (cpu) (node_cpu_seconds_total{instance=\"" + instance + "\"}))";
String cpuCoreQuery =
"count(count by (cpu) (node_cpu_seconds_total{instance=\"" + instance + "\"}))";
PrometheusResponse response = webClient.get()
.uri(buildUri(url,cpuCoreQuery))
.uri(buildUri(url, cpuCoreQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(response) &&
if (Objects.nonNull(response) &&
Objects.nonNull(response.getData()) &&
CollUtil.isNotEmpty(response.getData().getResult())
) {
PrometheusResponse.Result cpuInfo = response.getData().getResult().get(0);
if(CollUtil.isNotEmpty(cpuInfo.getValue())) {
PrometheusResponse.Result cpuInfo = response.getData().getResult().get(0);
if (CollUtil.isNotEmpty(cpuInfo.getValue())) {
Integer cpuCores = cpuInfo.getValue().get(1).intValue();
result.put("cpuCores", cpuCores);
}
}
}catch (Exception e){
log.error("获取CPU核心数错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取CPU核心数错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
return result;
}
/**
* 获取内存信息
*/
@Override
public Map<String,Object> getMemoryInfo(String ip) {
Map<String,Object> result = new HashMap<>();
public Map<String, Object> getMemoryInfo(String ip) {
Map<String, Object> result = new HashMap<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
@ -193,28 +208,33 @@ public class HostMonitorServiceImpl implements HostMonitorService {
// }
// }
//使用率
String usageRateQuery = "(1 - (node_memory_MemAvailable_bytes{instance=\""+instance+"\"} / node_memory_MemTotal_bytes{instance=\""+instance+"\"})) * 100";
String usageRateQuery = "(1 - (node_memory_MemAvailable_bytes{instance=\"" + instance +
"\"} / node_memory_MemTotal_bytes{instance=\"" + instance + "\"})) * 100";
PrometheusResponse usageRateResponse = webClient.get()
.uri(buildUri(url,usageRateQuery))
.uri(buildUri(url, usageRateQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(usageRateResponse) &&
if (Objects.nonNull(usageRateResponse) &&
Objects.nonNull(usageRateResponse.getData()) &&
CollUtil.isNotEmpty(usageRateResponse.getData().getResult())
) {
PrometheusResponse.Result usageRateInfo = usageRateResponse.getData().getResult().get(0);
if(CollUtil.isNotEmpty(usageRateInfo.getValue())) {
Date date = new Date(usageRateInfo.getValue().get(0).longValue()*1000);
Double usageRate = BigDecimal.valueOf(usageRateInfo.getValue().get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
PrometheusResponse.Result usageRateInfo =
usageRateResponse.getData().getResult().get(0);
if (CollUtil.isNotEmpty(usageRateInfo.getValue())) {
Date date = new Date(usageRateInfo.getValue().get(0).longValue() * 1000);
Double usageRate = BigDecimal.valueOf(usageRateInfo.getValue().get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put("date", DateUtil.format(date, "MM/dd HH:mm:ss"));
result.put("usageRate", usageRate);
}
}
}catch (Exception e){
log.error("获取内存信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取内存信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
return result;
}
/**
@ -223,43 +243,48 @@ public class HostMonitorServiceImpl implements HostMonitorService {
* @param conditions
*/
@Override
public List<Map<String,Object>> getMemoryInfoList(String ip,String conditions) {
List<Map<String, Object>> result = new ArrayList<>();
public List<Map<String, Object>> getMemoryInfoList(String ip, String conditions) {
List<Map<String, Object>> result = new ArrayList<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
//使用率
String usageRateQuery = "(1 - (node_memory_MemAvailable_bytes{instance=\""+instance+"\"} / node_memory_MemTotal_bytes{instance=\""+instance+"\"})) * 100";
PrometheusHostQueryTypeEnum queryTypeEnum = PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
String usageRateQuery = "(1 - (node_memory_MemAvailable_bytes{instance=\"" + instance +
"\"} / node_memory_MemTotal_bytes{instance=\"" + instance + "\"})) * 100";
PrometheusHostQueryTypeEnum queryTypeEnum =
PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
long end = Instant.now().getEpochSecond();
long start = end - queryTypeEnum.getLastSecond();
String step = queryTypeEnum.getStep();
PrometheusResponse response = webClient.get()
.uri(buildUri(url,usageRateQuery,start,end,step))
.uri(buildUri(url, usageRateQuery, start, end, step))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(response) &&
if (Objects.nonNull(response) &&
Objects.nonNull(response.getData()) &&
CollUtil.isNotEmpty(response.getData().getResult())
) {
PrometheusResponse.Result usageRateList = response.getData().getResult().get(0);
if(CollUtil.isNotEmpty(usageRateList.getValues())) {
PrometheusResponse.Result usageRateList = response.getData().getResult().get(0);
if (CollUtil.isNotEmpty(usageRateList.getValues())) {
List<List<Double>> pointDatas = usageRateList.getValues();
for(List<Double> pointData : pointDatas) {
Map<String,Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue()*1000);
Double useRate = BigDecimal.valueOf(pointData.get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
for (List<Double> pointData : pointDatas) {
Map<String, Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue() * 1000);
Double useRate = BigDecimal.valueOf(pointData.get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
pointDataMap.put("date", DateUtil.format(date, "MM/dd HH:mm:ss"));
pointDataMap.put("usageRate", useRate);
result.add(pointDataMap);
}
}
}
}catch (Exception e){
log.error("获取CPU信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取CPU信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
}
@ -279,18 +304,21 @@ public class HostMonitorServiceImpl implements HostMonitorService {
//查询总内存
String totalMemoryQuery = "node_memory_MemTotal_bytes{instance=\"" + instance + "\"}";
PrometheusResponse totalMemoryResponse = webClient.get()
.uri(buildUri(url,totalMemoryQuery))
.uri(buildUri(url, totalMemoryQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(totalMemoryResponse) &&
if (Objects.nonNull(totalMemoryResponse) &&
Objects.nonNull(totalMemoryResponse.getData()) &&
CollUtil.isNotEmpty(totalMemoryResponse.getData().getResult())
) {
PrometheusResponse.Result totalMemoryInfo = totalMemoryResponse.getData().getResult().get(0);
if(CollUtil.isNotEmpty(totalMemoryInfo.getValue())) {
Double totalMemory = BigDecimal.valueOf(totalMemoryInfo.getValue().get(1)/1024/1024/1024).setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put("totalMemory",totalMemory);
PrometheusResponse.Result totalMemoryInfo =
totalMemoryResponse.getData().getResult().get(0);
if (CollUtil.isNotEmpty(totalMemoryInfo.getValue())) {
Double totalMemory =
BigDecimal.valueOf(totalMemoryInfo.getValue().get(1) / 1024 / 1024 / 1024)
.setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put("totalMemory", totalMemory);
}
}
return result;
@ -300,58 +328,71 @@ public class HostMonitorServiceImpl implements HostMonitorService {
* 获取网络信息
*/
@Override
public Map<String,Object> getNetworkInfo(String ip,String conditions) {
Map<String,Object> result = new HashMap<>();
public Map<String, Object> getNetworkInfo(String ip, String conditions) {
Map<String, Object> result = new HashMap<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
PrometheusHostQueryTypeEnum queryTypeEnum = PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
PrometheusHostQueryTypeEnum queryTypeEnum =
PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
String exprTime = queryTypeEnum.getExprTime();
//接收带宽 (Kbps)
String receiveKbpsQuery = "rate(node_network_receive_bytes_total{instance=\"" + instance + "\", device=\""+serverProperties.getNetworkCardName()+"\"}["+exprTime+"]) * 8 / 1000";
String receiveKbpsQuery =
"rate(node_network_receive_bytes_total{instance=\"" + instance +
"\", device=\"" + serverProperties.getNetworkCardName() + "\"}[" +
exprTime + "]) * 8 / 1000";
PrometheusResponse receiveKbpsResponse = webClient.get()
.uri(buildUri(url,receiveKbpsQuery))
.uri(buildUri(url, receiveKbpsQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(receiveKbpsResponse) &&
if (Objects.nonNull(receiveKbpsResponse) &&
Objects.nonNull(receiveKbpsResponse.getData()) &&
CollUtil.isNotEmpty(receiveKbpsResponse.getData().getResult())
) {
PrometheusResponse.Result receiveKbpsInfo = receiveKbpsResponse.getData().getResult().get(0);
if(CollUtil.isNotEmpty(receiveKbpsInfo.getValue())) {
Date date = new Date(receiveKbpsInfo.getValue().get(0).longValue()*1000);
Double receiveKbps = BigDecimal.valueOf(receiveKbpsInfo.getValue().get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
PrometheusResponse.Result receiveKbpsInfo =
receiveKbpsResponse.getData().getResult().get(0);
if (CollUtil.isNotEmpty(receiveKbpsInfo.getValue())) {
Date date = new Date(receiveKbpsInfo.getValue().get(0).longValue() * 1000);
Double receiveKbps = BigDecimal.valueOf(receiveKbpsInfo.getValue().get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put("receiveDate", DateUtil.format(date, "MM/dd HH:mm:ss"));
result.put("receiveKbps", receiveKbps);
}
}
//发送带宽 (Kbps)
String transmitKbpsQuery = "rate(node_network_transmit_bytes_total{instance=\"" + instance + "\", device=\""+serverProperties.getNetworkCardName()+"\"}["+exprTime+"]) * 8 / 1000";
String transmitKbpsQuery =
"rate(node_network_transmit_bytes_total{instance=\"" + instance +
"\", device=\"" + serverProperties.getNetworkCardName() + "\"}[" +
exprTime + "]) * 8 / 1000";
PrometheusResponse transmitKbpsResponse = webClient.get()
.uri(buildUri(url,transmitKbpsQuery))
.uri(buildUri(url, transmitKbpsQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(transmitKbpsResponse) &&
if (Objects.nonNull(transmitKbpsResponse) &&
Objects.nonNull(transmitKbpsResponse.getData()) &&
CollUtil.isNotEmpty(transmitKbpsResponse.getData().getResult())
) {
PrometheusResponse.Result transmitKbpsInfo = transmitKbpsResponse.getData().getResult().get(0);
if(CollUtil.isNotEmpty(transmitKbpsInfo.getValue())) {
Date date = new Date(transmitKbpsInfo.getValue().get(0).longValue()*1000);
Double transmitKbps = BigDecimal.valueOf(transmitKbpsInfo.getValue().get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
PrometheusResponse.Result transmitKbpsInfo =
transmitKbpsResponse.getData().getResult().get(0);
if (CollUtil.isNotEmpty(transmitKbpsInfo.getValue())) {
Date date = new Date(transmitKbpsInfo.getValue().get(0).longValue() * 1000);
Double transmitKbps = BigDecimal.valueOf(transmitKbpsInfo.getValue().get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put("transmitDate", DateUtil.format(date, "MM/dd HH:mm:ss"));
result.put("transmitKbps", transmitKbps);
}
}
}catch (Exception e){
log.error("获取网络信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取网络信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
return result;
}
/**
@ -360,38 +401,44 @@ public class HostMonitorServiceImpl implements HostMonitorService {
* @return
*/
@Override
public Map<String, List<Map<String, Object>>> getNetworkInfoList(String ip,String conditions) {
Map<String,List<Map<String, Object>>> result = new HashMap<>();
public Map<String, List<Map<String, Object>>> getNetworkInfoList(String ip, String conditions) {
Map<String, List<Map<String, Object>>> result = new HashMap<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
//构建查询参数
PrometheusHostQueryTypeEnum queryTypeEnum = PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
PrometheusHostQueryTypeEnum queryTypeEnum =
PrometheusHostQueryTypeEnum.getQueryTypeEnum(conditions);
long end = Instant.now().getEpochSecond();
long start = end - queryTypeEnum.getLastSecond();
String step = queryTypeEnum.getStep();
String exprTime = queryTypeEnum.getExprTime();
//接收带宽 (Kbps)
String receiveKbpsQuery = "rate(node_network_receive_bytes_total{instance=\"" + instance + "\", device=\""+serverProperties.getNetworkCardName()+"\"}["+exprTime+"]) * 8 / 1000";
String receiveKbpsQuery =
"rate(node_network_receive_bytes_total{instance=\"" + instance +
"\", device=\"" + serverProperties.getNetworkCardName() + "\"}[" +
exprTime + "]) * 8 / 1000";
PrometheusResponse receiveKbpsResponse = webClient.get()
.uri(buildUri(url,receiveKbpsQuery,start,end,step))
.uri(buildUri(url, receiveKbpsQuery, start, end, step))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(receiveKbpsResponse) &&
if (Objects.nonNull(receiveKbpsResponse) &&
Objects.nonNull(receiveKbpsResponse.getData()) &&
CollUtil.isNotEmpty(receiveKbpsResponse.getData().getResult())
) {
PrometheusResponse.Result receiveKbpsInfo = receiveKbpsResponse.getData().getResult().get(0);
if(CollUtil.isNotEmpty(receiveKbpsInfo.getValues())) {
PrometheusResponse.Result receiveKbpsInfo =
receiveKbpsResponse.getData().getResult().get(0);
if (CollUtil.isNotEmpty(receiveKbpsInfo.getValues())) {
List<Map<String, Object>> receiveDataList = new ArrayList<>();
List<List<Double>> pointDatas = receiveKbpsInfo.getValues();
for(List<Double> pointData : pointDatas) {
Map<String,Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue()*1000);
Double useRate = BigDecimal.valueOf(pointData.get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
for (List<Double> pointData : pointDatas) {
Map<String, Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue() * 1000);
Double useRate = BigDecimal.valueOf(pointData.get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
pointDataMap.put("receiveDate", DateUtil.format(date, "MM/dd HH:mm:ss"));
pointDataMap.put("receiveKbps", useRate);
receiveDataList.add(pointDataMap);
@ -401,24 +448,29 @@ public class HostMonitorServiceImpl implements HostMonitorService {
}
//发送带宽 (Kbps)
String transmitKbpsQuery = "rate(node_network_transmit_bytes_total{instance=\"" + instance + "\", device=\""+serverProperties.getNetworkCardName()+"\"}["+exprTime+"]) * 8 / 1000";
String transmitKbpsQuery =
"rate(node_network_transmit_bytes_total{instance=\"" + instance +
"\", device=\"" + serverProperties.getNetworkCardName() + "\"}[" +
exprTime + "]) * 8 / 1000";
PrometheusResponse transmitKbpsResponse = webClient.get()
.uri(buildUri(url,transmitKbpsQuery,start,end,step))
.uri(buildUri(url, transmitKbpsQuery, start, end, step))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(transmitKbpsResponse) &&
if (Objects.nonNull(transmitKbpsResponse) &&
Objects.nonNull(transmitKbpsResponse.getData()) &&
CollUtil.isNotEmpty(transmitKbpsResponse.getData().getResult())
) {
PrometheusResponse.Result transmitKbpsInfo = transmitKbpsResponse.getData().getResult().get(0);
if(CollUtil.isNotEmpty(transmitKbpsInfo.getValues())) {
PrometheusResponse.Result transmitKbpsInfo =
transmitKbpsResponse.getData().getResult().get(0);
if (CollUtil.isNotEmpty(transmitKbpsInfo.getValues())) {
List<Map<String, Object>> transmitDataList = new ArrayList<>();
List<List<Double>> pointDatas = transmitKbpsInfo.getValues();
for(List<Double> pointData : pointDatas) {
Map<String,Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue()*1000);
Double useRate = BigDecimal.valueOf(pointData.get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
for (List<Double> pointData : pointDatas) {
Map<String, Object> pointDataMap = new HashMap<>();
Date date = new Date(pointData.get(0).longValue() * 1000);
Double useRate = BigDecimal.valueOf(pointData.get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
pointDataMap.put("receiveDate", DateUtil.format(date, "MM/dd HH:mm:ss"));
pointDataMap.put("receiveKbps", useRate);
transmitDataList.add(pointDataMap);
@ -426,42 +478,51 @@ public class HostMonitorServiceImpl implements HostMonitorService {
result.put("transmitData", transmitDataList);
}
}
}catch (Exception e){
log.error("获取网络信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取网络信息错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
return result;
}
/**
* 获取磁盘使用率
*/
@Override
public Map<String,Object> getDiskInfo(String ip) {
Map<String,Object> result = new HashMap<>();
public Map<String, Object> getDiskInfo(String ip) {
Map<String, Object> result = new HashMap<>();
try {
//Prometheus 服务器地址
String url = serverProperties.getServerUrl();
//目标主机实例node-exporter 的地址
String instance = this.getInstance(ip);
//磁盘使用率
String diskUsageQuery = "((node_filesystem_size_bytes{instance=\""+instance+"\", device!~\"rootfs\"} - node_filesystem_avail_bytes{instance=\""+instance+"\", device!~\"rootfs\"}) / node_filesystem_size_bytes{instance=\""+instance+"\", device!~\"rootfs\"}) * 100";
String diskUsageQuery = "((node_filesystem_size_bytes{instance=\"" + instance +
"\", device!~\"rootfs\"} - node_filesystem_avail_bytes{instance=\"" + instance +
"\", device!~\"rootfs\"}) / node_filesystem_size_bytes{instance=\"" + instance +
"\", device!~\"rootfs\"}) * 100";
PrometheusResponse diskUsageResponse = webClient.get()
.uri(buildUri(url,diskUsageQuery))
.uri(buildUri(url, diskUsageQuery))
.retrieve()
.bodyToMono(PrometheusResponse.class)
.block();
if(Objects.nonNull(diskUsageResponse) &&
if (Objects.nonNull(diskUsageResponse) &&
Objects.nonNull(diskUsageResponse.getData()) &&
CollUtil.isNotEmpty(diskUsageResponse.getData().getResult())
) {
for (PrometheusResponse.Result responseData :diskUsageResponse.getData().getResult()){
for (PrometheusResponse.Result responseData : diskUsageResponse.getData()
.getResult()) {
String mountpoint = responseData.getMetric().getMountpoint();
Double usageRate = BigDecimal.valueOf(responseData.getValue().get(1)).setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put(mountpoint,usageRate);
Double usageRate = BigDecimal.valueOf(responseData.getValue().get(1))
.setScale(2, RoundingMode.HALF_UP).doubleValue();
result.put(mountpoint, usageRate);
}
}
}catch (Exception e){
log.error("获取磁盘使用率错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",e.getMessage());
} catch (Exception e) {
log.error(
"获取磁盘使用率错误请检查Prometheus服务是否正常启动或Java请求参数是否正确,详细堆栈错误为:{}",
e.getMessage());
}
return result;
}
@ -478,29 +539,32 @@ public class HostMonitorServiceImpl implements HostMonitorService {
/**
* 获取服务器实例
*
* @param ip
* @return
*/
private String getInstance(String ip) {
if(StrUtil.isBlank(ip)){
Map.Entry<String, Integer> first = serverProperties.getInstances().entrySet().stream().findFirst().get();
return first.getKey()+":"+first.getValue();
if (StrUtil.isBlank(ip)) {
Map.Entry<String, Integer> first =
serverProperties.getInstances().entrySet().stream().findFirst().get();
return first.getKey() + ":" + first.getValue();
}
if (!serverProperties.getInstances().containsKey(ip)){
if (!serverProperties.getInstances().containsKey(ip)) {
throw new RuntimeException("此ip不在服务器列表中请检查监控ip列表配置");
}
Integer port = serverProperties.getInstances().get(ip);
//return "192.168.186.143"+":"+port;
return ip+":"+port;
return ip + ":" + port;
}
/**
* 构建URI
*
* @param url
* @param query
* @return
*/
private URI buildUri(String url,String query){
private URI buildUri(String url, String query) {
URI uri = UriComponentsBuilder.fromHttpUrl(url + "/api/v1/query")
.queryParam("query", query)
.build()
@ -510,11 +574,12 @@ public class HostMonitorServiceImpl implements HostMonitorService {
/**
* 构建URI
*
* @param url
* @param query
* @return
*/
private URI buildUri(String url,String query,Long start,Long end,String step){
private URI buildUri(String url, String query, Long start, Long end, String step) {
String uriAddr = String.format(
"%s/api/v1/query_range?query=%s&start=%d&end=%d&step=%s",
url,