Criteria criteria = new Criteria().orOperator(criteria,criteria)
Query: { "$or" : [{ "name" : "北京中电广通科技有限公司" }, { "province" : "北京", "score" : { "$gte" : 60, "$lte" : 80 }, "state" : "疑似" }] }, Fields: { }, Sort: { }
String format = TimeUtils.formatStrOfTime(time);
String pipeline = "[{$match: {'entName' : '"+companyName+"'}},{$group: {'_id':{'startdate': { $dateToString:{ format: '"+format+"', date: '$startdate' } }},'count':{'$sum':1}}},{$project: {'_id':0,'time':'$_id.startdate','groupCount':'$count'}},{$sort: {'time':1}}]";
return mongoTemplate.executeCommand("{aggregate: 'tyc_recruit_deal', pipeline: " + pipeline + "}");
Criteria criteria = new Criteria().and("entName").is(companyName);
long count = mongoTemplate.count(new Query(criteria), "tyc_recruit_deal");
if (0 == count) {
return new AjaxResult().success("无数据");
}
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(criteria),
Aggregation.group(type). count().as("groupCount"),
Aggregation.project("groupCount").andExpression("'$groupCount'/[0]*100",count).as("percentage").and("groupField").previousOperation(),
Aggregation.sort(Sort.Direction.DESC,"groupCount")
);
List<GroupResultVo> results = mongoTemplate.aggregate(aggregation, "tyc_recruit_deal", GroupResultVo.class).getMappedResults();
return new AjaxResult().success("成功",new HashMap(){
{put("count",count); put("results",results);}
});