<%@page import="java.util.Map.Entry"%> <%@page import="java.util.Comparator"%> <%@page import="java.util.Collections"%> <%@page import="java.util.List"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.HashMap"%> <%@page import="java.util.Map"%> <%@page import="com.hanweb.jcms.dao.WebSearchInfoDAO"%> <%@page import="com.hanweb.jcms.service.info.SearchInfoBLF"%> <%@page import="java.text.DecimalFormat"%> <%@page import="com.hanweb.common.util.StringUtil"%> <%@page import="java.util.Calendar"%> <%@page import="java.util.Date"%> <%@page import="com.hanweb.jcms.service.performance.StatSourceBLF"%> <%@page import="com.hanweb.jcms.entity.Jcms_InfoEntity"%> <%@page import="com.hanweb.jcms.service.info.Jcms_InfoBLF"%> <%@page import="com.hanweb.common.util.NumberUtil"%> <%@page import="com.hanweb.common.basedao.Query"%> <%@page import="com.hanweb.jcms.dao.InfoDAO"%> <%@page import="com.hanweb.common.util.SpringUtil"%> <%@ include file="config.jsp"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String style = " "; out.print(style); int type = NumberUtil.getInt(request.getParameter("type")); //type 0:取当月数据 1:取当年数据 int webid = NumberUtil.getInt(strWebID); //System.out.println("webid="+webid); Calendar now = Calendar.getInstance(); int year = 0; int month = 0; //获取当前年 year = now.get(Calendar.YEAR); //获取当前月 month = now.get(Calendar.MONTH) + 1; //System.out.println("年份="+ year +"年 月份="+ month+"月"); //month = 2; String starttime = ""; String endtime = ""; String month1 = ""; String month2 = ""; if (month < 12) { month1 = new DecimalFormat("00").format(NumberUtil .getInt(month));//本月 month2 = new DecimalFormat("00").format(NumberUtil .getInt(month + 1));//下月 } else { month1 = "12"; month2 = "01"; } //System.out.println("month1="+month1); //System.out.println("month2="+month2); //根据type取数据 如果没有type参数默认取当月数据 if (type == 0) { starttime = year + "-" + month1 + "-01"; if (month < 12) { endtime = year + "-" + month2 + "-01"; } else { endtime = StringUtil.getString(year + 1) + "-" + month2 + "-01"; } } else { starttime = StringUtil.getString(year); endtime = StringUtil.getString(year + 1); } //System.out.println("开始时间="+ starttime +" 结束时间="+ endtime); StatSourceBLF sourceBLF = SpringUtil.getBean(StatSourceBLF.class); String strShow = this.getShow(starttime, endtime, 0, 1, "i_incount", strAppID, webid); out.println(strShow); %> <%!public String getShow(String begintime, String endtime, int cataid, int scope, String orderField, String strAppID, int webid) { StringBuffer strReturn = new StringBuffer(); if (scope == 1) { //来源 String[][] luruData = findStatData(webid, strAppID, begintime, endtime, cataid, 0); String[][] caiyData = findStatData(webid, strAppID, begintime, endtime, cataid, 1); //by dzj: 江苏省政府定制,如果是地矿局的网站,则对来源进行拆分统计数目,后改为所有网站都这样 //if (webid == 20) { //地矿局的网站,webid=20 //将来源分词统计数目 List> result = divideSrcStat(caiyData); if (result != null && result.size() > 0) { //遍历 for (int i = 0; i < result.size(); i++) { Map.Entry anEntry = result.get(i); if(anEntry == null){ continue; } if ("i_incount".equals(orderField)) { if("互联网".equals(anEntry.getKey())){ continue; } strReturn.append("
  • "+anEntry.getKey()+": "+anEntry.getValue()+"篇   
  • "); } } } //添加表格头尾,不需要,外侧已经有 //strReturn = appendTableHeaderFooter(strReturn); } if (StringUtil.isEmpty(strReturn.toString())) { strReturn .append("
    \n"); strReturn .append("
    󵀻 无记录
    "); } return strReturn.toString(); } private String[][] findStatData(int nWebId, String strAppID, String begintime, String endtime, int cataid, int publish) { SearchInfoBLF searchInfoBLF = SpringUtil.getBean(SearchInfoBLF.class); WebSearchInfoDAO webSearchInfoDAO = SpringUtil .getBean(WebSearchInfoDAO.class); String tableName = searchInfoBLF.getTableName(nWebId); return webSearchInfoDAO.findSourceForjsp(begintime, endtime, cataid, publish, tableName); } private String getCaiyNum(String[][] caiyData, String luruName) { String caiyName = ""; for (int i = 0, len = caiyData == null ? 0 : caiyData.length; i < len; i++) { caiyName = StringUtil.getString(caiyData[i][0]).trim(); if (caiyName.equals(StringUtil.getString(luruName).trim())) { return caiyData[i][1]; } } return "0"; } private String getSourceName(String name) { if (name == null || "".equals(name.trim())) { return "无来源"; } return name; } //对来源进行分词统计数量并按照来源多少降序排序 private List> divideSrcStat(String[][] in) { if (in == null || in.length <= 0) { return null; } HashMap hashmap = new HashMap(); for (String[] one : in) { String temp = one[0]; if (StringUtil.isEmpty(temp)) { continue; } String[] splitArr = temp.split(" ");//分隔符为" " if (splitArr == null || splitArr.length <= 0) { continue; } for (String word : splitArr) { //为null或空串的不统计 if (StringUtil.isEmpty(word)) { continue; } int artNum = NumberUtil.getInt(one[1]); if (hashmap.containsKey(word)) { hashmap.put(word, hashmap.get(word) + artNum); } else { hashmap.put(word, artNum); } } } if (hashmap == null || hashmap.size() <= 0) { return null; } //统计完词频按照value大小排序 List> list = new ArrayList>( hashmap.entrySet()); Collections.sort(list, new Comparator>() { @Override public int compare(Map.Entry o1, Map.Entry o2) { //按value(此处即文章数)升序排列 return o2.getValue().compareTo(o1.getValue()); } }); return list; } //附上表头表尾 private StringBuffer appendTableHeaderFooter(StringBuffer in) { StringBuffer temp = new StringBuffer(); temp.append("头"); in.insert(0, temp.toString()); in.append("尾"); return in; }%>