信用分排行榜

master
panqihua 5 years ago
parent b36a85ddcf
commit 53af97358b
  1. 20
      src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java
  2. 14
      src/main/java/com/community/pocket/repository/android/UserDao.java

@ -10,6 +10,10 @@ public class QueryUserForm {
private String username;
//是否模糊查询
private boolean like;
//是否按照信用分排行
private boolean orderScore;
//信用分降序
private boolean desc;
private Long currentPage;
@ -44,4 +48,20 @@ public class QueryUserForm {
public void setLike(boolean like) {
this.like = like;
}
public boolean isOrderScore() {
return orderScore;
}
public void setOrderScore(boolean orderScore) {
this.orderScore = orderScore;
}
public boolean isDesc() {
return desc;
}
public void setDesc(boolean desc) {
this.desc = desc;
}
}

@ -67,12 +67,22 @@ public class UserDao extends BaseDao<MyInfo> {
Criteria criteria = new Criteria();
if (!StringUtils.isEmpty(queryUserForm.getUsername())) {
if (queryUserForm.isLike()) {
criteria = criteria.and("username").regex(Pattern.compile(".*" + queryUserForm.getUsername() + ".*"));
criteria = Criteria.where("username").regex(Pattern.compile(".*" + queryUserForm.getUsername() + ".*"));
} else {
criteria = criteria.and("username").is(queryUserForm.getUsername());
criteria = Criteria.where("username").is(queryUserForm.getUsername());
}
}
Query query = new Query(criteria);
if (queryUserForm.isOrderScore()) {
Sort sort = Sort.by("creditScore");
if (queryUserForm.isDesc()) {
query = query.with(sort.descending());
} else {
query = query.with(sort.ascending());
}
}
long count = mongoTemplate.count(query, entityClass());
Page<MyInfo> page = new Page<>(count, queryUserForm.getCurrentPage(), pageSize);
List<MyInfo> myInfos = mongoTemplate.find(query.with(PageRequest.of(queryUserForm.getCurrentPage().intValue() - 1, pageSize)), entityClass());

Loading…
Cancel
Save