@ResponseBody
@RequestMapping(value="/findByGene")
public YihaoResult findByGene(String gene,Integer page, final String asc,final String desc){
Varca findOne = mongoTemplate.findOne(new Query(Criteria.where("geneName").is(gene)), Varca.class);
page = page==null?1:page;
List<Study> List = findOne.getData();
if(asc!=null && !asc.equals("")){
Collections.sort(List, new Comparator<Study>() {
@Override
public int compare(Study p1, Study p2) {
switch (asc) {
case "gene":
return p1.getGene().compareTo(p2.getGene());
case "mutation":
return p1.getMutation().compareTo(p2.getMutation());
case "freq":
return p1.getMutation().compareTo(p2.getMutation());
case "sample":
return p1.getSample().compareTo(p2.getSample());
case "cancer":
return p1.getCancer().compareTo(p2.getMutation());
case "study":
return p1.getStudy().compareTo(p2.getStudy());
default:
return 0;
}
//return 0;
//return p1.name.compareTo(p2.name) ; // 调用String中的compareTo()方法
}
});
}
if(desc!=null && !desc.equals("")){
Collections.sort(List, new Comparator<Study>() {
@Override
public int compare(Study p1, Study p2) {
switch (desc) {
case "gene":
return p2.getGene().compareTo(p1.getGene());
case "mutation":
return p2.getMutation().compareTo(p1.getMutation());
case "freq":
return p2.getMutation().compareTo(p1.getMutation());
case "sample":
return p2.getSample().compareTo(p1.getSample());
case "cancer":
return p2.getCancer().compareTo(p1.getMutation());
case "study":
return p2.getStudy().compareTo(p1.getStudy());
default:
return 0;
}
//return 0;
//return p1.name.compareTo(p2.name) ; // 调用String中的compareTo()方法
}
});
}
Integer count = findOne.getTotal();
Integer start = (count<(page-1)*pagesize)?0:(page-1)*pagesize;
Integer end = page*pagesize>=count ? count :page*pagesize;
findOne.setData(List.subList(start, end));
return YihaoResult.build(200, "成功",findOne);
}
@ResponseBody
@RequestMapping(value="/findByMutation")
public YihaoResult findByMutation(String mutation){
Aggregation agg =Aggregation.newAggregation(Aggregation.unwind("$data"),Aggregation.match(Criteria.where("data.mutation").is(mutation)),Aggregation.project("data"));
AggregationResults<Object> results = mongoTemplate.aggregate(agg,Varca.class , Object.class);
List<Object> resultList = results.getMappedResults();
return YihaoResult.build(200, "成功",resultList);
}