package com.wgcloud.controller.dp; import com.wgcloud.entity.OspfErrorLog; import com.wgcloud.entity.OspfInfo; import com.wgcloud.entity.SnmpInfo; import com.wgcloud.service.OspfErrorLogService; 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; @Autowired private OspfErrorLogService ospfErrorLogService; @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<>(); Map query = new HashMap<>(); query.put("state","1"); List ospfErrorLogs = ospfErrorLogService.selectAllByParams(query); Map query2 = new HashMap<>(); query2.put("state","0"); List ospfErrorLogs2 = ospfErrorLogService.selectAllByParams(query2); ospfErrorLogs.addAll(ospfErrorLogs2); for (OspfErrorLog ospfInfo : ospfErrorLogs) { HashMap map = new HashMap<>(); map.put("date",sdf.format(ospfInfo.getCreateTime())); map.put("name",ospfInfo.getInfoContent()); map.put("ipaddress",ospfInfo.getHostname()); map.put("status",ospfInfo.getState()); list.add(map); } return R.ok(list); } @GetMapping("/getCount") public R getCount() throws Exception { Map queryMap = new HashMap<>(); queryMap.put("state","1"); List ospfInfos = ospfInfoService.selectAllByParams(null); List errorOspfInfos = ospfInfoService.selectAllByParams(queryMap); Map map = new HashMap<>(); map.put("allCount",ospfInfos.size()); map.put("normalCount",ospfInfos.size()-errorOspfInfos.size()); map.put("errorCount",errorOspfInfos.size()); double i = (double)(ospfInfos.size()-errorOspfInfos.size()) /(double) ospfInfos.size(); double o = (double)errorOspfInfos.size() /(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); HashMap hxMap = new HashMap<>(); hxMap.put("ipAddress","\n电信:192.168.1.1\n 联通:192.168.2.1\n 移动:192.168.3.1"); hxMap.put("name","北国核心"); hxMap.put("status","0"); list.add(hxMap); for (OspfInfo ospfInfo : ospfInfos) { HashMap map = new HashMap<>(); map.put("ipAddress",ospfInfo.getHostname()); map.put("name",ospfInfo.getInfoContent()); map.put("status",ospfInfo.getState()); list.add(map); } return R.ok(list); } }