1、新增串联设备运营商页面

This commit is contained in:
fangshunjian
2019-01-13 18:31:43 +06:00
parent b3df3047b5
commit 97248b92ba
8 changed files with 442 additions and 20 deletions

View File

@@ -8,12 +8,8 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -37,6 +33,7 @@ import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.Expression;
import org.hibernate.transform.Transformers;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.util.Assert;
@@ -203,6 +200,29 @@ public class CommonService<T> extends HibernateGeneralDaoImpl<T>{
return page;
}
public Page findByPageForSqlMap(String sql, int pageNo, int pageSize, Object... values) throws Exception {
Assert.hasText(sql);
Assert.isTrue(pageNo >= 1, "pageNo should start from 1");
// Count查询
if (values != null && values.length == 0) {
values = null;
}
List countlist = null;
long totalCount = 0;
String countQueryString = " select count(*) as totalCount from ( " + sql + " ) trySearch ";
totalCount = (Long)createSQLQuery(countQueryString, values)
.addScalar("totalCount", Hibernate.LONG)
.uniqueResult();
if (totalCount < 1) return new Page();
// 实际查询返回分页对象
int startIndex = Page.getStartOfPage(pageNo, pageSize);
Query query = createSQLQuery(sql, values);
List list = query.setFirstResult(startIndex).setMaxResults(pageSize).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
Page page = new Page(startIndex, totalCount, pageSize, list);
return page;
}
public List executeSQL(String sql,Class entity) throws Exception {
Assert.hasText(sql);
Query query = createSQLQuery(sql).addEntity(entity);

View File

@@ -0,0 +1,249 @@
package nis.nms.web.actions.detection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.hibernate.SQLQuery;
import com.nis.util.StringUtil;
import nis.nms.service.CommonService;
import nis.nms.util.BaseAction;
import nis.nms.util.Constant;
import nis.nms.util.Page;
@Results({
@Result(name = "inlineInfoList", value = "/page/detection/monitorData/inlineInfoList.jsp")
})
@SuppressWarnings("all")
public class InlineDeviceAction extends BaseAction{
private static final Logger logger = Logger.getLogger(InlineDeviceAction.class);
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final long serialVersionUID = 1L;
private CommonService commonService;
private int pageNo = 1;
private int pageSize = this.getDefaultPageSize(); // 每页显示的记录条数
private Page page;
private String action;
private String nodeIp;//查询条件节点ip
private String addrCode; //查询条件:地域编码
private String ispKeyCode;//查询条件:运营商唯一标识
@Override
public String executeAction() throws Exception {
String result = "inlineInfoList";
//查询运营商等信息
if("query".equalsIgnoreCase(this.action)) {
result = inlineInfoList();
}
return result;
}
/**
* 查询 串联设备运营商等信息
* @return
* @throws Exception
*/
public String inlineInfoList() throws Exception {
Long systemID = this.getSystemID();//当前登录的 视图 id
//运营商信息
String sql = "select * from sys_isp_info order by id";
List ispList = commonService.executeSQLMap(sql);
this.getRequest().setAttribute("ispList", ispList);
//地域信息
sql = "select * from sys_addr_info order by id";
List addrList = commonService.executeSQLMap(sql);
this.getRequest().setAttribute("addrList", addrList);
StringBuilder sbSql = new StringBuilder();
sql = "SELECT " +
" sdi.*, sii.isp_key_name, sai.addr_name, nt.* " +
" FROM " +
" sys_device_info sdi " +
" LEFT JOIN sys_isp_info sii ON sdi.isp = sii.isp_key_code " +
" LEFT JOIN sys_addr_info sai ON sdi.entrance_id = sai.addr_code " +
" LEFT JOIN ( SELECT node_ip, seq_id FROM node_table GROUP BY node_ip ) nt ON nt.node_ip = sdi.ip_addr " +
"where sdi.status != 0 ";
sbSql.append(sql);
if(systemID != -1) {
sbSql.append(" and sdi.system_id = ").append(systemID);
}
if(!StringUtil.isBlank(nodeIp)) {
sbSql.append(" and sdi.ip_addr like '%").append(nodeIp).append("%' ");
}
if(!StringUtil.isBlank(addrCode)) {
sbSql.append(" and sdi.entrance_id = ").append(addrCode);
}
if(!StringUtil.isBlank(ispKeyCode)) {
sbSql.append(" and sdi.isp = ").append(ispKeyCode);
}
sbSql.append(" order by sdi.ip_addr,sdi.link_id");
Page devicePage = commonService.findByPageForSqlMap(sbSql.toString(), pageNo, pageSize);
//List<Map<String,Object>> deviceList = commonService.executeSQLMap();
//查询所有的 串联设备 bypass 状态
sql = "SELECT " +
" dp.* " +
"FROM " +
" di_propmstatus dp " +
" LEFT JOIN detection_info_new din ON dp.detection_info_id = din.DETECTION_INFO_ID " +
" LEFT JOIN node_table nt ON nt.seq_id = din.SEQ_ID " +
"WHERE " +
" nt.network_element_type = 1 " +
" AND node_type = 1 " +
" AND node_state = 0 " ;
sbSql.setLength(0);
sbSql.append(sql);
if(systemID != -1) {
sbSql.append(" and nt.system_id = ").append(systemID);
}
List<Map<String,Object>> byPassList = commonService.executeSQLMap(sbSql.toString());
Map<String,Map<String,Object>> byPassMap = new HashMap<String, Map<String,Object>>(byPassList.size());
for(Map<String,Object> map : byPassList) {
String seqId = map.get("SEQ_ID")+"";
String status = map.get("propmStatus")+"";
String index = map.get("popmIndex")+"";
byPassMap.put(seqId+index, map);
}
//查询所有的串联设备的 端口数据
sql = "SELECT " +
" dp.* " +
"FROM " +
" di_switchport dp " +
" LEFT JOIN detection_info_new din ON dp.detection_info_id = din.DETECTION_INFO_ID " +
" LEFT JOIN node_table nt ON nt.seq_id = din.SEQ_ID " +
"WHERE " +
" nt.network_element_type = 1 " +
" AND node_type = 1 " +
" AND node_state = 0 " ;
sbSql.setLength(0);
sbSql.append(sql);
if(systemID != -1) {
sbSql.append(" and nt.system_id = ").append(systemID);
}
List<Map<String,Object>> portList = commonService.executeSQLMap(sbSql.toString());
Map<String,Map<String,Object>> portMap = new HashMap<String, Map<String,Object>>(byPassList.size());
for(Map<String,Object> map : portList) {
String seqId = map.get("SEQ_ID")+"";
String ifdescr = map.get("IFDESCR")+"";
portMap.put(seqId+ifdescr, map);
}
List<Map<String,Object>> deviceList = (List<Map<String,Object>>)devicePage.getResult();
for(Map<String,Object> device : deviceList) {
String seqId = device.get("seq_id")+"";
String linkIndex = device.get("link_id")+"";
String portName = device.get("port_name")+"";
Map<String, Object> map = byPassMap.get(seqId+linkIndex);
if(map != null) {
String s = map.get("propmStatus")+"";
s = (s == null ? "No Data": (s.equals("1") ? "pass" : "bypass"));
device.put("propmStatus", s);
}
if(!StringUtil.isBlank(portName)) {
String[] portArr = portName.split(",");
long inoctetsspeed = 0l;//输入
long inpktsspeed = 0l;//输入包速率
String checkTime = null;
for(String port : portArr) {
Map<String, Object> p = portMap.get(seqId+ port);
if(p != null) {
Object inOct = p.get("INOCTETSSPEED");
Object inPac = p.get("INPKTSSPEED");
if(inOct != null) {
inoctetsspeed += Long.valueOf(inOct+"");
}
if(inPac != null) {
inpktsspeed += Long.valueOf(inPac+"");
}
if(checkTime == null) {
checkTime = p.get("DATA_CHECK_TIME_DIGITAL") +"";
Date date = new Date(Long.valueOf(checkTime));
checkTime = sdf.format(date);
}
}
}
device.put("INOCTETSSPEED", String.format("%.2f", inoctetsspeed/1024.0/1024.0) +" Mbps");
device.put("INPKTSSPEED", inpktsspeed +" pps");
device.put("DATA_CHECK_TIME",checkTime);
}
}
this.getRequest().setAttribute("page", devicePage);
return "inlineInfoList";
}
public CommonService getCommonService() {
return commonService;
}
public void setCommonService(CommonService commonService) {
this.commonService = commonService;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getNodeIp() {
return nodeIp;
}
public void setNodeIp(String nodeIp) {
this.nodeIp = nodeIp;
}
public String getAddrCode() {
return addrCode;
}
public void setAddrCode(String addrCode) {
this.addrCode = addrCode;
}
public String getIspKeyCode() {
return ispKeyCode;
}
public void setIspKeyCode(String ispKeyCode) {
this.ispKeyCode = ispKeyCode;
}
}

View File

@@ -860,10 +860,9 @@ public class SwitchDetectionAction extends BaseAction {
si.setIfAdminStatus(objs[6] == null ? null : ((BigDecimal) objs[6]).intValue());
si.setIfOperStatus(objs[7] == null ? null : ((BigDecimal) objs[7]).intValue());
// si.setIfLastChange(objs[8]==null?null:Long.parseLong((String)objs[8]));
si.setIfInOctets(objs[9] == null ? null : ((BigDecimal) objs[9]).doubleValue());
si.setIfInUcastPkts(objs[10] == null ? null : ((BigDecimal) objs[10]).doubleValue());
si.setIfInNUcastPkts(objs[11] == null ? null : ((BigDecimal) objs[11]).doubleValue());
si.setIfInOctets(objs[9] == null ? 0.00d : ((BigDecimal) objs[9]).doubleValue());
si.setIfInUcastPkts(objs[10] == null ? 0.00d : ((BigDecimal) objs[10]).doubleValue());
si.setIfInNUcastPkts(objs[11] == null ? 0.00d : ((BigDecimal) objs[11]).doubleValue());
// logger.debug((objs[10]==null?null:((BigDecimal)objs[10]).doubleValue())+"
// vs
// "+(objs[11]==null?null:((BigDecimal)objs[11]).doubleValue()));
@@ -871,7 +870,7 @@ public class SwitchDetectionAction extends BaseAction {
si.setIfInErrors(objs[13] == null ? null : ((BigDecimal) objs[13]).doubleValue());
si.setIfInUnknownProtos(objs[14] == null ? null : ((BigDecimal) objs[14]).doubleValue());
si.setIfOutOctets(objs[15] == null ? null : ((BigDecimal) objs[15]).doubleValue());
si.setIfOutOctets(objs[15] == null ? 0.00d : ((BigDecimal) objs[15]).doubleValue());
si.setIfOutUcastPkts(objs[16] == null ? null : ((BigDecimal) objs[16]).doubleValue());
si.setIfOutNUcastPkts(objs[17] == null ? null : ((BigDecimal) objs[17]).doubleValue());
@@ -1050,8 +1049,7 @@ public class SwitchDetectionAction extends BaseAction {
portInfo.setIfInNUcastPkts(news.getIfInNUcastPkts() == null ? 0 : news.getIfInNUcastPkts().longValue());
portInfo.setIfInDiscards(news.getIfInDiscards() == null ? 0 : news.getIfInDiscards().longValue());
portInfo.setIfInErrors(news.getIfInErrors() == null ? 0 : news.getIfInErrors().longValue());
portInfo.setIfInUnknownProtos(
news.getIfInUnknownProtos() == null ? 0 : news.getIfInUnknownProtos().longValue());
portInfo.setIfInUnknownProtos(news.getIfInUnknownProtos() == null ? 0 : news.getIfInUnknownProtos().longValue());
portInfo.setIfOutOctets(news.getIfOutOctets() == null ? 0 : news.getIfOutOctets().longValue());
portInfo.setIfOutUcastPkts(news.getIfOutUcastPkts() == null ? 0 : news.getIfOutUcastPkts().longValue());
portInfo.setIfOutNUcastPkts(news.getIfOutNUcastPkts() == null ? 0 : news.getIfOutNUcastPkts().longValue());
@@ -1208,8 +1206,7 @@ public class SwitchDetectionAction extends BaseAction {
}
double dOutPks = oupks + onupks;
BigDecimal outPksSpeed = new BigDecimal(dOutPks * 1000).divide(new BigDecimal(waitTime), 2,
RoundingMode.HALF_UP);
BigDecimal outPksSpeed = new BigDecimal(dOutPks * 1000).divide(new BigDecimal(waitTime), 2,RoundingMode.HALF_UP);
// logger.debug("outdata:>"+"("+ifOutUcastPkts_n+"-"+ifOutUcastPkts_o+")+("+ifOutNucastPkts_n+"-"+ifOutNucastPkts_o+")="+((ifOutUcastPkts_n
// - ifOutUcastPkts_o)+(ifOutNucastPkts_n - ifOutNucastPkts_o))+" /
// timss"+waitTime+" values "+ (new
@@ -1227,7 +1224,7 @@ public class SwitchDetectionAction extends BaseAction {
logger.debug("端口数据计算抛弃数据:输入包速度与输入字节速度计算式:(" + inPksSpeed_a + " * " + minPacketSize + " > "
+ ifinoctetsspeed_a + ")");
logger.debug("端口数据计算抛弃数据-------");
inPksSpeed_a = null;
inPksSpeed_a = 0.0;
}
Double outPksSpeed_a = outPksSpeed.doubleValue(); // --单位pps
@@ -1237,7 +1234,7 @@ public class SwitchDetectionAction extends BaseAction {
logger.debug("端口数据计算抛弃数据:输出包速度与输入字节速度计算式:(" + outPksSpeed_a + " * " + minPacketSize + " > "
+ ifoutoctetsspeed_a + ")");
logger.debug("端口数据计算抛弃数据-------");
outPksSpeed_a = null;
outPksSpeed_a = 0.0;
}
double maxSpeed = (portInfo.getIfHighSpeed() == null || portInfo.getIfHighSpeed().longValue() == 0)
@@ -1251,7 +1248,7 @@ public class SwitchDetectionAction extends BaseAction {
logger.debug("端口数据计算抛弃数据:时间:(" + news.getLastLongTime() + "-" + old.getLastLongTime() + ")");
logger.debug("端口数据计算抛弃数据:输入字节速度和带宽:(" + ifinoctetsspeed_a + " vs " + maxSpeed + ")");
logger.debug("端口数据计算抛弃数据-------");
portInfo.setIfInOctetsSpeed(null);
portInfo.setIfInOctetsSpeed(0.0);
}
// System.out.println(" date "+portInfo.getIfDescr()+"
// "+portInfo.getIfInOctetsSpeed() +" "+ifinoctetsspeed_a);
@@ -1264,7 +1261,7 @@ public class SwitchDetectionAction extends BaseAction {
logger.debug("端口数据计算抛弃数据:时间:(" + news.getLastLongTime() + "-" + old.getLastLongTime() + ")");
logger.debug("端口数据计算抛弃数据:输出字节速度和带宽:(" + ifoutoctetsspeed_a + " vs " + maxSpeed + ")");
logger.debug("端口数据计算抛弃数据-------");
portInfo.setIfOutOctetsSpeed(null);
portInfo.setIfOutOctetsSpeed(0.0);
}
portInfo.setInpktsspeed(inPksSpeed_a);
portInfo.setOutpktsspeed(outPksSpeed_a);