package com.wgcloud.controller.dp; import com.wgcloud.entity.OspfInfo; import com.wgcloud.entity.SnmpInfo; import com.wgcloud.service.OspfInfoService; import com.wgcloud.service.SnmpInfoService; import com.wgcloud.util.R; 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.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; /** * @author kdq * @version 1.0.0 * @ClassName DpController.java * @Description TODO * @createTime 2025年11月16日 14:59:00 */ @RestController @RequestMapping("/dp") public class DpController { @Autowired private OspfInfoService ospfInfoService; @GetMapping("/getTop") public R getTop5() throws Exception { List> list = new ArrayList<>(); List ospfInfos = ospfInfoService.selectAllByParams(null); for (OspfInfo ospfInfo : ospfInfos) { HashMap map = new HashMap<>(); map.put("name",ospfInfo.getInfoContent()); map.put("ipaddress",ospfInfo.getHostname()); map.put("areaNum",ospfInfo.getAreaNum()); list.add(map); } if(list.size()>5){ return R.ok(list.subList(0,5)); }else { return R.ok(list); } } @GetMapping("/getWb") public R getWb() throws Exception { List> list = new ArrayList<>(); List ospfInfos = ospfInfoService.selectAllByParams(null); for (OspfInfo ospfInfo : ospfInfos) { HashMap map = new HashMap<>(); map.put("name",ospfInfo.getInfoContent()); map.put("ipaddress",ospfInfo.getHostname()); map.put("type",1); map.put("status",1); list.add(map); } return R.ok(list); } @GetMapping("/getError") public R getError() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd"); String format = sdf.format(new Date()); List> list = new ArrayList<>(); List ospfInfos = ospfInfoService.selectAllByParams(null); for (OspfInfo ospfInfo : ospfInfos) { HashMap map = new HashMap<>(); map.put("date",format); map.put("name",ospfInfo.getInfoContent()); map.put("ipaddress",ospfInfo.getHostname()); map.put("status",1); list.add(map); } return R.ok(list); } @GetMapping("/getCount") public R getCount() throws Exception { List ospfInfos = ospfInfoService.selectAllByParams(null); Map map = new HashMap<>(); map.put("allCount",ospfInfos.size()); map.put("normalCount",ospfInfos.size()-2); map.put("errorCount",2); double i = (double)(ospfInfos.size() - 2) /(double) ospfInfos.size(); double o = (double)2 /(double) ospfInfos.size(); BigDecimal n = new BigDecimal(i).setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal e = new BigDecimal(o).setScale(2, BigDecimal.ROUND_HALF_UP); map.put("normalProp",n); map.put("errorProp",e); return R.ok(map); } @GetMapping("/getInfo") public R getInfo() throws Exception { List> list = new ArrayList<>(); List ospfInfos = ospfInfoService.selectAllByParams(null); for (OspfInfo ospfInfo : ospfInfos) { HashMap map = new HashMap<>(); map.put("ipAddress",ospfInfo.getHostname()); map.put("status",1); list.add(map); } return R.ok(list); } }