增加信用分管理接口

master
panqihua 5 years ago
parent d466e2cf6d
commit 03bf3cd4e6
  1. 166
      src/main/java/com/community/pocket/api/android/AndroidForumController.java
  2. 84
      src/main/java/com/community/pocket/api/android/AndroidVisitorController.java
  3. 227
      src/main/java/com/community/pocket/api/android/ForumController.java
  4. 12
      src/main/java/com/community/pocket/api/android/UserController.java
  5. 108
      src/main/java/com/community/pocket/api/android/VisitorController.java
  6. 5
      src/main/java/com/community/pocket/api/web/ForumController.java
  7. 44
      src/main/java/com/community/pocket/api/web/UserController.java
  8. 5
      src/main/java/com/community/pocket/api/web/VisitorController.java
  9. 59
      src/main/java/com/community/pocket/entity/po/CreditScore.java
  10. 3
      src/main/java/com/community/pocket/entity/po/Forum.java
  11. 10
      src/main/java/com/community/pocket/entity/po/android/Active.java
  12. 7
      src/main/java/com/community/pocket/entity/po/android/MyInfo.java
  13. 30
      src/main/java/com/community/pocket/entity/po/android/Score.java
  14. 10
      src/main/java/com/community/pocket/entity/vo/ForumQuery.java
  15. 11
      src/main/java/com/community/pocket/entity/vo/android/ActiveVo.java
  16. 12
      src/main/java/com/community/pocket/entity/vo/android/ForumContentVo.java
  17. 10
      src/main/java/com/community/pocket/entity/vo/android/ForumDataResponse.java
  18. 15
      src/main/java/com/community/pocket/entity/vo/android/ForumDto.java
  19. 16
      src/main/java/com/community/pocket/entity/vo/android/ForumScoreVo.java
  20. 8
      src/main/java/com/community/pocket/entity/vo/android/Info.java
  21. 22
      src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java
  22. 3
      src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java
  23. 3
      src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java
  24. 47
      src/main/java/com/community/pocket/entity/vo/web/EditScore.java
  25. 35
      src/main/java/com/community/pocket/entity/vo/web/UserResponse.java
  26. 21
      src/main/java/com/community/pocket/repository/CreditScoreDao.java
  27. 1
      src/main/java/com/community/pocket/repository/android/ActiveDao.java
  28. 13
      src/main/java/com/community/pocket/repository/android/DoCheck.java
  29. 11
      src/main/java/com/community/pocket/repository/android/ForumContentDao.java
  30. 102
      src/main/java/com/community/pocket/repository/android/ForumDao.java
  31. 39
      src/main/java/com/community/pocket/repository/android/ScoreDao.java
  32. 3
      src/main/java/com/community/pocket/repository/android/TokenDao.java
  33. 25
      src/main/java/com/community/pocket/repository/android/TokenService.java
  34. 44
      src/main/java/com/community/pocket/repository/android/UserDao.java
  35. 3
      src/main/java/com/community/pocket/repository/android/VisitorDao.java
  36. 14
      src/main/java/com/community/pocket/util/BeanUtil.java
  37. 28
      src/main/java/com/community/pocket/util/LookupOperationUtil.java
  38. 6
      src/main/java/com/community/pocket/util/TableName.java
  39. 45
      src/test/java/com/community/pocket/DemoApplicationTests.java
  40. 39
      src/test/java/com/community/pocket/TestTokenDao.java

@ -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> userHot = userDao.rankUser(num);
List<ForumHot> topicHot = forumDao.rankReply(Forum.ForumType.topic, num);
List<ForumHot> 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<ForumDto> 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<ForumContentVo> 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);
}
}
}

@ -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<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(VisitorQuery query) {
if (tokenDao.checkToken(query)) {
List<Visitor> 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<Visitor> 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);
}
}
}

@ -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> userHot = userDao.rankUser(num);
List<ForumHot> topicHot = forumDao.rankReply(Forum.ForumType.topic, num);
List<ForumHot> 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<ForumPostResponse, ActiveVo>() {
@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<ForumPostResponse, ForumVo>() {
@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<ForumPostResponse, ForumScoreVo>() {
@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<ForumPostResponse, ComplainVo>() {
@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<ForumDto> 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<InfoResponse, Token>() {
@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<ForumContentVo> 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<ForumDataResponse, ForumReplyForm>() {
@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);
}
});
}
}

@ -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<String> 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;
}

@ -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<VisitorResponse, VisitorForm>() {
@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<VisitorPeople> 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<VisitorReservationResponse, VisitorQuery>() {
@Override
public VisitorReservationResponse ok(VisitorQuery visitorQuery) {
List<Visitor> 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<VisitorMyResponse, VisitorQuery>() {
@Override
public VisitorMyResponse ok(VisitorQuery visitorQuery) {
List<Visitor> 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);
}
});
}
}

@ -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

@ -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<MyInfo> 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);
}
}
}

@ -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;

@ -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;
}
}

@ -39,7 +39,8 @@ public class Forum {
public enum ForumType {
active,
topic,
complan
complan,
score
}
//发帖人

@ -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;
}

@ -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<Integer> scoreHistory;
private List<CreditScore> scoreHistory;
public String getUsername() {
return username;
@ -94,11 +95,11 @@ public class MyInfo {
this.email = email;
}
public List<Integer> getScoreHistory() {
public List<CreditScore> getScoreHistory() {
return scoreHistory;
}
public void setScoreHistory(List<Integer> scoreHistory) {
public void setScoreHistory(List<CreditScore> scoreHistory) {
this.scoreHistory = scoreHistory;
}
}

@ -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;
}
}

@ -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;
}

@ -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;
}

@ -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;
}
}

@ -8,6 +8,8 @@ import java.util.List;
public class ForumDataResponse extends Response<ForumDataResponse.Msg> {
private List<ForumContentVo> 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<ForumDataResponse.Msg> {
this.forumContentList = forumContentList;
}
public ForumDto getForumDto() {
return forumDto;
}
public void setForumDto(ForumDto forumDto) {
this.forumDto = forumDto;
}
public enum Msg implements CustomMessage {
ok,
fail,

@ -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;
}
}

@ -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;
}
}

@ -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<Integer> scoreHistory;
private List<CreditScore> scoreHistory;
public String getUsername() {
return username;
@ -76,11 +78,11 @@ public class Info {
this.email = email;
}
public List<Integer> getScoreHistory() {
public List<CreditScore> getScoreHistory() {
return scoreHistory;
}
public void setScoreHistory(List<Integer> scoreHistory) {
public void setScoreHistory(List<CreditScore> scoreHistory) {
this.scoreHistory = scoreHistory;
}
}

@ -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;
}
}

@ -25,6 +25,7 @@ public class QueryUserResponse extends Response<QueryUserResponse.Msg> {
public enum Msg implements CustomMessage {
ok,
fail
fail,
ok_empty
}
}

@ -27,6 +27,7 @@ public class VisitorPeopleResponse extends Response<VisitorPeopleResponse.Msg> {
public enum Msg implements CustomMessage {
ok,
fail
fail,
ok_empty
}
}

@ -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;
}
}

@ -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<UserResponse.Msg> {
private Page<MyInfo> myInfos;
public UserResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public Page<MyInfo> getMyInfos() {
return myInfos;
}
public void setMyInfos(Page<MyInfo> myInfos) {
this.myInfos = myInfos;
}
public enum Msg implements CustomMessage {
//查询成功
ok,
//查询失败
fail,
//修改成功
edit_ok,
//修改失败
edit_fail
}
}

@ -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<CreditScore> {
@Override
public CreditScore save(CreditScore creditScore) {
return mongoTemplate.save(creditScore);
}
@Override
public Class<CreditScore> entityClass() {
return CreditScore.class;
}
}

@ -18,6 +18,7 @@ public class ActiveDao extends BaseDao<Active>{
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());

@ -0,0 +1,13 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.Token;
//令牌校验
public interface DoCheck<T, E extends Token> {
//校验成功
T ok(E e);
//校验失败
T fail();
}

@ -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<ForumContent> {
@Autowired
private ForumDao forumDao;
//关联用户表查询
private static final LookupOperation lookupOperation = LookupOperation.newLookup().
from(TableName.info). //关联从表名
localField("username"). //主表关联字段
foreignField("_id").//从表关联的字段
as("myInfo"); //查询结果名
//查找帖子详情
public List<ForumContentVo> 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();
}

@ -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<Forum> {
@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,26 +75,35 @@ public class ForumDao extends BaseDao<Forum> {
//设置投诉贴投诉人详细信息
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<ForumDto> loadForum(ForumQuery forumQuery) {
// 根据审核状态按时间从大到小排序的帖子
try {
Criteria criteria = new Criteria();
List<Criteria> 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) {
Criteria criteria = new Criteria().andOperator(criteriaList.toArray(new Criteria[]{}));
long count = mongoTemplate.count(new Query(criteria), entityClass());
Page<ForumDto> page = new Page<>(count, forumQuery.getCurrentPage(), pageSize);
List<ForumDto> forumDtos = loadForum(complainforumLookup, activeforumLookup, infoLookup, Aggregation.match(criteria), Aggregation.skip((forumQuery.getCurrentPage() - 1) * pageSize), Aggregation.limit(pageSize), Aggregation.sort(Sort.by("time").descending()));
List<ForumDto> 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) {
@ -125,32 +113,7 @@ public class ForumDao extends BaseDao<Forum> {
}
page.setList(forumDtos);
return page;
} else {
return new Page<>(0L, forumQuery.getCurrentPage(), pageSize);
}
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//保存活动贴
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<Forum> {
public Forum save(ForumVo forumVo) {
try {
Forum forum = new Forum();
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<Forum> {
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();
}
//保存

@ -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<Score> {
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<Score> entityClass() {
return Score.class;
}
}

@ -29,7 +29,7 @@ public class TokenDao extends BaseDao<Token> {
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<Token> {
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());
}

@ -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 <T extends Response<F>, E extends Token, F extends CustomMessage> T checkToken(E e, DoCheck<T, E> doCheck) {
if (tokenDao.checkToken(e)) {
return doCheck.ok(e);
} else {
return doCheck.fail();
}
}
}

@ -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,6 +32,9 @@ public class UserDao extends BaseDao<MyInfo> {
private static final Logger LOG = LoggerFactory.getLogger(UserDao.class);
@Autowired
private CreditScoreDao creditScoreDao;
@Value("${register.credit-score}")
private int creditScore;
@ -37,6 +47,39 @@ public class UserDao extends BaseDao<MyInfo> {
}
}
//更新用户信用分
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<MyInfo> 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<MyInfo> page = new Page<>(count, queryUserForm.getCurrentPage(), pageSize);
List<MyInfo> 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)) {
@ -97,7 +140,6 @@ public class UserDao extends BaseDao<MyInfo> {
myInfo.setCreditScore(creditScore);
myInfo.setRecentPosts(0);
myInfo.setRecentVisitors(0);
myInfo.setScoreHistory(new ArrayList<>());
save(myInfo);
}

@ -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<Visitor> {
//访客预约放行
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();
}

@ -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";
}

@ -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);
}

@ -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";
}

@ -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,6 +91,12 @@ class DemoApplicationTests {
LOG.info(String.join(",", s));
}
MockHttpServletRequestBuilder addToken(MockHttpServletRequestBuilder builders) {
Token token = testTokenDao.loadToken();
return builders.param("username", token.getUsername())
.param("token", token.getToken());
}
// 初始化垃圾数据
@Test
void loadData() throws FileNotFoundException {
@ -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();
}
}

@ -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<Token> {
@Value("${token.day}")
private int day;
public Token loadToken() {
List<Token> 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<Token> entityClass() {
return Token.class;
}
}
Loading…
Cancel
Save