Authored by zhangmingm

修改现场返回的问题,当ping通的情况下才检查连接状态。

... ... @@ -35,14 +35,13 @@ public class CheckConnectionDao {
/**
* 插入ping结果。在插入数据之前,删除掉当前时间前1小时的数据,即只保留1小时的数据。
* 插入ping结果。在插入数据之前,删除掉当前时间前30分钟的数据,即只保留30分钟的数据。
* @param bean
*/
public void addPingConnectionState(ConnectionStateBean bean){
try {
deleteBeforeData();
sqlmapClient.insert("addPingConnectionState", bean);
log.info("******* CheckConnectionDao **** execute method addPingConnectionState ******");
} catch (SQLException e) {
log.error("Exception while addPingConnectionState.",e);
}
... ... @@ -51,12 +50,11 @@ public class CheckConnectionDao {
/**
* 清除TB_CONNECTION_STATE表里1小时前的数据。
* 清除TB_CONNECTION_STATE表里30分钟前的数据。
*/
public void deleteBeforeData(){
long temp=new Date().getTime()-1000*60*60;
long temp=new Date().getTime()-1000*60*30;
String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp;
log.info("******* deleteBeforeData **** sql["+sql+"]******");
try {
sqlmapClient.delete("deleteBeforeData", sql);
} catch (Exception e) {
... ... @@ -79,4 +77,26 @@ public class CheckConnectionDao {
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param sql
* @return
*/
public String getPingResultByIp(String sql){
List<ConnectionStateBean> beanList=new ArrayList<ConnectionStateBean>();
try {
beanList=sqlmapClient.queryForList("getPingResultByIp", sql);
} catch (SQLException e) {
e.printStackTrace();
}
String result="";
log.info("&&&&&&&& beanList.size()="+beanList.size()+" &&&&&&&&&&&&&&&&&&&&&&");
if(null !=beanList && beanList.size()>0){
ConnectionStateBean bean=beanList.get(0);
log.info("&&&&&&&& ConnectionStateBean ="+bean.toString()+" &&&&&&&&&&&&&&&&&&&&&&");
result=bean.getDEVICE_STATE();
}
return result;
}
}
... ...
... ... @@ -416,19 +416,18 @@ public class CheckConnectionService {
return dao.getStatByParam(map);
}
public static void main(String [] args){
long beforeTime = 15*60*1000+500;//15.5分钟前
long afterTime = 30*1000;//半分钟后
Date now = new Date();
long nn=now.getTime();
long before = nn - beforeTime;
long after = nn + afterTime;
System.out.println(nn);
System.out.println(after);
System.out.println(before);
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param ip
* @return
*/
public String getPingResultByIp(String ip){
String sql="SELECT DEVICE_STATE FROM TB_CONNECTION_STATE WHERE DEVICE_IP='"+ip+"' ORDER BY CREATE_DATE DESC";
CheckConnectionDao dao=new CheckConnectionDao();
String result=dao.getPingResultByIp(sql);
return result;
}
}
... ...
... ... @@ -52,12 +52,21 @@ public class CheckConnectionState {
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param ip
* @return
*/
public String getPingResultByIp(String ip){
return service.getPingResultByIp(ip);
}
/**
* 根据IP获取ping不通的次数。只取集合中的前3条数据。当都为down的时候表明已经宕机,少于3次不算宕机。
* @param ip
* @return
*/
public String getPingErrorState(String ip){
List<ConnectionStateBean> list=service.getStatByParam(ip);
log.info("**********&&&&& list .size ="+list.size()+"&&&&&&&&&********(((((((");
int temp=0;
String state=null;
ConnectionStateBean bean=null;
... ... @@ -71,7 +80,7 @@ public class CheckConnectionState {
}
}
String stat="UP";
if(temp==3){
if(temp!=0){
stat="DOWN";
}
return stat;
... ...