package com.xinsight.server; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.Mongo; import com.xinsight.Util.BeanUtil; import com.xinsight.Util.InitMongodb; import com.xinsight.Util.Manager; import com.xinsight.server.model.PhoneEntity; /** *查找Mongodb中列中的List集合 */ public class FindMongodbServer { public static void main(String args[]){ try { Mongo mg = new Mongo("localhost",27017); DB db = mg.getDB("admin"); if(db.authenticate("aa", "aa".toCharArray())){ db = mg.getDB("dxtext"); DBCollection dbc = db.getCollection("zq1"); DBCursor u = dbc.find(); while(u.hasNext()){ String n = ""; BasicDBObject obj = (BasicDBObject)u.next(); ArrayList<BasicDBObject> list = (ArrayList<BasicDBObject>)obj.get("l"); for(BasicDBObject basi : list){ n += basi.getString("n") + "_" + basi.getString("t") + "#"; //将list中的数据拼接 } n = n.substring(0, n.length() - 1); System.out.println(n); int sum = 0; //总共接听电话次数 String strs[] = n.split("#"); for(int i = 0;i < strs.length;i++){ int a = Integer.parseInt(strs[i].split("_")[1]); sum +=a; } System.out.println(obj.get("n") + " " + sum); //主叫号码 总共接听次数 System.out.println("----------------------"); Thread.sleep(1000); } } } catch (UnknownHostException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }
时间: 2024-12-15 20:23:12