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

评论优化

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