访客信息增加按时间查询逻辑

master
panqihua 5 years ago
parent d7743355f3
commit d466e2cf6d
  1. 13
      src/main/java/com/community/pocket/api/android/AndroidVisitorController.java
  2. 29
      src/main/java/com/community/pocket/entity/vo/android/VisitorQuery.java
  3. 26
      src/main/java/com/community/pocket/repository/android/VisitorDao.java
  4. 11
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -1,7 +1,6 @@
package com.community.pocket.api.android; package com.community.pocket.api.android;
import com.community.pocket.entity.po.Visitor; import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.po.android.VisitorPeople; import com.community.pocket.entity.po.android.VisitorPeople;
import com.community.pocket.entity.vo.Result; import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.*; import com.community.pocket.entity.vo.android.*;
@ -57,9 +56,9 @@ public class AndroidVisitorController {
* 我的预约 * 我的预约
*/ */
@GetMapping("/visitor/reservation") @GetMapping("/visitor/reservation")
public VisitorReservationResponse loadReservation(Token token) { public VisitorReservationResponse loadReservation(VisitorQuery query) {
if (tokenDao.checkToken(token)) { if (tokenDao.checkToken(query)) {
List<Visitor> visitorList = visitorDao.loadMyReservation(token); List<Visitor> visitorList = visitorDao.loadMyReservation(query);
VisitorReservationResponse response = new VisitorReservationResponse(Result.OK, VisitorReservationResponse.Msg.ok); VisitorReservationResponse response = new VisitorReservationResponse(Result.OK, VisitorReservationResponse.Msg.ok);
response.setVisitorList(visitorList); response.setVisitorList(visitorList);
return response; return response;
@ -72,9 +71,9 @@ public class AndroidVisitorController {
* 加载我的访客 * 加载我的访客
*/ */
@GetMapping("/visitor/my") @GetMapping("/visitor/my")
public VisitorMyResponse loadMy(Token token) { public VisitorMyResponse loadMy(VisitorQuery query) {
if (tokenDao.checkToken(token)) { if (tokenDao.checkToken(query)) {
List<Visitor> visitorList = visitorDao.loadMyVisitor(token); List<Visitor> visitorList = visitorDao.loadMyVisitor(query);
VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok); VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok);
response.setVisitorList(visitorList); response.setVisitorList(visitorList);
return response; return response;

@ -0,0 +1,29 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
import java.util.Date;
/**
* 访客查询
*/
public class VisitorQuery extends Token {
private Date startDate;
private Date endDate;
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}

@ -1,7 +1,6 @@
package com.community.pocket.repository.android; package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Visitor; import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.Page; import com.community.pocket.entity.vo.Page;
import com.community.pocket.entity.vo.android.VisitorForm; import com.community.pocket.entity.vo.android.VisitorForm;
import com.community.pocket.entity.vo.web.VisitorQuery; import com.community.pocket.entity.vo.web.VisitorQuery;
@ -64,14 +63,31 @@ public class VisitorDao extends BaseDao<Visitor> {
} }
private List<Visitor> load(com.community.pocket.entity.vo.android.VisitorQuery visitorQuery, Criteria criteria) {
if (visitorQuery.getStartDate() != null && visitorQuery.getEndDate() != null) {
criteria = criteria.andOperator(Criteria.where("time").gte(visitorQuery.getStartDate().getTime()), Criteria.where("time").lte(visitorQuery.getEndDate().getTime()));
} else {
if (visitorQuery.getStartDate() != null) {
criteria = criteria.and("time").gte(visitorQuery.getStartDate().getTime());
}
if (visitorQuery.getEndDate() != null) {
criteria = criteria.and("time").lte(visitorQuery.getEndDate().getTime());
}
}
return mongoTemplate.find(new Query(criteria).with(Sort.by("time").ascending()), entityClass());
}
//加载我的访客信息 //加载我的访客信息
public List<Visitor> loadMyVisitor(Token token) { public List<Visitor> loadMyVisitor(com.community.pocket.entity.vo.android.VisitorQuery visitorQuery) {
return mongoTemplate.find(new Query(Criteria.where("appointment").is(token.getUsername())).with(Sort.by("time").ascending()), entityClass()); Criteria criteria = Criteria.where("appointment").is(visitorQuery.getUsername());
return load(visitorQuery, criteria);
} }
//加载我的预约 //加载我的预约
public List<Visitor> loadMyReservation(Token token) { public List<Visitor> loadMyReservation(com.community.pocket.entity.vo.android.VisitorQuery visitorQuery) {
return mongoTemplate.find(new Query(Criteria.where("username").is(token.getUsername())).with(Sort.by("time").ascending()), entityClass()); Criteria criteria = Criteria.where("username").is(visitorQuery.getUsername());
return load(visitorQuery, criteria);
} }
@Override @Override

@ -180,4 +180,15 @@ void loadData() throws FileNotFoundException {
.param("name", "p") .param("name", "p")
.param("outPeople", String.valueOf(false))).andDo(MockMvcResultHandlers.print()).andReturn(); .param("outPeople", String.valueOf(false))).andDo(MockMvcResultHandlers.print()).andReturn();
} }
//加载访客信息
@Test
void queryVisitor() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/visitor/reservation")
.param("username", "panqihua")
.param("token", "e3c8ed5a74841556c57de6e17b166f68")
.param("startDate", "2020/04/18")
.param("endDate", "2020/04/19"))
.andDo(MockMvcResultHandlers.print()).andReturn();
}
} }

Loading…
Cancel
Save