信用分排行榜

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 String username;
//是否模糊查询 //是否模糊查询
private boolean like; private boolean like;
//是否按照信用分排行
private boolean orderScore;
//信用分降序
private boolean desc;
private Long currentPage; private Long currentPage;
@ -44,4 +48,20 @@ public class QueryUserForm {
public void setLike(boolean like) { public void setLike(boolean like) {
this.like = 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(); Criteria criteria = new Criteria();
if (!StringUtils.isEmpty(queryUserForm.getUsername())) { if (!StringUtils.isEmpty(queryUserForm.getUsername())) {
if (queryUserForm.isLike()) { if (queryUserForm.isLike()) {
criteria = criteria.and("username").regex(Pattern.compile(".*" + queryUserForm.getUsername() + ".*")); criteria = Criteria.where("username").regex(Pattern.compile(".*" + queryUserForm.getUsername() + ".*"));
} else { } else {
criteria = criteria.and("username").is(queryUserForm.getUsername()); criteria = Criteria.where("username").is(queryUserForm.getUsername());
} }
} }
Query query = new Query(criteria); 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()); long count = mongoTemplate.count(query, entityClass());
Page<MyInfo> page = new Page<>(count, queryUserForm.getCurrentPage(), pageSize); Page<MyInfo> page = new Page<>(count, queryUserForm.getCurrentPage(), pageSize);
List<MyInfo> myInfos = mongoTemplate.find(query.with(PageRequest.of(queryUserForm.getCurrentPage().intValue() - 1, pageSize)), entityClass()); List<MyInfo> myInfos = mongoTemplate.find(query.with(PageRequest.of(queryUserForm.getCurrentPage().intValue() - 1, pageSize)), entityClass());

Loading…
Cancel
Save