增加访客预约接口

master
panqihua 5 years ago
parent aaeabdad4a
commit 1f67f49039
  1. 26
      src/main/java/com/community/pocket/api/android/UserController.java
  2. 85
      src/main/java/com/community/pocket/api/android/VisitorController.java
  3. 84
      src/main/java/com/community/pocket/entity/po/android/Visitor.java
  4. 35
      src/main/java/com/community/pocket/entity/po/android/VisitorPeople.java
  5. 18
      src/main/java/com/community/pocket/entity/vo/android/QueryVisitorPeople.java
  6. 49
      src/main/java/com/community/pocket/entity/vo/android/VisitorForm.java
  7. 32
      src/main/java/com/community/pocket/entity/vo/android/VisitorMyResponse.java
  8. 31
      src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java
  9. 29
      src/main/java/com/community/pocket/entity/vo/android/VisitorReservationResponse.java
  10. 19
      src/main/java/com/community/pocket/entity/vo/android/VisitorResponse.java
  11. 71
      src/main/java/com/community/pocket/repository/android/VisitorDao.java
  12. 66
      src/main/java/com/community/pocket/repository/android/VisitorPeopleDao.java
  13. 15
      src/main/java/com/community/pocket/util/TableName.java
  14. 17
      src/main/resources/application.yaml
  15. 20
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -6,6 +6,7 @@ import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.EmailDao;
import com.community.pocket.repository.android.TokenDao;
import com.community.pocket.repository.android.UserDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
import com.community.pocket.util.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -30,21 +31,28 @@ public class UserController {
@Autowired
private TokenDao tokenDao;
@Autowired
private VisitorPeopleDao visitorPeopleDao;
/**
* 用户注册
*
* @param userRegister 注册表单信息
*/
@PostMapping("/register")
public RegisterResponse register(UserRegister userRegister){
if(userDao.hasUser(userRegister.getUsername())){
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.name,userRegister.getUsername());
}else if(userDao.hasMobie(userRegister.getMobie())){
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.mobie,userRegister.getMobie());
}else if(userDao.hasEmail(userRegister.getEmail())){
return new RegisterResponse(Result.FAIL,RegisterResponse.Msg.email,userRegister.getEmail());
}else{
public RegisterResponse register(UserRegister userRegister) {
if (userDao.hasUser(userRegister.getUsername())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.name, userRegister.getUsername());
} else if (userDao.hasMobie(userRegister.getMobie())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.mobie, userRegister.getMobie());
} else if (userDao.hasEmail(userRegister.getEmail())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.email, userRegister.getEmail());
} else {
//保存注册信息
userDao.save(userRegister);
return new RegisterResponse(Result.OK,RegisterResponse.Msg.ok);
//保存默认预约配置信息
visitorPeopleDao.save(userRegister);
return new RegisterResponse(Result.OK, RegisterResponse.Msg.ok);
}
}

@ -0,0 +1,85 @@
package com.community.pocket.api.android;
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.vo.Result;
import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.android.TokenDao;
import com.community.pocket.repository.android.VisitorDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
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.RestController;
import java.util.List;
/**
* 访客接口
*/
@RestController
public class VisitorController {
@Autowired
private VisitorDao visitorDao;
@Autowired
private VisitorPeopleDao visitorPeopleDao;
@Autowired
private TokenDao tokenDao;
//访客预约
@PostMapping("/visitor/visitor")
public VisitorResponse appointment(VisitorForm visitorForm) {
if (tokenDao.checkToken(visitorForm)) {
if (visitorDao.save(visitorForm) != null) {
return new VisitorResponse(Result.OK, VisitorResponse.Msg.ok);
} else {
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail);
}
} else {
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.token);
}
}
//获取预约人
@GetMapping("/visitor/people")
public VisitorPeopleResponse searchPeople(QueryVisitorPeople visitorPeople) {
List<VisitorPeople> visitorPeopleList = visitorPeopleDao.loadAll(visitorPeople);
VisitorPeopleResponse response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok);
response.setVisitorPeopleList(visitorPeopleList);
return response;
}
/**
* 我的预约
*/
@GetMapping("/visitor/reservation")
public VisitorReservationResponse loadReservation(Token token) {
if (tokenDao.checkToken(token)) {
List<Visitor> visitorList = visitorDao.loadMyReservation(token);
VisitorReservationResponse response = new VisitorReservationResponse(Result.OK, VisitorReservationResponse.Msg.ok);
response.setVisitorList(visitorList);
return response;
} else {
return new VisitorReservationResponse(Result.FAIL, VisitorReservationResponse.Msg.fail);
}
}
/**
* 加载我的访客
*/
@GetMapping("/visitor/my")
public VisitorMyResponse loadMy(Token token) {
if (tokenDao.checkToken(token)) {
List<Visitor> visitorList = visitorDao.loadMyVisitor(token);
VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok);
response.setVisitorList(visitorList);
return response;
} else {
return new VisitorMyResponse(Result.FAIL, VisitorMyResponse.Msg.fail);
}
}
}

@ -0,0 +1,84 @@
package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 访客预约
*/
@Document(TableName.visitor)
public class Visitor {
//访客id
@JsonIgnore
private ObjectId id;
//访客人
private String username;
//预约对象
private String appointment;
//预约日期
private String chooseDate;
//预约时间
private String chooseTime;
//备注信息
private String notes;
private Long time;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getAppointment() {
return appointment;
}
public void setAppointment(String appointment) {
this.appointment = appointment;
}
public String getChooseTime() {
return chooseTime;
}
public void setChooseTime(String chooseTime) {
this.chooseTime = chooseTime;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public String getChooseDate() {
return chooseDate;
}
public void setChooseDate(String chooseDate) {
this.chooseDate = chooseDate;
}
}

@ -0,0 +1,35 @@
package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* 预约人信息
*/
@Document(TableName.visitorPeople)
public class VisitorPeople {
@Id
//预约人
private String username;
//可预约时间
private List<String> time;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public List<String> getTime() {
return time;
}
public void setTime(List<String> time) {
this.time = time;
}
}

@ -0,0 +1,18 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
/**
* 查询预约人条件
*/
public class QueryVisitorPeople extends Token {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

@ -0,0 +1,49 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
/**
* 访客预约表单
*/
public class VisitorForm extends Token {
//预约人
private String appointment;
//预约日期
private String chooseDate;
//预约时间
private String chooseTime;
//备注信息
private String notes;
public String getAppointment() {
return appointment;
}
public void setAppointment(String appointment) {
this.appointment = appointment;
}
public String getChooseTime() {
return chooseTime;
}
public void setChooseTime(String chooseTime) {
this.chooseTime = chooseTime;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getChooseDate() {
return chooseDate;
}
public void setChooseDate(String chooseDate) {
this.chooseDate = chooseDate;
}
}

@ -0,0 +1,32 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Visitor;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 我的访客信息
*/
public class VisitorMyResponse extends AndroidResponse<VisitorMyResponse.Msg> {
private List<Visitor> visitorList;
public List<Visitor> getVisitorList() {
return visitorList;
}
public void setVisitorList(List<Visitor> visitorList) {
this.visitorList = visitorList;
}
public VisitorMyResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
ok,
fail,
token
}
}

@ -0,0 +1,31 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.VisitorPeople;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 查询预约人返回结果
*/
public class VisitorPeopleResponse extends AndroidResponse<VisitorPeopleResponse.Msg> {
private List<VisitorPeople> visitorPeopleList;
public VisitorPeopleResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public List<VisitorPeople> getVisitorPeopleList() {
return visitorPeopleList;
}
public void setVisitorPeopleList(List<VisitorPeople> visitorPeopleList) {
this.visitorPeopleList = visitorPeopleList;
}
public enum Msg implements CustomMessage {
ok,
fail
}
}

@ -0,0 +1,29 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Visitor;
import com.community.pocket.entity.vo.Result;
import java.util.List;
//我的预约信息
public class VisitorReservationResponse extends AndroidResponse<VisitorReservationResponse.Msg> {
private List<Visitor> visitorList;
public VisitorReservationResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public List<Visitor> getVisitorList() {
return visitorList;
}
public void setVisitorList(List<Visitor> visitorList) {
this.visitorList = visitorList;
}
public enum Msg implements CustomMessage {
ok,
fail,
token
}
}

@ -0,0 +1,19 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
/**
* 访客预约结果
*/
public class VisitorResponse extends AndroidResponse<VisitorResponse.Msg> {
public VisitorResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
ok,
fail,
token
}
}

@ -0,0 +1,71 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.po.android.Visitor;
import com.community.pocket.entity.vo.android.VisitorForm;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
//访客数据接口
@Repository
public class VisitorDao extends BaseDao<Visitor> {
private static final Logger LOG = LoggerFactory.getLogger(VisitorDao.class);
@Value("${visitor.dateformat}")
private String dateformat;
//保存访客信息
public Visitor save(VisitorForm visitorForm) {
Visitor visitor = new Visitor();
visitor.setAppointment(visitorForm.getAppointment());
visitor.setUsername(visitorForm.getUsername());
visitor.setChooseDate(visitorForm.getChooseDate());
visitor.setChooseTime(visitorForm.getChooseTime());
visitor.setNotes(visitorForm.getNotes());
try {
visitor.setTime(new SimpleDateFormat(dateformat).parse(visitor.getChooseDate() + " " + visitor.getChooseTime()).getTime());
return save(visitor);
} catch (ParseException e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//加载我的访客信息
public List<Visitor> loadMyVisitor(Token token) {
return mongoTemplate.find(new Query(Criteria.where("appointment").is(token.getUsername())).with(Sort.by("time").ascending()), entityClass());
}
//加载我的预约
public List<Visitor> loadMyReservation(Token token) {
return mongoTemplate.find(new Query(Criteria.where("username").is(token.getUsername())).with(Sort.by("time").ascending()), entityClass());
}
@Override
public Visitor save(Visitor visitor) {
try {
return mongoTemplate.save(visitor);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<Visitor> entityClass() {
return Visitor.class;
}
}

@ -0,0 +1,66 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.VisitorPeople;
import com.community.pocket.entity.vo.android.QueryVisitorPeople;
import com.community.pocket.entity.vo.android.UserRegister;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.regex.Pattern;
/**
* 预约人信息
*/
@Repository
@ConfigurationProperties(prefix = "register")
public class VisitorPeopleDao extends BaseDao<VisitorPeople> {
private static final Logger LOG = LoggerFactory.getLogger(VisitorPeopleDao.class);
private List<String> visitorList;
public void setVisitorList(List<String> visitorList) {
this.visitorList = visitorList;
}
public List<String> getVisitorList() {
return visitorList;
}
//加载预约人列表
public List<VisitorPeople> loadAll(QueryVisitorPeople queryVisitorPeople) {
return mongoTemplate.find(new Query(new Criteria().andOperator(
Criteria.where("username").regex(Pattern.compile(".*" + queryVisitorPeople.getName() + ".*")),
Criteria.where("username").ne(queryVisitorPeople.getUsername())))
, entityClass());
}
@Override
public VisitorPeople save(VisitorPeople visitorPeople) {
try {
return mongoTemplate.save(visitorPeople);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<VisitorPeople> entityClass() {
return VisitorPeople.class;
}
public VisitorPeople save(UserRegister userRegister) {
VisitorPeople visitorPeople = new VisitorPeople();
visitorPeople.setUsername(userRegister.getUsername());
visitorPeople.setTime(visitorList);
return save(visitorPeople);
}
}

@ -9,15 +9,18 @@ public class TableName {
//管理员信息
public static final String manager="manager";
//验证码邮件
public static final String emailCode="emailCode";
public static final String emailCode = "emailCode";
//令牌
public static final String token="token";
public static final String token = "token";
//帖子基础信息
public static final String forum="forum";
public static final String forum = "forum";
//帖子详情信息
public static final String forumContent="forumContent";
public static final String forumContent = "forumContent";
//活动帖子
public static final String active="active";
public static final String active = "active";
//公告
public static final String notice="notice";
public static final String notice = "notice";
//访客信息
public static final String visitor = "visitor";
public static final String visitorPeople = "visitorPeople";
}

@ -44,4 +44,19 @@ forum:
#注册配置
register:
#默认信用分
credit-score: 0
credit-score: 0
#访客配置默认可预约时间
visitor-list:
- '09:00'
- '10:00'
- '11:00'
- '13:00'
- '14:00'
- '15:00'
- '16:00'
- '17:00'
#访客配置
visitor:
#日期格式
dateformat: 'yyyy/MM/dd HH:mm'

@ -2,25 +2,41 @@ package com.community.pocket;
import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.repository.android.UserDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class DemoApplicationTests {
@Autowired
private UserDao userDao;
@Autowired
private VisitorPeopleDao visitorPeopleDao;
private static final Logger LOG = LoggerFactory.getLogger(DemoApplicationTests.class);
@Test
void contextLoads() {
}
@Test
void queryUser(){
QueryUserForm queryUserForm=new QueryUserForm();
void queryUser() {
QueryUserForm queryUserForm = new QueryUserForm();
queryUserForm.setName("p");
userDao.queryUser(queryUserForm);
}
@Test
void showTime() {
List<String> s = visitorPeopleDao.getVisitorList();
LOG.info(String.join(",", s));
}
}

Loading…
Cancel
Save