增加首页接口,心跳监控信息改为redis存储
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.AllInterfaceName;
|
||||
import com.ruoyi.system.service.IAllInterfaceNameService;
|
||||
@@ -35,5 +37,16 @@ public class AllInterfaceNameController extends BaseController
|
||||
List<AllInterfaceName> list = allInterfaceNameService.selectAllInterfaceNameList(allInterfaceName);
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* 查询所有接口名称列表
|
||||
*/
|
||||
@InnerAuth
|
||||
@PostMapping("/getMsgByClientId")
|
||||
public R<AllInterfaceName> getMsgByClientId(@RequestBody AllInterfaceName allInterfaceName)
|
||||
{
|
||||
List<AllInterfaceName> list = allInterfaceNameService.selectAllInterfaceNameList(allInterfaceName);
|
||||
AllInterfaceName allInterfaceName1 = list.isEmpty()?new AllInterfaceName():list.get(0);
|
||||
return R.ok(allInterfaceName1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.RmResourceRegistration;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
|
||||
import com.ruoyi.system.service.IInitialSwitchInfoDetailsService;
|
||||
import com.ruoyi.system.service.IRmResourceRegistrationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 首页Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-08-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/screen")
|
||||
public class ScreenController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IEpsServerRevenueConfigService epsServerRevenueConfigService;
|
||||
@Autowired
|
||||
private IRmResourceRegistrationService rmResourceRegistrationService;
|
||||
@Autowired
|
||||
private EpsInitialTrafficDataService epsInitialTrafficDataService;
|
||||
@Autowired
|
||||
private IInitialSwitchInfoDetailsService initialSwitchInfoDetailsService;
|
||||
|
||||
/**
|
||||
* 统计当前在线服务器的流量相关的业务数
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/countBusinessByTraffic")
|
||||
public AjaxResult countBusinessByTraffic()
|
||||
{
|
||||
return success(epsServerRevenueConfigService.countBusinessByTraffic());
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器在线率
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/getServerOnlineRate")
|
||||
public AjaxResult getServerOnlineRate()
|
||||
{
|
||||
return rmResourceRegistrationService.getServerOnlineRate();
|
||||
}
|
||||
/**
|
||||
* 交换机在线数量
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/countSwitchNum")
|
||||
public AjaxResult countSwitchNum()
|
||||
{
|
||||
RmResourceRegistration rmResourceRegistration = new RmResourceRegistration();
|
||||
rmResourceRegistration.setResourceType("2");
|
||||
// 查询资源列表(处理可能的null结果)
|
||||
List<RmResourceRegistration> resourceList = Optional.ofNullable(rmResourceRegistrationService.selectRmResourceRegistrationList(rmResourceRegistration))
|
||||
.orElse(Collections.emptyList());
|
||||
int onlineCount = (int) resourceList.stream()
|
||||
.filter(resource -> "1".equals(resource.getOnlineStatus()))
|
||||
.count();
|
||||
return AjaxResult.success()
|
||||
.put("total", resourceList.size())
|
||||
.put("onlineCount", onlineCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当日业务的在线设备数量统计TOP5
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/countDeviceNumTop5")
|
||||
public AjaxResult countDeviceNumTop5()
|
||||
{
|
||||
List<Map> maps = epsServerRevenueConfigService.countDeviceNumTop5();
|
||||
return success(maps);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前在线服务器发送带宽总流量
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/sumTrafficByServer")
|
||||
public AjaxResult sumTrafficByServer()
|
||||
{
|
||||
return success(epsInitialTrafficDataService.sumTrafficByServer());
|
||||
}
|
||||
/**
|
||||
* 当前在线交换机接收带宽总流量
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/sumTrafficBySwitch")
|
||||
public AjaxResult sumTrafficBySwitch()
|
||||
{
|
||||
return success(initialSwitchInfoDetailsService.sumTrafficBySwitch());
|
||||
}
|
||||
}
|
||||
@@ -79,4 +79,16 @@ public interface EpsServerRevenueConfigMapper
|
||||
public Map getNodeMsgByIp(@Param("ipAddress") String ipAddress);
|
||||
|
||||
int updateEpsServerRevenueConfigByServerSn(EpsServerRevenueConfig epsServerRevenueConfig);
|
||||
|
||||
/**
|
||||
* 当前在线服务器的流量相关的业务数
|
||||
* @return
|
||||
*/
|
||||
Integer countBusinessByTraffic();
|
||||
|
||||
/**
|
||||
* 当日业务的在线设备数量统计TOP5
|
||||
* @return
|
||||
*/
|
||||
List<Map> countDeviceNumTop5();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ruoyi.system.service;
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -55,4 +56,9 @@ public interface EpsInitialTrafficDataService {
|
||||
*/
|
||||
void recalculateServer95Bandwidth(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime);
|
||||
|
||||
/**
|
||||
* 当前在线服务器发送带宽总流量
|
||||
* @return
|
||||
*/
|
||||
BigDecimal sumTrafficByServer();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务器收益方式配置Service接口
|
||||
@@ -66,4 +67,14 @@ public interface IEpsServerRevenueConfigService
|
||||
* @param epsServerRevenueConfig
|
||||
*/
|
||||
R<String> autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig);
|
||||
/**
|
||||
* 当前在线服务器的流量相关的业务数
|
||||
* @return
|
||||
*/
|
||||
Integer countBusinessByTraffic();
|
||||
/**
|
||||
* 当日业务的在线设备数量统计TOP5
|
||||
* @return
|
||||
*/
|
||||
List<Map> countDeviceNumTop5();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
import com.ruoyi.system.domain.InitialSwitchInfoDetails;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -88,4 +89,9 @@ public interface IInitialSwitchInfoDetailsService
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> getRelevantSwitch(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime);
|
||||
/**
|
||||
* 当前在线交换机接收带宽总流量
|
||||
* @return
|
||||
*/
|
||||
BigDecimal sumTrafficBySwitch();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.system.domain.RmResourceRegistration;
|
||||
|
||||
import java.util.List;
|
||||
@@ -85,4 +86,6 @@ public interface IRmResourceRegistrationService
|
||||
* @return
|
||||
*/
|
||||
R<String> updateStatusByResource(RmResourceRegistration rmResourceRegistration);
|
||||
|
||||
AjaxResult getServerOnlineRate();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -257,6 +259,38 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前在线服务器发送带宽总流量
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal sumTrafficByServer() {
|
||||
// 获取当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 结束时间
|
||||
LocalDateTime endTime = now.minusSeconds(1);
|
||||
// 开始时间
|
||||
LocalDateTime startTime = now.minusMinutes(5);
|
||||
// 定义日期时间格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 格式化为字符串
|
||||
String dailyStartTime = startTime.format(formatter);
|
||||
String dailyEndTime = endTime.format(formatter);
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
|
||||
epsInitialTrafficData.setStartTime(dailyStartTime);
|
||||
epsInitialTrafficData.setEndTime(dailyEndTime);
|
||||
List<EpsInitialTrafficData> dataList = query(epsInitialTrafficData);
|
||||
if(!dataList.isEmpty()){
|
||||
for (EpsInitialTrafficData initialTrafficData : dataList) {
|
||||
// 服务器发送带宽流量
|
||||
BigDecimal outSpeed = CalculateUtil.parseSpeedToMbps(initialTrafficData.getOutSpeed());
|
||||
total = total.add(outSpeed);
|
||||
}
|
||||
}
|
||||
return total.setScale(0, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个设备的带宽计算
|
||||
*/
|
||||
|
||||
@@ -213,6 +213,23 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
|
||||
return R.fail("数据保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 当前在线服务器的流量相关的业务数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer countBusinessByTraffic() {
|
||||
return epsServerRevenueConfigMapper.countBusinessByTraffic();
|
||||
}
|
||||
/**
|
||||
* 当日业务的在线设备数量统计TOP5
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Map> countDeviceNumTop5() {
|
||||
return epsServerRevenueConfigMapper.countDeviceNumTop5();
|
||||
}
|
||||
|
||||
private static String getNullableString(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : null;
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -342,8 +344,9 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> {
|
||||
// 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed
|
||||
String speed = ("1".equals(data.getInterfaceDeviceType())) ?
|
||||
data.getInSpeed() + "" : data.getOutSpeed() + "";
|
||||
String speed = "1".equals(data.getInterfaceDeviceType())
|
||||
? (data.getInSpeed() != null ? data.getInSpeed().toString() : BigDecimal.ZERO.toString())
|
||||
: (data.getOutSpeed() != null ? data.getOutSpeed().toString() : BigDecimal.ZERO.toString());
|
||||
// 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s)
|
||||
if (speed.matches("^\\d+(\\.\\d+)?$")) {
|
||||
speed += " B/S";
|
||||
@@ -388,6 +391,40 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
return dataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal sumTrafficBySwitch() {
|
||||
// 获取当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 结束时间
|
||||
LocalDateTime endTime = now.minusSeconds(1);
|
||||
// 开始时间
|
||||
LocalDateTime startTime = now.minusMinutes(5);
|
||||
// 定义日期时间格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 格式化为字符串
|
||||
String dailyStartTime = startTime.format(formatter);
|
||||
String dailyEndTime = endTime.format(formatter);
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
InitialSwitchInfoDetails switchInfoDetails = new InitialSwitchInfoDetails();
|
||||
switchInfoDetails.setStartTime(dailyStartTime);
|
||||
switchInfoDetails.setEndTime(dailyEndTime);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(switchInfoDetails);
|
||||
if(!dataList.isEmpty()){
|
||||
for (InitialSwitchInfoDetails initialSwitchInfoDetails : dataList) {
|
||||
// 交换机接收带宽流量
|
||||
String speed = initialSwitchInfoDetails.getInSpeed() != null ? initialSwitchInfoDetails.getInSpeed().toString() : BigDecimal.ZERO.toString();
|
||||
// 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s)
|
||||
if (speed.matches("^\\d+(\\.\\d+)?$")) {
|
||||
speed += " B/S";
|
||||
}
|
||||
BigDecimal inSpeed = CalculateUtil.parseSpeedToMbps(speed);
|
||||
total = total.add(inSpeed);
|
||||
}
|
||||
}
|
||||
return total.setScale(0, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理单个交换机的带宽计算
|
||||
@@ -565,8 +602,10 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
// 1. 提取并转换带宽值
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> {
|
||||
String speed = ("1".equals(data.getInterfaceDeviceType())) ?
|
||||
data.getInSpeed() + "" : data.getOutSpeed() + "";
|
||||
// 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed
|
||||
String speed = "1".equals(data.getInterfaceDeviceType())
|
||||
? (data.getInSpeed() != null ? data.getInSpeed().toString() : BigDecimal.ZERO.toString())
|
||||
: (data.getOutSpeed() != null ? data.getOutSpeed().toString() : BigDecimal.ZERO.toString());
|
||||
if (speed.matches("^\\d+(\\.\\d+)?$")) {
|
||||
speed += " B/S";
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
@@ -15,6 +16,8 @@ import com.ruoyi.system.service.IRmResourceRegistrationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -241,4 +244,41 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
return R.ok("状态修改成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器在线率
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getServerOnlineRate() {
|
||||
// 查询所有符合条件的资源
|
||||
RmResourceRegistration queryParam = new RmResourceRegistration();
|
||||
queryParam.setResourceType("1");
|
||||
List<RmResourceRegistration> resourceList = rmResourceRegistrationMapper.selectRmResourceRegistrationList(queryParam);
|
||||
|
||||
// 计算在线数量和总数
|
||||
int totalCount = resourceList.size();
|
||||
if (totalCount == 0) {
|
||||
return AjaxResult.error("没有找到符合条件的资源");
|
||||
}
|
||||
|
||||
int onlineCount = (int) resourceList.stream()
|
||||
.filter(resource -> "1".equals(resource.getOnlineStatus()))
|
||||
.count();
|
||||
int offlineCount = (int) resourceList.stream()
|
||||
.filter(resource -> "0".equals(resource.getOnlineStatus()))
|
||||
.count();
|
||||
|
||||
// 计算在线率
|
||||
BigDecimal onlineRate = BigDecimal.valueOf(onlineCount)
|
||||
.divide(BigDecimal.valueOf(totalCount), 0, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
|
||||
|
||||
// 返回结果
|
||||
return AjaxResult.success()
|
||||
.put("onlineCount", onlineCount)
|
||||
.put("offlineCount", offlineCount)
|
||||
.put("total", totalCount)
|
||||
.put("onlineRate", onlineRate);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -152,4 +152,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectEpsServerRevenueConfigVo"/>
|
||||
where hardware_sn = #{hardwareSn}
|
||||
</select>
|
||||
|
||||
<select id="countBusinessByTraffic" resultType="java.lang.Integer">
|
||||
select count(1) from eps_server_revenue_config a left join rm_resource_registration b on a.hardware_sn=b.hardware_sn where a.revenue_method = '1' and b.online_status='1'
|
||||
</select>
|
||||
<select id="countDeviceNumTop5" resultType="java.util.Map">
|
||||
select count(1) total,a.business_name businessName from eps_server_revenue_config a left join rm_resource_registration b on a.hardware_sn=b.hardware_sn where a.revenue_method = '1' and b.online_status='1' group by a.business_name order by total desc limit 5
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -267,6 +267,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updaterId != null">updater_id = #{updaterId},</if>
|
||||
<if test="updaterName != null">updater_name = #{updaterName},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
where ip_address = #{ipAddress}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user