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

master
panqihua 5 years ago
parent 53af97358b
commit 1d8162514d
  1. 23
      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. 21
      src/main/java/com/community/pocket/repository/android/UserDao.java

@ -1,10 +1,6 @@
package com.community.pocket.api.android; package com.community.pocket.api.android;
import com.community.pocket.entity.po.Forum; 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.po.android.Token;
import com.community.pocket.entity.vo.ForumQuery; import com.community.pocket.entity.vo.ForumQuery;
import com.community.pocket.entity.vo.Page; import com.community.pocket.entity.vo.Page;
@ -71,9 +67,7 @@ public class ForumController {
public ForumPostResponse ok(ActiveVo activeVo) { public ForumPostResponse ok(ActiveVo activeVo) {
Forum forum = forumDao.save(activeVo); Forum forum = forumDao.save(activeVo);
if (forum != null) { if (forum != null) {
ForumContent forumContent = forumContentDao.save(activeVo, forum); if (forumContentDao.save(activeVo, forum) != null && activeDao.save(activeVo, forum) != null && userDao.updatePosts(activeVo)) {
Active active = activeDao.save(activeVo, forum);
if (forumContent != null && active != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
} }
} }
@ -95,8 +89,7 @@ public class ForumController {
public ForumPostResponse ok(ForumVo forumVo) { public ForumPostResponse ok(ForumVo forumVo) {
Forum forum = forumDao.save(forumVo); Forum forum = forumDao.save(forumVo);
if (forum != null) { if (forum != null) {
ForumContent forumContent = forumContentDao.save(forumVo, forum); if (forumContentDao.save(forumVo, forum) != null && userDao.updatePosts(forumVo)) {
if (forumContent != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
} }
} }
@ -117,13 +110,11 @@ public class ForumController {
@Override @Override
public ForumPostResponse ok(ForumScoreVo forumVo) { public ForumPostResponse ok(ForumScoreVo forumVo) {
Forum forum = forumDao.save(forumVo); Forum forum = forumDao.save(forumVo);
if (forum != null) { if (forum != null &&
ForumContent forumContent = forumContentDao.save(forumVo, forum); forumContentDao.save(forumVo, forum) != null &&
Score score = scoreDao.save(scoreVo, forum); scoreDao.save(scoreVo, forum) != null && userDao.updatePosts(forumVo)) {
if (forumContent != null && score != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
} }
}
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
} }
@ -142,9 +133,7 @@ public class ForumController {
public ForumPostResponse ok(ComplainVo complainVo) { public ForumPostResponse ok(ComplainVo complainVo) {
Forum forum = forumDao.save(complainVo); Forum forum = forumDao.save(complainVo);
if (forum != null) { if (forum != null) {
ForumContent forumContent = forumContentDao.save(complainVo, forum); if (forumContentDao.save(complainVo, forum) != null && complainDao.save(complainVo, forum) != null && userDao.updatePosts(complainVo)) {
Complain complain = complainDao.save(complainVo, forum);
if (forumContent != null && complain != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); 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.po.android.VisitorPeople;
import com.community.pocket.entity.vo.Result; import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.*; import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.android.DoCheck; import com.community.pocket.repository.android.*;
import com.community.pocket.repository.android.TokenService;
import com.community.pocket.repository.android.VisitorDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -27,6 +24,9 @@ public class VisitorController {
@Autowired @Autowired
private VisitorPeopleDao visitorPeopleDao; private VisitorPeopleDao visitorPeopleDao;
@Autowired
private UserDao userDao;
@Autowired @Autowired
private TokenService tokenService; private TokenService tokenService;
@ -36,7 +36,7 @@ public class VisitorController {
return tokenService.checkToken(visitorForm, new DoCheck<VisitorResponse, VisitorForm>() { return tokenService.checkToken(visitorForm, new DoCheck<VisitorResponse, VisitorForm>() {
@Override @Override
public VisitorResponse ok(VisitorForm visitorForm) { 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); return new VisitorResponse(Result.OK, VisitorResponse.Msg.ok);
} else { } else {
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail); return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail);

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

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

@ -61,6 +61,19 @@ public class UserDao extends BaseDao<MyInfo> {
return false; 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) { public Page<MyInfo> loadAll(QueryUserForm queryUserForm) {
@ -148,8 +161,8 @@ public class UserDao extends BaseDao<MyInfo> {
myInfo.setMobie(userRegister.getMobie()); myInfo.setMobie(userRegister.getMobie());
myInfo.setEmail(userRegister.getEmail()); myInfo.setEmail(userRegister.getEmail());
myInfo.setCreditScore(creditScore); myInfo.setCreditScore(creditScore);
myInfo.setRecentPosts(0); myInfo.setPosts(0);
myInfo.setRecentVisitors(0); myInfo.setVisitors(0);
save(myInfo); save(myInfo);
} }
@ -189,8 +202,8 @@ public class UserDao extends BaseDao<MyInfo> {
info.setEmail(myInfo.getEmail()); info.setEmail(myInfo.getEmail());
info.setHeadImg(myInfo.getHeadImg()); info.setHeadImg(myInfo.getHeadImg());
info.setMobie(myInfo.getMobie()); info.setMobie(myInfo.getMobie());
info.setRecentPosts(myInfo.getRecentPosts()); info.setPosts(myInfo.getPosts());
info.setRecentVisitors(myInfo.getRecentVisitors()); info.setVisitors(myInfo.getVisitors());
info.setScoreHistory(myInfo.getScoreHistory()); info.setScoreHistory(myInfo.getScoreHistory());
return info; return info;
} else { } else {

Loading…
Cancel
Save