添加访客管理接口

master
panqihua 5 years ago
parent 093f5a3b20
commit d7743355f3
  1. 4
      src/main/java/com/community/pocket/api/android/AndroidVisitorController.java
  2. 2
      src/main/java/com/community/pocket/api/web/ManagerController.java
  3. 6
      src/main/java/com/community/pocket/api/web/WebForumController.java
  4. 41
      src/main/java/com/community/pocket/api/web/WebVisitorController.java
  5. 25
      src/main/java/com/community/pocket/entity/po/Visitor.java
  6. 11
      src/main/java/com/community/pocket/entity/vo/android/QueryVisitorPeople.java
  7. 12
      src/main/java/com/community/pocket/entity/vo/android/VisitorForm.java
  8. 2
      src/main/java/com/community/pocket/entity/vo/android/VisitorMyResponse.java
  9. 2
      src/main/java/com/community/pocket/entity/vo/android/VisitorReservationResponse.java
  10. 37
      src/main/java/com/community/pocket/entity/vo/web/VisitorForm.java
  11. 16
      src/main/java/com/community/pocket/entity/vo/web/VisitorQuery.java
  12. 30
      src/main/java/com/community/pocket/entity/vo/web/VisitorResponse.java
  13. 7
      src/main/java/com/community/pocket/entity/vo/web/VisitorStatus.java
  14. 23
      src/main/java/com/community/pocket/repository/android/VisitorDao.java
  15. 12
      src/main/java/com/community/pocket/repository/android/VisitorPeopleDao.java
  16. 30
      src/main/java/com/community/pocket/util/CrosConfiguration.java
  17. 4
      src/main/resources/application.yaml
  18. 8
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -1,7 +1,7 @@
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.android.Token; import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.po.android.Visitor;
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.*;
@ -19,7 +19,7 @@ import java.util.List;
* 访客接口 * 访客接口
*/ */
@RestController @RestController
public class VisitorController { public class AndroidVisitorController {
@Autowired @Autowired
private VisitorDao visitorDao; private VisitorDao visitorDao;

@ -19,8 +19,6 @@ import java.util.Date;
@RestController @RestController
@RequestMapping("/api/manager") @RequestMapping("/api/manager")
//客户端跨域测试
@CrossOrigin("http://localhost:4200")
//管理员接口 //管理员接口
public class ManagerController { public class ManagerController {

@ -7,14 +7,16 @@ import com.community.pocket.entity.vo.web.ForumCheckResponse;
import com.community.pocket.repository.android.ForumDao; import com.community.pocket.repository.android.ForumDao;
import com.community.pocket.repository.android.NoticeDao; import com.community.pocket.repository.android.NoticeDao;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
/** /**
* web和android端共用论坛接口 * web和android端共用论坛接口
*/ */
@CrossOrigin("http://localhost:4200")
@RestController @RestController
public class WebForumController { public class WebForumController {

@ -0,0 +1,41 @@
package com.community.pocket.api.web;
import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.vo.Page;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.web.VisitorForm;
import com.community.pocket.entity.vo.web.VisitorQuery;
import com.community.pocket.entity.vo.web.VisitorResponse;
import com.community.pocket.repository.android.VisitorDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
//访客预约管理
public class WebVisitorController {
@Autowired
private VisitorDao visitorDao;
//加载访客信息
@GetMapping("/api/visitor")
public VisitorResponse loadAll(VisitorQuery visitorQuery) {
Page<Visitor> visitorList = visitorDao.loadAllVisitor(visitorQuery);
VisitorResponse visitorResponse = new VisitorResponse(Result.OK, VisitorResponse.Msg.ok);
visitorResponse.setVisitorList(visitorList);
return visitorResponse;
}
//访客预约放行
@PostMapping("/api/visitor")
public VisitorResponse update(@RequestBody VisitorForm visitorForm) {
if (visitorDao.updateVisitor(visitorForm)) {
return new VisitorResponse(Result.OK, VisitorResponse.Msg.check_ok);
} else {
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.check_fail);
}
}
}

@ -1,5 +1,6 @@
package com.community.pocket.entity.po.android; package com.community.pocket.entity.po;
import com.community.pocket.entity.vo.web.VisitorStatus;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@ -18,8 +19,12 @@ public class Visitor {
private String chooseDate; private String chooseDate;
//预约时间 //预约时间
private String chooseTime; private String chooseTime;
//备注信息 //拜访目的
private String notes; private String notes;
//审核状态
private VisitorStatus status;
//审核管理员
private String managerName;
private Long time; private Long time;
@ -78,4 +83,20 @@ public class Visitor {
public void setChooseDate(String chooseDate) { public void setChooseDate(String chooseDate) {
this.chooseDate = chooseDate; this.chooseDate = chooseDate;
} }
public VisitorStatus getStatus() {
return status;
}
public void setStatus(VisitorStatus status) {
this.status = status;
}
public String getManagerName() {
return managerName;
}
public void setManagerName(String managerName) {
this.managerName = managerName;
}
} }

@ -6,7 +6,10 @@ import com.community.pocket.entity.po.android.Token;
* 查询预约人条件 * 查询预约人条件
*/ */
public class QueryVisitorPeople extends Token { public class QueryVisitorPeople extends Token {
//预约人
private String name; private String name;
//是否外来人口预约
private Boolean outPeople;
public String getName() { public String getName() {
return name; return name;
@ -15,4 +18,12 @@ public class QueryVisitorPeople extends Token {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public Boolean getOutPeople() {
return outPeople;
}
public void setOutPeople(Boolean outPeople) {
this.outPeople = outPeople;
}
} }

@ -12,8 +12,10 @@ public class VisitorForm extends Token {
private String chooseDate; private String chooseDate;
//预约时间 //预约时间
private String chooseTime; private String chooseTime;
//备注信息 //拜访目的
private String notes; private String notes;
//是否外来人口预约
private Boolean isOutPeople;
public String getAppointment() { public String getAppointment() {
return appointment; return appointment;
@ -46,4 +48,12 @@ public class VisitorForm extends Token {
public void setChooseDate(String chooseDate) { public void setChooseDate(String chooseDate) {
this.chooseDate = chooseDate; this.chooseDate = chooseDate;
} }
public Boolean getOutPeople() {
return isOutPeople;
}
public void setOutPeople(Boolean outPeople) {
isOutPeople = outPeople;
}
} }

@ -1,6 +1,6 @@
package com.community.pocket.entity.vo.android; package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Visitor; import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.vo.Response; import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result; import com.community.pocket.entity.vo.Result;

@ -1,6 +1,6 @@
package com.community.pocket.entity.vo.android; package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Visitor; import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.vo.Response; import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result; import com.community.pocket.entity.vo.Result;

@ -0,0 +1,37 @@
package com.community.pocket.entity.vo.web;
/**
* 访客预约表单
*/
public class VisitorForm {
//访客id
private String id;
//审核状态
private VisitorStatus status;
//审核管理员
private String managerName;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public VisitorStatus getStatus() {
return status;
}
public void setStatus(VisitorStatus status) {
this.status = status;
}
public String getManagerName() {
return managerName;
}
public void setManagerName(String managerName) {
this.managerName = managerName;
}
}

@ -0,0 +1,16 @@
package com.community.pocket.entity.vo.web;
/**
* 访客查询条件
*/
public class VisitorQuery {
private Long currentPage;
public Long getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Long currentPage) {
this.currentPage = currentPage;
}
}

@ -0,0 +1,30 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.vo.Page;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
public class VisitorResponse extends Response<VisitorResponse.Msg> {
private Page<Visitor> visitorList;
public VisitorResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public Page<Visitor> getVisitorList() {
return visitorList;
}
public void setVisitorList(Page<Visitor> visitorList) {
this.visitorList = visitorList;
}
public enum Msg implements CustomMessage {
ok,
fail,
check_ok,
check_fail
}
}

@ -0,0 +1,7 @@
package com.community.pocket.entity.vo.web;
public enum VisitorStatus {
uncheck,
ok,
fail
}

@ -1,15 +1,20 @@
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.android.Token; import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.po.android.Visitor; 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.VisitorStatus;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.text.ParseException; import java.text.ParseException;
@ -35,6 +40,7 @@ public class VisitorDao extends BaseDao<Visitor> {
visitor.setNotes(visitorForm.getNotes()); visitor.setNotes(visitorForm.getNotes());
try { try {
visitor.setTime(new SimpleDateFormat(dateformat).parse(visitor.getChooseDate() + " " + visitor.getChooseTime()).getTime()); visitor.setTime(new SimpleDateFormat(dateformat).parse(visitor.getChooseDate() + " " + visitor.getChooseTime()).getTime());
visitor.setStatus(VisitorStatus.uncheck);
return save(visitor); return save(visitor);
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
@ -43,6 +49,21 @@ public class VisitorDao extends BaseDao<Visitor> {
return null; return null;
} }
//加载所有访客信息
public Page<Visitor> loadAllVisitor(VisitorQuery visitorQuery) {
long count = mongoTemplate.count(new Query(), entityClass());
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());
page.setList(visitorList);
return page;
}
//访客预约放行
public boolean updateVisitor(com.community.pocket.entity.vo.web.VisitorForm visitorForm) {
return mongoTemplate.updateFirst(new Query(Criteria.where("_id").is(visitorForm.getId())), Update.update("status", visitorForm.getStatus()).set("managerName", visitorForm.getManagerName()), entityClass()).wasAcknowledged();
}
//加载我的访客信息 //加载我的访客信息
public List<Visitor> loadMyVisitor(Token token) { public List<Visitor> loadMyVisitor(Token token) {
return mongoTemplate.find(new Query(Criteria.where("appointment").is(token.getUsername())).with(Sort.by("time").ascending()), entityClass()); return mongoTemplate.find(new Query(Criteria.where("appointment").is(token.getUsername())).with(Sort.by("time").ascending()), entityClass());

@ -35,10 +35,14 @@ public class VisitorPeopleDao extends BaseDao<VisitorPeople> {
//加载预约人列表 //加载预约人列表
public List<VisitorPeople> loadAll(QueryVisitorPeople queryVisitorPeople) { public List<VisitorPeople> loadAll(QueryVisitorPeople queryVisitorPeople) {
return mongoTemplate.find(new Query(new Criteria().andOperator( if (queryVisitorPeople.getOutPeople()) {
Criteria.where("username").regex(Pattern.compile(".*" + queryVisitorPeople.getName() + ".*")), return mongoTemplate.find(new Query(Criteria.where("username").regex(Pattern.compile(".*" + queryVisitorPeople.getName() + ".*"))), entityClass());
Criteria.where("username").ne(queryVisitorPeople.getUsername()))) } else {
, entityClass()); return mongoTemplate.find(new Query(new Criteria().andOperator(
Criteria.where("username").regex(Pattern.compile(".*" + queryVisitorPeople.getName() + ".*")),
Criteria.where("username").ne(queryVisitorPeople.getUsername())))
, entityClass());
}
} }
@Override @Override

@ -0,0 +1,30 @@
package com.community.pocket.util;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class CrosConfiguration {
@Value("${cros.allow-origin}")
private String allowOrigin;
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin(allowOrigin);
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/api/**", config);
FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
}

@ -72,3 +72,7 @@ waste:
manage: manage:
name: admin name: admin
mobie: 10086 mobie: 10086
#跨域配置
cros:
allow-origin: 'http://localhost:4200'

@ -172,4 +172,12 @@ void loadData() throws FileNotFoundException {
.param("name", "安") .param("name", "安")
).andDo(MockMvcResultHandlers.print()).andReturn(); ).andDo(MockMvcResultHandlers.print()).andReturn();
} }
//测试检索预约人
@Test
void queryPeople() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/visitor/people")
.param("name", "p")
.param("outPeople", String.valueOf(false))).andDo(MockMvcResultHandlers.print()).andReturn();
}
} }

Loading…
Cancel
Save