增加用户模块、论坛模块接口

master
panqihua 5 years ago
parent 38102abcfe
commit 5c942d230c
  1. 4
      build.gradle
  2. 158
      src/main/java/com/community/pocket/api/android/ForumController.java
  3. 141
      src/main/java/com/community/pocket/api/android/UserController.java
  4. 11
      src/main/java/com/community/pocket/api/web/ManagerController.java
  5. 12
      src/main/java/com/community/pocket/entity/po/EmailCode.java
  6. 101
      src/main/java/com/community/pocket/entity/po/Forum.java
  7. 62
      src/main/java/com/community/pocket/entity/po/ForumContent.java
  8. 5
      src/main/java/com/community/pocket/entity/po/Manager.java
  9. 60
      src/main/java/com/community/pocket/entity/po/Notice.java
  10. 49
      src/main/java/com/community/pocket/entity/po/android/Active.java
  11. 29
      src/main/java/com/community/pocket/entity/po/android/Complain.java
  12. 104
      src/main/java/com/community/pocket/entity/po/android/MyInfo.java
  13. 42
      src/main/java/com/community/pocket/entity/po/android/Token.java
  14. 21
      src/main/java/com/community/pocket/entity/vo/Common.java
  15. 84
      src/main/java/com/community/pocket/entity/vo/EmailTypeConfig.java
  16. 8
      src/main/java/com/community/pocket/entity/vo/JSONResponse.java
  17. 3
      src/main/java/com/community/pocket/entity/vo/ManagerRegister.java
  18. 38
      src/main/java/com/community/pocket/entity/vo/android/ActiveForm.java
  19. 47
      src/main/java/com/community/pocket/entity/vo/android/AndroidResponse.java
  20. 13
      src/main/java/com/community/pocket/entity/vo/android/ComplainForm.java
  21. 9
      src/main/java/com/community/pocket/entity/vo/android/CustomMessage.java
  22. 27
      src/main/java/com/community/pocket/entity/vo/android/ForumForm.java
  23. 38
      src/main/java/com/community/pocket/entity/vo/android/ForumHot.java
  24. 27
      src/main/java/com/community/pocket/entity/vo/android/ForumHotResponse.java
  25. 31
      src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java
  26. 31
      src/main/java/com/community/pocket/entity/vo/android/ForumNewResponse.java
  27. 31
      src/main/java/com/community/pocket/entity/vo/android/ForumNoticeResponse.java
  28. 18
      src/main/java/com/community/pocket/entity/vo/android/ForumPostResponse.java
  29. 33
      src/main/java/com/community/pocket/entity/vo/android/Hot.java
  30. 28
      src/main/java/com/community/pocket/entity/vo/android/LoginResponse.java
  31. 27
      src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java
  32. 29
      src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java
  33. 24
      src/main/java/com/community/pocket/entity/vo/android/RegisterResponse.java
  34. 24
      src/main/java/com/community/pocket/entity/vo/android/ResetPwdResponse.java
  35. 28
      src/main/java/com/community/pocket/entity/vo/android/UserHot.java
  36. 47
      src/main/java/com/community/pocket/entity/vo/android/UserRegister.java
  37. 45
      src/main/java/com/community/pocket/entity/vo/android/UserResetPwd.java
  38. 16
      src/main/java/com/community/pocket/repository/BaseDao.java
  39. 49
      src/main/java/com/community/pocket/repository/EmailDao.java
  40. 31
      src/main/java/com/community/pocket/repository/ManagerDao.java
  41. 42
      src/main/java/com/community/pocket/repository/android/ActiveDao.java
  42. 41
      src/main/java/com/community/pocket/repository/android/ComplainDao.java
  43. 46
      src/main/java/com/community/pocket/repository/android/ForumContentDao.java
  44. 151
      src/main/java/com/community/pocket/repository/android/ForumDao.java
  45. 45
      src/main/java/com/community/pocket/repository/android/NoticeDao.java
  46. 83
      src/main/java/com/community/pocket/repository/android/TokenDao.java
  47. 137
      src/main/java/com/community/pocket/repository/android/UserDao.java
  48. 61
      src/main/java/com/community/pocket/util/EmailService.java
  49. 23
      src/main/java/com/community/pocket/util/TableName.java
  50. 19
      src/main/resources/application.yaml

@ -23,6 +23,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest' implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-mail' implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
testImplementation 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'

@ -0,0 +1,158 @@
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.Notice;
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.android.ActiveForm;
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 NoticeDao noticeDao;
@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/notice")
public ForumNoticeResponse loadNotices() {
List<Notice> noticeList = noticeDao.loadNotices();
if (noticeList != null) {
ForumNoticeResponse response = new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.ok);
response.setNoticeList(noticeList);
return response;
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.fail);
}
}
//加载热榜接口
@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;
}
//加载最新帖子
@GetMapping("/forum/new")
public ForumNewResponse loadForumNew() {
List<Forum> forumList = forumDao.loadNewForum();
if (forumList != null) {
ForumNewResponse response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok);
response.setForumList(forumList);
return response;
} else {
return new ForumNewResponse(Result.FAIL, ForumNewResponse.Msg.fail);
}
}
//发送活动贴
@PostMapping("/forum/sendActive")
public ForumPostResponse sendActive(ActiveForm activeForm) {
if (tokenDao.checkToken(activeForm)) {
Forum forum = forumDao.save(activeForm);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(activeForm, forum);
Active active = activeDao.save(activeForm, 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(ForumForm forumForm) {
if (tokenDao.checkToken(forumForm)) {
Forum forum=forumDao.save(forumForm);
if(forum!=null){
ForumContent forumContent=forumContentDao.save(forumForm,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(ComplainForm complainForm) {
if (tokenDao.checkToken(complainForm)) {
Forum forum=forumDao.save(complainForm);
if(forum!=null){
ForumContent forumContent=forumContentDao.save(complainForm,forum);
Complain complain=complainDao.save(complainForm,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(Token token) {
if(tokenDao.checkToken(token)){
List<Forum> forumList=forumDao.loadMyForum(token.getUsername());
ForumMyResponse response=new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
response.setForumList(forumList);
return response;
}else {
return new ForumMyResponse(Result.FAIL, ForumMyResponse.Msg.token);
}
}
}

@ -0,0 +1,141 @@
package com.community.pocket.api.android;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.EmailDao;
import com.community.pocket.repository.android.TokenDao;
import com.community.pocket.repository.android.UserDao;
import com.community.pocket.util.EmailService;
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;
/**
* 用户接口
*/
@RestController
public class UserController {
@Autowired
private UserDao userDao;
@Autowired
private EmailDao emailDao;
@Autowired
private EmailService emailService;
@Autowired
private TokenDao tokenDao;
/**
* 用户注册
* @param userRegister 注册表单信息
*/
@PostMapping("/register")
public RegisterResponse register(UserRegister userRegister){
if(userDao.hasUser(userRegister.getUsername())){
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.name,userRegister.getUsername());
}else if(userDao.hasMobie(userRegister.getMobie())){
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.mobie,userRegister.getMobie());
}else if(userDao.hasEmail(userRegister.getEmail())){
return new RegisterResponse(Result.FAIL,RegisterResponse.Msg.email,userRegister.getEmail());
}else{
userDao.save(userRegister);
return new RegisterResponse(Result.OK,RegisterResponse.Msg.ok);
}
}
/**
* 检查用户邮箱
*/
@PostMapping("/resetpwd/checkUser")
public ResetPwdResponse checkUser(UserResetPwd userResetPwd){
if(userDao.hasUseWithEmail(userResetPwd.getUsername(),userResetPwd.getEmail())){
return new ResetPwdResponse(Result.OK,ResetPwdResponse.Msg.step1_ok);
}else{
return new ResetPwdResponse(Result.FAIL,ResetPwdResponse.Msg.step1_fail);
}
}
/**
* 发送重置密码验证码
*/
@PostMapping("/resetpwd/sendCode")
public ResetPwdResponse sendCode(UserResetPwd userResetPwd) {
if(emailService.sendUserCode(userResetPwd.getEmail())){
return new ResetPwdResponse(Result.OK,ResetPwdResponse.Msg.step2_ok);
}else{
return new ResetPwdResponse(Result.FAIL,ResetPwdResponse.Msg.step2_fail);
}
}
/**
* 检查验证码
*/
@PostMapping("/resetpwd/checkCode")
public ResetPwdResponse checkCode(UserResetPwd userResetPwd) {
if(emailDao.checkCode(userResetPwd.getEmail(),userResetPwd.getCode())){
return new ResetPwdResponse(Result.OK, ResetPwdResponse.Msg.step2_valid_ok);
}else{
return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step2_valid_fail);
}
}
/**
* 重置密码
*/
@PostMapping("/resetpwd/resetPwd")
public ResetPwdResponse resetPwd(UserResetPwd userResetPwd) {
if(userDao.resetPwd(userResetPwd.getUsername(),userResetPwd.getPassword())){
return new ResetPwdResponse(Result.OK, ResetPwdResponse.Msg.step3_ok);
}else{
return new ResetPwdResponse(Result.FAIL, ResetPwdResponse.Msg.step3_fail);
}
}
/**
* 用户登录
* @param username 用户
* @param password 密码
*/
@PostMapping("/login")
public LoginResponse login(String username, String password) {
if(userDao.login(username, password)){
Token token=tokenDao.save(username);
LoginResponse response;
if(token!=null) {
response=new LoginResponse(Result.OK, LoginResponse.Msg.ok,username);
response.setToken(token);
}else{
response=new LoginResponse(Result.FAIL,LoginResponse.Msg.fail);
}
return response;
}else{
return new LoginResponse(Result.FAIL,LoginResponse.Msg.fail);
}
}
@PostMapping("/login/token")
public LoginResponse check(String token){
if(tokenDao.checkToken(token)){
Token t=tokenDao.get(token);
if(t!=null){
LoginResponse response= new LoginResponse(Result.OK, LoginResponse.Msg.ok,t.getUsername());
response.setToken(t);
return response;
}
}
return new LoginResponse(Result.FAIL, LoginResponse.Msg.fail);
}
//检索投诉人
@GetMapping("/query/user")
public QueryUserResponse searchPeople(QueryUserForm userForm) {
QueryUserResponse queryUserResponse=new QueryUserResponse(Result.OK, QueryUserResponse.Msg.ok);
queryUserResponse.setPeopleList(userDao.queryUser(userForm));
return queryUserResponse;
}
}

@ -1,4 +1,4 @@
package com.community.pocket.api; package com.community.pocket.api.web;
import com.community.pocket.entity.po.Manager; import com.community.pocket.entity.po.Manager;
import com.community.pocket.entity.po.Token; import com.community.pocket.entity.po.Token;
@ -24,9 +24,11 @@ public class ManagerController {
@Autowired @Autowired
private ManagerDao managerDao; private ManagerDao managerDao;
//邮箱配置
@Autowired @Autowired
private Common common; private EmailTypeConfig emailTypeConfig;
//邮箱服务
@Autowired @Autowired
private EmailService emailService; private EmailService emailService;
@ -59,16 +61,15 @@ public class ManagerController {
/** /**
* 获取邮箱类型 * 获取邮箱类型
* @return
*/ */
@GetMapping("emailType") @GetMapping("emailType")
public JSONResponse<List<EmailType>> getEmailType(){ public JSONResponse<List<EmailType>> getEmailType(){
return new JSONResponse<>(Result.OK,"获取邮箱类型成功", common.getSupportType()); return new JSONResponse<>(Result.OK,"获取邮箱类型成功", emailTypeConfig.getSupportType());
} }
@PostMapping("sendcode") @PostMapping("sendcode")
public JSONResponse<String> sendEmail(String sender){ public JSONResponse<String> sendEmail(String sender){
if(emailService.sendCode(sender)){ if(emailService.sendManagerCode(sender)){
return new JSONResponse<>(Result.OK,"发送邮件成功",null); return new JSONResponse<>(Result.OK,"发送邮件成功",null);
}else{ }else{
return new JSONResponse<>(Result.OK,"发送邮件失败",null); return new JSONResponse<>(Result.OK,"发送邮件失败",null);

@ -1,8 +1,12 @@
package com.community.pocket.entity.po; package com.community.pocket.entity.po;
import com.community.pocket.util.TableName;
import org.springframework.data.mongodb.core.mapping.Document;
/** /**
* 邮箱验证码 * 邮箱验证码
*/ */
@Document(TableName.emailCode)
public class EmailCode { public class EmailCode {
//发送邮箱 //发送邮箱
private String emailAddress; private String emailAddress;
@ -23,4 +27,12 @@ public class EmailCode {
public void setEmailAddress(String emailAddress) { public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress; this.emailAddress = emailAddress;
} }
public String getEmailAddress() {
return emailAddress;
}
public Long getSendTime() {
return sendTime;
}
} }

@ -1,17 +1,108 @@
package com.community.pocket.entity.po; package com.community.pocket.entity.po;
import org.springframework.data.annotation.Id; import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.util.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
//论坛贴 //论坛贴
@Document(TableName.forum)
public class Forum { public class Forum {
@Id
private String id;
public String getId() { @JsonIgnore
private ObjectId id;
//发帖时间
private Long time;
//帖子标题
private String title;
//回复数
private Integer reply;
//帖子类型
private ForumType forumType;
//缩略内容
private String content;
@JsonIgnore
private MyInfo myInfo;
/**
* 帖子类型
*/
public enum ForumType{
active,
topic,
complan
}
//发帖人
private String username;
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public ForumType getForumType() {
return forumType;
}
public void setForumType(ForumType forumType) {
this.forumType = forumType;
}
public Integer getReply() {
return reply;
}
public void setReply(Integer reply) {
this.reply = reply;
}
public MyInfo getMyInfo() {
return myInfo;
}
public void setMyInfo(MyInfo myInfo) {
this.myInfo = myInfo;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public ObjectId getId() {
return id; return id;
} }
public void setId(String id) { public String getForumId(){
return this.id.toString();
}
public void setId(ObjectId id) {
this.id = id; this.id = id;
} }
} }

@ -0,0 +1,62 @@
package com.community.pocket.entity.po;
import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 帖子详情
*/
@Document(TableName.forumContent)
public class ForumContent {
//帖子id
private ObjectId id;
//用户名
private String username;
//发帖时间
private Long time;
//楼层
private Integer tower;
//帖子正文
private String content;
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public Integer getTower() {
return tower;
}
public void setTower(Integer tower) {
this.tower = tower;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

@ -1,8 +1,11 @@
package com.community.pocket.entity.po; package com.community.pocket.entity.po;
import com.community.pocket.util.TableName;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
//管理员 //管理员
@Document(TableName.manager)
public class Manager { public class Manager {
// 管理员 // 管理员
@Id @Id
@ -13,7 +16,7 @@ public class Manager {
private Long mobie; private Long mobie;
// 邮箱 // 邮箱
private String email; private String email;
//令牌
private Token token; private Token token;
public String getManagerName() { public String getManagerName() {

@ -0,0 +1,60 @@
package com.community.pocket.entity.po;
import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
//公告信息
@Document(TableName.notice)
public class Notice {
private ObjectId id;
//公告标题
private String title;
//公告内容
private String content;
//公告人
private String author;
//公告时间
private Long time;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
}

@ -0,0 +1,49 @@
package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(TableName.active)
public class Active {
//帖子id
private ObjectId id;
//活动开始时间
private String activeStartTime;
//活动结束时间
private String activeEndTime;
//活动信用分
private String activeScore;
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
public String getActiveStartTime() {
return activeStartTime;
}
public void setActiveStartTime(String activeStartTime) {
this.activeStartTime = activeStartTime;
}
public String getActiveEndTime() {
return activeEndTime;
}
public void setActiveEndTime(String activeEndTime) {
this.activeEndTime = activeEndTime;
}
public String getActiveScore() {
return activeScore;
}
public void setActiveScore(String activeScore) {
this.activeScore = activeScore;
}
}

@ -0,0 +1,29 @@
package com.community.pocket.entity.po.android;
import org.bson.types.ObjectId;
/**
* 投诉人
*/
public class Complain {
private ObjectId id;
//投诉人
private String complain;
public String getComplain() {
return complain;
}
public void setComplain(String complain) {
this.complain = complain;
}
public ObjectId getId() {
return id;
}
public void setId(ObjectId id) {
this.id = id;
}
}

@ -0,0 +1,104 @@
package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
//用户信息
@Document(TableName.info)
public class MyInfo {
//用户名
@Id
private String username;
//密码
private String password;
//信用分
private Integer creditScore;
//头像
private String headImg;
//最近发帖数
private Integer recentPosts;
//最近访客数
private Integer recentVisitors;
//手机号
private String mobie;
//邮箱
private String email;
//信用分历史记录
private List<Integer> scoreHistory;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getCreditScore() {
return creditScore;
}
public void setCreditScore(Integer creditScore) {
this.creditScore = creditScore;
}
public String getHeadImg() {
return headImg;
}
public void setHeadImg(String headImg) {
this.headImg = headImg;
}
public Integer getRecentPosts() {
return recentPosts;
}
public void setRecentPosts(Integer recentPosts) {
this.recentPosts = recentPosts;
}
public Integer getRecentVisitors() {
return recentVisitors;
}
public void setRecentVisitors(Integer recentVisitors) {
this.recentVisitors = recentVisitors;
}
public String getMobie() {
return mobie;
}
public void setMobie(String mobie) {
this.mobie = mobie;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Integer> getScoreHistory() {
return scoreHistory;
}
public void setScoreHistory(List<Integer> scoreHistory) {
this.scoreHistory = scoreHistory;
}
}

@ -0,0 +1,42 @@
package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 用户令牌
*/
@Document(TableName.token)
public class Token {
@Id
private String token;
private long time;
private String username;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

@ -1,21 +0,0 @@
package com.community.pocket.entity.vo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@ConfigurationProperties(prefix = "email")
public class Common {
private List<EmailType> supportType;
public List<EmailType> getSupportType() {
return supportType;
}
public void setSupportType(List<EmailType> supportType) {
this.supportType = supportType;
}
}

@ -0,0 +1,84 @@
package com.community.pocket.entity.vo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 读取邮箱配置
*/
@Component
@ConfigurationProperties("email")
public class EmailTypeConfig {
//发件地址
private String from;
//发件人
private String subject;
//验证码长度
@Value("${email.code.length}")
private Integer length;
//管理员注册验证信息
@Value("${email.code.manager}")
private String managerCodeMessage;
//用户重置密码信息
@Value("${email.code.user}")
private String userCodeMessage;
public String getManagerCodeMessage() {
return managerCodeMessage;
}
public void setManagerCodeMessage(String managerCodeMessage) {
this.managerCodeMessage = managerCodeMessage;
}
public String getUserCodeMessage() {
return userCodeMessage;
}
public void setUserCodeMessage(String userCodeMessage) {
this.userCodeMessage = userCodeMessage;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
//支持邮箱类型
private List<EmailType> supportType;
public List<EmailType> getSupportType() {
return supportType;
}
public void setSupportType(List<EmailType> supportType) {
this.supportType = supportType;
}
}

@ -7,11 +7,19 @@ public class JSONResponse<T> {
// 响应详细结果 // 响应详细结果
private String message; private String message;
// 自定义其他响应信息 // 自定义其他响应信息
@Deprecated
private T body; private T body;
public JSONResponse() { public JSONResponse() {
} }
public JSONResponse(Result result, String message) {
this.result = result;
this.message = message;
}
@Deprecated
public JSONResponse(Result result, String message, T body) { public JSONResponse(Result result, String message, T body) {
this.result = result; this.result = result;
this.message = message; this.message = message;

@ -1,5 +1,8 @@
package com.community.pocket.entity.vo; package com.community.pocket.entity.vo;
/**
* 管理员注册
*/
public class ManagerRegister { public class ManagerRegister {
// 管理员 // 管理员
private String managerName; private String managerName;

@ -0,0 +1,38 @@
package com.community.pocket.entity.vo.android;
/**
* 活动贴
*/
public class ActiveForm extends ForumForm {
//活动开始时间
private String activeStartTime;
//活动结束时间
private String activeEndTime;
//活动信用分
private String activeScore;
public String getActiveStartTime() {
return activeStartTime;
}
public void setActiveStartTime(String activeStartTime) {
this.activeStartTime = activeStartTime;
}
public String getActiveEndTime() {
return activeEndTime;
}
public void setActiveEndTime(String activeEndTime) {
this.activeEndTime = activeEndTime;
}
public String getActiveScore() {
return activeScore;
}
public void setActiveScore(String activeScore) {
this.activeScore = activeScore;
}
}

@ -0,0 +1,47 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
/**
* android接口响应体
* @param <T>
*/
public abstract class AndroidResponse<T extends CustomMessage> {
//操作结果
private Result result;
private T message;
private Object[] args;
public AndroidResponse(Result result, T message,Object ...args) {
this.result = result;
this.message = message;
this.args=args;
}
public Object[] getArgs() {
return args;
}
public void setArgs(Object[] args) {
this.args = args;
}
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public T getMessage() {
return message;
}
public void setMessage(T message) {
this.message = message;
}
}

@ -0,0 +1,13 @@
package com.community.pocket.entity.vo.android;
public class ComplainForm extends ForumForm{
private String complain;
public String getComplain() {
return complain;
}
public void setComplain(String complain) {
this.complain = complain;
}
}

@ -0,0 +1,9 @@
package com.community.pocket.entity.vo.android;
/**
* 自定义响应信息
*/
public interface CustomMessage {
}

@ -0,0 +1,27 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
public class ForumForm extends Token {
//标题
private String title;
//正文
private String content;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,38 @@
package com.community.pocket.entity.vo.android;
/**
* 帖子列表
*/
public class ForumHot {
//论坛ID
private String forumId;
//论坛标题
private String title;
//回复数
private Integer reply;
public Integer getReply() {
return reply;
}
public void setReply(Integer reply) {
this.reply = reply;
}
public String getForumId() {
return forumId;
}
public void setForumId(String forumId) {
this.forumId = forumId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

@ -0,0 +1,27 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
/**
* 热榜信息响应体
*/
public class ForumHotResponse extends AndroidResponse<ForumHotResponse.Msg> {
private Hot hot;
public Hot getHot() {
return hot;
}
public void setHot(Hot hot) {
this.hot = hot;
}
public ForumHotResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage{
ok,
fail
}
}

@ -0,0 +1,31 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 我的帖子响应结果
*/
public class ForumMyResponse extends AndroidResponse<ForumMyResponse.Msg>{
private List<Forum> forumList;
public ForumMyResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public List<Forum> getForumList() {
return forumList;
}
public void setForumList(List<Forum> forumList) {
this.forumList = forumList;
}
public enum Msg implements CustomMessage{
ok,
fail,
token
}
}

@ -0,0 +1,31 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 最新帖子响应
*/
public class ForumNewResponse extends AndroidResponse<ForumNewResponse.Msg> {
private List<Forum> forumList;
public List<Forum> getForumList() {
return forumList;
}
public void setForumList(List<Forum> forumList) {
this.forumList = forumList;
}
public ForumNewResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage{
ok,
fail
}
}

@ -0,0 +1,31 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.Notice;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 公告响应体
*/
public class ForumNoticeResponse extends AndroidResponse<ForumNoticeResponse.Msg> {
private List<Notice> noticeList;
public List<Notice> getNoticeList() {
return noticeList;
}
public void setNoticeList(List<Notice> noticeList) {
this.noticeList = noticeList;
}
public ForumNoticeResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
ok,
fail
}
}

@ -0,0 +1,18 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
/**
* 发帖响应
*/
public class ForumPostResponse extends AndroidResponse<ForumPostResponse.Msg>{
public ForumPostResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage{
ok,
fail,
token
}
}

@ -0,0 +1,33 @@
package com.community.pocket.entity.vo.android;
import java.util.List;
/**
* 热门动态实体
*/
public class Hot {
//活跃用户
private List<UserHot> userHots;
//热门动态
private List<ForumHot> topicHots;
//热门活动
private List<ForumHot> activeHots;
public Hot(List<UserHot> userHots, List<ForumHot> topicHots, List<ForumHot> activeHots) {
this.userHots = userHots;
this.topicHots = topicHots;
this.activeHots = activeHots;
}
public List<UserHot> getUserHots() {
return userHots;
}
public List<ForumHot> getTopicHots() {
return topicHots;
}
public List<ForumHot> getActiveHots() {
return activeHots;
}
}

@ -0,0 +1,28 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.Result;
/**
* 登陆响应
*/
public class LoginResponse extends AndroidResponse<LoginResponse.Msg> {
private Token token;
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}
public LoginResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage{
ok,
fail
}
}

@ -0,0 +1,27 @@
package com.community.pocket.entity.vo.android;
/**
* 检索用户表单
*/
public class QueryUserForm {
//模糊匹配关键字
private String name;
//排除自己
private String username;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

@ -0,0 +1,29 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 查询用户
*/
public class QueryUserResponse extends AndroidResponse<QueryUserResponse.Msg>{
private List<String> peopleList;
public QueryUserResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public List<String> getPeopleList() {
return peopleList;
}
public void setPeopleList(List<String> peopleList) {
this.peopleList = peopleList;
}
public enum Msg implements CustomMessage{
ok,
fail
}
}

@ -0,0 +1,24 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
/**
* 注册响应
*/
public class RegisterResponse extends AndroidResponse<RegisterResponse.Msg> {
public RegisterResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
/**
* 响应类型
*/
public enum Msg implements CustomMessage {
ok,
name,
mobie,
email
}
}

@ -0,0 +1,24 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Result;
/**
* 重置密码响应
*/
public class ResetPwdResponse extends AndroidResponse<ResetPwdResponse.Msg>{
public ResetPwdResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
step1_ok,
step1_fail,
step2_ok,
step2_fail,
step2_valid_ok,
step2_valid_fail,
step3_ok,
step3_fail
}
}

@ -0,0 +1,28 @@
package com.community.pocket.entity.vo.android;
/**
* 活跃用户
*/
public class UserHot {
//用户名
private String userName;
//信用分
private Integer creditScore;
public Integer getCreditScore() {
return creditScore;
}
public void setCreditScore(Integer creditScore) {
this.creditScore = creditScore;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}

@ -0,0 +1,47 @@
package com.community.pocket.entity.vo.android;
/**
* 用户注册
*/
public class UserRegister {
//用户名
private String username;
//密码
private String password;
//手机
private String mobie;
//邮箱
private String email;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getMobie() {
return mobie;
}
public void setMobie(String mobie) {
this.mobie = mobie;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

@ -0,0 +1,45 @@
package com.community.pocket.entity.vo.android;
//用户重置密码
public class UserResetPwd {
//用户名
private String username;
//邮箱
private String email;
//验证码
private String code;
//重置密码
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -0,0 +1,16 @@
package com.community.pocket.repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
public abstract class BaseDao<T> {
@Autowired
protected MongoTemplate mongoTemplate;
//增加
public abstract T save(T t);
public abstract Class<T> entityClass();
}

@ -0,0 +1,49 @@
package com.community.pocket.repository;
import com.community.pocket.entity.po.EmailCode;
import com.mongodb.client.result.DeleteResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
/**
* 邮件管理
*/
@Repository
public class EmailDao extends BaseDao<EmailCode> {
private static final Logger LOG = LoggerFactory.getLogger(EmailDao.class);
//检查验证码
public boolean checkCode(String email,String code){
if(!StringUtils.isEmpty(email)&&!StringUtils.isEmpty(code)){
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("emailAddress").is(email).and("code").is(code)), entityClass());
}else {
return false;
}
}
public boolean clearEmail(String email){
DeleteResult result= mongoTemplate.remove(new Query(Criteria.where("emailAddress").is(email)),entityClass());
return result.wasAcknowledged();
}
@Override
public EmailCode save(EmailCode emailCode) {
try {
return mongoTemplate.save(emailCode);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<EmailCode> entityClass() {
return EmailCode.class;
}
}

@ -3,18 +3,20 @@ package com.community.pocket.repository;
import com.community.pocket.entity.po.Manager; import com.community.pocket.entity.po.Manager;
import com.community.pocket.entity.vo.ManagerLogin; import com.community.pocket.entity.vo.ManagerLogin;
import org.springframework.beans.factory.annotation.Autowired; import org.slf4j.Logger;
import org.springframework.data.mongodb.core.MongoTemplate; import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
/**
* 管理员接口
*/
@Repository @Repository
public class ManagerDao { public class ManagerDao extends BaseDao<Manager>{
@Autowired private static final Logger LOG = LoggerFactory.getLogger(ManagerDao.class);
private MongoTemplate mongoTemplate;
// 登陆 // 登陆
public boolean login(ManagerLogin managerLogin){ public boolean login(ManagerLogin managerLogin){
@ -23,7 +25,7 @@ public class ManagerDao {
try { try {
// 查询管理员 // 查询管理员
Manager manager= mongoTemplate.findOne(new Query(criteria), Manager.class); Manager manager= mongoTemplate.findOne(new Query(criteria), entityClass());
//查询出来的管理员非空,并且管理员名和MD5(密码)匹配返回true //查询出来的管理员非空,并且管理员名和MD5(密码)匹配返回true
return manager!=null&&manager.getManagerName().equals(managerLogin.getManagerName())&&manager.getPassword().equals(DigestUtils.md5DigestAsHex(managerLogin.getPassword().getBytes())); return manager!=null&&manager.getManagerName().equals(managerLogin.getManagerName())&&manager.getPassword().equals(DigestUtils.md5DigestAsHex(managerLogin.getPassword().getBytes()));
} catch (Exception e) { } catch (Exception e) {
@ -35,7 +37,7 @@ public class ManagerDao {
//查询管理员名字是否已经注册 //查询管理员名字是否已经注册
public boolean hasUser(String name){ public boolean hasUser(String name){
try { try {
Manager manager=mongoTemplate.findOne(new Query(Criteria.where("managerName").is(name)),Manager.class); Manager manager=mongoTemplate.findOne(new Query(Criteria.where("managerName").is(name)),entityClass());
//非空返回true //非空返回true
return manager!=null; return manager!=null;
} catch (Exception e) { } catch (Exception e) {
@ -44,12 +46,19 @@ public class ManagerDao {
} }
// 保存管理员注册信息 // 保存管理员注册信息
public boolean save(Manager manager){ @Override
public Manager save(Manager manager){
try { try {
mongoTemplate.save(manager); return mongoTemplate.save(manager);
return true;
} catch (Exception e) { } catch (Exception e) {
return false; e.printStackTrace();
LOG.error(e.toString());
} }
return null;
}
@Override
public Class<Manager> entityClass() {
return Manager.class;
} }
} }

@ -0,0 +1,42 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Active;
import com.community.pocket.entity.vo.android.ActiveForm;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
//活动贴数据接口
@Repository
public class ActiveDao extends BaseDao<Active>{
private static final Logger LOG = LoggerFactory.getLogger(ForumDao.class);
//保存活动贴
public Active save(ActiveForm activeForm, Forum forum) {
Active active=new Active();
active.setId(forum.getId());
active.setActiveStartTime(activeForm.getActiveStartTime());
active.setActiveEndTime(activeForm.getActiveEndTime());
active.setActiveScore(activeForm.getActiveScore());
return save(active);
}
@Override
public Active save(Active active) {
try {
return mongoTemplate.save(active);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<Active> entityClass() {
return Active.class;
}
}

@ -0,0 +1,41 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.vo.android.ComplainForm;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
/**
* 投诉人保存
*/
@Repository
public class ComplainDao extends BaseDao<Complain> {
private static final Logger LOG = LoggerFactory.getLogger(ComplainDao.class);
//保存投诉贴
public Complain save(ComplainForm complainForm, Forum forum) {
Complain complain=new Complain();
complain.setComplain(complainForm.getComplain());
complain.setId(forum.getId());
return save(complain);
}
@Override
public Complain save(Complain complain) {
try {
return mongoTemplate.save(complain);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<Complain> entityClass() {
return Complain.class;
}
}

@ -0,0 +1,46 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.ForumContent;
import com.community.pocket.entity.vo.android.ForumForm;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
/**
* 帖子正文详情
*/
@Repository
public class ForumContentDao extends BaseDao<ForumContent> {
private static final Logger LOG = LoggerFactory.getLogger(ForumDao.class);
/**
* 保存帖子详情
*/
public ForumContent save(ForumForm forumForm, Forum forum){
ForumContent forumContent=new ForumContent();
forumContent.setContent(forumForm.getContent());
forumContent.setId(forum.getId());
forumContent.setTime(forum.getTime());
forumContent.setTower(1);
forumContent.setUsername(forum.getUsername());
return save(forumContent);
}
//保存
@Override
public ForumContent save(ForumContent forumContent) {
try {
return mongoTemplate.save(forumContent);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<ForumContent> entityClass() {
return ForumContent.class;
}
}

@ -0,0 +1,151 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.vo.android.ActiveForm;
import com.community.pocket.entity.vo.android.ComplainForm;
import com.community.pocket.entity.vo.android.ForumForm;
import com.community.pocket.entity.vo.android.ForumHot;
import com.community.pocket.repository.BaseDao;
import com.community.pocket.util.TableName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.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.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
/**
* 帖子数据接口
*/
@Repository
public class ForumDao extends BaseDao<Forum> {
private static final Logger LOG = LoggerFactory.getLogger(ForumDao.class);
@Value("${forum.content-length}")
private int contentLength;
//关联用户表查询
private static final LookupOperation lookupOperation=LookupOperation.newLookup().
from(TableName.info). //关联从表名
localField("username"). //主表关联字段
foreignField("_id").//从表关联的字段
as("myInfo"); //查询结果名
//查找热门贴
public List<ForumHot> rankReply(Forum.ForumType type, int num){
List<ForumHot> forumHots=new ArrayList<>();
List<Forum> forumList =mongoTemplate.find(new Query(Criteria.where("forumType").is(type)).with(Sort.by("reply").descending()).limit(num),entityClass());
for(Forum forum:forumList){
ForumHot forumHot=new ForumHot();
forumHot.setForumId(forum.getForumId());
forumHot.setReply(forum.getReply());
forumHot.setTitle(forum.getTitle());
forumHots.add(forumHot);
}
return forumHots;
}
//查找帖子
private List<Forum> loadForum(AggregationOperation ...operation) {
try {
Aggregation aggregation=Aggregation.newAggregation(operation);
return mongoTemplate.aggregate(aggregation,TableName.forum, Forum.class).getMappedResults();
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//查找所有帖子
public List<Forum> loadNewForum(){
return loadForum(lookupOperation,Aggregation.unwind("myInfo"),Aggregation.sort(Sort.by("time").descending()));
}
//查找最新帖子
public List<Forum> loadMyForum(String username){
return loadForum(lookupOperation,Aggregation.unwind("myInfo"),Aggregation.match(Criteria.where("username").is(username)),Aggregation.sort(Sort.by("time").descending()));
}
//保存活动贴
public Forum save(ActiveForm activeForm){
try {
Forum forum=new Forum();
forum.setUsername(activeForm.getUsername());
forum.setForumType(Forum.ForumType.active);
forum.setReply(0);
forum.setTitle(activeForm.getTitle());
forum.setTime(System.currentTimeMillis());
if(activeForm.getContent().length()>contentLength){
forum.setContent(activeForm.getContent().substring(0,contentLength));
}else{
forum.setContent(activeForm.getContent());
}
return save(forum);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//保存动态
public Forum save(ForumForm forumForm){
try {
Forum forum=new Forum();
forum.setContent(forumForm.getContent());
forum.setTitle(forumForm.getTitle());
forum.setForumType(Forum.ForumType.topic);
forum.setTime(System.currentTimeMillis());
forum.setReply(0);
forum.setUsername(forumForm.getUsername());
return save(forum);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//保存投诉
public Forum save(ComplainForm complainForm){
try {
Forum forum=new Forum();
forum.setContent(complainForm.getContent());
forum.setTitle(complainForm.getTitle());
forum.setForumType(Forum.ForumType.complan);
forum.setTime(System.currentTimeMillis());
forum.setReply(0);
forum.setUsername(complainForm.getUsername());
return save(forum);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//保存
@Override
public Forum save(Forum forum) {
try {
return mongoTemplate.save(forum);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<Forum> entityClass() {
return Forum.class;
}
}

@ -0,0 +1,45 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Notice;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 公告信息数据接口
*/
@Repository
public class NoticeDao extends BaseDao<Notice> {
private static final Logger LOG = LoggerFactory.getLogger(NoticeDao.class);
@Override
public Notice save(Notice notice) {
try {
return mongoTemplate.save(notice);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//加载所有公告
public List<Notice> loadNotices(){
try {
return mongoTemplate.findAll(Notice.class);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<Notice> entityClass() {
return Notice.class;
}
}

@ -0,0 +1,83 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.DigestUtils;
import java.util.concurrent.TimeUnit;
//令牌数据接口
@Repository
public class TokenDao extends BaseDao<Token> {
@Value("${token.day}")
private int day;
private static final Logger LOG = LoggerFactory.getLogger(TokenDao.class);
/**
* 保存令牌
*/
public Token save(String username){
try {
if(cleanToken(username)) {
Token token = new Token();
token.setTime(System.currentTimeMillis()+ TimeUnit.DAYS.toMillis(1));
token.setUsername(username);
token.setToken(DigestUtils.md5DigestAsHex((token.getUsername() + token.getTime()).getBytes()));
save(token);
return token;
}
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//清空令牌
public boolean cleanToken(String username){
Query query=new Query(Criteria.where("username").is(username));
if(mongoTemplate.exists(query,entityClass())){
return mongoTemplate.remove(query,entityClass()).wasAcknowledged();
}else {
return true;
}
}
//判断令牌是否有效
public <T extends Token> boolean checkToken(T 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());
}
public Token get(String token){
return mongoTemplate.findOne(new Query(Criteria.where("token").is(token)),entityClass());
}
@Override
public Token save(Token token) {
try {
mongoTemplate.save(token);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<Token> entityClass() {
return Token.class;
}
}

@ -0,0 +1,137 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.entity.vo.android.UserHot;
import com.community.pocket.entity.vo.android.UserRegister;
import com.community.pocket.repository.BaseDao;
import com.mongodb.client.result.UpdateResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
//用户数据接口
@Repository
public class UserDao extends BaseDao<MyInfo> {
private static final Logger LOG = LoggerFactory.getLogger(UserDao.class);
//检查用户名是否已注册
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 hasMobie(String mobie) {
if (!StringUtils.isEmpty(mobie)) {
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("mobie").is(mobie)),entityClass());
}else{
return false;
}
}
//检查邮箱是否已绑定
public boolean hasEmail(String email){
if(!StringUtils.isEmpty(email)){
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("email").is(email)),entityClass());
}else{
return false;
}
}
//检查用户和邮箱是否对应
public boolean hasUseWithEmail(String username, String email){
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(email)){
return mongoTemplate.exists(new Query().addCriteria(Criteria.where("username").is(username).and("email").is(email)),entityClass());
}else{
return false;
}
}
//重置密码
public boolean resetPwd(String username,String password){
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(password)){
String md5Password= DigestUtils.md5DigestAsHex(password.getBytes());
UpdateResult result=mongoTemplate.updateFirst(new Query().addCriteria(Criteria.where("username").is(username)), Update.update("password",md5Password),entityClass());
return result.wasAcknowledged();
}else{
return false;
}
}
//登陆用户
public boolean login(String username, String password) {
if(!StringUtils.isEmpty(username)&&!StringUtils.isEmpty(password)){
String md5Password= DigestUtils.md5DigestAsHex(password.getBytes());
return mongoTemplate.exists(new Query(Criteria.where("username").is(username).and("password").is(md5Password)),entityClass());
}else{
return false;
}
}
//注册用户
public void save(UserRegister userRegister){
MyInfo myInfo=new MyInfo();
myInfo.setUsername(userRegister.getUsername());
myInfo.setPassword(DigestUtils.md5DigestAsHex(userRegister.getPassword().getBytes()));
myInfo.setMobie(userRegister.getMobie());
myInfo.setEmail(userRegister.getEmail());
myInfo.setCreditScore(0);
save(myInfo);
}
//获取活跃用户
public List<UserHot> rankUser(int num){
List<UserHot> userHots=new ArrayList<>();
List<MyInfo> myInfos=mongoTemplate.find(new Query().with(Sort.by("creditScore").descending()).limit(num),entityClass());
for(MyInfo info:myInfos){
UserHot userHot=new UserHot();
userHot.setUserName(info.getUsername());
userHot.setCreditScore(info.getCreditScore());
userHots.add(userHot);
}
return userHots;
}
//获取用户
public List<String> queryUser(QueryUserForm userForm){
List<String> userNames=new ArrayList<>();
List<MyInfo> myInfos=mongoTemplate.find(new Query(Criteria.where("username").ne(userForm.getUsername()).and("username").regex(Pattern.compile(".*"+userForm.getName()+".*"))),entityClass());
for(MyInfo info:myInfos){
userNames.add(info.getUsername());
}
return userNames;
}
@Override
public MyInfo save(MyInfo myInfo) {
try {
mongoTemplate.save(myInfo);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<MyInfo> entityClass() {
return MyInfo.class;
}
}

@ -1,39 +1,76 @@
package com.community.pocket.util; package com.community.pocket.util;
import com.community.pocket.entity.po.EmailCode; import com.community.pocket.entity.po.EmailCode;
import com.community.pocket.entity.vo.EmailTypeConfig;
import com.community.pocket.repository.EmailDao;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.mail.MailException; import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Random;
@Service @Service
public class EmailService { public class EmailService {
@Autowired @Autowired
private JavaMailSenderImpl javaMailSender; private JavaMailSenderImpl javaMailSender;
@Autowired @Autowired
private MongoTemplate mongoTemplate; private EmailTypeConfig emailTypeConfig;
@Autowired
private EmailDao emailDao;
public boolean sendCode(String sender) { /**
* 发送管理员注册激活邮件
* @param sender 发送人
*/
public boolean sendManagerCode(String sender) {
EmailCode emailCode=new EmailCode();
emailCode.setCode(RandomStringUtils.randomNumeric(emailTypeConfig.getLength()));
emailCode.setEmailAddress(sender);
SimpleMailMessage message = new SimpleMailMessage(); SimpleMailMessage message = new SimpleMailMessage();
message.setSubject("口袋社区激活邮箱"); message.setSubject(emailTypeConfig.getSubject());
message.setText("欢迎注册口袋社区后台服务,您获取到的验证码是:xxxx"); message.setText(String.format(emailTypeConfig.getManagerCodeMessage(),emailCode.getCode()));
message.setTo(sender); message.setTo(sender);
message.setFrom("15920722180@163.com"); message.setFrom(emailTypeConfig.getFrom());
try { try {
javaMailSender.send(message); javaMailSender.send(message);
EmailCode emailCode=new EmailCode();
emailCode.setCode(new Random().nextInt(1000)+""); emailDao.save(emailCode);
emailCode.setEmailAddress(sender);
mongoTemplate.save(emailCode);
return true; return true;
} catch (MailException e) { } catch (MailException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} }
/**
* 发送用户重置密码邮件
* @param sender 发送目标
*
*/
public boolean sendUserCode(String sender){
if(emailDao.clearEmail(sender)) {
EmailCode emailCode = new EmailCode();
emailCode.setCode(RandomStringUtils.randomNumeric(emailTypeConfig.getLength()));
emailCode.setEmailAddress(sender);
SimpleMailMessage message = new SimpleMailMessage();
message.setSubject(emailTypeConfig.getSubject());
message.setText(String.format(emailTypeConfig.getUserCodeMessage(),emailCode.getCode()));
message.setTo(sender);
message.setFrom(emailTypeConfig.getFrom());
try {
javaMailSender.send(message);
emailDao.save(emailCode);
return true;
} catch (MailException e) {
e.printStackTrace();
return false;
}
}else{
return false;
}
}
} }

@ -0,0 +1,23 @@
package com.community.pocket.util;
/**
* 集合名
*/
public class TableName {
//用户信息
public static final String info="myInfo";
//管理员信息
public static final String manager="manager";
//验证码邮件
public static final String emailCode="emailCode";
//令牌
public static final String token="token";
//帖子基础信息
public static final String forum="forum";
//帖子详情信息
public static final String forumContent="forumContent";
//活动帖子
public static final String active="active";
//公告
public static final String notice="notice";
}

@ -15,6 +15,21 @@ spring:
#邮箱配置 #邮箱配置
email: email:
supportType: support-type:
- name: 网易 - name: 网易
suffix: '@163.com' suffix: '@163.com'
subject: 口袋社区
from: 15920722180@163.com
code:
length: 6
manager: 欢迎注册口袋社区后台服务,您获取到的验证码是:%s
user: 重置密码,您获取到的验证码是:%s
#令牌配置
token:
day: 1
#论坛配置
forum:
#帖子正文缩略长度
content-length: 10
Loading…
Cancel
Save