增加用户总发帖数、总访客数逻辑

master
panqihua 5 years ago
parent 53af97358b
commit 1d8162514d
  1. 25
      src/main/java/com/community/pocket/api/android/ForumController.java
  2. 10
      src/main/java/com/community/pocket/api/android/VisitorController.java
  3. 24
      src/main/java/com/community/pocket/entity/po/android/MyInfo.java
  4. 20
      src/main/java/com/community/pocket/entity/vo/android/Info.java
  5. 25
      src/main/java/com/community/pocket/repository/android/UserDao.java

@ -1,10 +1,6 @@
package com.community.pocket.api.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.ForumContent;
import com.community.pocket.entity.po.android.Active;
import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.po.android.Score;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.ForumQuery;
import com.community.pocket.entity.vo.Page;
@ -71,9 +67,7 @@ public class ForumController {
public ForumPostResponse ok(ActiveVo activeVo) {
Forum forum = forumDao.save(activeVo);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(activeVo, forum);
Active active = activeDao.save(activeVo, forum);
if (forumContent != null && active != null) {
if (forumContentDao.save(activeVo, forum) != null && activeDao.save(activeVo, forum) != null && userDao.updatePosts(activeVo)) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
}
@ -95,8 +89,7 @@ public class ForumController {
public ForumPostResponse ok(ForumVo forumVo) {
Forum forum = forumDao.save(forumVo);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(forumVo, forum);
if (forumContent != null) {
if (forumContentDao.save(forumVo, forum) != null && userDao.updatePosts(forumVo)) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
}
@ -117,12 +110,10 @@ public class ForumController {
@Override
public ForumPostResponse ok(ForumScoreVo forumVo) {
Forum forum = forumDao.save(forumVo);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(forumVo, forum);
Score score = scoreDao.save(scoreVo, forum);
if (forumContent != null && score != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
if (forum != null &&
forumContentDao.save(forumVo, forum) != null &&
scoreDao.save(scoreVo, forum) != null && userDao.updatePosts(forumVo)) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
}
@ -142,9 +133,7 @@ public class ForumController {
public ForumPostResponse ok(ComplainVo complainVo) {
Forum forum = forumDao.save(complainVo);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(complainVo, forum);
Complain complain = complainDao.save(complainVo, forum);
if (forumContent != null && complain != null) {
if (forumContentDao.save(complainVo, forum) != null && complainDao.save(complainVo, forum) != null && userDao.updatePosts(complainVo)) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
}

@ -4,10 +4,7 @@ import com.community.pocket.entity.po.Visitor;
import com.community.pocket.entity.po.android.VisitorPeople;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.android.DoCheck;
import com.community.pocket.repository.android.TokenService;
import com.community.pocket.repository.android.VisitorDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
import 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;
@ -27,6 +24,9 @@ public class VisitorController {
@Autowired
private VisitorPeopleDao visitorPeopleDao;
@Autowired
private UserDao userDao;
@Autowired
private TokenService tokenService;
@ -36,7 +36,7 @@ public class VisitorController {
return tokenService.checkToken(visitorForm, new DoCheck<VisitorResponse, VisitorForm>() {
@Override
public VisitorResponse ok(VisitorForm visitorForm) {
if (visitorDao.save(visitorForm) != null) {
if (visitorDao.save(visitorForm) != null && userDao.updateVisitors(visitorForm)) {
return new VisitorResponse(Result.OK, VisitorResponse.Msg.ok);
} else {
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail);

@ -19,10 +19,10 @@ public class MyInfo {
private Integer creditScore;
//头像
private String headImg;
//最近发帖数
private Integer recentPosts;
//最近访客数
private Integer recentVisitors;
//发帖数
private Integer posts;
//访客数
private Integer visitors;
//手机号
private String mobie;
//邮箱
@ -63,20 +63,20 @@ public class MyInfo {
this.headImg = headImg;
}
public Integer getRecentPosts() {
return recentPosts;
public Integer getPosts() {
return posts;
}
public void setRecentPosts(Integer recentPosts) {
this.recentPosts = recentPosts;
public void setPosts(Integer posts) {
this.posts = posts;
}
public Integer getRecentVisitors() {
return recentVisitors;
public Integer getVisitors() {
return visitors;
}
public void setRecentVisitors(Integer recentVisitors) {
this.recentVisitors = recentVisitors;
public void setVisitors(Integer visitors) {
this.visitors = visitors;
}
public String getMobie() {

@ -12,9 +12,9 @@ public class Info {
//头像
private String headImg;
//最近发帖数
private Integer recentPosts;
private Integer posts;
//最近访客数
private Integer recentVisitors;
private Integer visitors;
//手机号
private String mobie;
//邮箱
@ -46,20 +46,20 @@ public class Info {
this.headImg = headImg;
}
public Integer getRecentPosts() {
return recentPosts;
public Integer getPosts() {
return posts;
}
public void setRecentPosts(Integer recentPosts) {
this.recentPosts = recentPosts;
public void setPosts(Integer posts) {
this.posts = posts;
}
public Integer getRecentVisitors() {
return recentVisitors;
public Integer getVisitors() {
return visitors;
}
public void setRecentVisitors(Integer recentVisitors) {
this.recentVisitors = recentVisitors;
public void setVisitors(Integer visitors) {
this.visitors = visitors;
}
public String getMobie() {

@ -61,6 +61,19 @@ public class UserDao extends BaseDao<MyInfo> {
return false;
}
private boolean updateUserInfo(String username, String key) {
return mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(username)), new Update().inc(key, 1), entityClass()).wasAcknowledged();
}
//更新用户发帖数
public boolean updatePosts(ForumVo forumVo) {
return updateUserInfo(forumVo.getUsername(), "posts");
}
//更新用户访客数
public boolean updateVisitors(VisitorForm visitorForm) {
return updateUserInfo(visitorForm.getAppointment(), "visitors");
}
//获取所有用户
public Page<MyInfo> loadAll(QueryUserForm queryUserForm) {
@ -141,15 +154,15 @@ public class UserDao extends BaseDao<MyInfo> {
//注册用户
public void save(UserRegister userRegister){
MyInfo myInfo=new MyInfo();
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(creditScore);
myInfo.setRecentPosts(0);
myInfo.setRecentVisitors(0);
myInfo.setPosts(0);
myInfo.setVisitors(0);
save(myInfo);
}
@ -189,8 +202,8 @@ public class UserDao extends BaseDao<MyInfo> {
info.setEmail(myInfo.getEmail());
info.setHeadImg(myInfo.getHeadImg());
info.setMobie(myInfo.getMobie());
info.setRecentPosts(myInfo.getRecentPosts());
info.setRecentVisitors(myInfo.getRecentVisitors());
info.setPosts(myInfo.getPosts());
info.setVisitors(myInfo.getVisitors());
info.setScoreHistory(myInfo.getScoreHistory());
return info;
} else {

Loading…
Cancel
Save