按周统计: DBCollection userSColl = db.getCollection("paysource");BasicDBObject key = new BasicDBObject("userId", true); BasicDBObject cond = new BasicDBObject("userId", userId); SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); cond.put( "createtime", new BasicDBObject("$gte", sdf .format(getTimesWeekmorning())).append("$lte", sdf.format(getTimesWeeknight()))); BasicDBObject initial = new BasicDBObject("praise", 0); String reduce = "function(obj,pre){pre.praise+=obj.money}"; BasicDBList returnList = (BasicDBList) userSColl.group(key, cond, initial, reduce); if (returnList.size() > 0) { DBObject obj = (DBObject) returnList.get(0); money = Double.parseDouble(obj.get("praise").toString()); } |
List<FreindDoctor> docts = new ArrayList<FreindDoctor>();
List<String> mobiles = getFreindMobiles(userId);
DB db = MyMongo.getDB();
if (db != null) {
DBCollection collection = db.getCollection("user");
BasicDBList values = new BasicDBList();
for (String info : mobiles) {
values.add(info);
}
BasicDBObject cond = new BasicDBObject();
cond.put("typeId", User.DOCTOR);
cond.put("userId", new BasicDBObject("$in", values));
DBCursor cursor = collection.find(cond);
try {
while (cursor.hasNext()) {
DBObject obj = cursor.next();
User doctor = gson.fromJson(obj.toString(), User.class);
if (doctor != null) {
FreindDoctor tm = new FreindDoctor();
tm.doctorId = doctor.userId;
ContactBean cont=getFreind(userId,doctor.userId);
tm.doctorName =cont.name;
tm.healUrl=doctor.headUrl;
docts.add(tm);
}
}
} catch (Exception e) {
logger.error("getContactDoctors " + e.getMessage());
} finally {
cursor.close();
}
}