package com.nis.web.service.restful; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.nis.domain.Page; import com.nis.domain.restful.dashboard.TrafficHttpStatistic; import com.nis.domain.restful.dashboard.TrafficIpActiveStatistic; import com.nis.domain.restful.dashboard.TrafficPortActiveStatistic; import com.nis.domain.restful.dashboard.TrafficUaStatistic; import com.nis.web.dao.dashboard.NtcTotalReportDao; import com.nis.web.dao.dashboard.TrafficAppStatisticDao; import com.nis.web.dao.dashboard.TrafficHttpStatisticDao; import com.nis.web.dao.dashboard.TrafficIpActiveStatisticDao; import com.nis.web.dao.dashboard.TrafficPortActiveStatisticDao; import com.nis.web.dao.dashboard.TrafficProtocolStatisticDao; import com.nis.web.dao.dashboard.TrafficUaStatisticDao; import com.nis.web.service.BaseService; @Service public class DashboardService extends BaseService{ @Autowired public TrafficIpActiveStatisticDao trafficIpActiveStatisticDao; @Autowired public TrafficProtocolStatisticDao trafficProtocolStatisticDao; @Autowired public TrafficAppStatisticDao trafficAppStatisticDao; @Autowired public TrafficUaStatisticDao trafficUaStatisticDao; @Autowired public TrafficHttpStatisticDao trafficHttpStatisticDao; @Autowired public NtcTotalReportDao ntcTotalReportDao; @Autowired public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao; /** * 流量统计 数据显示 * @return Map */ public List getTotalReportList(){ List totalReportList = ntcTotalReportDao.getTotalReportList(); //统计带宽的流入流出 单位 五分钟 的 byte List newData = ntcTotalReportDao.getNetFlowPortInfoNew(); List oldData = ntcTotalReportDao.getNetFlowPortInfoOld(); Double inoctets=0d; Double outoctets=0d; if(newData!=null&&newData.size()>0&&oldData!=null&&oldData.size()>0&&newData.get(0)!=null&&oldData.get(0)!=null){ Double newInoctets=Double.parseDouble(newData.get(0).get("inoctets").toString()) ; Double newOutoctets=Double.parseDouble(newData.get(0).get("outoctets").toString()) ; Double oldInoctets=Double.parseDouble(oldData.get(0).get("inoctets").toString()); Double oldOutoctets=Double.parseDouble(oldData.get(0).get("outoctets").toString()); //结果为当前五分钟减去上个五分钟 inoctets=newInoctets-oldInoctets; outoctets=newOutoctets-oldOutoctets; if(inoctets<0||outoctets<0){ inoctets=0d; outoctets=0d; } } if(totalReportList!=null&&totalReportList.size()>0){ for (Map map : totalReportList) { map.put("inoctets", inoctets); map.put("outoctets", outoctets); } } return totalReportList; } /** * 当前时间五分钟数据 * @return */ public List getPortActiveList(){ List list = new ArrayList(); List portActiveList = trafficPortActiveStatisticDao.getPortActiveList(); //上个时间五分钟数据 if(portActiveList!=null&&portActiveList.size()>0) { for (TrafficPortActiveStatistic port : portActiveList) { if(port.getPort()!=null) { Map map = new HashMap(); map.put("port", port.getPort()); map.put("sum", port.getSum()); TrafficPortActiveStatistic portActiveOld = trafficPortActiveStatisticDao.getPortActiveOld(port.getPort()); if(portActiveOld!=null&&portActiveOld.getSum()!=null){ map.put("preSum",portActiveOld.getSum()); }else{ map.put("preSum",0); } list.add(map); } } } return list; } /** * 分页查询活跃IPtop100 * @return */ public Page getIpList(Page page,TrafficIpActiveStatistic entry){ // 设置分页参数 entry.setPage(page); // 执行分页查询 page.setList(trafficIpActiveStatisticDao.getIpList(entry)); return page; } public List ipActiveFiveMinute(){ ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(); ArrayList listMap=new ArrayList(); if(list!=null&&list.size()>0) { for (LinkedHashMap map : list) { HashMap m = new HashMap(); if(map.get("ipAddr")!=null) { String ipAddr = (String) map.get("ipAddr"); m.put("ipAddr", ipAddr); ArrayList ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipAddr); List linkList = new ArrayList(); List timeList = new ArrayList(); if(ipList!=null&&ipList.size()>0) { for (TrafficIpActiveStatistic ip : ipList) { if(ip.getLinkNum()!=null&&ip.getTime()!=null) { linkList.add(ip.getLinkNum()); timeList.add(ip.getTime()); } } } m.put("linkNum",linkList); m.put("statTime",timeList); listMap.add(m); } } } return listMap; } public List ipActiveOneHour(){ ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(); ArrayList listMap=new ArrayList(); if(list!=null&&list.size()>0) { for (LinkedHashMap map : list) { if(map.get("ipAddr")!=null) { String ipAddr = (String) map.get("ipAddr"); ArrayList iplList = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr); listMap.add(iplList.get(0)); } } } return listMap; } public List ipActiveChart(){ ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(); return list; } public List protocolChart() { List list = trafficProtocolStatisticDao.protocolChart(); return list; } public List appChart() { List list = trafficAppStatisticDao.appChart(); return list; } // 操作系统列表 排名TOP10 @SuppressWarnings({ "unchecked", "rawtypes" }) public List systemList(){ List result = new ArrayList(); List list = trafficUaStatisticDao.systemList(); Integer preCount=0; for (TrafficUaStatistic ua : list) { Map map = new HashMap(); map.put("osType",ua.getOsType()); map.put("count",ua.getCount()); map.put("pktNum",ua.getPktNum()); map.put("byteLen",ua.getByteLen()); preCount = trafficUaStatisticDao.preSystemListCount(ua.getOsType());//上个时段的量 用于与现在对比 if(preCount!=null){ map.put("preCount",preCount); }else{ map.put("preCount",0); } result.add(map); } return result; } public List getBrowserBySystem(Integer osType ){ List list = trafficUaStatisticDao.getBrowserBySystem(osType); List bsType = new ArrayList(); //查新固定操系统下的除了TOP10以外的others if(list!=null&& list.size()>0){ for (Map map : list) { bsType.add(map.get("bsType")); } Map others = new HashMap(); others = trafficUaStatisticDao.systemOthers(bsType,osType); if(others!=null&&others.size()>0){ others.put("bsType", "-1"); list.add(others); } } return list; } public List browserList() { List result = new ArrayList(); List list = trafficUaStatisticDao.browserList(); Integer preCount=0; if(list!=null&&list.size()>0){ for (TrafficUaStatistic ua : list) { Map map = new HashMap(); map.put("bsType",ua.getBsType()); map.put("count",ua.getCount()); map.put("pktNum",ua.getPktNum()); map.put("byteLen",ua.getByteLen()); preCount = trafficUaStatisticDao.preBrowserListCount(ua.getBsType());//上个时段的量 用于与现在对比 if(preCount!=null){ map.put("preCount",preCount); }else{ map.put("preCount",0); } result.add(map); } } return result; } public List getSystemBybrowser(Integer bsType ){ List list = trafficUaStatisticDao.getSystemBybrowser(bsType); List osType = new ArrayList(); //查询固定操系统下的除了TOP10以外的others if(list!=null&& list.size()>0){ for (Map map : list) { osType.add(map.get("osType")); } Map others = new HashMap(); others = trafficUaStatisticDao.browserOthers(osType,bsType); if(others!=null&&others.size()>0){ others.put("osType", "-1"); list.add(others); } } return list; } public List websiteList() { List result = new ArrayList(); List list = trafficHttpStatisticDao.websiteList(); Integer preCount=0; if(list!=null&&list.size()>0){ for (TrafficHttpStatistic website : list) { Map map = new HashMap(); map.put("webId",website.getWebId()); map.put("count",website.getCount()); map.put("pktNum",website.getPktNum()); map.put("byteLen",website.getByteLen()); preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWebId());//上个时段的量 用于与现在对比 if(preCount!=null){ map.put("preCount",preCount); }else{ map.put("preCount",0); } result.add(map); } } return result; } /** * 根据网站服务查询子域名 * @param websiteServiceId * @return list */ public List getDomainByWebsiteServiceId(Integer websiteServiceId ){ List list = trafficHttpStatisticDao.getDomainByWebsiteServiceId(websiteServiceId); List webIdList = new ArrayList(); //查询固定网站下的域名除了TOP10以外的others域名 if(list!=null&& list.size()>0){ for (Map map : list) { webIdList.add(map.get("webId")); } Map others = new HashMap(); others = trafficHttpStatisticDao.websiteDomainOthers(webIdList,websiteServiceId); if(others!=null&&others.size()>0){ others.put("webId", "-1"); list.add(others); } } return list; } /** 获取网站列表 * @return */ @SuppressWarnings("unchecked") public List getDomainByWebsiteList(){ List websiteList = trafficHttpStatisticDao.getDomainByWebsiteList(); List result = new ArrayList(); if(websiteList!=null&&websiteList.size()>0){ Integer preCount=0; for (TrafficHttpStatistic website : websiteList) { Map map = new HashMap(); map.put("websiteServiceId",website.getWesiteServiceId()); map.put("count",website.getCount()); map.put("pktNum",website.getPktNum()); map.put("byteLen",website.getByteLen()); preCount = trafficHttpStatisticDao.preWebsiteListCount(website.getWesiteServiceId());//上个时段的量 用于与现在对比 if(preCount!=null){ map.put("preCount",preCount); }else{ map.put("preCount",0); } result.add(map); } } return result; } /** *主题网站分类,域名 * * **/ public List getTopicAndDomainList(){ //按照主题分类 获得主题 List topicList = trafficHttpStatisticDao.getDomainByTopicList(); if(topicList!=null&&topicList.size()>0){ for (Map m : topicList) { List domainList= new ArrayList(); if(m!=null&&m.get("topicId")!=null){ domainList = trafficHttpStatisticDao.getDomainByTopicId(m.get("topicId")); m.put("domainData", domainList); } } } return topicList; } }