package com.nis.web.controller.dashboard; import java.lang.reflect.Type; import java.net.URISyntaxException; import java.net.URLEncoder; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.http.client.utils.URIBuilder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.beust.jcommander.internal.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.reflect.TypeToken; import com.nis.domain.PageLog; import com.nis.domain.SysDataDictionaryItem; import com.nis.domain.configuration.WebsiteDomainTopic; import com.nis.domain.dashboard.TrafficIpActiveStatistic; import com.nis.util.CodeDicUtils; import com.nis.util.Constants; import com.nis.util.DateUtils; import com.nis.util.DictUtils; import com.nis.util.LogUtils; import com.nis.util.StringUtil; import com.nis.util.excel.ExportExcel; import com.nis.util.httpclient.HttpClientUtil; import com.nis.web.controller.BaseController; import com.nis.web.dao.dashboard.codedic.CodeResult; import antlr.StringUtils; @SuppressWarnings("rawtypes") @Controller @RequestMapping(value = "${adminPath}/dashboard") public class DashboardController extends BaseController{ /** * 跳转到图表界面 * @return */ @RequestMapping(value="logChart") public String logChart(Model model){ // 默认当前时间一小时 Calendar cal = Calendar. getInstance (); cal.setTime(new Date()); String endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); String beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); return "/dashboard/dashBoardIndex"; } /** * 活跃端口 TOP10 */ @RequestMapping(value="portActive") @ResponseBody public List portActive(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_PORT_ACTIVE); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (ArrayList) fromJsonList.get("data"); logger.debug("活跃端口数据"+fromJsonList); return list; } catch (Exception e) { e.printStackTrace(); logger.error("活跃端口数据错误"+e); list.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return list; } /** * 跳转活跃端口详情界面 * @return */ @RequestMapping(value="portActiveChart") @ResponseBody public List portActiveChart(String beginDate,String endDate,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); try { String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_PORTACTIVE_FIVEMINUTE;//+Constants.TRAFFIC_IPACTIVE_ONEHOUR; url=urlAddDate(url, beginDate, endDate); String string = HttpClientUtil.get(url); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); logger.debug("活跃端口从"+beginDate+"到"+endDate+",间隔5分钟数据"+fromJsonList); list = (ArrayList) fromJsonList.get("data"); return list; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); logger.error("活跃端口详情界面数据获取错误"+e); LogUtils.saveLog(request, null, e, null); } return list; } /** * 跳转活跃端口详情界面 * @return */ @RequestMapping(value="portActiveList") public String portActiveList(Model model){ // 默认当前时间一小时 Calendar cal = Calendar. getInstance (); cal.setTime(new Date()); String endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); String beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); return "/dashboard/trafficPortActiveList"; } /** * 活跃IP TOP10 */ @RequestMapping(value="ipActive") @ResponseBody public List ipActive(String beginDate,String endDate,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); try { String url =Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE; url = urlAddDate(url, beginDate, endDate); String string = HttpClientUtil.get(url); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); logger.debug("活跃IP数据"+fromJsonList); list = (ArrayList) fromJsonList.get("data"); return list; } catch (Exception e) { e.printStackTrace(); logger.error("活跃IP错误"+e); list.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return list; } /** * 活跃IP TOP10 一小时 间隔5分钟数据 */ @RequestMapping(value="ipActiveMinuteList") @ResponseBody public List ipActiveMinuteList(String beginDate,String endDate,Integer entranceId,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); try { String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_FIVEMINUTE; url=urlAddDate(url, beginDate, endDate); if(entranceId!=null){ url=url+"&entranceId="+entranceId; } String string = HttpClientUtil.get(url); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); logger.debug("活跃IP1小时,间隔5分钟数据"+fromJsonList); list = (ArrayList) fromJsonList.get("data"); return list; } catch (Exception e) { e.printStackTrace(); logger.error("活跃IP数据获取错误"+e); list.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return list; } /** * 活跃IP详情 * @param request * @param response * @param model * @return */ public static Gson getIntGson() { Gson gson = new GsonBuilder() .registerTypeAdapter( new TypeToken>() { }.getType(), new JsonDeserializer>() { @Override public Map deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Map treeMap = new HashMap(); JsonObject jsonObject = json.getAsJsonObject(); Set> entrySet = jsonObject.entrySet(); for (Map.Entry entry : entrySet) { treeMap.put(entry.getKey(), entry.getValue()); } return treeMap; } }).create(); return gson; } @RequestMapping(value="ipActiveList") public String ipActiveList(@RequestParam(value="beginDate",required=false)String beginDate,@RequestParam(value="endDate",required=false)String endDate,HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes){ try { // 默认当前时间一小时 if(StringUtil.isEmpty(beginDate)||StringUtil.isEmpty(endDate)){ Calendar cal = Calendar. getInstance (); cal.setTime(new Date()); endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); } model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); } catch (Exception e) { e.printStackTrace(); logger.error("活跃IP统计错误"+e); addMessage(redirectAttributes,"error","request_service_failed"); LogUtils.saveLog(request, null, e, null); } return "/dashboard/trafficIpActiveList"; } /** * 活跃IP TOP10 一小时每个IP的最大值 */ @RequestMapping(value="ajaxIpActiveList") @ResponseBody public List ajaxIpActiveList(String beginDate,String endDate,Integer entranceId,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); try { String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_ONEHOUR; url=urlAddDate(url, beginDate, endDate); if(entranceId!=null){ url=url+"&entranceId="+entranceId; } String string = HttpClientUtil.get(url); Gson gson = getIntGson(); fromJsonList = gson.fromJson(string, new TypeToken>(){}.getType()); logger.debug("活跃IP1小时"+fromJsonList); list = gson.fromJson(fromJsonList.get("data").toString(), new TypeToken>() {}.getType()) ; if(list.size()>0) { DecimalFormat lf = new DecimalFormat("0"); DecimalFormat f = new DecimalFormat("0.00"); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //两个时间段之间的秒数 double allSeconds = DateUtils.getSecondsOfTwoDate(sdf.parse(beginDate),sdf.parse(endDate)); for(TrafficIpActiveStatistic data:list) { data.setAvgByte(f.format(Long.parseLong(data.get_byte())*8/1024/1024/1024/allSeconds)); data.setAvgPacket(lf.format(Long.parseLong(data.get_packet())/allSeconds)); } } Collections.sort(list, new Comparator() { @Override public int compare(TrafficIpActiveStatistic o1, TrafficIpActiveStatistic o2) { if(o1==null&&o2!=null){ return 1; } if(o1!=null&&o2==null){ return -1; } if(o1==o2&&o1==null){ return 0; } Long ob1 = o1.getLinkNum(); Long ob2 = o2.getLinkNum(); return -(ob1).compareTo(ob2); } }); } catch (Exception e) { e.printStackTrace(); logger.error("活跃IP数据获取错误"+e); LogUtils.saveLog(request, null, e, null); //list.add(Maps.newHashMap("error","request_service_failed")); } return list; } //IP活跃导出 @RequestMapping(value = "export") public void exportddos(Model model,HttpServletRequest request,HttpServletResponse response, @ModelAttribute("entry")TrafficIpActiveStatistic entity,String ids,String beginDate,String endDate,RedirectAttributes redirectAttributes){ try { //export data info List titleList=new ArrayList(); Map> classMap=new HashMap>(); Map dataMap=new HashMap(); Map noExportMap=new HashMap(); Map fromJsonList = new HashMap(); List ipActiveList = new ArrayList(); String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE_ONEHOUR; if(org.apache.commons.lang3.StringUtils.isNotBlank(beginDate)&&org.apache.commons.lang3.StringUtils.isNotBlank(endDate)) { url=urlAddDate(url, beginDate, endDate); } String string = HttpClientUtil.get(url); Gson gson = getIntGson(); fromJsonList = gson.fromJson(string, new TypeToken>(){}.getType()); ipActiveList = gson.fromJson(fromJsonList.get("data").toString(), new TypeToken>() {}.getType()) ; titleList.add("traffic_ipactive_hour_max"); classMap.put(null, TrafficIpActiveStatistic.class); String cfgIndexInfoNoExport=",id,"; noExportMap.put("traffic_ipactive_hour_max",cfgIndexInfoNoExport); dataMap.put(null, ipActiveList); // 获取国际化配置 Properties msgProp = getMsgProp(); Map map = new HashMap(); String fileName = "IP-Active-Hour-Max" + "-" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx"; new ExportExcel("", TrafficIpActiveStatistic.class, 1).setDataList(msgProp,ipActiveList,new HashMap()) .write(request,response, fileName).dispose(); } catch (Exception e) { e.printStackTrace(); logger.error("IPActive export failed",e); addMessage(redirectAttributes,"error","export_failed"); LogUtils.saveLog(request, null, e, null); } // return "/dashboard/trafficIpActiveList"; } /** * 协议统计 */ @RequestMapping(value="protocol") @ResponseBody public List protocolChart(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_PROTOCOL); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 List codeList = CodeDicUtils.getCodeList("protocolCode"); List appCodeList = CodeDicUtils.getCodeList("appCode"); //将数字替换为标签文字 if(list!=null&&!list.isEmpty()){ for (Map map : list) { Double value1 = Double.parseDouble(map.get("protoType").toString().trim()); for (CodeResult code : codeList) { Double value2 = Double.valueOf(code.getCode().trim()); if(value1.equals(value2)){ map.put("protoType", code.getItem().trim()); break; } } // 协议没匹配的匹配app码表 for (CodeResult code : appCodeList) { Double value3 = Double.valueOf(code.getCode().trim()); if(value1.equals(value3)){ map.put("protoType", code.getItem().trim()); break; } } resultList.add(map); } logger.debug("协议统计"+fromJsonList); return resultList; } } catch (Exception e) { e.printStackTrace(); logger.error("协议统计错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * app流量分析 */ @RequestMapping(value="app") @ResponseBody public List appChart(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_APP); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 List codeList = CodeDicUtils.getCodeList("appCode"); //将数字替换为标签文字 if(list!=null&&!list.isEmpty()){ for (Map map : list) { Double value1 = Double.parseDouble(map.get("appType").toString().trim()); for (CodeResult code : codeList) { Double value2 = Double.valueOf(code.getCode().trim()); if(value1.equals(value2)){ map.put("appType", code.getItem().trim()); break; } } resultList.add(map); } logger.debug("app流量分析"+fromJsonList); return resultList; } } catch (Exception e) { e.printStackTrace(); logger.error("app流量分析错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * 终端用户-操作系统列表 */ @RequestMapping(value="osList") @ResponseBody public List osList(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_OSLIST); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 List codeList = CodeDicUtils.getCodeList("osCode"); //将数字替换为标签文字 if(list!=null&&!list.isEmpty()){ for (Map map : list) { Double value1 = Double.parseDouble(map.get("osType").toString().trim()); for (CodeResult code : codeList) { Double value2 = Double.valueOf(code.getCode().trim()); if(value1.equals(value2)){ map.put("osType", code.getItem().trim()); break; } } resultList.add(map); } logger.debug("终端用户-获取操作系统列表"+fromJsonList); return resultList; } } catch (Exception e) { e.printStackTrace(); logger.error("终端用户-获取操作系统列表错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * 终端用户-指定操作系统下浏览器分类流量统计 */ @RequestMapping(value="browserChart") @ResponseBody public List browserChart(@RequestParam("osType") String osType,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); //标签集合 List codeList1 = CodeDicUtils.getCodeList("osCode"); //将标签文字转为数字 Integer os=null; for (CodeResult codeResult : codeList1) { if(osType.equalsIgnoreCase(codeResult.getItem().trim())){ os=Integer.parseInt(codeResult.getCode().trim()); break; } } if(os==null){ os=Integer.parseInt(osType);//处理为匹配项编码 } try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_BROWSER_CHART+"?osType="+os); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 List codeList2 = CodeDicUtils.getCodeList("browserCode"); //将数字替换为标签文字 if(null!=list&&!list.isEmpty()){ for (Map map : list) { Double value1 = Double.parseDouble(map.get("bsType").toString().trim()); for (CodeResult code : codeList2) { Double value2 = Double.valueOf(code.getCode().trim()); if(value1.equals(value2)){ map.put("bsType", code.getItem().trim()); break; } //10个域名之外的为others 设为-1外 if(map.get("bsType").toString().equals("-1")){ map.put("bsType", "Others"); break; } } resultList.add(map); } } logger.debug("终端用户-获取操作系统下浏览器类型"+fromJsonList); return resultList; } catch (Exception e) { e.printStackTrace(); logger.error("终端用户-获取操作系统下浏览器类型错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * 终端用户-浏览器列表 */ @RequestMapping(value="bsList") @ResponseBody public List bsList(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_BSLISTL); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 List codeList = CodeDicUtils.getCodeList("browserCode"); //将数字替换为标签文字 if(list!=null&&!list.isEmpty()){ for (Map map : list) { Double value1 = Double.parseDouble(map.get("bsType").toString().trim()); for (CodeResult code : codeList) { Double value2 = Double.valueOf(code.getCode().trim()); if(value1.equals(value2)){ map.put("bsType", code.getItem().trim()); break; } } resultList.add(map); } } logger.debug("终端用户-获取浏览器列表"+fromJsonList); return resultList; } catch (Exception e) { e.printStackTrace(); logger.error("终端用户-获取浏览器列表错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * 终端用户-指定操作系统下浏览器分类流量统计 */ @RequestMapping(value="systemChart") @ResponseBody public List systemChart(@RequestParam("bsType") String bsType,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); //标签集合 List codeList1 = CodeDicUtils.getCodeList("browserCode"); //将标签文字转为数字 Integer bs=null; for (CodeResult codeResult : codeList1) { if(bsType.equalsIgnoreCase(codeResult.getItem().trim())){ bs=Integer.parseInt(codeResult.getCode().trim()); break; } } if(bs==null){ bs=Integer.parseInt(bsType.trim());//处理为匹配项编码 } try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_SYSTEM_CHART+"?bsType="+bs); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 List codeList2 = CodeDicUtils.getCodeList("osCode"); //将数字替换为标签文字 if(null!=list&&!list.isEmpty()){ for (Map map : list) { Double value1 = Double.parseDouble(map.get("osType").toString().trim()); for (CodeResult code : codeList2) { Double value2 = Double.valueOf(code.getCode().trim()); //10个域名之外的为others webId设为-1外 if(map.get("osType").toString().equals("-1")){ map.put("osType", "Others"); break; } if(value1.equals(value2)){ map.put("osType", code.getItem().trim()); break; } } resultList.add(map); } } logger.debug("终端用户-获取浏览器下操作系统类型"+fromJsonList); return resultList; } catch (Exception e) { e.printStackTrace(); logger.error("终端用户-获取浏览器下操作系统类型错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * http网站统计 */ @RequestMapping(value="websiteList") @ResponseBody public List websiteList(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_WEBSITELIST); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 // List codeList = CodeDicUtils.getCodeList("webCode"); List codeList = DictUtils.getDictList("WEBSITE_SERVER");//网站名 //将数字替换为标签文字 if(list!=null&&!list.isEmpty()){ for (Map map : list) { Double value1=0d; if(StringUtil.isBlank(map.get("websiteServiceId").toString().trim())){ value1=268435455d; }else{ value1 = Double.parseDouble(map.get("websiteServiceId").toString().trim()); } for (SysDataDictionaryItem code : codeList) { Double value2 = Double.valueOf(code.getItemCode().trim()); if(value1.equals(value2)){ map.put("websiteService", code.getItemValue().trim()); break; } } resultList.add(map); } } logger.debug("http网站流量分析数据:"+fromJsonList); return resultList; } catch (Exception e) { e.printStackTrace(); logger.error("http网站流量分析数据错误:"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * http网站-某个网站的子域名统计 */ @RequestMapping(value="webTypeChart") @ResponseBody public List webTypeChart(@RequestParam("websiteServiceId") String websiteServiceId,HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_WEBTYPECHART+"?websiteServiceId="+websiteServiceId); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); //标签集合 // List codeList2 = CodeDicUtils.getCodeList("webCode");//网站子域名表获取域名domain List domainList = appCfgService.getDomainDict(new WebsiteDomainTopic());// domain 域名 if(list!=null&&list.size()>0&&domainList!=null&&domainList.size()>0){ for (Map dataMap : list) { for (WebsiteDomainTopic wdt : domainList) { // Map map = Maps.newHashMap(); if(wdt!=null){ String domain = wdt.getDomain(); Double domainId = wdt.getId().doubleValue(); Double webId = Double.parseDouble(dataMap.get("webId").toString().trim()); //10个域名之外的为others webId设为-1外 if(dataMap.get("webId").toString().equals("-1")){ dataMap.put("domain", "Others"); break; } if(domainId.equals(webId)){ dataMap.put("domain", domain); break; } } } resultList.add(dataMap); } } logger.debug("http某个网站子域名流量统计"+fromJsonList); return resultList; } catch (Exception e) { e.printStackTrace(); logger.error("http某个网站子域名流量统计错误"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * http网站主题跟域名统计 */ @RequestMapping(value="topicAndDomainList") @ResponseBody public List topicAndDomainList(HttpServletRequest request){ Map fromJsonList = new HashMap(); List list = new ArrayList(); List resultList = new ArrayList(); try { String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_TOPIC_AND_DOMAIN_CHART); Gson gson = new GsonBuilder().create(); fromJsonList = gson.fromJson(string, new TypeToken(){}.getType()); list = (List) fromJsonList.get("data"); List codeList = DictUtils.getDictList("TOPIC"); //将数字替换为标签文字 List domainList = appCfgService.getDomainDict(new WebsiteDomainTopic()); if(list!=null&&!list.isEmpty()){ for (Map map : list) { Double value1=0d; if(StringUtil.isBlank(map.get("topicId").toString())){ value1=268435455d; }else{ value1 = Double.parseDouble(map.get("topicId").toString().trim()); } for (SysDataDictionaryItem code : codeList) { Double value2 = Double.valueOf(code.getItemCode().trim()); if(value1.equals(value2)){ map.put("topic", code.getItemValue().trim()); break; } } //将domain添加名称 List dataDomainList = (List)map.get("domainData"); if(dataDomainList!=null&&dataDomainList.size()>0&&domainList!=null&&domainList.size()>0){ for (WebsiteDomainTopic wdt : domainList) { for (Map dataMap : dataDomainList) { if(wdt!=null){ String domain = wdt.getDomain(); Double domainId = wdt.getId().doubleValue(); Double webId = Double.parseDouble(dataMap.get("webId").toString().trim()); //10个域名之外的为others webId设为-1 // if(dataMap.get("webId").toString().equals("-1")){ // dataMap.put("domain", "Others"); // break; // } if(domainId.equals(webId)){ dataMap.put("domain", domain); break; } } } } } resultList.add(map); } } logger.debug("http网站主题流量分析数据:"+fromJsonList); return resultList; } catch (Exception e) { e.printStackTrace(); logger.error("http网站主题流量分析数据错误:"+e); resultList.add(Maps.newHashMap("error","request_service_failed")); LogUtils.saveLog(request, null, e, null); } return resultList; } /** * * * url路径时间参数格式化 * @param url * @param beginDate * @param endDate * @return * @throws URISyntaxException */ public String urlAddDate(String url,String beginDate,String endDate) throws URISyntaxException{ if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){ Calendar cal = Calendar. getInstance (); cal.setTime(new Date()); endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); } URIBuilder uriBuilder = new URIBuilder(url); uriBuilder.addParameter("beginDate",beginDate); uriBuilder.addParameter("endDate",endDate); return uriBuilder.toString(); } @RequestMapping(value="httpStatisticList") public String httpStatisticList( HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes){ Calendar cal = Calendar. getInstance (); cal.setTime(new Date()); String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); model.addAttribute("beginDate", oneHoursAgo); model.addAttribute("endDate", now); return "/dashboard/trafficHttpStatisticList"; } }