kongdeqiang
2025-12-02 4910c350e379c180bdb7c3194e8ea0770928129f
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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<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<>();
        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 (OspfErrorLog ospfInfo : ospfErrorLogs) {
            HashMap<String, Object> 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<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()-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<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("name",ospfInfo.getInfoContent());
            map.put("status",ospfInfo.getState());
            list.add(map);
        }
        return R.ok(list);
    }
 
 
}