kongdeqiang
2025-11-13 ca4d537c4065315be5c5c27cdef733fc383c4b74
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
128
129
130
131
132
133
134
135
136
137
package com.wgcloud.service;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgcloud.entity.OspfInfo;
import com.wgcloud.entity.SnmpInfo;
import com.wgcloud.mapper.OspfInfoMapper;
import com.wgcloud.util.DateUtil;
import com.wgcloud.util.UUIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:OspfInfoService.java
 * @author: http://www.wgstart.com
 * @date: 2021年1月16日
 * @Description: OspfInfoService.java
 * @Copyright: 2019-2021 wgcloud. All rights reserved.
 */
@Service
public class OspfInfoService {
 
    @Autowired
    private RouterConnectionService routerConnectionService;
 
    private static final Logger logger = LoggerFactory.getLogger(OspfInfoService.class);
 
    public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
        PageHelper.startPage(currPage, pageSize);
        List<OspfInfo> list = OspfInfoMapper.selectByParams(params);
        PageInfo<OspfInfo> pageInfo = new PageInfo<OspfInfo>(list);
        return pageInfo;
    }
 
    public void saveRecord(List<OspfInfo> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        for (OspfInfo as : recordList) {
            as.setId(UUIDUtil.getUUID());
            as.setCreateTime(DateUtil.getNowTime());
        }
        OspfInfoMapper.insertList(recordList);
    }
 
    public void save(OspfInfo ospfInfo) {
        ospfInfo.setId(UUIDUtil.getUUID());
        ospfInfo.setCreateTime(DateUtil.getNowTime());
        try {
            OspfInfoMapper.save(ospfInfo);
        } catch (Exception e) {
            logger.error("保存日志信息异常:", e);
        }
    }
 
    public void updateById(OspfInfo ospfInfo)
            throws Exception {
        if (StringUtils.isEmpty(ospfInfo.getHostname())) {
            ospfInfo.setHostname(ospfInfo.getHostname().trim());
        }
        OspfInfoMapper.updateById(ospfInfo);
    }
 
    public boolean checkOspfStatus() {
        String command = "display ospf brief";
        String output = routerConnectionService.executeCommand(command);
 
        if (output == null) {
            return false;
        }
 
        // 检查输出中是否包含OSPF相关信息
        boolean containsRouterId = StringUtils.containsIgnoreCase(output, "Router ID");
        boolean containsArea = StringUtils.containsIgnoreCase(output, "Area");
        boolean containsProcessId = StringUtils.containsIgnoreCase(output, "Process ID");
 
        // 检查是否有错误信息
        boolean containsError = StringUtils.containsIgnoreCase(output, "Error") ||
                StringUtils.containsIgnoreCase(output, "Fail") ||
                StringUtils.containsIgnoreCase(output, "Invalid");
 
        return (containsRouterId && containsArea && containsProcessId) && !containsError;
    }
 
    /**
     * 获取详细的OSPF邻居信息
     */
    public String getDetailedOspfNeighborInfo() {
        String command = "display ospf peer";
        return routerConnectionService.executeCommand(command);
    }
 
    /**
     * 获取OSPF接口状态
     */
    public String getOspfInterfaceStatus() {
        String command = "display ospf interface";
        return routerConnectionService.executeCommand(command);
    }
 
    
 
 
    public int countByParams(Map<String, Object> params) throws Exception {
        return OspfInfoMapper.countByParams(params);
    }
 
    public int deleteById(String[] id) throws Exception {
        return OspfInfoMapper.deleteById(id);
    }
 
    public OspfInfo selectById(String id) throws Exception {
        return OspfInfoMapper.selectById(id);
    }
 
    public List<OspfInfo> selectAllByParams(Map<String, Object> params) throws Exception {
        return OspfInfoMapper.selectAllByParams(params);
    }
 
    public int deleteByDate(Map<String, Object> map) throws Exception{
        return OspfInfoMapper.deleteByDate(map);
    }
 
    @Autowired
    private OspfInfoMapper OspfInfoMapper;
 
 
}