Commit b72761d6 authored by 万成波's avatar 万成波

评论优化

parent ba84247c
...@@ -89,7 +89,7 @@ public class TableDataInfo implements Serializable { ...@@ -89,7 +89,7 @@ public class TableDataInfo implements Serializable {
rspData.setCode(HttpStatus.SUCCESS); rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功"); rspData.setMsg("查询成功");
rspData.setRows(list); rspData.setRows(list);
rspData.setTotal(new PageInfo(list).getTotal()); rspData.setTotal(new PageInfo<Object>(list).getTotal());
return rspData; return rspData;
} }
......
...@@ -53,9 +53,8 @@ public class MBbsMomentController { ...@@ -53,9 +53,8 @@ public class MBbsMomentController {
@MobileAuth @MobileAuth
@GetMapping("/moments") @GetMapping("/moments")
public TableDataInfo getMoments(String content) { public TableDataInfo getMoments(String content) {
String username = MobileTokenHelper.getUserName();
PageUtils.clearPage(); PageUtils.clearPage();
List<BbsMomentListVO> moments = this.momentService.getMoments(username, content); List<BbsMomentListVO> moments = this.momentService.getMoments(content);
return TableDataInfo.getDataTable(moments); return TableDataInfo.getDataTable(moments);
} }
......
...@@ -54,11 +54,10 @@ public interface IBbsMomentService extends IService<BbsMoment> { ...@@ -54,11 +54,10 @@ public interface IBbsMomentService extends IService<BbsMoment> {
/** /**
* 查询动态列表 * 查询动态列表
* *
* @param userName 用户名
* @param content 动态内容 * @param content 动态内容
* @return 动态列表 * @return 动态列表
*/ */
List<BbsMomentListVO> getMoments(String userName, String content); List<BbsMomentListVO> getMoments(String content);
/** /**
......
...@@ -109,12 +109,12 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -109,12 +109,12 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
/** /**
* 查询动态列表 * 查询动态列表
* *
* @param userName 用户名
* @param content 动态内容 * @param content 动态内容
* @return 动态列表 * @return 动态列表
*/ */
@Override @Override
public List<BbsMomentListVO> getMoments(String userName, String content) { public List<BbsMomentListVO> getMoments(String content) {
String userName = MobileTokenHelper.getUserName();
List<BbsMomentListVO> dbMoments = this.baseMapper.selectMoments(userName, content); List<BbsMomentListVO> dbMoments = this.baseMapper.selectMoments(userName, content);
this.fillMoment(dbMoments, userName); this.fillMoment(dbMoments, userName);
return dbMoments; return dbMoments;
...@@ -498,19 +498,19 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -498,19 +498,19 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
CompletableFuture<Map<Long, List<BbsMomentAttachment>>> af = CompletableFuture.supplyAsync(() -> { CompletableFuture<Map<Long, List<BbsMomentAttachment>>> af = CompletableFuture.supplyAsync(() -> {
List<BbsMomentAttachment> atts = this.attachmentsService.getAttachments(momentIds); List<BbsMomentAttachment> atts = this.attachmentsService.getAttachments(momentIds);
return atts.stream().collect(Collectors.groupingBy(BbsMomentAttachment::getMomentId)); return atts.stream().collect(Collectors.groupingBy(BbsMomentAttachment::getMomentId));
}); }).exceptionally(ex -> new HashMap<>(0));
// 查询动态投票选项 // 查询动态投票选项
CompletableFuture<Map<Long, List<BbsMomentVoteOption>>> of = CompletableFuture.supplyAsync(() -> { CompletableFuture<Map<Long, List<BbsMomentVoteOption>>> of = CompletableFuture.supplyAsync(() -> {
List<BbsMomentVoteOption> opts = this.voteOptionService.getVoteOptions(momentIds); List<BbsMomentVoteOption> opts = this.voteOptionService.getVoteOptions(momentIds);
return opts.stream().collect(Collectors.groupingBy(BbsMomentVoteOption::getMomentId)); return opts.stream().collect(Collectors.groupingBy(BbsMomentVoteOption::getMomentId));
}); }).exceptionally(ex -> new HashMap<>(0));
// 查询动态评论 // 查询动态评论
CompletableFuture<Map<Long, List<BbsMomentComment>>> cf = CompletableFuture.supplyAsync(() -> { CompletableFuture<Map<Long, List<BbsMomentComment>>> cf = CompletableFuture.supplyAsync(() -> {
List<BbsMomentComment> opts = this.commentService.getMomentLimitComments(momentIds, userName); List<BbsMomentComment> opts = this.commentService.getMomentLimitComments(momentIds, userName);
return opts.stream().collect(Collectors.groupingBy(BbsMomentComment::getMomentId)); return opts.stream().collect(Collectors.groupingBy(BbsMomentComment::getMomentId));
}); }).exceptionally(ex -> new HashMap<>(0));
// 等待全部任务处理完毕 // 等待全部任务处理完毕
CompletableFuture.allOf(af, of, cf).join(); CompletableFuture.allOf(af, of, cf).join();
......
...@@ -56,7 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -56,7 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
INNER JOIN INNER JOIN
( (
SELECT SELECT
id, is_enable_featured_comment id, user_name, is_enable_featured_comment
FROM FROM
bbs_moment bbs_moment
WHERE WHERE
...@@ -71,8 +71,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -71,8 +71,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.status = 1 c.status = 1
AND AND
( (
m.is_enable_featured_comment = 1 m.user_name = #{userName}
OR (m.is_enable_featured_comment = 0 AND (c.user_name = #{userName} OR c.is_featured = 1)) OR m.is_enable_featured_comment = 0
OR (m.is_enable_featured_comment = 1 AND (c.user_name = #{userName} OR c.is_featured = 1))
) )
) AS c ) AS c
WHERE rn &lt;= #{rows}; WHERE rn &lt;= #{rows};
......
...@@ -70,10 +70,12 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -70,10 +70,12 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
if (Objects.isNull(qwmhSysUser)) { if (Objects.isNull(qwmhSysUser)) {
throw new ServiceException("查询用户积分失败,未查询到当前用户数据。"); throw new ServiceException("查询用户积分失败,未查询到当前用户数据。");
} else { } else {
// 初始积分
dbUserPoints = new BbsUserPoints(); dbUserPoints = new BbsUserPoints();
dbUserPoints.setUserName(userName); dbUserPoints.setUserName(userName);
dbUserPoints.setAccumulatedPoints(0); dbUserPoints.setAccumulatedPoints(0);
dbUserPoints.setCurrentPoints(0); dbUserPoints.setCurrentPoints(0);
// 初始等级
BbsGrade dbGrade = this.gradeService.getInitialGrade(); BbsGrade dbGrade = this.gradeService.getInitialGrade();
if (Objects.nonNull(dbGrade)) { if (Objects.nonNull(dbGrade)) {
dbUserPoints.setGradeCode(dbGrade.getCode()); dbUserPoints.setGradeCode(dbGrade.getCode());
...@@ -163,21 +165,21 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -163,21 +165,21 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
// 更新用户积分 // 更新用户积分
String userName = detail.getUserName(); String userName = detail.getUserName();
BbsUserPoints userPoints = this.pointsServiceImpl.getAndInitUserPoints(userName); BbsUserPoints dbUserPoints = this.pointsServiceImpl.getAndInitUserPoints(userName);
int beforeCurrentPoints = userPoints.getCurrentPoints(); int beforeCurrentPoints = dbUserPoints.getCurrentPoints();
int afterCurrentPoints = beforeCurrentPoints + points; int afterCurrentPoints = beforeCurrentPoints + points;
userPoints.setCurrentPoints(afterCurrentPoints); int accumulatedPoints = dbUserPoints.getAccumulatedPoints() + points;
int accumulatedPoints = userPoints.getAccumulatedPoints() + points; dbUserPoints.setCurrentPoints(afterCurrentPoints);
userPoints.setAccumulatedPoints(accumulatedPoints); dbUserPoints.setAccumulatedPoints(accumulatedPoints);
// 更新用户等级 // 更新用户等级
BbsGrade dbGrade = this.gradeService.getGradeByPoints(accumulatedPoints); BbsGrade dbGrade = this.gradeService.getGradeByPoints(accumulatedPoints);
if (Objects.nonNull(dbGrade) && !dbGrade.getCode().equals(userPoints.getGradeCode())) { if (Objects.nonNull(dbGrade) && !dbGrade.getCode().equals(dbUserPoints.getGradeCode())) {
userPoints.setGradeName(dbGrade.getName()); dbUserPoints.setGradeName(dbGrade.getName());
userPoints.setGradeCode(dbGrade.getCode()); dbUserPoints.setGradeCode(dbGrade.getCode());
userPoints.setLastUpgradeTime(new Date()); dbUserPoints.setLastUpgradeTime(new Date());
} }
this.updateById(userPoints); this.updateById(dbUserPoints);
// 添加用户积分明细 // 添加用户积分明细
BbsUserPointsDetail newDetail = new BbsUserPointsDetail(); BbsUserPointsDetail newDetail = new BbsUserPointsDetail();
...@@ -204,17 +206,19 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B ...@@ -204,17 +206,19 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。"); throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
} }
// 更新用户积分
String userName = detail.getUserName(); String userName = detail.getUserName();
BbsUserPoints userPoints = this.pointsServiceImpl.getAndInitUserPoints(userName); BbsUserPoints dbUserPoints = this.pointsServiceImpl.getAndInitUserPoints(userName);
Integer beforeCurrentPoints = userPoints.getCurrentPoints(); Integer beforeCurrentPoints = dbUserPoints.getCurrentPoints();
if (points > beforeCurrentPoints) { if (points > beforeCurrentPoints) {
throw new ServiceException("扣减用户积分失败,当前用户可用积分不足。"); throw new ServiceException("扣减用户积分失败,当前用户可用积分不足。");
} }
// 更新用户积分
int afterCurrentPoints = beforeCurrentPoints - points; int afterCurrentPoints = beforeCurrentPoints - points;
userPoints.setCurrentPoints(afterCurrentPoints); BbsUserPoints updUserPoints = new BbsUserPoints();
this.updateById(userPoints); updUserPoints.setId(dbUserPoints.getId());
updUserPoints.setCurrentPoints(afterCurrentPoints);
this.updateById(updUserPoints);
// 添加用户积分明细 // 添加用户积分明细
BbsUserPointsDetail newDetail = new BbsUserPointsDetail(); BbsUserPointsDetail newDetail = new 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