From ec67475fe8676815e7a39a7031d1bfa1eee88d4b Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Tue, 7 Jan 2025 15:41:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20dashboard=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../omada/api/organization/OmadaSiteApi.java | 5 + wfc-modules/wfc-system/pom.xml | 5 + .../controller/SysDashboardController.java | 36 ++++++ .../domain/convert/SysDashboardConvert.java | 20 ++++ .../system/domain/vo/SysDashboardSiteVo.java | 76 ++++++++++++ .../wfc/system/domain/vo/SysDashboardVo.java | 52 ++++++++ .../system/service/ISysDashboardService.java | 16 +++ .../service/impl/SysDashboardServiceImpl.java | 112 ++++++++++++++++++ 8 files changed, 322 insertions(+) create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysDashboardController.java create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/convert/SysDashboardConvert.java create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardSiteVo.java create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardVo.java create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysDashboardService.java create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysDashboardServiceImpl.java diff --git a/wfc-api/wfc-api-omada/src/main/java/org/wfc/omada/api/organization/OmadaSiteApi.java b/wfc-api/wfc-api-omada/src/main/java/org/wfc/omada/api/organization/OmadaSiteApi.java index af5b5c7..cc60e3b 100644 --- a/wfc-api/wfc-api-omada/src/main/java/org/wfc/omada/api/organization/OmadaSiteApi.java +++ b/wfc-api/wfc-api-omada/src/main/java/org/wfc/omada/api/organization/OmadaSiteApi.java @@ -279,6 +279,11 @@ public interface OmadaSiteApi { method = RequestMethod.GET) ResponseEntity getSiteList(@NotNull @ApiParam(value = "Start page number. Start from 1.", required = true) @Valid @RequestParam(value = "page", required = true) Integer page,@NotNull @ApiParam(value = "Number of entries per page. It should be within the range of 1–1000.", required = true) @Valid @RequestParam(value = "pageSize", required = true) Integer pageSize); + @RequestMapping(value = "/openapi/v1/${omada.omadac-id}/sites", + produces = "*/*", + method = RequestMethod.GET) + ResponseEntity getSiteList(@NotNull @ApiParam(value = "Start page number. Start from 1.", required = true) @Valid @RequestParam(value = "page", required = true) Integer page,@NotNull @ApiParam(value = "Number of entries per page. It should be within the range of 1–1000.", required = true) @Valid @RequestParam(value = "pageSize", required = true) Integer pageSize, @ApiParam(value = "Fuzzy query parameters, support field name") @Valid @RequestParam(value = "searchKey", required = false) String searchKey); + /** * GET /openapi/v1/{omadacId}/sites/tags : Get site tag list diff --git a/wfc-modules/wfc-system/pom.xml b/wfc-modules/wfc-system/pom.xml index 4e046a2..67e2a89 100644 --- a/wfc-modules/wfc-system/pom.xml +++ b/wfc-modules/wfc-system/pom.xml @@ -84,6 +84,11 @@ org.wfc wfc-common-mybatis + + + org.mapstruct + mapstruct + diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysDashboardController.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysDashboardController.java new file mode 100644 index 0000000..9d2d60c --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysDashboardController.java @@ -0,0 +1,36 @@ +package org.wfc.system.controller; + +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.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.wfc.common.core.web.controller.BaseController; +import org.wfc.common.core.web.domain.AjaxResult; +import org.wfc.common.core.web.page.TableDataInfo; +import org.wfc.system.service.ISysDashboardService; + +/** + * @description: + * @author: cyc + * @since: 2025-01-07 + */ +@RestController +@RequestMapping("/dashboard") +public class SysDashboardController extends BaseController { + + @Autowired + private ISysDashboardService sysDashboardService; + + + @GetMapping("/page") + public TableDataInfo page(@RequestParam(value = "searchKey", required = false) String searchKey) { + startPage(); + return sysDashboardService.getSiteList(searchKey); + } + + @GetMapping("/overview") + public AjaxResult overview() { + return success(sysDashboardService.overview()); + } +} diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/convert/SysDashboardConvert.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/convert/SysDashboardConvert.java new file mode 100644 index 0000000..636e2ce --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/convert/SysDashboardConvert.java @@ -0,0 +1,20 @@ +package org.wfc.system.domain.convert; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.wfc.omada.api.organization.model.SiteSummaryInfo; +import org.wfc.system.domain.vo.SysDashboardSiteVo; + +/** + * @description: OmadaMapping + * @author: cyc + * @since: 2024-12-30 + */ +@Mapper +public interface SysDashboardConvert { + + SysDashboardConvert INSTANCE = Mappers.getMapper(SysDashboardConvert.class); + + SysDashboardSiteVo toSysDashboardSiteVo(SiteSummaryInfo siteSummaryInfo); + +} diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardSiteVo.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardSiteVo.java new file mode 100644 index 0000000..3b0278c --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardSiteVo.java @@ -0,0 +1,76 @@ +package org.wfc.system.domain.vo; + + + +import lombok.Data; + +import java.util.List; + +/** + * @author: cyc + * @since: 2025-01-07 + */ +@Data +public class SysDashboardSiteVo { + private String siteId; + + private String name; + + private List tagIds = null; + + private String region; + + private String timeZone; + + private String scenario; + + private Double longitude; + + private Double latitude; + + private String address; + + private Integer type; + + private Boolean supportES; + + private Boolean supportL2; + + private Integer totalGatewayNum; + + private Integer connectedGatewayNum; + + private Integer disconnectedGatewayNum; + + private Integer netCapacity; + + private Double netUsage; + + private Integer totalSwitchNum; + + private Integer connectedSwitchNum; + + private Integer disconnectedSwitchNum; + + private Integer totalPorts; + + private Integer availablePorts; + + private Double powerConsumption; + + private Integer totalApNum; + + private Integer connectedApNum; + + private Integer isolatedApNum; + + private Integer disconnectedApNum; + + private Integer totalClientNum; + + private Integer wiredClientNum; + + private Integer wirelessClientNum; + + private Integer guestNum; +} diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardVo.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardVo.java new file mode 100644 index 0000000..bd589cb --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/vo/SysDashboardVo.java @@ -0,0 +1,52 @@ +package org.wfc.system.domain.vo; + + +import lombok.Data; + +/** + * @author: cyc + * @since: 2025-01-07 + */ +@Data +public class SysDashboardVo { + + private Integer SiteNum = 0; + + private Integer totalGatewayNum = 0; + + private Integer connectedGatewayNum = 0; + + private Integer disconnectedGatewayNum = 0; + + private Integer netCapacity = 0; + + private Double netUsage = 0.0; + + private Integer totalSwitchNum = 0; + + private Integer connectedSwitchNum = 0; + + private Integer disconnectedSwitchNum = 0; + + private Integer totalPorts = 0; + + private Integer availablePorts = 0; + + private Double powerConsumption = 0.0; + + private Integer totalApNum = 0; + + private Integer connectedApNum = 0; + + private Integer isolatedApNum = 0; + + private Integer disconnectedApNum = 0; + + private Integer totalClientNum = 0; + + private Integer wiredClientNum = 0; + + private Integer wirelessClientNum = 0; + + private Integer guestNum = 0; +} diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysDashboardService.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysDashboardService.java new file mode 100644 index 0000000..2eebcc6 --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysDashboardService.java @@ -0,0 +1,16 @@ +package org.wfc.system.service; + +import org.wfc.common.core.web.page.TableDataInfo; +import org.wfc.system.domain.vo.SysDashboardVo; + +/** + * @description: + * @author: cyc + * @since: 2025-01-07 + */ +public interface ISysDashboardService { + + TableDataInfo getSiteList(String searchKey); + + SysDashboardVo overview(); +} diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysDashboardServiceImpl.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysDashboardServiceImpl.java new file mode 100644 index 0000000..0026dc8 --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysDashboardServiceImpl.java @@ -0,0 +1,112 @@ +package org.wfc.system.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.github.pagehelper.PageHelper; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.wfc.common.core.constant.HttpStatus; +import org.wfc.common.core.web.page.TableDataInfo; +import org.wfc.omada.api.monitor.OmadaDashboardApi; +import org.wfc.omada.api.monitor.model.GetDashboardOverview; +import org.wfc.omada.api.monitor.model.OperationResponseGetDashboardOverview; +import org.wfc.omada.api.organization.OmadaSiteApi; +import org.wfc.omada.api.organization.model.OperationResponseGridVoSiteSummaryInfo; +import org.wfc.omada.api.organization.model.SiteSummaryInfo; +import org.wfc.system.domain.convert.SysDashboardConvert; +import org.wfc.system.domain.vo.SysDashboardSiteVo; +import org.wfc.system.domain.vo.SysDashboardVo; +import org.wfc.system.service.ISysDashboardService; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @description: + * @author: cyc + * @since: 2025-01-07 + */ +@Service +public class SysDashboardServiceImpl implements ISysDashboardService { + @Autowired + private OmadaSiteApi omadaSiteApi; + + @Autowired + private OmadaDashboardApi omadaDashboardApi; + + @Override + public TableDataInfo getSiteList(String searchKey) { + ResponseEntity siteList = omadaSiteApi.getSiteList(PageHelper.getLocalPage().getPageNum(), PageHelper.getLocalPage().getPageSize(), searchKey); + if (siteList.getBody() == null) { + return getDataTable(Collections.emptyList(), 0L); + } + List sites = siteList.getBody().getResult().getData(); + List siteVos = new ArrayList<>(); + for (SiteSummaryInfo site : sites) { + SysDashboardSiteVo siteVo = SysDashboardConvert.INSTANCE.toSysDashboardSiteVo(site); + ResponseEntity overview = omadaDashboardApi.getOverview(site.getSiteId()); + if (overview.getBody() == null) { + continue; + } + GetDashboardOverview dashboardOverview = overview.getBody().getResult(); + BeanUtils.copyProperties(dashboardOverview, siteVo); + siteVos.add(siteVo); + } + return getDataTable(siteVos, siteList.getBody().getResult().getTotalRows()); + } + + @Override + public SysDashboardVo overview() { + ResponseEntity siteList = omadaSiteApi.getSiteList(1, 1000); + SysDashboardVo sysDashboardVo = new SysDashboardVo(); + if (siteList.getBody() == null) { + return sysDashboardVo; + } + List sites = siteList.getBody().getResult().getData(); + + List dashboardOverviews = new ArrayList<>(); + for (SiteSummaryInfo site : sites) { + ResponseEntity overview = omadaDashboardApi.getOverview(site.getSiteId()); + if (overview.getBody() == null) { + continue; + } + GetDashboardOverview dashboardOverview = overview.getBody().getResult(); + dashboardOverviews.add(dashboardOverview); + } + sysDashboardVo.setAvailablePorts(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getAvailablePorts())).mapToInt(GetDashboardOverview::getAvailablePorts).sum()); + sysDashboardVo.setConnectedGatewayNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getConnectedGatewayNum())).mapToInt(GetDashboardOverview::getConnectedGatewayNum).sum()); + sysDashboardVo.setConnectedApNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getConnectedApNum())).mapToInt(GetDashboardOverview::getConnectedApNum).sum()); + sysDashboardVo.setConnectedSwitchNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getConnectedSwitchNum())).mapToInt(GetDashboardOverview::getConnectedSwitchNum).sum()); + sysDashboardVo.setGuestNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getGuestNum())).mapToInt(GetDashboardOverview::getGuestNum).sum()); + sysDashboardVo.setDisconnectedApNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getDisconnectedApNum())).mapToInt(GetDashboardOverview::getDisconnectedApNum).sum()); + sysDashboardVo.setNetCapacity(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getNetCapacity())).mapToInt(GetDashboardOverview::getNetCapacity).sum()); + sysDashboardVo.setIsolatedApNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getIsolatedApNum())).mapToInt(GetDashboardOverview::getIsolatedApNum).sum()); + sysDashboardVo.setNetUsage(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getNetUsage())).mapToDouble(GetDashboardOverview::getNetUsage).sum()); + sysDashboardVo.setDisconnectedGatewayNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getDisconnectedGatewayNum())).mapToInt(GetDashboardOverview::getDisconnectedGatewayNum).sum()); + sysDashboardVo.setTotalApNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getTotalApNum())).mapToInt(GetDashboardOverview::getTotalApNum).sum()); + sysDashboardVo.setTotalPorts(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getTotalPorts())).mapToInt(GetDashboardOverview::getTotalPorts).sum()); + sysDashboardVo.setTotalClientNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getTotalClientNum())).mapToInt(GetDashboardOverview::getTotalClientNum).sum()); + sysDashboardVo.setTotalSwitchNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getTotalSwitchNum())).mapToInt(GetDashboardOverview::getTotalSwitchNum).sum()); + sysDashboardVo.setPowerConsumption(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getPowerConsumption())).mapToDouble(GetDashboardOverview::getPowerConsumption).sum()); + sysDashboardVo.setWirelessClientNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getWirelessClientNum())).mapToInt(GetDashboardOverview::getWirelessClientNum).sum()); + sysDashboardVo.setWiredClientNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getWiredClientNum())).mapToInt(GetDashboardOverview::getWiredClientNum).sum()); + sysDashboardVo.setDisconnectedApNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getDisconnectedApNum())).mapToInt(GetDashboardOverview::getDisconnectedApNum).sum()); + sysDashboardVo.setTotalGatewayNum(dashboardOverviews.stream().filter(c -> ObjectUtil.isNotNull(c.getTotalGatewayNum())).mapToInt(GetDashboardOverview::getTotalGatewayNum).sum()); + sysDashboardVo.setSiteNum(sites.size()); + + return sysDashboardVo; + } + + /** + * 响应请求分页数据 + */ + protected TableDataInfo getDataTable(List list, Long total) { + TableDataInfo rspData = new TableDataInfo(list, total); + rspData.setCode(HttpStatus.SUCCESS); + rspData.setMsg("查询成功"); + + return rspData; + } +}