From 4910c350e379c180bdb7c3194e8ea0770928129f Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期二, 02 十二月 2025 10:53:22 +0800
Subject: [PATCH] 大屏接口修改

---
 src/main/java/com/wgcloud/WgcloudServiceApplication.java       |    2 
 src/main/java/com/wgcloud/service/RouterConnectionService.java |   30 ++
 src/main/java/com/wgcloud/controller/dp/DpController.java      |   32 ++
 src/main/java/com/wgcloud/task/ScheduledTask.java              |   11 +
 src/main/resources/mybatis/mapper/OspfErrorLogMapper.xml       |  178 +++++++++++++++++
 src/main/java/com/wgcloud/entity/OspfErrorLog.java             |   82 ++++++++
 src/main/java/com/wgcloud/service/OspfInfoService.java         |  101 +++++++--
 src/main/java/com/wgcloud/mapper/OspfErrorLogMapper.java       |   39 +++
 src/main/java/com/wgcloud/service/OspfErrorLogService.java     |   94 +++++++++
 9 files changed, 526 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/wgcloud/WgcloudServiceApplication.java b/src/main/java/com/wgcloud/WgcloudServiceApplication.java
index 3f01e40..0acffdc 100644
--- a/src/main/java/com/wgcloud/WgcloudServiceApplication.java
+++ b/src/main/java/com/wgcloud/WgcloudServiceApplication.java
@@ -31,7 +31,7 @@
 @ServletComponentScan("com.wgcloud.filter")
 @ComponentScan(basePackages = "com.wgcloud")
 @EnableCaching
-//@EnableScheduling
+@EnableScheduling
 public class WgcloudServiceApplication {
     public static void main(String[] args) {
         SpringApplication.run(WgcloudServiceApplication.class, args);
diff --git a/src/main/java/com/wgcloud/controller/dp/DpController.java b/src/main/java/com/wgcloud/controller/dp/DpController.java
index e56b21c..53d4ba2 100644
--- a/src/main/java/com/wgcloud/controller/dp/DpController.java
+++ b/src/main/java/com/wgcloud/controller/dp/DpController.java
@@ -1,7 +1,9 @@
 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;
@@ -27,6 +29,8 @@
 
     @Autowired
     private OspfInfoService ospfInfoService;
+    @Autowired
+    private OspfErrorLogService ospfErrorLogService;
 
     @GetMapping("/getTop")
     public R getTop5() throws Exception {
@@ -68,14 +72,20 @@
         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("ipaddress",ospfInfo.getHostname());
-            map.put("status",1);
+            map.put("status",ospfInfo.getState());
             list.add(map);
         }
         return R.ok(list);
@@ -83,13 +93,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);
@@ -103,7 +116,8 @@
         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);
diff --git a/src/main/java/com/wgcloud/entity/OspfErrorLog.java b/src/main/java/com/wgcloud/entity/OspfErrorLog.java
new file mode 100644
index 0000000..0551c54
--- /dev/null
+++ b/src/main/java/com/wgcloud/entity/OspfErrorLog.java
@@ -0,0 +1,82 @@
+package com.wgcloud.entity;
+
+import java.util.Date;
+
+/**
+ * @version v3.3
+ * @ClassName:ospf.java
+ * @author: http://www.wgstart.com
+ * @date: 2021骞�1鏈�16鏃�
+ * @Description: ospf鐩戞帶璁惧
+ * @Copyright: 2019-2021 wgcloud. All rights reserved.
+ */
+public class OspfErrorLog extends BaseEntity {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 鏍囬
+     */
+    private String hostname;
+
+    /**
+     * 鎻忚堪
+     */
+    private String infoContent;
+
+    /**
+     * 0宸插鐞嗭紝1鏈鐞�
+     */
+    private String state;
+
+    /**
+     * 鍒涘缓鏃堕棿
+     */
+    private Date createTime;
+
+    public String getHostname() {
+        return hostname;
+    }
+
+
+    public void setHostname(String hostname) {
+        this.hostname = hostname;
+    }
+
+
+    public String getInfoContent() {
+        return infoContent;
+    }
+
+
+    public void setInfoContent(String infoContent) {
+        this.infoContent = infoContent;
+    }
+
+
+    public String getState() {
+        return state;
+    }
+
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+
+
+
+}
diff --git a/src/main/java/com/wgcloud/mapper/OspfErrorLogMapper.java b/src/main/java/com/wgcloud/mapper/OspfErrorLogMapper.java
new file mode 100644
index 0000000..705d671
--- /dev/null
+++ b/src/main/java/com/wgcloud/mapper/OspfErrorLogMapper.java
@@ -0,0 +1,39 @@
+package com.wgcloud.mapper;
+
+import com.wgcloud.entity.OspfErrorLog;
+import com.wgcloud.entity.OspfMonitor;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @version v3.3
+ * @ClassName:LogInfoDao.java
+ * @author: http://www.wgstart.com
+ * @date: 2021骞�1鏈�16鏃�
+ * @Description: 鏌ョ湅鏃ュ織淇℃伅
+ * @Copyright: 2019-2021 wgcloud. All rights reserved.
+ */
+@Repository
+public interface OspfErrorLogMapper {
+
+
+    public List<OspfErrorLog> selectAllByParams(Map<String, Object> map);
+
+    public int countByParams(Map<String, Object> params) throws Exception;
+
+    public List<OspfErrorLog> selectByParams(Map<String, Object> params) throws Exception;
+
+    public OspfErrorLog selectById(String id) throws Exception;
+
+    public void save(OspfErrorLog LogInfo) throws Exception;
+
+    public int deleteById(String[] id) throws Exception;
+
+    public void insertList(List<OspfErrorLog> recordList) throws Exception;
+
+    public int deleteByDate(Map<String, Object> map) throws Exception;
+
+    public void updateById(OspfErrorLog ospfInfo);
+}
diff --git a/src/main/java/com/wgcloud/service/OspfErrorLogService.java b/src/main/java/com/wgcloud/service/OspfErrorLogService.java
new file mode 100644
index 0000000..e38dc44
--- /dev/null
+++ b/src/main/java/com/wgcloud/service/OspfErrorLogService.java
@@ -0,0 +1,94 @@
+package com.wgcloud.service;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.wgcloud.entity.OspfErrorLog;
+import com.wgcloud.entity.OspfErrorLog;
+import com.wgcloud.mapper.OspfErrorLogMapper;
+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:OspfErrorLogService.java
+ * @author: http://www.wgstart.com
+ * @date: 2021骞�1鏈�16鏃�
+ * @Description: OspfErrorLogService.java
+ * @Copyright: 2019-2021 wgcloud. All rights reserved.
+ */
+@Service
+public class OspfErrorLogService {
+
+    private static final Logger logger = LoggerFactory.getLogger(OspfErrorLogService.class);
+
+    public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
+        PageHelper.startPage(currPage, pageSize);
+        List<OspfErrorLog> list = ospfErrorLogMapper.selectByParams(params);
+        PageInfo<OspfErrorLog> pageInfo = new PageInfo<OspfErrorLog>(list);
+        return pageInfo;
+    }
+
+    public void saveRecord(List<OspfErrorLog> recordList) throws Exception {
+        if (recordList.size() < 1) {
+            return;
+        }
+        Map<String, Object> map = new HashMap<String, Object>();
+        for (OspfErrorLog as : recordList) {
+            as.setId(UUIDUtil.getUUID());
+            as.setCreateTime(DateUtil.getNowTime());
+        }
+        ospfErrorLogMapper.insertList(recordList);
+    }
+
+    public void save(OspfErrorLog OspfErrorLog) {
+        OspfErrorLog.setId(UUIDUtil.getUUID());
+        OspfErrorLog.setCreateTime(DateUtil.getNowTime());
+        try {
+            ospfErrorLogMapper.save(OspfErrorLog);
+        } catch (Exception e) {
+            logger.error("淇濆瓨鏃ュ織淇℃伅寮傚父锛�", e);
+        }
+    }
+
+    public void updateById(OspfErrorLog OspfErrorLog)
+            throws Exception {
+        if (StringUtils.isEmpty(OspfErrorLog.getHostname())) {
+            OspfErrorLog.setHostname(OspfErrorLog.getHostname().trim());
+        }
+        ospfErrorLogMapper.updateById(OspfErrorLog);
+    }
+
+    public int countByParams(Map<String, Object> params) throws Exception {
+        return ospfErrorLogMapper.countByParams(params);
+    }
+
+    public int deleteById(String[] id) throws Exception {
+        return ospfErrorLogMapper.deleteById(id);
+    }
+
+    public OspfErrorLog selectById(String id) throws Exception {
+        return ospfErrorLogMapper.selectById(id);
+    }
+
+    public List<OspfErrorLog> selectAllByParams(Map<String, Object> params) throws Exception {
+        return ospfErrorLogMapper.selectAllByParams(params);
+    }
+
+    public int deleteByDate(Map<String, Object> map) throws Exception{
+        return ospfErrorLogMapper.deleteByDate(map);
+    }
+
+    @Autowired
+    private OspfErrorLogMapper ospfErrorLogMapper;
+
+
+}
diff --git a/src/main/java/com/wgcloud/service/OspfInfoService.java b/src/main/java/com/wgcloud/service/OspfInfoService.java
index 2f2257b..1f2f36f 100644
--- a/src/main/java/com/wgcloud/service/OspfInfoService.java
+++ b/src/main/java/com/wgcloud/service/OspfInfoService.java
@@ -2,10 +2,14 @@
 
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.wgcloud.entity.OspfErrorLog;
 import com.wgcloud.entity.OspfInfo;
 import com.wgcloud.entity.SnmpInfo;
+import com.wgcloud.entity.vo.OspfNeighbor;
+import com.wgcloud.mapper.OspfErrorLogMapper;
 import com.wgcloud.mapper.OspfInfoMapper;
 import com.wgcloud.util.DateUtil;
+import com.wgcloud.util.OspfNeighborUtil;
 import com.wgcloud.util.UUIDUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -30,6 +34,10 @@
 
     @Autowired
     private RouterConnectionService routerConnectionService;
+    @Autowired
+    private OspfNeighborUtil ospfNeighborUtil;
+    @Autowired
+    private OspfErrorLogMapper errorLogMapper;
 
     private static final Logger logger = LoggerFactory.getLogger(OspfInfoService.class);
 
@@ -70,44 +78,81 @@
         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;
-    }
+//    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;
+//    }
 
     /**
      * 鑾峰彇璇︾粏鐨凮SPF閭诲眳淇℃伅
      */
-    public String getDetailedOspfNeighborInfo() {
-        String command = "display ospf peer";
-        return routerConnectionService.executeCommand(command);
+    public void getDetailedOspfNeighborInfo() {
+        List<OspfInfo> ospfInfos = OspfInfoMapper.selectAllByParams(null);
+        for (OspfInfo ospfInfo : ospfInfos) {
+            String command = "display ospf peer "+ospfInfo.getHostname();
+            String result =  routerConnectionService.executeCommand(command,ospfInfo.getMonitorUsername(),ospfInfo.getMonitorPassword(),ospfInfo.getMonitorIp());
+            if(StringUtils.isNotBlank(result)){
+                List<OspfNeighbor> neighbors = ospfNeighborUtil.analysisStr(result);
+                if(neighbors != null || neighbors.size()>0){
+                    OspfNeighbor ospfNeighbor = neighbors.get(0);
+                    String state = ospfNeighbor.getState();
+                    if (state.contains("Down") || state.contains("Init")) {
+                        ospfInfo.setState("1");
+                        OspfInfoMapper.updateById(ospfInfo);
+
+                        HashMap<String, Object> hashMap = new HashMap<>();
+                        hashMap.put("state","1");
+                        hashMap.put("hostname",ospfInfo.getHostname());
+                        List<OspfErrorLog> ospfErrorLogs = errorLogMapper.selectAllByParams(hashMap);
+                        if(ospfErrorLogs==null||ospfErrorLogs.size()==0){
+                            OspfErrorLog ospfErrorLog = new OspfErrorLog();
+                            ospfErrorLog.setInfoContent(ospfInfo.getInfoContent());
+                            ospfErrorLog.setHostname(ospfInfo.getHostname());
+                            ospfErrorLog.setState("1");
+                            try {
+                                errorLogMapper.save(ospfErrorLog);
+                            }catch (Exception e){
+                                e.printStackTrace();
+                            }
+                        }
+                    }else {
+                        ospfInfo.setState("0");
+                        OspfInfoMapper.updateById(ospfInfo);
+                    }
+                }
+            }else {
+                ospfInfo.setState("1");
+                OspfInfoMapper.updateById(ospfInfo);
+            }
+
+        }
     }
 
     /**
      * 鑾峰彇OSPF鎺ュ彛鐘舵��
      */
-    public String getOspfInterfaceStatus() {
-        String command = "display ospf interface";
-        return routerConnectionService.executeCommand(command);
-    }
+//    public String getOspfInterfaceStatus() {
+//        String command = "display ospf interface";
+//        return routerConnectionService.executeCommand(command);
+//    }
 
-    
+
 
 
     public int countByParams(Map<String, Object> params) throws Exception {
diff --git a/src/main/java/com/wgcloud/service/RouterConnectionService.java b/src/main/java/com/wgcloud/service/RouterConnectionService.java
index afc6364..61ff536 100644
--- a/src/main/java/com/wgcloud/service/RouterConnectionService.java
+++ b/src/main/java/com/wgcloud/service/RouterConnectionService.java
@@ -48,6 +48,28 @@
     }
 
     /**
+     * 杩炴帴鍒拌矾鐢卞櫒
+     */
+    public boolean connect(String username,String hostname,String password) {
+        try {
+            JSch jsch = new JSch();
+            session = jsch.getSession(username, hostname, 22);
+            session.setPassword(password);
+
+            // 璁剧疆涓嶈繘琛屼富鏈哄瘑閽ユ鏌�
+            Properties config = new Properties();
+            config.put("StrictHostKeyChecking", "no");
+            session.setConfig(config);
+
+            session.connect(5000); // 5绉掕秴鏃�
+            return true;
+        } catch (JSchException e) {
+            System.err.println("杩炴帴璺敱鍣ㄥけ璐�: " + e.getMessage());
+            return false;
+        }
+    }
+
+    /**
      * 鏂紑杩炴帴
      */
     public void disconnect() {
@@ -59,9 +81,9 @@
     /**
      * 鎵ц璺敱鍣ㄥ懡浠�
      */
-    public String executeCommand(String command) {
+    public String executeCommand(String command,String username,String password,String hostname) {
         if (!isConnected()) {
-            if (!connect()) {
+            if (!connect(username,hostname,password)) {
                 return null;
             }
         }
@@ -69,8 +91,6 @@
         try {
             ChannelExec channel = (ChannelExec) session.openChannel("exec");
             channel.setCommand(command);
-            channel.connect();
-
             BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream()));
             StringBuilder output = new StringBuilder();
             String line;
@@ -95,4 +115,4 @@
     public boolean isConnected() {
         return session != null && session.isConnected();
     }
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/wgcloud/task/ScheduledTask.java b/src/main/java/com/wgcloud/task/ScheduledTask.java
index 4a057d6..55899af 100644
--- a/src/main/java/com/wgcloud/task/ScheduledTask.java
+++ b/src/main/java/com/wgcloud/task/ScheduledTask.java
@@ -69,12 +69,23 @@
     @Autowired
     private SnmpInfoService snmpInfoService;
     @Autowired
+    private OspfInfoService ospfInfoService;
+    @Autowired
     private CommonConfig commonConfig;
     @Autowired
     private MailConfig mailConfig;
     @Autowired
     private ServletContext servletContext;
 
+    /**
+     * 30绉掑悗鎵ц锛屾瘡2鍒嗛挓妫�娴嬩竴娆�
+     * 妫�娴媜spf鐘舵��
+     */
+    @Scheduled(initialDelay = 30000L, fixedRate = 2 * 60 * 1000)
+    public void ospfDownCheckTask() {
+        logger.info("ospfDownCheckTask------------" + DateUtil.getDateTimeString(new Date()));
+        ospfInfoService.getDetailedOspfNeighborInfo();
+    }
 
     /**
      * 5绉掑悗鎵ц锛屼箣鍚庢瘡24灏忔椂鍒锋柊涓�娆�
diff --git a/src/main/resources/mybatis/mapper/OspfErrorLogMapper.xml b/src/main/resources/mybatis/mapper/OspfErrorLogMapper.xml
new file mode 100644
index 0000000..fe46fe1
--- /dev/null
+++ b/src/main/resources/mybatis/mapper/OspfErrorLogMapper.xml
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.wgcloud.mapper.OspfErrorLogMapper">
+	<resultMap id="resultMap" type="com.wgcloud.entity.OspfErrorLog">
+		<id column="ID" property="id" jdbcType="CHAR" />
+		<result column="HOST_NAME" property="hostname" jdbcType="CHAR" />
+		<result column="INFO_CONTENT" property="infoContent" jdbcType="CHAR" />
+		<result column="STATE" property="state" jdbcType="CHAR" />
+		<result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" />
+	</resultMap>
+
+	<sql id="tableColumnList">
+		ID,HOST_NAME, INFO_CONTENT, STATE,CREATE_TIME
+	</sql>
+
+	<sql id="queryByParams">
+		<if test="hostname != null">
+			<choose>
+				<when test="_databaseId == 'oracle'">
+					<![CDATA[ AND HOST_NAME LIKE  CONCAT(CONCAT('%',#{hostname}),'%') ]]>
+				</when>
+				<otherwise>
+					<![CDATA[ AND HOST_NAME LIKE  CONCAT('%',#{hostname},'%') ]]>
+				</otherwise>
+			</choose>
+		</if>
+		<if test="hostnameNe != null">
+			<choose>
+				<when test="_databaseId == 'oracle'">
+					<![CDATA[ AND HOST_NAME NOT LIKE  CONCAT(CONCAT('%',#{hostnameNe}),'%') ]]>
+				</when>
+				<otherwise>
+					<![CDATA[ AND HOST_NAME NOT LIKE  CONCAT('%',#{hostnameNe},'%') ]]>
+				</otherwise>
+			</choose>
+		</if>
+		<if test="startTime != null and endTime !=null and startTime !='' and endTime != '' ">
+			<if test="_databaseId == 'mysql'">
+				<![CDATA[ AND CREATE_TIME >= #{startTime} and CREATE_TIME <=#{endTime}]]>
+			</if>
+			<if test="_databaseId == 'postgresql'">
+				<![CDATA[ AND CREATE_TIME >= cast(#{startTime} as timestamp) and CREATE_TIME <= cast(#{endTime} as timestamp)]]>
+			</if>
+			<if test="_databaseId == 'oracle'">
+				<![CDATA[ AND CREATE_TIME >= to_date(#{startTime},'yyyy-MM-dd hh24:mi:ss') and CREATE_TIME <= to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')]]>
+			</if>
+		</if>
+		<if test="state != null">
+			<![CDATA[ AND STATE = #{state} ]]>
+		</if>
+
+	</sql>
+
+
+	<select id="selectById" resultMap="resultMap" parameterType="java.lang.String">
+		SELECT
+		<include refid="tableColumnList" />
+		FROM OSPF_ERROR_LOG WHERE ID=#{id}
+	</select>
+
+
+	<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+		DELETE FROM OSPF_ERROR_LOG WHERE ID = #{id}
+	</delete>
+
+	<delete id="deleteByDate"  parameterType="map">
+		DELETE FROM OSPF_ERROR_LOG WHERE
+		<if test="_databaseId == 'mysql'">
+			<![CDATA[  CREATE_TIME <=#{endTime}]]>
+		</if>
+		<if test="_databaseId == 'postgresql'">
+			<![CDATA[  CREATE_TIME <= cast(#{endTime} as timestamp)]]>
+		</if>
+		<if test="_databaseId == 'oracle'">
+			<![CDATA[  CREATE_TIME <=  to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')]]>
+		</if>
+	</delete>
+
+
+	<delete id="deleteByAccHname"  parameterType="map">
+		DELETE FROM OSPF_ERROR_LOG WHERE ACCOUNT = #{account} AND HOST_NAME = #{hostname}
+	</delete>
+
+	<delete id="deleteById" parameterType="java.lang.String">
+		DELETE FROM OSPF_ERROR_LOG WHERE ID IN
+		<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
+			#{item}
+		</foreach>
+	</delete>
+
+	<insert id="insertList" parameterType="java.util.List" >
+		<choose>
+			<when test="_databaseId == 'oracle'">
+				begin
+				<foreach collection="list" item="item" index="index">
+					INSERT INTO OSPF_ERROR_LOG (ID,HOST_NAME,INFO_CONTENT,STATE,CREATE_TIME)  VALUES
+					(#{item.id},#{item.hostname},#{item.infoContent},#{item.state},#{item.createTime});
+				</foreach>
+				end;
+			</when>
+			<otherwise>
+				INSERT INTO OSPF_ERROR_LOG (ID,HOST_NAME,INFO_CONTENT,STATE,CREATE_TIME)  VALUES
+				<foreach collection="list" item="item" index="index" separator="," >
+					(#{item.id},#{item.hostname},#{item.infoContent},#{item.state},#{item.createTime})
+				</foreach>
+			</otherwise>
+		</choose>
+	</insert>
+
+	<insert id="save" parameterType="com.wgcloud.entity.OspfErrorLog">
+		INSERT INTO OSPF_ERROR_LOG
+    	<trim prefix="(" suffix=")" suffixOverrides="," >
+      		<if test="id != null" >ID,</if>
+      		<if test="hostname != null" > HOST_NAME,</if>
+      		<if test="infoContent != null">INFO_CONTENT,</if>
+      		<if test="state != null" >STATE,</if>
+      		<if test="createTime != null" >CREATE_TIME</if>
+    	</trim>
+    	<trim prefix="values (" suffix=")" suffixOverrides="," >
+      		<if test="id != null" >#{id},</if>
+      		<if test="hostname != null" >#{hostname},</if>
+      		<if test="infoContent != null" >#{infoContent},</if>
+      		<if test="state != null" >#{state},</if>
+      		<if test="createTime != null" >#{createTime}</if>
+    	</trim>
+	</insert>
+
+
+	<select id="countByParams" parameterType="map" resultType="java.lang.Integer">
+		SELECT count(*)  FROM OSPF_ERROR_LOG t
+		<where>
+			<include refid="queryByParams" />
+		</where>
+	</select>
+
+
+	  <select id="selectAllByParams" parameterType="map" resultMap="resultMap">
+		SELECT
+		<include refid="tableColumnList" />
+		FROM OSPF_ERROR_LOG t
+		<where>
+			<include refid="queryByParams" />
+		</where>
+		 ORDER BY CREATE_TIME DESC
+	</select>
+
+	<select id="selectByParams" parameterType="map" resultMap="resultMap">
+		SELECT
+		<include refid="tableColumnList" />
+		FROM OSPF_ERROR_LOG
+		<where>
+			<include refid="queryByParams" />
+		</where>
+		 ORDER BY CREATE_TIME DESC
+	</select>
+
+
+	<update id="updateById" parameterType="com.wgcloud.entity.OspfErrorLog">
+		UPDATE OSPF_ERROR_LOG
+		<set>
+			<if test="hostname != null">
+				HOST_NAME = #{hostname},
+			</if>
+			<if test="infoContent != null">
+				INFO_CONTENT = #{infoContent},
+			</if>
+			<if test="state != null">
+				STATE = #{state},
+			</if>
+			<if test="createTime != null">
+				CREATE_TIME = #{createTime},
+			</if>
+		</set>
+		WHERE ID = #{id}
+	</update>
+
+
+</mapper>

--
Gitblit v1.9.1