web访客管理增加按预约人条件检索信息

master
panqihua 5 years ago
parent 096dea346c
commit 74d22d2e5a
  1. 10
      src/main/java/com/community/pocket/entity/vo/web/VisitorQuery.java
  2. 9
      src/main/java/com/community/pocket/repository/android/VisitorDao.java
  3. 23
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -6,6 +6,8 @@ package com.community.pocket.entity.vo.web;
public class VisitorQuery { public class VisitorQuery {
private Long currentPage; private Long currentPage;
private String appointment;
public Long getCurrentPage() { public Long getCurrentPage() {
return currentPage; return currentPage;
} }
@ -13,4 +15,12 @@ public class VisitorQuery {
public void setCurrentPage(Long currentPage) { public void setCurrentPage(Long currentPage) {
this.currentPage = currentPage; this.currentPage = currentPage;
} }
public String getAppointment() {
return appointment;
}
public void setAppointment(String appointment) {
this.appointment = appointment;
}
} }

@ -20,6 +20,7 @@ import org.springframework.stereotype.Repository;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
//访客数据接口 //访客数据接口
@Repository @Repository
@ -51,9 +52,11 @@ public class VisitorDao extends BaseDao<Visitor> {
//加载所有访客信息 //加载所有访客信息
public Page<Visitor> loadAllVisitor(VisitorQuery visitorQuery) { public Page<Visitor> loadAllVisitor(VisitorQuery visitorQuery) {
long count = mongoTemplate.count(new Query(), entityClass()); Criteria criteria = Criteria.where("appointment").regex(Pattern.compile(".*") + visitorQuery.getAppointment() + ".*");
Query query = new Query(criteria);
long count = mongoTemplate.count(query, entityClass());
Page<Visitor> page = new Page<>(count, visitorQuery.getCurrentPage(), pageSize); Page<Visitor> page = new Page<>(count, visitorQuery.getCurrentPage(), pageSize);
List<Visitor> visitorList = mongoTemplate.find(new Query().with(PageRequest.of(visitorQuery.getCurrentPage().intValue() - 1, pageSize)), entityClass()); List<Visitor> visitorList = mongoTemplate.find(query.with(PageRequest.of(visitorQuery.getCurrentPage().intValue() - 1, pageSize)), entityClass());
page.setList(visitorList); page.setList(visitorList);
return page; return page;
} }
@ -63,7 +66,7 @@ public class VisitorDao extends BaseDao<Visitor> {
return mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(visitorForm.getId())), Update.update("status", visitorForm.getStatus()).set("managerName", visitorForm.getManagerName()), entityClass()).wasAcknowledged(); return mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(visitorForm.getId())), Update.update("status", visitorForm.getStatus()).set("managerName", visitorForm.getManagerName()), entityClass()).wasAcknowledged();
} }
//用户加载访客信息
private List<Visitor> load(com.community.pocket.entity.vo.android.VisitorQuery visitorQuery, Criteria criteria) { private List<Visitor> load(com.community.pocket.entity.vo.android.VisitorQuery visitorQuery, Criteria criteria) {
if (visitorQuery.getStartDate() != null && visitorQuery.getEndDate() != null) { if (visitorQuery.getStartDate() != null && visitorQuery.getEndDate() != null) {
criteria = criteria.andOperator(Criteria.where("time").gte(visitorQuery.getStartDate().getTime()), Criteria.where("time").lte(visitorQuery.getEndDate().getTime())); criteria = criteria.andOperator(Criteria.where("time").gte(visitorQuery.getStartDate().getTime()), Criteria.where("time").lte(visitorQuery.getEndDate().getTime()));

@ -8,10 +8,8 @@ import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.android.GarbageCateGory; import com.community.pocket.entity.vo.android.GarbageCateGory;
import com.community.pocket.entity.vo.android.Info; import com.community.pocket.entity.vo.android.Info;
import com.community.pocket.entity.vo.android.QueryUserForm; import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.repository.android.GarbageDao; import com.community.pocket.entity.vo.android.VisitorForm;
import com.community.pocket.repository.android.GarbagePriceDao; import com.community.pocket.repository.android.*;
import com.community.pocket.repository.android.UserDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
import com.community.pocket.util.MessageService; import com.community.pocket.util.MessageService;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
@ -65,6 +63,9 @@ class DemoApplicationTests {
@Autowired @Autowired
private TestTokenDao testTokenDao; private TestTokenDao testTokenDao;
@Autowired
private VisitorDao visitorDao;
private MockMvc mockMvc; private MockMvc mockMvc;
@BeforeEach @BeforeEach
@ -240,4 +241,18 @@ class DemoApplicationTests {
void findUser() { void findUser() {
Info myInfo = userDao.queryUser("panqihua"); Info myInfo = userDao.queryUser("panqihua");
} }
//测试访客保存
@Test
void saveVisitor() {
for (int i = 0; i < 20; i++) {
VisitorForm visitorForm = new VisitorForm();
visitorForm.setAppointment("abc" + i);
visitorForm.setChooseDate("2020/04/01");
visitorForm.setChooseTime("11:00");
visitorForm.setNotes("备注");
visitorForm.setUsername("eee" + i);
visitorDao.save(visitorForm);
}
}
} }

Loading…
Cancel
Save