Commit 0d2c4a9c authored by 万成波's avatar 万成波

优化代码

parent 0230113b
...@@ -8,9 +8,9 @@ import com.tangguo.common.core.domain.entity.SysMenu; ...@@ -8,9 +8,9 @@ import com.tangguo.common.core.domain.entity.SysMenu;
import com.tangguo.common.core.domain.entity.SysUser; import com.tangguo.common.core.domain.entity.SysUser;
import com.tangguo.common.core.domain.model.LoginBody; import com.tangguo.common.core.domain.model.LoginBody;
import com.tangguo.common.core.domain.model.LoginUser; import com.tangguo.common.core.domain.model.LoginUser;
import com.tangguo.common.core.domain.model.WxcpCodeLogin;
import com.tangguo.common.exception.ServiceException; import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils; import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.core.domain.model.WxcpCodeLogin;
import com.tangguo.framework.config.ServerConfig; import com.tangguo.framework.config.ServerConfig;
import com.tangguo.framework.web.service.SysLoginService; import com.tangguo.framework.web.service.SysLoginService;
import com.tangguo.framework.web.service.SysPermissionService; import com.tangguo.framework.web.service.SysPermissionService;
...@@ -28,7 +28,9 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -28,7 +28,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.*; import java.util.List;
import java.util.Objects;
import java.util.Set;
/** /**
* 登录验证 * 登录验证
......
package com.tangguo; package com.tangguo;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.common.domain.PointsDetail;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service; import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpService;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.core.MessagePostProcessor;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.jms.*;
/** /**
* *
......
...@@ -196,8 +196,10 @@ public class MBbsMomentController { ...@@ -196,8 +196,10 @@ public class MBbsMomentController {
*/ */
@DeleteMapping("/comment/delete/{commentId}") @DeleteMapping("/comment/delete/{commentId}")
public AjaxResult deleteComment(@PathVariable Long commentId) { public AjaxResult deleteComment(@PathVariable Long commentId) {
this.momentService.userDeleteComment(commentId); synchronized (String.valueOf(commentId).intern()) {
return AjaxResult.success(); this.momentService.userDeleteComment(commentId);
return AjaxResult.success();
}
} }
......
...@@ -31,4 +31,22 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> { ...@@ -31,4 +31,22 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> {
BbsMomentListVO selectMomentDetail(@Param("momentId") Long momentId, @Param("userName") String userName); BbsMomentListVO selectMomentDetail(@Param("momentId") Long momentId, @Param("userName") String userName);
int incrMomentLikeCount(@Param("momentId") Long momentId, @Param("count") int count);
int decrMomentLikeCount(@Param("momentId") Long momentId, @Param("count") int count);
int incrMomentCommentCount(@Param("momentId") Long momentId, @Param("count") int count);
int decrMomentCommentCount(@Param("momentId") Long momentId, @Param("count") int count);
int incrMomentVoteCount(@Param("momentId") Long momentId, @Param("count") int count);
int decrMomentVoteCount(@Param("momentId") Long momentId, @Param("count") int count);
} }
...@@ -11,7 +11,6 @@ import org.springframework.stereotype.Service; ...@@ -11,7 +11,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
......
...@@ -43,9 +43,6 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -43,9 +43,6 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
@Resource @Resource
private ApplicationEventPublisher eventPublisher; private ApplicationEventPublisher eventPublisher;
@Resource
private BbsMomentMapper bbsMomentMapper;
@Resource @Resource
private IBbsMomentAttachmentService attachmentsService; private IBbsMomentAttachmentService attachmentsService;
...@@ -245,32 +242,27 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -245,32 +242,27 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("点赞失败,未查询到当前动态数据。"); throw new ServiceException("点赞失败,未查询到当前动态数据。");
} }
Long dbMomentId = dbMoment.getId();
String username = SecurityUtils.getUsername(); String username = SecurityUtils.getUsername();
long likeStatus = this.likeService.getUserMomentLikeCount(dbMoment.getId(), username); long likeStatus = this.likeService.getUserMomentLikeCount(dbMomentId, username);
int likeCount = dbMoment.getLikeCount();
if (LikeStatus.LIKE.getStatus() == bo.getLikeStatus()) { if (LikeStatus.LIKE.getStatus() == bo.getLikeStatus()) {
if (likeStatus > 0) { if (likeStatus > 0) {
throw new ServiceException("点赞失败,已对当前动态点赞。"); throw new ServiceException("点赞失败,已对当前动态点赞。");
} else { } else {
this.likeService.addMomentLike(dbMoment.getId(), username); this.likeService.addMomentLike(dbMomentId, username);
likeCount++; this.baseMapper.incrMomentLikeCount(dbMomentId, 1);
} }
} else { }
else {
if (likeStatus < 1) { if (likeStatus < 1) {
throw new ServiceException("取消失败,没有对当前动态点赞。"); throw new ServiceException("取消失败,没有对当前动态点赞。");
} else { } else {
this.likeService.deleteMomentLike(dbMoment.getId(), username); this.likeService.deleteMomentLike(dbMomentId, username);
likeCount--; this.baseMapper.decrMomentLikeCount(dbMomentId, 1);
} }
} }
// 更新动态点赞人数
BbsMoment updMoment = new BbsMoment();
updMoment.setId(dbMoment.getId());
updMoment.setLikeCount(likeCount);
this.updateById(updMoment);
// 发布用户操作事件 // 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(username, OperateType.DZDT); OperateEvent operateEvent = new OperateEvent(username, OperateType.DZDT);
this.eventPublisher.publishEvent(operateEvent); this.eventPublisher.publishEvent(operateEvent);
...@@ -293,20 +285,21 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -293,20 +285,21 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("投票失败,当前动态未开启投票。"); throw new ServiceException("投票失败,当前动态未开启投票。");
} }
Long dbMomentId = dbMoment.getId();
String username = SecurityUtils.getUsername(); String username = SecurityUtils.getUsername();
long voteCount = this.voteService.getUserMomentVoteCount(dbMoment.getId(), username); long voteCount = this.voteService.getUserMomentVoteCount(dbMomentId, username);
if (voteCount > 0) { if (voteCount > 0) {
throw new ServiceException("投票失败,已对当前动态投票。"); throw new ServiceException("投票失败,已对当前动态投票。");
} }
String optionCode = bo.getOptionCode(); String optionCode = bo.getOptionCode();
BbsMomentVoteOption dbOption = this.voteOptionService.getVoteOption(dbMoment.getId(), optionCode); BbsMomentVoteOption dbOption = this.voteOptionService.getVoteOption(dbMomentId, optionCode);
if (Objects.isNull(dbOption)) { if (Objects.isNull(dbOption)) {
throw new ServiceException("投票失败,未查询到当前投票选项数据。"); throw new ServiceException("投票失败,未查询到当前投票选项数据。");
} }
// 添加投票记录 // 添加投票记录
this.voteService.addMomentVoteCount(dbMoment.getId(), username, optionCode); this.voteService.addMomentVoteCount(dbMomentId, username, optionCode);
// 更新投票选项投票人数 // 更新投票选项投票人数
BbsMomentVoteOption updOption = new BbsMomentVoteOption(); BbsMomentVoteOption updOption = new BbsMomentVoteOption();
...@@ -315,10 +308,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -315,10 +308,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
this.voteOptionService.updateById(updOption); this.voteOptionService.updateById(updOption);
// 更新动态投票人数 // 更新动态投票人数
BbsMoment updMoment = new BbsMoment(); this.baseMapper.incrMomentVoteCount(dbMomentId, 1);
updMoment.setId(dbMoment.getId());
updMoment.setVoteCount(dbMoment.getVoteCount() + 1);
this.updateById(updMoment);
// 发布用户操作事件 // 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(username, OperateType.TPDT); OperateEvent operateEvent = new OperateEvent(username, OperateType.TPDT);
...@@ -360,9 +350,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -360,9 +350,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
} }
// 添加动态评论 // 添加动态评论
Long dbMomentId = dbMoment.getId();
SysUser dbUser = SecurityUtils.getLoginUser().getUser(); SysUser dbUser = SecurityUtils.getLoginUser().getUser();
BbsMomentComment newComment = new BbsMomentComment(); BbsMomentComment newComment = new BbsMomentComment();
newComment.setMomentId(dbMoment.getId()); newComment.setMomentId(dbMomentId);
newComment.setUserName(dbUser.getUserName()); newComment.setUserName(dbUser.getUserName());
newComment.setNickName(dbUser.getNickName()); newComment.setNickName(dbUser.getNickName());
newComment.setContent(content); newComment.setContent(content);
...@@ -383,10 +374,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -383,10 +374,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
this.commentService.updateById(updComment); this.commentService.updateById(updComment);
// 更新动态评论人数 // 更新动态评论人数
BbsMoment updMoment = new BbsMoment(); this.baseMapper.incrMomentCommentCount(dbMomentId, 1);
updMoment.setId(dbMoment.getId());
updMoment.setCommentCount(dbMoment.getCommentCount() + 1);
this.updateById(updMoment);
// 发布用户操作事件 // 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(dbUser.getUserName(), OperateType.TPDT); OperateEvent operateEvent = new OperateEvent(dbUser.getUserName(), OperateType.TPDT);
...@@ -412,10 +400,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -412,10 +400,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("删除失败,没有对当前动态评论的操作权限。"); throw new ServiceException("删除失败,没有对当前动态评论的操作权限。");
} }
BbsMomentComment updComment = new BbsMomentComment(); this.commentService.removeById(dbComment.getId());
updComment.setId(dbComment.getId());
updComment.setStatus(CommentStatus.SC.getStatus()); // 更新动态评论人数
this.commentService.updateById(updComment); this.baseMapper.incrMomentCommentCount(dbComment.getMomentId(), 1);
} }
......
...@@ -22,7 +22,6 @@ import com.tangguo.service.IBbsTopicService; ...@@ -22,7 +22,6 @@ import com.tangguo.service.IBbsTopicService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsMomentMapper"> <mapper namespace="com.tangguo.mapper.BbsMomentMapper">
<select id="selectBbsMomentList" resultType="com.tangguo.domain.BbsMoment"> <select id="selectBbsMomentList" resultType="com.tangguo.domain.BbsMoment">
SELECT SELECT
m.*, m.*,
uv.nick_name, uv.nick_name,
...@@ -156,5 +156,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -156,5 +156,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY ORDER BY
m.create_time DESC m.create_time DESC
</select> </select>
<update id="incrMomentLikeCount">
UPDATE bbs_moment SET like_count = like_count + #{count} WHERE id = #{momentId}
</update>
<update id="decrMomentLikeCount">
UPDATE bbs_moment SET like_count = like_count - #{count} WHERE id = #{momentId}
</update>
<update id="incrMomentCommentCount">
UPDATE bbs_moment SET comment_count = comment_count + #{count} WHERE id = #{momentId}
</update>
<update id="decrMomentCommentCount">
UPDATE bbs_moment SET comment_count = comment_count - #{count} WHERE id = #{momentId}
</update>
<update id="incrMomentVoteCount">
UPDATE bbs_moment SET vote_count = vote_count + #{count} WHERE id = #{momentId}
</update>
<update id="decrMomentVoteCount">
UPDATE bbs_moment SET vote_count = vote_count - #{count} WHERE id = #{momentId}
</update>
</mapper> </mapper>
package com.tangguo.controller; package com.tangguo.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tangguo.common.annotation.Log; import com.tangguo.common.annotation.Log;
import com.tangguo.common.core.controller.BaseController; import com.tangguo.common.core.controller.BaseController;
import com.tangguo.common.core.domain.AjaxResult; import com.tangguo.common.core.domain.AjaxResult;
......
...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.domain.PointsDetail; import com.tangguo.common.domain.PointsDetail;
import com.tangguo.common.exception.ServiceException; import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.BbsGrade; import com.tangguo.domain.BbsGrade;
import com.tangguo.domain.BbsUserPoints; import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail; import com.tangguo.domain.BbsUserPointsDetail;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment