public List getMessageCount(String agentId,Date detectingTime,Date endTime) {
StringBuffer sbf = new StringBuffer();
sbf.append("select targetAddress,sourceaddress, count(targetAddress) from VpnRecord where 1=1");
String sf = "";
if(agentId != null && !"".equals(agentId)){
sf = " and agentid='"+ agentId+"'";
}
if(detectingTime != null && endTime != null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String start = sdf.format(detectingTime);
String end = sdf.format(endTime);
sf += " and detectingTime >='" + start + "' and endTime <= '" + end + "'";
}
if(detectingTime == null && endTime != null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String end = sdf.format(endTime);
sf += " and endTime <= '" + end + "'";
}
sbf.append(sf+" group by targetAddress ,sourceaddress");
List ls=this.getSession().createSQLQuery(sbf.toString()).list();
ArrayList list = new ArrayList();
int i = 0;
for(Object[] rows : ls){
i++;
String queryHql = "from VpnRecord where targetaddress='"+ rows[0]+"' and sourceaddress = '"+rows[1]+"'" + sf;
Query queryObject2 = this.getSession().createQuery(queryHql);
queryObject2.setFirstResult(0);
queryObject2.setMaxResults(10);
List list3=queryObject2.list();
VpnTemporary vpn = new VpnTemporary();
vpn.setId(i);
vpn.setTargetAddress(rows[0].toString());
vpn.setSourceAddress(rows[1].toString());
vpn.setMessageCount(Integer.parseInt(rows[2].toString()));
vpn.setList2(list3);
list.add(vpn);
log.info("target 值: " + rows[0] + "source 值: " + rows[1]+"\t 通讯总数="+Integer.parseInt(rows[2].toString()));
}
return list;
}
![图片说明](https://img-ask.csdn.net/upload/201506/19/1434699386_154547.png)