diff --git a/build.gradle b/build.gradle index 078c142..da0666d 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-rest' implementation 'org.springframework.boot:spring-boot-starter-mail' 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-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' diff --git a/src/main/java/com/community/pocket/api/android/ForumController.java b/src/main/java/com/community/pocket/api/android/ForumController.java new file mode 100644 index 0000000..c2fde76 --- /dev/null +++ b/src/main/java/com/community/pocket/api/android/ForumController.java @@ -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 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 = userDao.rankUser(num); + List topicHot = forumDao.rankReply(Forum.ForumType.topic, num); + List activeHot = forumDao.rankReply(Forum.ForumType.active, num); + ForumHotResponse response; + if (userHot != null && topicHot != null && activeHot != null) { + Hot hot = new Hot(userHot, topicHot, activeHot); + response = new ForumHotResponse(Result.OK, ForumHotResponse.Msg.ok); + response.setHot(hot); + } else { + response = new ForumHotResponse(Result.FAIL, ForumHotResponse.Msg.fail); + } + return response; + } + + //加载最新帖子 + @GetMapping("/forum/new") + public ForumNewResponse loadForumNew() { + List 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 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); + } + } + +} diff --git a/src/main/java/com/community/pocket/api/android/UserController.java b/src/main/java/com/community/pocket/api/android/UserController.java new file mode 100644 index 0000000..bc9eb03 --- /dev/null +++ b/src/main/java/com/community/pocket/api/android/UserController.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/api/ManagerController.java b/src/main/java/com/community/pocket/api/web/ManagerController.java similarity index 95% rename from src/main/java/com/community/pocket/api/ManagerController.java rename to src/main/java/com/community/pocket/api/web/ManagerController.java index be01294..ff47a9d 100644 --- a/src/main/java/com/community/pocket/api/ManagerController.java +++ b/src/main/java/com/community/pocket/api/web/ManagerController.java @@ -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.Token; @@ -24,9 +24,11 @@ public class ManagerController { @Autowired private ManagerDao managerDao; + //邮箱配置 @Autowired - private Common common; + private EmailTypeConfig emailTypeConfig; + //邮箱服务 @Autowired private EmailService emailService; @@ -59,16 +61,15 @@ public class ManagerController { /** * 获取邮箱类型 - * @return */ @GetMapping("emailType") public JSONResponse> getEmailType(){ - return new JSONResponse<>(Result.OK,"获取邮箱类型成功", common.getSupportType()); + return new JSONResponse<>(Result.OK,"获取邮箱类型成功", emailTypeConfig.getSupportType()); } @PostMapping("sendcode") public JSONResponse sendEmail(String sender){ - if(emailService.sendCode(sender)){ + if(emailService.sendManagerCode(sender)){ return new JSONResponse<>(Result.OK,"发送邮件成功",null); }else{ return new JSONResponse<>(Result.OK,"发送邮件失败",null); diff --git a/src/main/java/com/community/pocket/entity/po/EmailCode.java b/src/main/java/com/community/pocket/entity/po/EmailCode.java index 877d277..217a7a9 100644 --- a/src/main/java/com/community/pocket/entity/po/EmailCode.java +++ b/src/main/java/com/community/pocket/entity/po/EmailCode.java @@ -1,8 +1,12 @@ 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 { //发送邮箱 private String emailAddress; @@ -23,4 +27,12 @@ public class EmailCode { public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } + + public String getEmailAddress() { + return emailAddress; + } + + public Long getSendTime() { + return sendTime; + } } diff --git a/src/main/java/com/community/pocket/entity/po/Forum.java b/src/main/java/com/community/pocket/entity/po/Forum.java index aed7367..4456f71 100644 --- a/src/main/java/com/community/pocket/entity/po/Forum.java +++ b/src/main/java/com/community/pocket/entity/po/Forum.java @@ -1,17 +1,108 @@ 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 { - @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; } - public void setId(String id) { + public String getForumId(){ + return this.id.toString(); + } + + public void setId(ObjectId id) { this.id = id; } } diff --git a/src/main/java/com/community/pocket/entity/po/ForumContent.java b/src/main/java/com/community/pocket/entity/po/ForumContent.java new file mode 100644 index 0000000..6851b0a --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/ForumContent.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/po/Manager.java b/src/main/java/com/community/pocket/entity/po/Manager.java index 4b1c092..55a3de6 100644 --- a/src/main/java/com/community/pocket/entity/po/Manager.java +++ b/src/main/java/com/community/pocket/entity/po/Manager.java @@ -1,8 +1,11 @@ package com.community.pocket.entity.po; +import com.community.pocket.util.TableName; import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; //管理员 +@Document(TableName.manager) public class Manager { // 管理员 @Id @@ -13,7 +16,7 @@ public class Manager { private Long mobie; // 邮箱 private String email; - + //令牌 private Token token; public String getManagerName() { diff --git a/src/main/java/com/community/pocket/entity/po/Notice.java b/src/main/java/com/community/pocket/entity/po/Notice.java new file mode 100644 index 0000000..117c9e2 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/Notice.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/po/android/Active.java b/src/main/java/com/community/pocket/entity/po/android/Active.java new file mode 100644 index 0000000..472660b --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/android/Active.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/po/android/Complain.java b/src/main/java/com/community/pocket/entity/po/android/Complain.java new file mode 100644 index 0000000..0388ecb --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/android/Complain.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/po/android/MyInfo.java b/src/main/java/com/community/pocket/entity/po/android/MyInfo.java new file mode 100644 index 0000000..6226553 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/android/MyInfo.java @@ -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 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 getScoreHistory() { + return scoreHistory; + } + + public void setScoreHistory(List scoreHistory) { + this.scoreHistory = scoreHistory; + } +} diff --git a/src/main/java/com/community/pocket/entity/po/android/Token.java b/src/main/java/com/community/pocket/entity/po/android/Token.java new file mode 100644 index 0000000..0c20007 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/po/android/Token.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/Common.java b/src/main/java/com/community/pocket/entity/vo/Common.java deleted file mode 100644 index 6e451a0..0000000 --- a/src/main/java/com/community/pocket/entity/vo/Common.java +++ /dev/null @@ -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 supportType; - - public List getSupportType() { - return supportType; - } - - public void setSupportType(List supportType) { - this.supportType = supportType; - } -} diff --git a/src/main/java/com/community/pocket/entity/vo/EmailTypeConfig.java b/src/main/java/com/community/pocket/entity/vo/EmailTypeConfig.java new file mode 100644 index 0000000..3ef9075 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/EmailTypeConfig.java @@ -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 supportType; + + public List getSupportType() { + return supportType; + } + + public void setSupportType(List supportType) { + this.supportType = supportType; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/JSONResponse.java b/src/main/java/com/community/pocket/entity/vo/JSONResponse.java index 065b4f1..f7098bc 100644 --- a/src/main/java/com/community/pocket/entity/vo/JSONResponse.java +++ b/src/main/java/com/community/pocket/entity/vo/JSONResponse.java @@ -7,11 +7,19 @@ public class JSONResponse { // 响应详细结果 private String message; // 自定义其他响应信息 + @Deprecated private T body; public JSONResponse() { } + + public JSONResponse(Result result, String message) { + this.result = result; + this.message = message; + } + + @Deprecated public JSONResponse(Result result, String message, T body) { this.result = result; this.message = message; diff --git a/src/main/java/com/community/pocket/entity/vo/ManagerRegister.java b/src/main/java/com/community/pocket/entity/vo/ManagerRegister.java index 5642751..93917b5 100644 --- a/src/main/java/com/community/pocket/entity/vo/ManagerRegister.java +++ b/src/main/java/com/community/pocket/entity/vo/ManagerRegister.java @@ -1,5 +1,8 @@ package com.community.pocket.entity.vo; +/** + * 管理员注册 + */ public class ManagerRegister { // 管理员 private String managerName; diff --git a/src/main/java/com/community/pocket/entity/vo/android/ActiveForm.java b/src/main/java/com/community/pocket/entity/vo/android/ActiveForm.java new file mode 100644 index 0000000..28ec374 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ActiveForm.java @@ -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; + } + +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/AndroidResponse.java b/src/main/java/com/community/pocket/entity/vo/android/AndroidResponse.java new file mode 100644 index 0000000..33d57a4 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/AndroidResponse.java @@ -0,0 +1,47 @@ +package com.community.pocket.entity.vo.android; + +import com.community.pocket.entity.vo.Result; + +/** + * android接口响应体 + * @param + */ +public abstract class AndroidResponse { + + //操作结果 + 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; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ComplainForm.java b/src/main/java/com/community/pocket/entity/vo/android/ComplainForm.java new file mode 100644 index 0000000..60e3440 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ComplainForm.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/CustomMessage.java b/src/main/java/com/community/pocket/entity/vo/android/CustomMessage.java new file mode 100644 index 0000000..deab099 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/CustomMessage.java @@ -0,0 +1,9 @@ +package com.community.pocket.entity.vo.android; + +/** + * 自定义响应信息 + */ +public interface CustomMessage { + +} + diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumForm.java b/src/main/java/com/community/pocket/entity/vo/android/ForumForm.java new file mode 100644 index 0000000..8824c70 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumForm.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumHot.java b/src/main/java/com/community/pocket/entity/vo/android/ForumHot.java new file mode 100644 index 0000000..88bb958 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumHot.java @@ -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; + } + +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumHotResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ForumHotResponse.java new file mode 100644 index 0000000..c6ee0ce --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumHotResponse.java @@ -0,0 +1,27 @@ +package com.community.pocket.entity.vo.android; + +import com.community.pocket.entity.vo.Result; + +/** + * 热榜信息响应体 + */ +public class ForumHotResponse extends AndroidResponse { + 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 + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java new file mode 100644 index 0000000..2e1537e --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java @@ -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{ + private List forumList; + + public ForumMyResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + public List getForumList() { + return forumList; + } + + public void setForumList(List forumList) { + this.forumList = forumList; + } + + public enum Msg implements CustomMessage{ + ok, + fail, + token + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumNewResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ForumNewResponse.java new file mode 100644 index 0000000..ec9b134 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumNewResponse.java @@ -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 { + + private List forumList; + + public List getForumList() { + return forumList; + } + + public void setForumList(List forumList) { + this.forumList = forumList; + } + + public ForumNewResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + public enum Msg implements CustomMessage{ + ok, + fail + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumNoticeResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ForumNoticeResponse.java new file mode 100644 index 0000000..0d596e1 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumNoticeResponse.java @@ -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 { + + private List noticeList; + + public List getNoticeList() { + return noticeList; + } + + public void setNoticeList(List noticeList) { + this.noticeList = noticeList; + } + + public ForumNoticeResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + public enum Msg implements CustomMessage { + ok, + fail + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ForumPostResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ForumPostResponse.java new file mode 100644 index 0000000..cdc2208 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ForumPostResponse.java @@ -0,0 +1,18 @@ +package com.community.pocket.entity.vo.android; + +import com.community.pocket.entity.vo.Result; + +/** + * 发帖响应 + */ +public class ForumPostResponse extends AndroidResponse{ + public ForumPostResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + public enum Msg implements CustomMessage{ + ok, + fail, + token + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/Hot.java b/src/main/java/com/community/pocket/entity/vo/android/Hot.java new file mode 100644 index 0000000..8eed035 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/Hot.java @@ -0,0 +1,33 @@ +package com.community.pocket.entity.vo.android; + +import java.util.List; + +/** + * 热门动态实体 + */ +public class Hot { + //活跃用户 + private List userHots; + //热门动态 + private List topicHots; + //热门活动 + private List activeHots; + + public Hot(List userHots, List topicHots, List activeHots) { + this.userHots = userHots; + this.topicHots = topicHots; + this.activeHots = activeHots; + } + + public List getUserHots() { + return userHots; + } + + public List getTopicHots() { + return topicHots; + } + + public List getActiveHots() { + return activeHots; + } +} \ No newline at end of file diff --git a/src/main/java/com/community/pocket/entity/vo/android/LoginResponse.java b/src/main/java/com/community/pocket/entity/vo/android/LoginResponse.java new file mode 100644 index 0000000..313b51f --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/LoginResponse.java @@ -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 { + 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 + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java b/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java new file mode 100644 index 0000000..4868d55 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/QueryUserForm.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java b/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java new file mode 100644 index 0000000..5bba5c6 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java @@ -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{ + private List peopleList; + + public QueryUserResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + public List getPeopleList() { + return peopleList; + } + + public void setPeopleList(List peopleList) { + this.peopleList = peopleList; + } + + public enum Msg implements CustomMessage{ + ok, + fail + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/RegisterResponse.java b/src/main/java/com/community/pocket/entity/vo/android/RegisterResponse.java new file mode 100644 index 0000000..0e9d276 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/RegisterResponse.java @@ -0,0 +1,24 @@ +package com.community.pocket.entity.vo.android; + +import com.community.pocket.entity.vo.Result; + +/** + * 注册响应 + */ +public class RegisterResponse extends AndroidResponse { + + + public RegisterResponse(Result result, Msg message, Object... args) { + super(result, message, args); + } + + /** + * 响应类型 + */ + public enum Msg implements CustomMessage { + ok, + name, + mobie, + email + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/ResetPwdResponse.java b/src/main/java/com/community/pocket/entity/vo/android/ResetPwdResponse.java new file mode 100644 index 0000000..50996c0 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/ResetPwdResponse.java @@ -0,0 +1,24 @@ +package com.community.pocket.entity.vo.android; + +import com.community.pocket.entity.vo.Result; + +/** + * 重置密码响应 + */ +public class ResetPwdResponse extends AndroidResponse{ + + 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 + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/UserHot.java b/src/main/java/com/community/pocket/entity/vo/android/UserHot.java new file mode 100644 index 0000000..82beb42 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/UserHot.java @@ -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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/community/pocket/entity/vo/android/UserRegister.java b/src/main/java/com/community/pocket/entity/vo/android/UserRegister.java new file mode 100644 index 0000000..239b309 --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/UserRegister.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/entity/vo/android/UserResetPwd.java b/src/main/java/com/community/pocket/entity/vo/android/UserResetPwd.java new file mode 100644 index 0000000..a53b50d --- /dev/null +++ b/src/main/java/com/community/pocket/entity/vo/android/UserResetPwd.java @@ -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; + } +} diff --git a/src/main/java/com/community/pocket/repository/BaseDao.java b/src/main/java/com/community/pocket/repository/BaseDao.java new file mode 100644 index 0000000..16d2b13 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/BaseDao.java @@ -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 { + + + @Autowired + protected MongoTemplate mongoTemplate; + + //增加 + public abstract T save(T t); + + public abstract Class entityClass(); +} diff --git a/src/main/java/com/community/pocket/repository/EmailDao.java b/src/main/java/com/community/pocket/repository/EmailDao.java new file mode 100644 index 0000000..b17e5f6 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/EmailDao.java @@ -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 { + + 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 entityClass() { + return EmailCode.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/ManagerDao.java b/src/main/java/com/community/pocket/repository/ManagerDao.java index 4cf2719..94e5dd0 100644 --- a/src/main/java/com/community/pocket/repository/ManagerDao.java +++ b/src/main/java/com/community/pocket/repository/ManagerDao.java @@ -3,18 +3,20 @@ package com.community.pocket.repository; import com.community.pocket.entity.po.Manager; import com.community.pocket.entity.vo.ManagerLogin; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; +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.DigestUtils; +/** + * 管理员接口 + */ @Repository -public class ManagerDao { +public class ManagerDao extends BaseDao{ - @Autowired - private MongoTemplate mongoTemplate; + private static final Logger LOG = LoggerFactory.getLogger(ManagerDao.class); // 登陆 public boolean login(ManagerLogin managerLogin){ @@ -23,7 +25,7 @@ public class ManagerDao { try { // 查询管理员 - Manager manager= mongoTemplate.findOne(new Query(criteria), Manager.class); + Manager manager= mongoTemplate.findOne(new Query(criteria), entityClass()); //查询出来的管理员非空,并且管理员名和MD5(密码)匹配返回true return manager!=null&&manager.getManagerName().equals(managerLogin.getManagerName())&&manager.getPassword().equals(DigestUtils.md5DigestAsHex(managerLogin.getPassword().getBytes())); } catch (Exception e) { @@ -35,7 +37,7 @@ public class ManagerDao { //查询管理员名字是否已经注册 public boolean hasUser(String name){ 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 return manager!=null; } catch (Exception e) { @@ -44,12 +46,19 @@ public class ManagerDao { } // 保存管理员注册信息 - public boolean save(Manager manager){ + @Override + public Manager save(Manager manager){ try { - mongoTemplate.save(manager); - return true; + return mongoTemplate.save(manager); } catch (Exception e) { - return false; + e.printStackTrace(); + LOG.error(e.toString()); } + return null; + } + + @Override + public Class entityClass() { + return Manager.class; } } diff --git a/src/main/java/com/community/pocket/repository/android/ActiveDao.java b/src/main/java/com/community/pocket/repository/android/ActiveDao.java new file mode 100644 index 0000000..0987233 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/ActiveDao.java @@ -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{ + + 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 entityClass() { + return Active.class; + } +} \ No newline at end of file diff --git a/src/main/java/com/community/pocket/repository/android/ComplainDao.java b/src/main/java/com/community/pocket/repository/android/ComplainDao.java new file mode 100644 index 0000000..e7304a7 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/ComplainDao.java @@ -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 { + 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 entityClass() { + return Complain.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/ForumContentDao.java b/src/main/java/com/community/pocket/repository/android/ForumContentDao.java new file mode 100644 index 0000000..52d407b --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/ForumContentDao.java @@ -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 { + 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 entityClass() { + return ForumContent.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/ForumDao.java b/src/main/java/com/community/pocket/repository/android/ForumDao.java new file mode 100644 index 0000000..16dba9a --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/ForumDao.java @@ -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 { + + 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 rankReply(Forum.ForumType type, int num){ + List forumHots=new ArrayList<>(); + List 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 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 loadNewForum(){ + return loadForum(lookupOperation,Aggregation.unwind("myInfo"),Aggregation.sort(Sort.by("time").descending())); + } + + //查找最新帖子 + public List 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 entityClass() { + return Forum.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/NoticeDao.java b/src/main/java/com/community/pocket/repository/android/NoticeDao.java new file mode 100644 index 0000000..ba6d70c --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/NoticeDao.java @@ -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 { + + 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 loadNotices(){ + try { + return mongoTemplate.findAll(Notice.class); + } catch (Exception e) { + e.printStackTrace(); + LOG.error(e.toString()); + } + return null; + } + + @Override + public Class entityClass() { + return Notice.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/TokenDao.java b/src/main/java/com/community/pocket/repository/android/TokenDao.java new file mode 100644 index 0000000..9269665 --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/TokenDao.java @@ -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 { + + @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 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 entityClass() { + return Token.class; + } +} diff --git a/src/main/java/com/community/pocket/repository/android/UserDao.java b/src/main/java/com/community/pocket/repository/android/UserDao.java new file mode 100644 index 0000000..a207b8b --- /dev/null +++ b/src/main/java/com/community/pocket/repository/android/UserDao.java @@ -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 { + + 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 rankUser(int num){ + List userHots=new ArrayList<>(); + List 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 queryUser(QueryUserForm userForm){ + List userNames=new ArrayList<>(); + List 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 entityClass() { + return MyInfo.class; + } +} diff --git a/src/main/java/com/community/pocket/util/EmailService.java b/src/main/java/com/community/pocket/util/EmailService.java index 83e8cb7..652ea59 100644 --- a/src/main/java/com/community/pocket/util/EmailService.java +++ b/src/main/java/com/community/pocket/util/EmailService.java @@ -1,39 +1,76 @@ package com.community.pocket.util; 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.data.mongodb.core.MongoTemplate; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.stereotype.Service; -import java.util.Random; - @Service public class EmailService { @Autowired private JavaMailSenderImpl javaMailSender; @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(); - message.setSubject("口袋社区激活邮箱"); - message.setText("欢迎注册口袋社区后台服务,您获取到的验证码是:xxxx"); + message.setSubject(emailTypeConfig.getSubject()); + message.setText(String.format(emailTypeConfig.getManagerCodeMessage(),emailCode.getCode())); message.setTo(sender); - message.setFrom("15920722180@163.com"); + message.setFrom(emailTypeConfig.getFrom()); try { javaMailSender.send(message); - EmailCode emailCode=new EmailCode(); - emailCode.setCode(new Random().nextInt(1000)+""); - emailCode.setEmailAddress(sender); - mongoTemplate.save(emailCode); + + emailDao.save(emailCode); return true; } catch (MailException e) { e.printStackTrace(); 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; + } + } } diff --git a/src/main/java/com/community/pocket/util/TableName.java b/src/main/java/com/community/pocket/util/TableName.java new file mode 100644 index 0000000..44223a6 --- /dev/null +++ b/src/main/java/com/community/pocket/util/TableName.java @@ -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"; +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 9a16588..c42b790 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -15,6 +15,21 @@ spring: #邮箱配置 email: - supportType: + support-type: - name: 网易 - suffix: '@163.com' \ No newline at end of file + suffix: '@163.com' + subject: 口袋社区 + from: 15920722180@163.com + code: + length: 6 + manager: 欢迎注册口袋社区后台服务,您获取到的验证码是:%s + user: 重置密码,您获取到的验证码是:%s + +#令牌配置 +token: + day: 1 + +#论坛配置 +forum: + #帖子正文缩略长度 + content-length: 10 \ No newline at end of file