kongdeqiang
2025-12-03 285b20e698b0f26bdb3e9182d367ecae2c5a63d0
src/main/java/com/wgcloud/controller/dp/DpController.java
@@ -1,12 +1,15 @@
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -27,6 +30,8 @@
    @Autowired
    private OspfInfoService ospfInfoService;
    @Autowired
    private OspfErrorLogService ospfErrorLogService;
    @GetMapping("/getTop")
    public R getTop5() throws Exception {
@@ -68,14 +73,21 @@
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
        String format = sdf.format(new Date());
        List<Map<String,Object>> list = new ArrayList<>();
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
        Map<String,Object> query = new HashMap<>();
        query.put("state","1");
        List<OspfErrorLog> ospfErrorLogs = ospfErrorLogService.selectAllByParams(query);
        Map<String,Object> query2 = new HashMap<>();
        query2.put("state","0");
        List<OspfErrorLog> ospfErrorLogs2 = ospfErrorLogService.selectAllByParams(query2);
        ospfErrorLogs.addAll(ospfErrorLogs2);
        for (OspfInfo ospfInfo : ospfInfos) {
        for (OspfErrorLog ospfInfo : ospfErrorLogs) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("date",format);
            map.put("date",sdf.format(ospfInfo.getCreateTime()));
            map.put("name",ospfInfo.getInfoContent());
            map.put("id",ospfInfo.getId());
            map.put("ipaddress",ospfInfo.getHostname());
            map.put("status",1);
            map.put("status",ospfInfo.getState());
            list.add(map);
        }
        return R.ok(list);
@@ -83,13 +95,16 @@
    @GetMapping("/getCount")
    public R getCount() throws Exception {
        Map<String,Object> queryMap = new HashMap<>();
        queryMap.put("state","1");
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
        List<OspfInfo> errorOspfInfos = ospfInfoService.selectAllByParams(queryMap);
        Map<String,Object> 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();
        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);
@@ -100,14 +115,32 @@
    public R getInfo() throws Exception {
        List<Map<String,Object>> list = new ArrayList<>();
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
        HashMap<String, Object> 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<String, Object> map = new HashMap<>();
            map.put("ipAddress",ospfInfo.getHostname());
            map.put("status",1);
            map.put("name",ospfInfo.getInfoContent());
            map.put("status",ospfInfo.getState());
            list.add(map);
        }
        return R.ok(list);
    }
    @GetMapping("/handle")
    public R handle(String id) throws Exception {
        OspfErrorLog ospfErrorLog = ospfErrorLogService.selectById(id);
        if(ospfErrorLog.getState().equals("1")){
            ospfErrorLog.setState("0");
            ospfErrorLogService.updateById(ospfErrorLog);
            return R.ok();
        }else {
            return R.ok();
        }
    }
}