kongdeqiang
2025-12-01 b2f0547067840c6ef5333216c5ee2cf38e07025a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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<Map<String,Object>> list = new ArrayList<>();
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
 
        for (OspfInfo ospfInfo : ospfInfos) {
            HashMap<String, Object> 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<Map<String,Object>> list = new ArrayList<>();
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
 
        for (OspfInfo ospfInfo : ospfInfos) {
            HashMap<String, Object> 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<Map<String,Object>> list = new ArrayList<>();
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
 
        for (OspfInfo ospfInfo : ospfInfos) {
            HashMap<String, Object> 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<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
        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();
        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<Map<String,Object>> list = new ArrayList<>();
        List<OspfInfo> ospfInfos = ospfInfoService.selectAllByParams(null);
        for (OspfInfo ospfInfo : ospfInfos) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("ipAddress",ospfInfo.getHostname());
            map.put("status",1);
            list.add(map);
        }
        return R.ok(list);
    }
 
 
}