From f984421fc1cf33b43c89720506f21e5ba99b6eec Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 21 Sep 2023 20:49:31 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9AServer=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/modules/base/dto/IdCount.java | 11 +++++++ .../base/entity/monitor/ItemHistoryData.java | 24 +++++++++++++++ .../modules/feignclient/MonitorAlarm.java | 3 ++ .../jeecg/modules/mapper/SysServerMapper.java | 1 + .../modules/mapper/xml/SysServerMapper.xml | 3 +- .../service/impl/SysServerServiceImpl.java | 29 +++++++++++++++---- 6 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/IdCount.java create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistoryData.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/IdCount.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/IdCount.java new file mode 100644 index 00000000..8427f5da --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/IdCount.java @@ -0,0 +1,11 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; + +@Data +public class IdCount { + + private String id; + + private Integer count; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistoryData.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistoryData.java new file mode 100644 index 00000000..77ad9b67 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/monitor/ItemHistoryData.java @@ -0,0 +1,24 @@ +package org.jeecg.modules.base.entity.monitor; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.io.Serializable; + +/** + * 返回的是List集合 + */ +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ItemHistoryData implements Serializable { + + private String date; + + private String itemId; + + private Long ns; + + private Long clock; + + private Double value; +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java index 61cc8ecd..073b3b02 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/MonitorAlarm.java @@ -17,6 +17,9 @@ public interface MonitorAlarm { @GetMapping("list") Result listBack(@RequestParam String code); + @GetMapping("list") + Result listAllBack(); + @GetMapping("queryItemHistory") Result itemBack(@RequestParam String itemId, @RequestParam Integer itemType, diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java index b2291004..bbf10e90 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/SysServerMapper.java @@ -1,6 +1,7 @@ package org.jeecg.modules.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.base.dto.IdCount; import org.jeecg.modules.base.dto.ServerDto; import org.jeecg.modules.base.entity.postgre.SysServer; import org.jeecg.modules.entity.AlarmHistory; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml index 2df95dba..4bd3cc04 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/SysServerMapper.xml @@ -42,10 +42,9 @@ LEFT JOIN alarm_rule r ON s.ID = r.source_id LEFT JOIN alarm_log l ON r.ID = l.rule_id AND l.alarm_start_date BETWEEN #{startDate} AND #{endDate} - GROUP BY s.ID,s.NAME,s.ip_address + GROUP BY s.ID, s.NAME, s.ip_address LIMIT #{pageSize} OFFSET #{pageStart} - \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java index 338105eb..534dd334 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java @@ -2,6 +2,7 @@ package org.jeecg.modules.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -14,11 +15,14 @@ import org.jeecg.common.constant.DateConstant; import org.jeecg.common.constant.Prompt; import org.jeecg.modules.base.dto.ServerDto; import org.jeecg.modules.base.dto.SourceDto; +import org.jeecg.modules.base.entity.monitor.Servers; import org.jeecg.modules.base.entity.postgre.SysServer; import org.jeecg.modules.base.bizVo.SourceVo; import org.jeecg.modules.entity.AlarmHistory; +import org.jeecg.modules.feignclient.MonitorAlarm; import org.jeecg.modules.mapper.SysServerMapper; import org.jeecg.modules.service.ISysServerService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,8 +33,11 @@ import java.util.*; @Service("sysServerService") public class SysServerServiceImpl extends ServiceImpl implements ISysServerService { + @Autowired + private MonitorAlarm monitorAlarm; + @Override - public Result findPage(QueryRequest query) { + public Result findPage(QueryRequest query) { Integer pageNo = query.getPageNo(); Integer pageSize = query.getPageSize(); Integer pageStart = (pageNo - 1) * pageSize; @@ -45,21 +52,33 @@ public class SysServerServiceImpl extends ServiceImpl serverDtos = baseMapper.findPage(params); + // 获取服务器信息列表 + Servers servers = monitorAlarm.listAllBack().getResult(); for (ServerDto serverDto : serverDtos) { + serverDto.setOnline(true) .setServerInfo("(4-core (vCPU)16GiB)") .setCpuUutilzation("35.8%").setMemoryUsage("55.8%") .setDiskUsage("85.68%").setDiskRed(true); + } params.put("pageFlag","noPage"); - long total = baseMapper.findPage(params).size(); + // 统计Alarm总数 + List noPage = baseMapper.findPage(params); + int alarms = noPage.stream().mapToInt(ServerDto::getAlarms).sum(); + // 获取记录总条数 + long total = noPage.size(); Page page = new Page<>(pageNo, pageSize, total); page.setRecords(serverDtos); return Result.OK(page); } + public static void main(String[] args) { + System.out.println(NumberUtil.formatPercent(0.2367, 1)); + } + @Override - public Result findInfo(String id) { + public Result findInfo(String id) { Result result = new Result(); if (StringUtils.isBlank(id)){ result.error500("id信息不能为空"); @@ -85,11 +104,11 @@ public class SysServerServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); wrapper.eq(SysServer::getName,name); if (CollUtil.isNotEmpty(list(wrapper))) - return Result.error("Name"+Prompt.NOT_REPEAT); + return Result.error("Name" + Prompt.NOT_REPEAT); wrapper.clear(); wrapper.eq(SysServer::getIpAddress,ipAddress); if (CollUtil.isNotEmpty(list(wrapper))) - return Result.error("IP Address"+Prompt.NOT_REPEAT); + return Result.error("IP Address" + Prompt.NOT_REPEAT); int count = baseMapper.insert(sysServer); if (count == 1)