From 03bf3cd4e6a3300b5dac5ae5e724e57ba651aea7 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sun, 19 Apr 2020 13:46:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=A1=E7=94=A8=E5=88=86?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/android/AndroidForumController.java | 166 ------------- .../api/android/AndroidVisitorController.java | 84 ------- .../pocket/api/android/ForumController.java | 227 ++++++++++++++++++ .../pocket/api/android/UserController.java | 12 +- .../pocket/api/android/VisitorController.java | 108 +++++++++ ...umController.java => ForumController.java} | 5 +- .../pocket/api/web/UserController.java | 44 ++++ ...Controller.java => VisitorController.java} | 5 +- .../pocket/entity/po/CreditScore.java | 59 +++++ .../com/community/pocket/entity/po/Forum.java | 3 +- .../pocket/entity/po/android/Active.java | 10 + .../pocket/entity/po/android/MyInfo.java | 7 +- .../pocket/entity/po/android/Score.java | 30 +++ .../pocket/entity/vo/ForumQuery.java | 10 + .../pocket/entity/vo/android/ActiveVo.java | 11 + .../entity/vo/android/ForumContentVo.java | 12 +- .../entity/vo/android/ForumDataResponse.java | 10 + .../pocket/entity/vo/android/ForumDto.java | 15 +- .../entity/vo/android/ForumScoreVo.java | 16 ++ .../pocket/entity/vo/android/Info.java | 8 +- .../entity/vo/android/QueryUserForm.java | 22 +- .../entity/vo/android/QueryUserResponse.java | 5 +- .../vo/android/VisitorPeopleResponse.java | 3 +- .../pocket/entity/vo/web/EditScore.java | 47 ++++ .../pocket/entity/vo/web/UserResponse.java | 35 +++ .../pocket/repository/CreditScoreDao.java | 21 ++ .../pocket/repository/android/ActiveDao.java | 1 + .../pocket/repository/android/DoCheck.java | 13 + .../repository/android/ForumContentDao.java | 11 +- .../pocket/repository/android/ForumDao.java | 120 +++------ .../pocket/repository/android/ScoreDao.java | 39 +++ .../pocket/repository/android/TokenDao.java | 3 +- .../repository/android/TokenService.java | 25 ++ .../pocket/repository/android/UserDao.java | 56 ++++- .../pocket/repository/android/VisitorDao.java | 3 +- .../com/community/pocket/util/BeanUtil.java | 14 ++ .../pocket/util/LookupOperationUtil.java | 28 +++ .../com/community/pocket/util/TableName.java | 6 +- .../pocket/DemoApplicationTests.java | 61 ++++- .../com/community/pocket/TestTokenDao.java | 39 +++ 40 files changed, 1006 insertions(+), 388 deletions(-) delete mode 100644 src/main/java/com/community/pocket/api/android/AndroidForumController.java delete mode 100644 src/main/java/com/community/pocket/api/android/AndroidVisitorController.java create mode 100644 src/main/java/com/community/pocket/api/android/ForumController.java create mode 100644 src/main/java/com/community/pocket/api/android/VisitorController.java rename src/main/java/com/community/pocket/api/web/{WebForumController.java => ForumController.java} (96%) create mode 100644 src/main/java/com/community/pocket/api/web/UserController.java rename src/main/java/com/community/pocket/api/web/{WebVisitorController.java => VisitorController.java} (93%) create mode 100644 src/main/java/com/community/pocket/entity/po/CreditScore.java create mode 100644 src/main/java/com/community/pocket/entity/po/android/Score.java create mode 100644 src/main/java/com/community/pocket/entity/vo/android/ForumScoreVo.java create mode 100644 src/main/java/com/community/pocket/entity/vo/web/EditScore.java create mode 100644 src/main/java/com/community/pocket/entity/vo/web/UserResponse.java create mode 100644 src/main/java/com/community/pocket/repository/CreditScoreDao.java create mode 100644 src/main/java/com/community/pocket/repository/android/DoCheck.java create mode 100644 src/main/java/com/community/pocket/repository/android/ScoreDao.java create mode 100644 src/main/java/com/community/pocket/repository/android/TokenService.java create mode 100644 src/main/java/com/community/pocket/util/BeanUtil.java create mode 100644 src/main/java/com/community/pocket/util/LookupOperationUtil.java create mode 100644 src/test/java/com/community/pocket/TestTokenDao.java diff --git a/src/main/java/com/community/pocket/api/android/AndroidForumController.java b/src/main/java/com/community/pocket/api/android/AndroidForumController.java deleted file mode 100644 index 8d4368e..0000000 --- a/src/main/java/com/community/pocket/api/android/AndroidForumController.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.community.pocket.api.android; - -import com.community.pocket.entity.po.Forum; -import com.community.pocket.entity.po.ForumContent; -import com.community.pocket.entity.po.android.Active; -import com.community.pocket.entity.po.android.Complain; -import com.community.pocket.entity.po.android.Token; -import com.community.pocket.entity.vo.ForumQuery; -import com.community.pocket.entity.vo.Page; -import com.community.pocket.entity.vo.Result; -import com.community.pocket.entity.vo.android.*; -import com.community.pocket.repository.android.*; -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 AndroidForumController { - - @Autowired - private ForumDao forumDao; - - @Autowired - private UserDao userDao; - - @Autowired - private TokenDao tokenDao; - - @Autowired - private ForumContentDao forumContentDao; - - @Autowired - private ActiveDao activeDao; - - @Autowired - private ComplainDao complainDao; - - //加载热榜接口 - @GetMapping("/forum/hot") - public ForumHotResponse loadHot(Integer num) { - List userHot = userDao.rankUser(num); - List topicHot = forumDao.rankReply(Forum.ForumType.topic, num); - List activeHot = forumDao.rankReply(Forum.ForumType.active, num); - ForumHotResponse response; - if (userHot != null && topicHot != null && activeHot != null) { - Hot hot = new Hot(userHot, topicHot, activeHot); - response = new ForumHotResponse(Result.OK, ForumHotResponse.Msg.ok); - response.setHot(hot); - } else { - response = new ForumHotResponse(Result.FAIL, ForumHotResponse.Msg.fail); - } - return response; - } - - //发送活动贴 - @PostMapping("/forum/sendActive") - public ForumPostResponse sendActive(ActiveVo activeVo) { - if (tokenDao.checkToken(activeVo)) { - Forum forum = forumDao.save(activeVo); - if (forum != null) { - ForumContent forumContent = forumContentDao.save(activeVo, forum); - Active active = activeDao.save(activeVo, forum); - if (forumContent != null && active != null) { - return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); - } - } - return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); - } else { - return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); - } - } - - //发送动态贴 - @PostMapping("/forum/sendTopic") - public ForumPostResponse sendTopic(ForumVo forumVo) { - if (tokenDao.checkToken(forumVo)) { - Forum forum = forumDao.save(forumVo); - if (forum != null) { - ForumContent forumContent = forumContentDao.save(forumVo, forum); - if (forumContent != null) { - return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); - } - } - return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); - } else { - return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); - } - } - - //发送投诉贴 - @PostMapping("/forum/sendComplain") - public ForumPostResponse sendComplain(ComplainVo complainVo) { - if (tokenDao.checkToken(complainVo)) { - Forum forum = forumDao.save(complainVo); - if (forum != null) { - ForumContent forumContent = forumContentDao.save(complainVo, forum); - Complain complain = complainDao.save(complainVo, forum); - if (forumContent != null && complain != null) { - return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); - } - } - return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); - } else { - return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); - } - } - - /** - * 加载我的帖子 - */ - @GetMapping("/forum/my") - public ForumMyResponse loadForumMy(ForumQuery forumQuery) { - Page forumList = forumDao.loadForum(forumQuery); - ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok); - response.setForumList(forumList); - return response; - - } - - //获取个人信息 - @GetMapping("/my/info") - public InfoResponse loadInfo(Token token) { - if (tokenDao.checkToken(token)) { - Info myInfo = userDao.queryUser(token.getUsername()); - if (myInfo != null) { - InfoResponse response = new InfoResponse(Result.OK, InfoResponse.Msg.ok); - response.setMyInfo(myInfo); - return response; - } else { - return new InfoResponse(Result.FAIL, InfoResponse.Msg.fail); - } - } else { - return new InfoResponse(Result.FAIL, InfoResponse.Msg.token); - } - } - - //获取帖子详情数据 - @GetMapping("/forum/content") - public ForumDataResponse loadData(QueryForum queryForum) { - List forumContents = forumContentDao.find(queryForum); - ForumDataResponse response = new ForumDataResponse(Result.OK, ForumDataResponse.Msg.ok); - response.setForumContentList(forumContents); - return response; - } - - //回帖 - @PostMapping("/forum/content/reply") - public ForumDataResponse sendReply(ForumReplyForm replyForm) { - if (tokenDao.checkToken(replyForm)) { - if (forumContentDao.save(replyForm) != null && forumDao.update(replyForm)) { - return new ForumDataResponse(Result.OK, ForumDataResponse.Msg.reply_ok); - } else { - return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.reply_fail); - } - } else { - return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.token); - } - } -} diff --git a/src/main/java/com/community/pocket/api/android/AndroidVisitorController.java b/src/main/java/com/community/pocket/api/android/AndroidVisitorController.java deleted file mode 100644 index 20dba4f..0000000 --- a/src/main/java/com/community/pocket/api/android/AndroidVisitorController.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.community.pocket.api.android; - -import com.community.pocket.entity.po.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 AndroidVisitorController { - - @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 visitorPeopleList = visitorPeopleDao.loadAll(visitorPeople); - VisitorPeopleResponse response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok); - response.setVisitorPeopleList(visitorPeopleList); - return response; - } - - /** - * 我的预约 - */ - @GetMapping("/visitor/reservation") - public VisitorReservationResponse loadReservation(VisitorQuery query) { - if (tokenDao.checkToken(query)) { - List visitorList = visitorDao.loadMyReservation(query); - 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(VisitorQuery query) { - if (tokenDao.checkToken(query)) { - List visitorList = visitorDao.loadMyVisitor(query); - VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok); - response.setVisitorList(visitorList); - return response; - } else { - return new VisitorMyResponse(Result.FAIL, VisitorMyResponse.Msg.fail); - } - } -} diff --git a/src/main/java/com/community/pocket/api/android/ForumController.java b/src/main/java/com/community/pocket/api/android/ForumController.java new file mode 100644 index 0000000..b8b73a5 --- /dev/null +++ b/src/main/java/com/community/pocket/api/android/ForumController.java @@ -0,0 +1,227 @@ +package com.community.pocket.api.android; + +import com.community.pocket.entity.po.Forum; +import com.community.pocket.entity.po.ForumContent; +import com.community.pocket.entity.po.android.Active; +import com.community.pocket.entity.po.android.Complain; +import com.community.pocket.entity.po.android.Score; +import com.community.pocket.entity.po.android.Token; +import com.community.pocket.entity.vo.ForumQuery; +import com.community.pocket.entity.vo.Page; +import com.community.pocket.entity.vo.Result; +import com.community.pocket.entity.vo.android.*; +import com.community.pocket.repository.android.*; +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 ForumController { + + @Autowired + private ForumDao forumDao; + + @Autowired + private UserDao userDao; + + @Autowired + private TokenService tokenService; + + @Autowired + private ForumContentDao forumContentDao; + + @Autowired + private ActiveDao activeDao; + + @Autowired + private ComplainDao complainDao; + + @Autowired + private ScoreDao scoreDao; + + //加载热榜接口 + @GetMapping("/forum/hot") + public ForumHotResponse loadHot(Integer num) { + List userHot = userDao.rankUser(num); + List topicHot = forumDao.rankReply(Forum.ForumType.topic, num); + List activeHot = forumDao.rankReply(Forum.ForumType.active, num); + ForumHotResponse response; + if (userHot != null && topicHot != null && activeHot != null) { + Hot hot = new Hot(userHot, topicHot, activeHot); + response = new ForumHotResponse(Result.OK, ForumHotResponse.Msg.ok); + response.setHot(hot); + } else { + response = new ForumHotResponse(Result.FAIL, ForumHotResponse.Msg.fail); + } + return response; + } + + //发送活动贴 + @PostMapping("/forum/sendActive") + public ForumPostResponse sendActive(ActiveVo activeVo) { + return tokenService.checkToken(activeVo, new DoCheck() { + @Override + public ForumPostResponse ok(ActiveVo activeVo) { + Forum forum = forumDao.save(activeVo); + if (forum != null) { + ForumContent forumContent = forumContentDao.save(activeVo, forum); + Active active = activeDao.save(activeVo, forum); + if (forumContent != null && active != null) { + return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); + } + } + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); + } + + @Override + public ForumPostResponse fail() { + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); + } + }); + } + + //发送动态贴 + @PostMapping("/forum/sendTopic") + public ForumPostResponse sendTopic(ForumVo forumVo) { + return tokenService.checkToken(forumVo, new DoCheck() { + @Override + public ForumPostResponse ok(ForumVo forumVo) { + Forum forum = forumDao.save(forumVo); + if (forum != null) { + ForumContent forumContent = forumContentDao.save(forumVo, forum); + if (forumContent != null) { + return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); + } + } + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); + } + + @Override + public ForumPostResponse fail() { + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); + } + }); + } + + //发送结算贴 + @PostMapping("/forum/sendScore") + public ForumPostResponse sendScore(ForumScoreVo scoreVo) { + return tokenService.checkToken(scoreVo, new DoCheck() { + @Override + public ForumPostResponse ok(ForumScoreVo forumVo) { + Forum forum = forumDao.save(forumVo); + if (forum != null) { + ForumContent forumContent = forumContentDao.save(forumVo, forum); + Score score = scoreDao.save(scoreVo, forum); + if (forumContent != null && score != null) { + return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); + } + } + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); + } + + @Override + public ForumPostResponse fail() { + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); + } + }); + } + + //发送投诉贴 + @PostMapping("/forum/sendComplain") + public ForumPostResponse sendComplain(ComplainVo complainVo) { + return tokenService.checkToken(complainVo, new DoCheck() { + @Override + public ForumPostResponse ok(ComplainVo complainVo) { + Forum forum = forumDao.save(complainVo); + if (forum != null) { + ForumContent forumContent = forumContentDao.save(complainVo, forum); + Complain complain = complainDao.save(complainVo, forum); + if (forumContent != null && complain != null) { + return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); + } + } + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); + } + + @Override + public ForumPostResponse fail() { + return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); + } + }); + } + + + /** + * 加载我的帖子 + */ + @GetMapping("/forum/my") + public ForumMyResponse loadForumMy(ForumQuery forumQuery) { + Page forumList = forumDao.loadForum(forumQuery); + ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok); + response.setForumList(forumList); + return response; + + } + + //获取个人信息 + @GetMapping("/my/info") + public InfoResponse loadInfo(Token token) { + return tokenService.checkToken(token, new DoCheck() { + @Override + public InfoResponse ok(Token token) { + Info myInfo = userDao.queryUser(token.getUsername()); + if (myInfo != null) { + InfoResponse response = new InfoResponse(Result.OK, InfoResponse.Msg.ok); + response.setMyInfo(myInfo); + return response; + } else { + return new InfoResponse(Result.FAIL, InfoResponse.Msg.fail); + } + } + + @Override + public InfoResponse fail() { + return new InfoResponse(Result.FAIL, InfoResponse.Msg.token); + } + }); + } + + //获取帖子详情数据 + @GetMapping("/forum/content") + public ForumDataResponse loadData(QueryForum queryForum) { + ForumDto forumDto = forumDao.loadForum(queryForum); + List forumContents = forumContentDao.find(queryForum); + ForumDataResponse response = new ForumDataResponse(Result.OK, ForumDataResponse.Msg.ok); + response.setForumContentList(forumContents); + response.setForumDto(forumDto); + return response; + } + + //回帖 + @PostMapping("/forum/content/reply") + public ForumDataResponse sendReply(ForumReplyForm replyForm) { + return tokenService.checkToken(replyForm, new DoCheck() { + @Override + public ForumDataResponse ok(ForumReplyForm forumReplyForm) { + if (forumContentDao.save(replyForm) != null && forumDao.update(replyForm)) { + return new ForumDataResponse(Result.OK, ForumDataResponse.Msg.reply_ok); + } else { + return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.reply_fail); + } + } + + @Override + public ForumDataResponse fail() { + return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.token); + } + }); + } +} diff --git a/src/main/java/com/community/pocket/api/android/UserController.java b/src/main/java/com/community/pocket/api/android/UserController.java index 6ac771a..40d71d1 100644 --- a/src/main/java/com/community/pocket/api/android/UserController.java +++ b/src/main/java/com/community/pocket/api/android/UserController.java @@ -13,6 +13,8 @@ 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; + /** * 用户接口 */ @@ -142,8 +144,14 @@ public class UserController { //检索投诉人 @GetMapping("/query/user") public QueryUserResponse searchPeople(QueryUserForm userForm) { - QueryUserResponse queryUserResponse=new QueryUserResponse(Result.OK, QueryUserResponse.Msg.ok); - queryUserResponse.setPeopleList(userDao.queryUser(userForm)); + QueryUserResponse queryUserResponse; + List peopleList = userDao.queryUser(userForm); + if (peopleList.isEmpty()) { + queryUserResponse = new QueryUserResponse(Result.OK, QueryUserResponse.Msg.ok_empty); + } else { + queryUserResponse = new QueryUserResponse(Result.OK, QueryUserResponse.Msg.ok); + } + queryUserResponse.setPeopleList(peopleList); return queryUserResponse; } diff --git a/src/main/java/com/community/pocket/api/android/VisitorController.java b/src/main/java/com/community/pocket/api/android/VisitorController.java new file mode 100644 index 0000000..1bc2699 --- /dev/null +++ b/src/main/java/com/community/pocket/api/android/VisitorController.java @@ -0,0 +1,108 @@ +package com.community.pocket.api.android; + +import com.community.pocket.entity.po.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.DoCheck; +import com.community.pocket.repository.android.TokenService; +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 TokenService tokenService; + + //访客预约 + @PostMapping("/visitor/visitor") + public VisitorResponse appointment(VisitorForm visitorForm) { + return tokenService.checkToken(visitorForm, new DoCheck() { + @Override + public VisitorResponse ok(VisitorForm visitorForm) { + if (visitorDao.save(visitorForm) != null) { + return new VisitorResponse(Result.OK, VisitorResponse.Msg.ok); + } else { + return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail); + } + } + + @Override + public VisitorResponse fail() { + return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.token); + } + }); + } + + //获取预约人 + @GetMapping("/visitor/people") + public VisitorPeopleResponse searchPeople(QueryVisitorPeople visitorPeople) { + List visitorPeopleList = visitorPeopleDao.loadAll(visitorPeople); + VisitorPeopleResponse response; + if (visitorPeopleList.isEmpty()) { + response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok_empty); + } else { + response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok); + } + response.setVisitorPeopleList(visitorPeopleList); + return response; + } + + /** + * 我的预约 + */ + @GetMapping("/visitor/reservation") + public VisitorReservationResponse loadReservation(VisitorQuery query) { + return tokenService.checkToken(query, new DoCheck() { + @Override + public VisitorReservationResponse ok(VisitorQuery visitorQuery) { + List visitorList = visitorDao.loadMyReservation(query); + VisitorReservationResponse response = new VisitorReservationResponse(Result.OK, VisitorReservationResponse.Msg.ok); + response.setVisitorList(visitorList); + return response; + } + + @Override + public VisitorReservationResponse fail() { + return new VisitorReservationResponse(Result.FAIL, VisitorReservationResponse.Msg.token); + } + }); + } + + /** + * 加载我的访客 + */ + @GetMapping("/visitor/my") + public VisitorMyResponse loadMy(VisitorQuery query) { + return tokenService.checkToken(query, new DoCheck() { + @Override + public VisitorMyResponse ok(VisitorQuery visitorQuery) { + List visitorList = visitorDao.loadMyVisitor(query); + VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok); + response.setVisitorList(visitorList); + return response; + } + + @Override + public VisitorMyResponse fail() { + return new VisitorMyResponse(Result.FAIL, VisitorMyResponse.Msg.token); + } + }); + } +} diff --git a/src/main/java/com/community/pocket/api/web/WebForumController.java b/src/main/java/com/community/pocket/api/web/ForumController.java similarity index 96% rename from src/main/java/com/community/pocket/api/web/WebForumController.java rename to src/main/java/com/community/pocket/api/web/ForumController.java index b074e12..638dde0 100644 --- a/src/main/java/com/community/pocket/api/web/WebForumController.java +++ b/src/main/java/com/community/pocket/api/web/ForumController.java @@ -6,6 +6,7 @@ import com.community.pocket.entity.vo.web.ForumCheck; import com.community.pocket.entity.vo.web.ForumCheckResponse; import com.community.pocket.repository.android.ForumDao; import com.community.pocket.repository.android.NoticeDao; +import com.community.pocket.util.BeanUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -17,8 +18,8 @@ import java.util.List; /** * web和android端共用论坛接口 */ -@RestController -public class WebForumController { +@RestController(BeanUtil.forumName) +public class ForumController { @Autowired diff --git a/src/main/java/com/community/pocket/api/web/UserController.java b/src/main/java/com/community/pocket/api/web/UserController.java new file mode 100644 index 0000000..c953cae --- /dev/null +++ b/src/main/java/com/community/pocket/api/web/UserController.java @@ -0,0 +1,44 @@ +package com.community.pocket.api.web; + +import com.community.pocket.entity.po.android.MyInfo; +import com.community.pocket.entity.vo.Page; +import com.community.pocket.entity.vo.Result; +import com.community.pocket.entity.vo.android.QueryUserForm; +import com.community.pocket.entity.vo.web.EditScore; +import com.community.pocket.entity.vo.web.UserResponse; +import com.community.pocket.repository.android.UserDao; +import com.community.pocket.util.BeanUtil; +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; + +/** + * web用户接口 + */ +@RestController(BeanUtil.userName) +public class UserController { + + @Autowired + private UserDao userDao; + + //查询用户信息 + @GetMapping("/api/users") + public UserResponse loadAll(QueryUserForm queryUserForm) { + Page infos = userDao.loadAll(queryUserForm); + UserResponse response = new UserResponse(Result.OK, UserResponse.Msg.ok); + response.setMyInfos(infos); + return response; + } + + //修改信用分 + @PostMapping("/api/users/score") + public UserResponse editScore(@RequestBody EditScore editScore) { + if (userDao.updateScore(editScore)) { + return new UserResponse(Result.OK, UserResponse.Msg.edit_ok); + } else { + return new UserResponse(Result.FAIL, UserResponse.Msg.edit_fail); + } + } +} diff --git a/src/main/java/com/community/pocket/api/web/WebVisitorController.java b/src/main/java/com/community/pocket/api/web/VisitorController.java similarity index 93% rename from src/main/java/com/community/pocket/api/web/WebVisitorController.java rename to src/main/java/com/community/pocket/api/web/VisitorController.java index 44e03f7..f88bda9 100644 --- a/src/main/java/com/community/pocket/api/web/WebVisitorController.java +++ b/src/main/java/com/community/pocket/api/web/VisitorController.java @@ -7,15 +7,16 @@ 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 com.community.pocket.util.BeanUtil; 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 { +@RestController(BeanUtil.visitorName) +public class VisitorController { @Autowired private VisitorDao visitorDao; diff --git a/src/main/java/com/community/pocket/entity/po/CreditScore.java b/src/main/java/com/community/pocket/entity/po/CreditScore.java new file mode 100644 index 0000000..28c1f58 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/CreditScore.java @@ -0,0 +1,59 @@ +package com.community.pocket.entity.po; + +import com.community.pocket.util.TableName; +import org.springframework.data.mongodb.core.mapping.Document; + +//信用分历史记录 +@Document(TableName.creditScore) +public class CreditScore { + //用户名 + private String username; + //信用分变化 + private Integer score; + //变化前分数 + private Integer beforeScore; + //备注 + private String notes; + //记录时间 + private Long time; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } + + public Integer getBeforeScore() { + return beforeScore; + } + + public void setBeforeScore(Integer beforeScore) { + this.beforeScore = beforeScore; + } + + public void setTime(Long time) { + this.time = time; + } + + public Long getTime() { + return time; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } +} diff --git a/src/main/java/com/community/pocket/entity/po/Forum.java b/src/main/java/com/community/pocket/entity/po/Forum.java index 83bc0eb..3425bfd 100644 --- a/src/main/java/com/community/pocket/entity/po/Forum.java +++ b/src/main/java/com/community/pocket/entity/po/Forum.java @@ -39,7 +39,8 @@ public class Forum { public enum ForumType { active, topic, - complan + complan, + score } //发帖人 diff --git a/src/main/java/com/community/pocket/entity/po/android/Active.java b/src/main/java/com/community/pocket/entity/po/android/Active.java index fa0dfde..18b323d 100644 --- a/src/main/java/com/community/pocket/entity/po/android/Active.java +++ b/src/main/java/com/community/pocket/entity/po/android/Active.java @@ -7,6 +7,8 @@ import org.springframework.data.mongodb.core.mapping.Document; public class Active { //帖子id private String id; + //报名截止日期 + private String registrationDeadline; //活动开始时间 private String activeStartTime; //活动结束时间 @@ -22,6 +24,14 @@ public class Active { this.id = id; } + public String getRegistrationDeadline() { + return registrationDeadline; + } + + public void setRegistrationDeadline(String registrationDeadline) { + this.registrationDeadline = registrationDeadline; + } + public String getActiveStartTime() { return activeStartTime; } diff --git a/src/main/java/com/community/pocket/entity/po/android/MyInfo.java b/src/main/java/com/community/pocket/entity/po/android/MyInfo.java index 6226553..7c62f0f 100644 --- a/src/main/java/com/community/pocket/entity/po/android/MyInfo.java +++ b/src/main/java/com/community/pocket/entity/po/android/MyInfo.java @@ -1,5 +1,6 @@ package com.community.pocket.entity.po.android; +import com.community.pocket.entity.po.CreditScore; import com.community.pocket.util.TableName; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -28,7 +29,7 @@ public class MyInfo { private String email; //信用分历史记录 - private List scoreHistory; + private List scoreHistory; public String getUsername() { return username; @@ -94,11 +95,11 @@ public class MyInfo { this.email = email; } - public List getScoreHistory() { + public List getScoreHistory() { return scoreHistory; } - public void setScoreHistory(List scoreHistory) { + public void setScoreHistory(List scoreHistory) { this.scoreHistory = scoreHistory; } } diff --git a/src/main/java/com/community/pocket/entity/po/android/Score.java b/src/main/java/com/community/pocket/entity/po/android/Score.java new file mode 100644 index 0000000..a1f07b0 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/android/Score.java @@ -0,0 +1,30 @@ +package com.community.pocket.entity.po.android; + +import com.community.pocket.util.TableName; +import org.springframework.data.mongodb.core.mapping.Document; + +/** + * 结算贴 + */ +@Document(TableName.score) +public class Score { + private String id; + //结算分数 + private Integer activeScore; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Integer getActiveScore() { + return activeScore; + } + + public void setActiveScore(Integer activeScore) { + this.activeScore = activeScore; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/ForumQuery.java b/src/main/java/com/community/pocket/entity/vo/ForumQuery.java index 4da5fe1..bb4db9a 100644 --- a/src/main/java/com/community/pocket/entity/vo/ForumQuery.java +++ b/src/main/java/com/community/pocket/entity/vo/ForumQuery.java @@ -12,6 +12,16 @@ public class ForumQuery { private String username; + private Object[] forumType; + + public Object[] getForumType() { + return forumType; + } + + public void setForumType(Object[] forumType) { + this.forumType = forumType; + } + public Forum.ForumStatus getStatus() { return status; } diff --git a/src/main/java/com/community/pocket/entity/vo/android/ActiveVo.java b/src/main/java/com/community/pocket/entity/vo/android/ActiveVo.java index b1474f2..9fb08db 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/ActiveVo.java +++ b/src/main/java/com/community/pocket/entity/vo/android/ActiveVo.java @@ -4,6 +4,8 @@ package com.community.pocket.entity.vo.android; * 活动贴 */ public class ActiveVo extends ForumVo { + //报名截止日期 + private String registrationDeadline; //活动开始时间 private String activeStartTime; //活动结束时间 @@ -11,6 +13,15 @@ public class ActiveVo extends ForumVo { //活动信用分 private String activeScore; + + public String getRegistrationDeadline() { + return registrationDeadline; + } + + public void setRegistrationDeadline(String registrationDeadline) { + this.registrationDeadline = registrationDeadline; + } + public String getActiveStartTime() { return activeStartTime; } diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumContentVo.java b/src/main/java/com/community/pocket/entity/vo/android/ForumContentVo.java index 1c16ac7..989cec9 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/ForumContentVo.java +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumContentVo.java @@ -1,5 +1,7 @@ package com.community.pocket.entity.vo.android; +import com.community.pocket.entity.po.android.MyInfo; + public class ForumContentVo { //帖子详情id private String id; @@ -14,7 +16,7 @@ public class ForumContentVo { //帖子正文 private String content; - private InfoWithScore myInfo; + private MyInfo info; public String getId() { return id; @@ -64,11 +66,11 @@ public class ForumContentVo { this.content = content; } - public InfoWithScore getMyInfo() { - return myInfo; + public MyInfo getInfo() { + return info; } - public void setMyInfo(InfoWithScore myInfo) { - this.myInfo = myInfo; + public void setInfo(MyInfo info) { + this.info = info; } } diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumDataResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ForumDataResponse.java index 86dc38c..3899c26 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/ForumDataResponse.java +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumDataResponse.java @@ -8,6 +8,8 @@ import java.util.List; public class ForumDataResponse extends Response { private List forumContentList; + private ForumDto forumDto; + public ForumDataResponse(Result result, Msg message, Object... args) { super(result, message, args); } @@ -20,6 +22,14 @@ public class ForumDataResponse extends Response { this.forumContentList = forumContentList; } + public ForumDto getForumDto() { + return forumDto; + } + + public void setForumDto(ForumDto forumDto) { + this.forumDto = forumDto; + } + public enum Msg implements CustomMessage { ok, fail, diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumDto.java b/src/main/java/com/community/pocket/entity/vo/android/ForumDto.java index 254a518..a52fd82 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/ForumDto.java +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumDto.java @@ -4,6 +4,7 @@ import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.android.Active; import com.community.pocket.entity.po.android.Complain; import com.community.pocket.entity.po.android.MyInfo; +import com.community.pocket.entity.po.android.Score; //帖子 public class ForumDto { @@ -27,10 +28,12 @@ public class ForumDto { //发帖人详情信息 private MyInfo info; - //其他信息 + //悬赏信息 private Active activeDto; - + //投诉信息 private Complain complainDto; + //结算信息 + private Score score; public Active getActiveDto() { return activeDto; @@ -119,4 +122,12 @@ public class ForumDto { public void setStatus(Forum.ForumStatus status) { this.status = status; } + + public Score getScore() { + return score; + } + + public void setScore(Score score) { + this.score = score; + } } diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumScoreVo.java b/src/main/java/com/community/pocket/entity/vo/android/ForumScoreVo.java new file mode 100644 index 0000000..4f83faf --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumScoreVo.java @@ -0,0 +1,16 @@ +package com.community.pocket.entity.vo.android; + +/** + * 结算贴表单 + */ +public class ForumScoreVo extends ForumVo { + private Integer activeScore; + + public Integer getActiveScore() { + return activeScore; + } + + public void setActiveScore(Integer activeScore) { + this.activeScore = activeScore; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/Info.java b/src/main/java/com/community/pocket/entity/vo/android/Info.java index 89a3807..4d3fc91 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/Info.java +++ b/src/main/java/com/community/pocket/entity/vo/android/Info.java @@ -1,5 +1,7 @@ package com.community.pocket.entity.vo.android; +import com.community.pocket.entity.po.CreditScore; + import java.util.List; public class Info { @@ -18,7 +20,7 @@ public class Info { //邮箱 private String email; //信用分历史记录 - private List scoreHistory; + private List scoreHistory; public String getUsername() { return username; @@ -76,11 +78,11 @@ public class Info { this.email = email; } - public List getScoreHistory() { + public List getScoreHistory() { return scoreHistory; } - public void setScoreHistory(List scoreHistory) { + public void setScoreHistory(List scoreHistory) { this.scoreHistory = scoreHistory; } } diff --git a/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java b/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java index 4868d55..0f1ea1f 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java +++ b/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java @@ -4,10 +4,14 @@ package com.community.pocket.entity.vo.android; * 检索用户表单 */ public class QueryUserForm { - //模糊匹配关键字 + //匹配关键字 private String name; //排除自己 private String username; + //是否模糊查询 + private boolean like; + + private Long currentPage; public String getName() { return name; @@ -24,4 +28,20 @@ public class QueryUserForm { public void setUsername(String username) { this.username = username; } + + public Long getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(Long currentPage) { + this.currentPage = currentPage; + } + + public boolean isLike() { + return like; + } + + public void setLike(boolean like) { + this.like = like; + } } diff --git a/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java b/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java index 907fe56..1e6e598 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java +++ b/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java @@ -23,8 +23,9 @@ public class QueryUserResponse extends Response { this.peopleList = peopleList; } - public enum Msg implements CustomMessage{ + public enum Msg implements CustomMessage { ok, - fail + fail, + ok_empty } } diff --git a/src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java b/src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java index 647f48e..d6e4731 100644 --- a/src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java +++ b/src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java @@ -27,6 +27,7 @@ public class VisitorPeopleResponse extends Response { public enum Msg implements CustomMessage { ok, - fail + fail, + ok_empty } } diff --git a/src/main/java/com/community/pocket/entity/vo/web/EditScore.java b/src/main/java/com/community/pocket/entity/vo/web/EditScore.java new file mode 100644 index 0000000..06a3865 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/web/EditScore.java @@ -0,0 +1,47 @@ +package com.community.pocket.entity.vo.web; + +/** + * 修改信用分表单 + */ +public class EditScore { + //用户名 + private String username; + //加减分数 + private Integer score; + //变化前分数 + private Integer beforeScore; + //备注信息 + private String notes; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + public Integer getBeforeScore() { + return beforeScore; + } + + public void setBeforeScore(Integer beforeScore) { + this.beforeScore = beforeScore; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/web/UserResponse.java b/src/main/java/com/community/pocket/entity/vo/web/UserResponse.java new file mode 100644 index 0000000..5fd8f93 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/web/UserResponse.java @@ -0,0 +1,35 @@ +package com.community.pocket.entity.vo.web; + +import com.community.pocket.entity.po.android.MyInfo; +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 UserResponse extends Response { + + private Page myInfos; + + public UserResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + public Page getMyInfos() { + return myInfos; + } + + public void setMyInfos(Page myInfos) { + this.myInfos = myInfos; + } + + public enum Msg implements CustomMessage { + //查询成功 + ok, + //查询失败 + fail, + //修改成功 + edit_ok, + //修改失败 + edit_fail + } +} diff --git a/src/main/java/com/community/pocket/repository/CreditScoreDao.java b/src/main/java/com/community/pocket/repository/CreditScoreDao.java new file mode 100644 index 0000000..044e91d --- /dev/null +++ b/src/main/java/com/community/pocket/repository/CreditScoreDao.java @@ -0,0 +1,21 @@ +package com.community.pocket.repository; + +import com.community.pocket.entity.po.CreditScore; +import org.springframework.stereotype.Repository; + +/** + * 信用分 + */ +@Repository +public class CreditScoreDao extends BaseDao { + + @Override + public CreditScore save(CreditScore creditScore) { + return mongoTemplate.save(creditScore); + } + + @Override + public Class entityClass() { + return CreditScore.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/ActiveDao.java b/src/main/java/com/community/pocket/repository/android/ActiveDao.java index 4ab7c8d..d7f7f40 100644 --- a/src/main/java/com/community/pocket/repository/android/ActiveDao.java +++ b/src/main/java/com/community/pocket/repository/android/ActiveDao.java @@ -18,6 +18,7 @@ public class ActiveDao extends BaseDao{ public Active save(ActiveVo activeVo, Forum forum) { Active active = new Active(); active.setId(forum.getId()); + active.setRegistrationDeadline(activeVo.getRegistrationDeadline()); active.setActiveStartTime(activeVo.getActiveStartTime()); active.setActiveEndTime(activeVo.getActiveEndTime()); active.setActiveScore(activeVo.getActiveScore()); diff --git a/src/main/java/com/community/pocket/repository/android/DoCheck.java b/src/main/java/com/community/pocket/repository/android/DoCheck.java new file mode 100644 index 0000000..5a00067 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/DoCheck.java @@ -0,0 +1,13 @@ +package com.community.pocket.repository.android; + +import com.community.pocket.entity.po.android.Token; + +//令牌校验 +public interface DoCheck { + + //校验成功 + T ok(E e); + + //校验失败 + T fail(); +} diff --git a/src/main/java/com/community/pocket/repository/android/ForumContentDao.java b/src/main/java/com/community/pocket/repository/android/ForumContentDao.java index 4bfeafd..bacbeb1 100644 --- a/src/main/java/com/community/pocket/repository/android/ForumContentDao.java +++ b/src/main/java/com/community/pocket/repository/android/ForumContentDao.java @@ -7,12 +7,12 @@ import com.community.pocket.entity.vo.android.ForumReplyForm; import com.community.pocket.entity.vo.android.ForumVo; import com.community.pocket.entity.vo.android.QueryForum; import com.community.pocket.repository.BaseDao; +import com.community.pocket.util.LookupOperationUtil; import com.community.pocket.util.TableName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.aggregation.Aggregation; -import org.springframework.data.mongodb.core.aggregation.LookupOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Repository; @@ -29,16 +29,9 @@ public class ForumContentDao extends BaseDao { @Autowired private ForumDao forumDao; - //关联用户表查询 - private static final LookupOperation lookupOperation = LookupOperation.newLookup(). - from(TableName.info). //关联从表名 - localField("username"). //主表关联字段 - foreignField("_id").//从表关联的字段 - as("myInfo"); //查询结果名 - //查找帖子详情 public List find(QueryForum queryForum) { - Aggregation aggregation = Aggregation.newAggregation(lookupOperation, Aggregation.unwind("myInfo"), Aggregation.match(Criteria.where("forumId").is(queryForum.getForumId()))); + Aggregation aggregation = Aggregation.newAggregation(LookupOperationUtil.infoLookup, Aggregation.match(Criteria.where("forumId").is(queryForum.getForumId()))); return mongoTemplate.aggregate(aggregation, TableName.forumContent, ForumContentVo.class).getMappedResults(); } diff --git a/src/main/java/com/community/pocket/repository/android/ForumDao.java b/src/main/java/com/community/pocket/repository/android/ForumDao.java index 536b4a4..8347e15 100644 --- a/src/main/java/com/community/pocket/repository/android/ForumDao.java +++ b/src/main/java/com/community/pocket/repository/android/ForumDao.java @@ -8,16 +8,16 @@ import com.community.pocket.entity.vo.Page; import com.community.pocket.entity.vo.android.*; import com.community.pocket.entity.vo.web.ForumCheck; import com.community.pocket.repository.BaseDao; +import com.community.pocket.util.LookupOperationUtil; import com.community.pocket.util.TableName; +import org.apache.commons.lang3.ObjectUtils; import org.bson.types.ObjectId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationOperation; -import org.springframework.data.mongodb.core.aggregation.LookupOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; @@ -38,27 +38,6 @@ public class ForumDao extends BaseDao { @Value("${forum.content-length}") private int contentLength; - //活动贴 - //关联帖子外键属性 - private static final String idKey = "_id"; - //定义管道操作 - private static final String activeKey = "activeDto"; - //关联 - private static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey); - - //投诉贴 - //关联属性 - private static final String complainKey = "complainDto"; - //定义管道操作 - private static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey); - //关联属性 - private static final String infoKey = "info"; - - //关联用户外键属性 - private static final String usernameKey = "username"; - //定义管道操作 - private static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey); - //添加回复数 public boolean update(ForumReplyForm forumReplyForm) { return mongoTemplate.updateFirst(new Query(Criteria.where("id").is(new ObjectId(forumReplyForm.getForumId()))), @@ -96,61 +75,45 @@ public class ForumDao extends BaseDao { //设置投诉贴投诉人详细信息 private void loadComplain(ForumDto forumDto) { Complain complain = forumDto.getComplainDto(); - complain.setInfo(mongoTemplate.findOne(new Query(Criteria.where(idKey).is(complain.getComplain())), MyInfo.class)); + complain.setInfo(mongoTemplate.findOne(new Query(Criteria.where(LookupOperationUtil.idKey).is(complain.getComplain())), MyInfo.class)); + } + + //查询帖子 + public ForumDto loadForum(QueryForum queryForum) { + Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(Criteria.where(LookupOperationUtil.idKey).is(queryForum.getForumId())), LookupOperationUtil.complainforumLookup, LookupOperationUtil.activeforumLookup, LookupOperationUtil.infoLookup); + return mongoTemplate.aggregate(aggregation, TableName.forum, ForumDto.class).getUniqueMappedResult(); } //查询最新帖子 + public Page loadForum(ForumQuery forumQuery) { // 根据审核状态按时间从大到小排序的帖子 try { - Criteria criteria = new Criteria(); + List criteriaList = new ArrayList<>(); if (!StringUtils.isEmpty(forumQuery.getStatus())) { - criteria = Criteria.where("status").is(forumQuery.getStatus()); + criteriaList.add(Criteria.where("status").is(forumQuery.getStatus())); } if (!StringUtils.isEmpty(forumQuery.getUsername())) { - criteria = criteria.and("username").is(forumQuery.getUsername()); + criteriaList.add(Criteria.where("username").is(forumQuery.getUsername())); + } + if (ObjectUtils.isNotEmpty(forumQuery.getForumType())) { + criteriaList.add(Criteria.where("forumType").in(forumQuery.getForumType())); } - Query query = new Query(criteria).with(PageRequest.of(forumQuery.getCurrentPage().intValue() - 1, pageSize)); - long currentCount = mongoTemplate.count(query, entityClass()); - if (currentCount > 0) { - long count = mongoTemplate.count(new Query(criteria), entityClass()); - Page page = new Page<>(count, forumQuery.getCurrentPage(), pageSize); - List forumDtos = loadForum(complainforumLookup, activeforumLookup, infoLookup, Aggregation.match(criteria), Aggregation.skip((forumQuery.getCurrentPage() - 1) * pageSize), Aggregation.limit(pageSize), Aggregation.sort(Sort.by("time").descending())); - if (forumDtos != null) { - for (ForumDto forumDto : forumDtos) { - if (forumDto.getComplainDto() != null) { - loadComplain(forumDto); - } + + Criteria criteria = new Criteria().andOperator(criteriaList.toArray(new Criteria[]{})); + long count = mongoTemplate.count(new Query(criteria), entityClass()); + Page page = new Page<>(count, forumQuery.getCurrentPage(), pageSize); + List forumDtos = loadForum(LookupOperationUtil.complainforumLookup, LookupOperationUtil.activeforumLookup, LookupOperationUtil.scoreforumLookup, LookupOperationUtil.infoLookup, Aggregation.match(criteria), Aggregation.skip((forumQuery.getCurrentPage() - 1) * pageSize), Aggregation.limit(pageSize), Aggregation.sort(Sort.by("time").descending())); + if (forumDtos != null) { + for (ForumDto forumDto : forumDtos) { + if (forumDto.getComplainDto() != null) { + loadComplain(forumDto); } } - page.setList(forumDtos); - return page; - } else { - return new Page<>(0L, forumQuery.getCurrentPage(), pageSize); } - } catch (Exception e) { - e.printStackTrace(); - LOG.error(e.toString()); - } - return null; - } + page.setList(forumDtos); + return page; - //保存活动贴 - public Forum save(ActiveVo activeVo) { - try { - Forum forum = new Forum(); - forum.setUsername(activeVo.getUsername()); - forum.setForumType(Forum.ForumType.active); - forum.setReply(0); - forum.setTitle(activeVo.getTitle()); - forum.setTime(System.currentTimeMillis()); - forum.setStatus(Forum.ForumStatus.uncheck); - if (activeVo.getContent().length() > contentLength) { - forum.setContent(activeVo.getContent().substring(0, contentLength)); - } else { - forum.setContent(activeVo.getContent()); - } - return save(forum); } catch (Exception e) { e.printStackTrace(); LOG.error(e.toString()); @@ -162,9 +125,13 @@ public class ForumDao extends BaseDao { public Forum save(ForumVo forumVo) { try { Forum forum = new Forum(); - forum.setContent(forumVo.getContent()); + if (forumVo.getContent().length() > contentLength) { + forum.setContent(forumVo.getContent().substring(0, contentLength)); + } else { + forum.setContent(forumVo.getContent()); + } forum.setTitle(forumVo.getTitle()); - forum.setForumType(Forum.ForumType.topic); + forum.setForumType(forumVo.getForumType()); forum.setTime(System.currentTimeMillis()); forum.setReply(0); forum.setUsername(forumVo.getUsername()); @@ -177,28 +144,9 @@ public class ForumDao extends BaseDao { return null; } - //保存投诉 - public Forum save(ComplainVo complainVo) { - try { - Forum forum = new Forum(); - forum.setContent(complainVo.getContent()); - forum.setTitle(complainVo.getTitle()); - forum.setForumType(Forum.ForumType.complan); - forum.setTime(System.currentTimeMillis()); - forum.setReply(0); - forum.setUsername(complainVo.getUsername()); - forum.setStatus(Forum.ForumStatus.uncheck); - return save(forum); - } catch (Exception e) { - e.printStackTrace(); - LOG.error(e.toString()); - } - return null; - } - //审核帖子 public boolean check(ForumCheck forumCheck) { - return mongoTemplate.updateFirst(new Query(Criteria.where(idKey).is(forumCheck.getId())), Update.update("status", forumCheck.getStatus()), entityClass()).wasAcknowledged(); + return mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(forumCheck.getId())), Update.update("status", forumCheck.getStatus()), entityClass()).wasAcknowledged(); } //保存 diff --git a/src/main/java/com/community/pocket/repository/android/ScoreDao.java b/src/main/java/com/community/pocket/repository/android/ScoreDao.java new file mode 100644 index 0000000..adcac81 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/ScoreDao.java @@ -0,0 +1,39 @@ +package com.community.pocket.repository.android; + +import com.community.pocket.entity.po.Forum; +import com.community.pocket.entity.po.android.Score; +import com.community.pocket.entity.vo.android.ForumScoreVo; +import com.community.pocket.repository.BaseDao; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class ScoreDao extends BaseDao { + + private static final Logger LOG = LoggerFactory.getLogger(ScoreDao.class); + + //保存结算贴 + public Score save(ForumScoreVo scoreVo, Forum forum) { + Score score = new Score(); + score.setId(forum.getId()); + score.setActiveScore(scoreVo.getActiveScore()); + return save(score); + } + + @Override + public Score save(Score score) { + try { + return mongoTemplate.save(score); + } catch (Exception e) { + e.printStackTrace(); + LOG.error(e.toString()); + } + return null; + } + + @Override + public Class entityClass() { + return Score.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/TokenDao.java b/src/main/java/com/community/pocket/repository/android/TokenDao.java index 9269665..d3d28f3 100644 --- a/src/main/java/com/community/pocket/repository/android/TokenDao.java +++ b/src/main/java/com/community/pocket/repository/android/TokenDao.java @@ -29,7 +29,7 @@ public class TokenDao extends BaseDao { try { if(cleanToken(username)) { Token token = new Token(); - token.setTime(System.currentTimeMillis()+ TimeUnit.DAYS.toMillis(1)); + token.setTime(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(day)); token.setUsername(username); token.setToken(DigestUtils.md5DigestAsHex((token.getUsername() + token.getTime()).getBytes())); save(token); @@ -57,6 +57,7 @@ public class TokenDao extends BaseDao { return checkToken(token.getToken()); } + //判断令牌是否存在 public boolean checkToken(String token){ return mongoTemplate.exists(new Query(Criteria.where("token").is(token).and("time").gt(System.currentTimeMillis())),entityClass()); } diff --git a/src/main/java/com/community/pocket/repository/android/TokenService.java b/src/main/java/com/community/pocket/repository/android/TokenService.java new file mode 100644 index 0000000..dd78d87 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/TokenService.java @@ -0,0 +1,25 @@ +package com.community.pocket.repository.android; + +import com.community.pocket.entity.po.android.Token; +import com.community.pocket.entity.vo.Response; +import com.community.pocket.entity.vo.android.CustomMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * 令牌校验 + */ +@Service +public class TokenService { + + @Autowired + private TokenDao tokenDao; + + public , E extends Token, F extends CustomMessage> T checkToken(E e, DoCheck doCheck) { + if (tokenDao.checkToken(e)) { + return doCheck.ok(e); + } else { + return doCheck.fail(); + } + } +} diff --git a/src/main/java/com/community/pocket/repository/android/UserDao.java b/src/main/java/com/community/pocket/repository/android/UserDao.java index 88957de..71f904a 100644 --- a/src/main/java/com/community/pocket/repository/android/UserDao.java +++ b/src/main/java/com/community/pocket/repository/android/UserDao.java @@ -1,12 +1,19 @@ package com.community.pocket.repository.android; +import com.community.pocket.entity.po.CreditScore; import com.community.pocket.entity.po.android.MyInfo; +import com.community.pocket.entity.vo.Page; import com.community.pocket.entity.vo.android.*; +import com.community.pocket.entity.vo.web.EditScore; import com.community.pocket.repository.BaseDao; +import com.community.pocket.repository.CreditScoreDao; +import com.community.pocket.util.LookupOperationUtil; import com.mongodb.client.result.UpdateResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -25,23 +32,59 @@ public class UserDao extends BaseDao { private static final Logger LOG = LoggerFactory.getLogger(UserDao.class); + @Autowired + private CreditScoreDao creditScoreDao; + @Value("${register.credit-score}") private int creditScore; //检查用户名是否已注册 - public boolean hasUser(String username){ - if(!StringUtils.isEmpty(username)){ - return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username)),entityClass()); - }else{ + public boolean hasUser(String username) { + if (!StringUtils.isEmpty(username)) { + return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username)), entityClass()); + } else { return false; } } + //更新用户信用分 + public boolean updateScore(EditScore editScore) { + if (mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(editScore.getUsername())), new Update().inc("creditScore", editScore.getScore()), entityClass()).wasAcknowledged()) { + CreditScore creditScore = new CreditScore(); + creditScore.setUsername(editScore.getUsername()); + creditScore.setBeforeScore(editScore.getBeforeScore()); + creditScore.setScore(editScore.getScore()); + creditScore.setNotes(editScore.getNotes()); + creditScore.setTime(System.currentTimeMillis()); + return creditScoreDao.save(creditScore) != null; + } + return false; + } + + + //获取所有用户 + public Page loadAll(QueryUserForm queryUserForm) { + Criteria criteria = new Criteria(); + if (!StringUtils.isEmpty(queryUserForm.getUsername())) { + if (queryUserForm.isLike()) { + criteria = criteria.and("username").regex(Pattern.compile(".*" + queryUserForm.getUsername() + ".*")); + } else { + criteria = criteria.and("username").is(queryUserForm.getUsername()); + } + } + Query query = new Query(criteria); + long count = mongoTemplate.count(query, entityClass()); + Page page = new Page<>(count, queryUserForm.getCurrentPage(), pageSize); + List myInfos = mongoTemplate.find(query.with(PageRequest.of(queryUserForm.getCurrentPage().intValue() - 1, pageSize)), entityClass()); + page.setList(myInfos); + return page; + } + //检查手机是否已绑定 public boolean hasMobie(String mobie) { if (!StringUtils.isEmpty(mobie)) { - return mongoTemplate.exists(new Query().addCriteria(Criteria.where("mobie").is(mobie)),entityClass()); - }else{ + return mongoTemplate.exists(new Query().addCriteria(Criteria.where("mobie").is(mobie)), entityClass()); + } else { return false; } } @@ -97,7 +140,6 @@ public class UserDao extends BaseDao { myInfo.setCreditScore(creditScore); myInfo.setRecentPosts(0); myInfo.setRecentVisitors(0); - myInfo.setScoreHistory(new ArrayList<>()); save(myInfo); } diff --git a/src/main/java/com/community/pocket/repository/android/VisitorDao.java b/src/main/java/com/community/pocket/repository/android/VisitorDao.java index f88282a..fe98160 100644 --- a/src/main/java/com/community/pocket/repository/android/VisitorDao.java +++ b/src/main/java/com/community/pocket/repository/android/VisitorDao.java @@ -6,6 +6,7 @@ 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.util.LookupOperationUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -59,7 +60,7 @@ public class VisitorDao extends BaseDao { //访客预约放行 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(); + return mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(visitorForm.getId())), Update.update("status", visitorForm.getStatus()).set("managerName", visitorForm.getManagerName()), entityClass()).wasAcknowledged(); } diff --git a/src/main/java/com/community/pocket/util/BeanUtil.java b/src/main/java/com/community/pocket/util/BeanUtil.java new file mode 100644 index 0000000..78b8190 --- /dev/null +++ b/src/main/java/com/community/pocket/util/BeanUtil.java @@ -0,0 +1,14 @@ +package com.community.pocket.util; + +//解决bean命名冲突 +public class BeanUtil { + private static final String webPrefix = "web"; + + //web Controller bean重命名,防止同名类默认bean命名冲突 + //论坛Controller bean name + public static final String forumName = webPrefix + "forum"; + //访客Controller bean name + public static final String visitorName = webPrefix + "visitor"; + //用户Controller bean name + public static final String userName = webPrefix + "user"; +} diff --git a/src/main/java/com/community/pocket/util/LookupOperationUtil.java b/src/main/java/com/community/pocket/util/LookupOperationUtil.java new file mode 100644 index 0000000..63aedb6 --- /dev/null +++ b/src/main/java/com/community/pocket/util/LookupOperationUtil.java @@ -0,0 +1,28 @@ +package com.community.pocket.util; + +import org.springframework.data.mongodb.core.aggregation.LookupOperation; + +public class LookupOperationUtil { + //活动贴 + //关联帖子外键属性 + public static final String idKey = "_id"; + //定义管道操作 + private static final String activeKey = "activeDto"; + //关联 + public static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey); + //投诉贴 + //关联属性 + private static final String complainKey = "complainDto"; + //定义管道操作 + public static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey); + //结算贴 + private static final String scoreKey = "score"; + //定义管道操作 + public static final LookupOperation scoreforumLookup = LookupOperation.newLookup().from(TableName.score).localField(idKey).foreignField(idKey).as(scoreKey); + //关联属性 + private static final String infoKey = "info"; + //关联用户外键属性 + private static final String usernameKey = "username"; + //定义管道操作 + public static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey); +} diff --git a/src/main/java/com/community/pocket/util/TableName.java b/src/main/java/com/community/pocket/util/TableName.java index 697573b..a60b32e 100644 --- a/src/main/java/com/community/pocket/util/TableName.java +++ b/src/main/java/com/community/pocket/util/TableName.java @@ -16,10 +16,12 @@ public class TableName { public static final String forum = "forum"; //帖子详情信息 public static final String forumContent = "forumContent"; - //活动帖子 + //悬赏贴 public static final String active = "active"; //投诉贴 public static final String complain = "complain"; + //结算贴 + public static final String score = "score"; //公告 public static final String notice = "notice"; //访客信息 @@ -32,4 +34,6 @@ public class TableName { public static final String garbageWastePrice = "garbageWastePrice"; //管理员令牌 public static final String managerToken = "managerToken"; + //信用分记录 + public static final String creditScore = "creditScore"; } diff --git a/src/test/java/com/community/pocket/DemoApplicationTests.java b/src/test/java/com/community/pocket/DemoApplicationTests.java index 6641077..768994a 100644 --- a/src/test/java/com/community/pocket/DemoApplicationTests.java +++ b/src/test/java/com/community/pocket/DemoApplicationTests.java @@ -3,6 +3,8 @@ package com.community.pocket; import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.android.Garbage; import com.community.pocket.entity.po.android.GarbageWastePrice; +import com.community.pocket.entity.po.android.MyInfo; +import com.community.pocket.entity.po.android.Token; import com.community.pocket.entity.vo.android.GarbageCateGory; import com.community.pocket.entity.vo.android.QueryUserForm; import com.community.pocket.repository.android.GarbageDao; @@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -58,6 +61,9 @@ class DemoApplicationTests { @Autowired private WebApplicationContext webApplicationContext; + @Autowired + private TestTokenDao testTokenDao; + private MockMvc mockMvc; @BeforeEach @@ -85,15 +91,21 @@ class DemoApplicationTests { LOG.info(String.join(",", s)); } -// 初始化垃圾数据 -@Test -void loadData() throws FileNotFoundException { - Gson gson = new Gson(); - MyGarbage g = gson.fromJson(new InputStreamReader(new FileInputStream("src/main/resources/garbage.json"), StandardCharsets.UTF_8), MyGarbage.class); - for (Garbage garbage : g.getList()) { - garbageDao.save(garbage); + MockHttpServletRequestBuilder addToken(MockHttpServletRequestBuilder builders) { + Token token = testTokenDao.loadToken(); + return builders.param("username", token.getUsername()) + .param("token", token.getToken()); + } + + // 初始化垃圾数据 + @Test + void loadData() throws FileNotFoundException { + Gson gson = new Gson(); + MyGarbage g = gson.fromJson(new InputStreamReader(new FileInputStream("src/main/resources/garbage.json"), StandardCharsets.UTF_8), MyGarbage.class); + for (Garbage garbage : g.getList()) { + garbageDao.save(garbage); + } } -} @Test void loadPriceData() { @@ -151,8 +163,10 @@ void loadData() throws FileNotFoundException { @Test void queryForum() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/forum/posts") - .param("status", Forum.ForumStatus.ok.name()) + .param("status", Forum.ForumStatus.uncheck.name()) + .param("username", "panqihua") .param("currentPage", "1") + .param("forumType", Forum.ForumType.active.name(), Forum.ForumType.complan.name()) ).andDo(MockMvcResultHandlers.print()).andReturn(); } @@ -191,4 +205,33 @@ void loadData() throws FileNotFoundException { .param("endDate", "2020/04/19")) .andDo(MockMvcResultHandlers.print()).andReturn(); } + + //加载帖子信息 + @Test + void queryForumContent() throws Exception { + MockHttpServletRequestBuilder builders = MockMvcRequestBuilders.get("/forum/content") + .param("forumId", "5e950cae51e7a9796b05c596"); + mockMvc.perform(addToken(builders)) + .andDo(MockMvcResultHandlers.print()).andReturn(); + } + + //添加测试用户 + @Test + void insertUser() { + for (int i = 0; i <= 20; i++) { + MyInfo myInfo = new MyInfo(); + myInfo.setUsername("fff" + i); + userDao.save(myInfo); + } + } + + //加载所有用户 + @Test + void loadUser() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/api/users") + .param("currentPage", String.valueOf(1)) + .param("username", "fff") + .param("like", String.valueOf(false)) + ).andDo(MockMvcResultHandlers.print()).andReturn().getResponse(); + } } diff --git a/src/test/java/com/community/pocket/TestTokenDao.java b/src/test/java/com/community/pocket/TestTokenDao.java new file mode 100644 index 0000000..64f4b62 --- /dev/null +++ b/src/test/java/com/community/pocket/TestTokenDao.java @@ -0,0 +1,39 @@ +package com.community.pocket; + +import com.community.pocket.entity.po.android.Token; +import com.community.pocket.repository.BaseDao; +import com.community.pocket.util.LookupOperationUtil; +import org.apache.commons.lang3.RandomUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +//测试令牌 +@Repository +public class TestTokenDao extends BaseDao { + + @Value("${token.day}") + private int day; + + public Token loadToken() { + List tokenList = mongoTemplate.findAll(entityClass()); + Token token = tokenList.get(RandomUtils.nextInt(0, tokenList.size() - 1)); + mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(token.getToken())), Update.update("time", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(day)), entityClass()); + return mongoTemplate.findById(token.getToken(), entityClass()); + } + + @Override + public Token save(Token token) { + return null; + } + + @Override + public Class entityClass() { + return Token.class; + } +}