查看剩余投票次数

上级 b7e15972
流水线 #8292 已通过 于阶段
in 2 分 43 秒
......@@ -52,6 +52,13 @@ public class DynamicController extends BaseController {
this.getUserLoginInfoFromRedis(request).getUserAccountId(), dynamicId);
}
@ApiOperation(value = "查看剩余投票次数")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/getRemainingVotes")
public ResultBody getRemainingVotes(@ApiParam(value = "动态id") @RequestParam Integer gambitId,HttpServletRequest request) {
return dynamicService.getRemainingVotes(gambitId,this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
@ApiOperation(value = "update-评论动态/回复")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/comment")
......
......@@ -96,7 +96,7 @@ public interface DynamicDao {
*/
List<ForumDynamicDO> dynamicList(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,String description,Integer needSort);
List<ForumDynamicDO> dynamicListGambit(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,Integer gambitId);
List<ForumDynamicDO> dynamicListGambit(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,Integer gambitId,Integer needSort);
/**
* 列表动态图片
......
......@@ -33,6 +33,14 @@ public interface DynamicService {
ResultBody likeDynamic(Integer userId, Integer dynamicId);
/**
* 返回剩余可投票次数
* @param gambitId 帖子id
* @param userAccountId 用户id
* @return {@link ResultBody}
*/
ResultBody getRemainingVotes(Integer gambitId, Integer userAccountId);
/**
* 评论动态
*
* @param commentVO 评论信息
......
......@@ -215,6 +215,18 @@ public class DynamicServiceImpl implements DynamicService {
}
@Override
public ResultBody getRemainingVotes(Integer gambitId, Integer userAccountId) {
boolean keyExists = stringRedisTemplate.hasKey(RedisConstant.VOTE + gambitId + userAccountId);
if(keyExists){
String voteStr = stringRedisTemplate.opsForValue().get(RedisConstant.VOTE + gambitId +userAccountId);
int voteCount = Integer.parseInt(voteStr);
//voteCount是已经投票的次数,一个最多投五次
return ResultBody.success(5-voteCount);
}
return ResultBody.success(5);
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultBody commentDynamic(CommentVO commentVO, Integer userAccountId, HttpServletRequest request) {
UserAccountSimpleDTO userAccountSimpleDTO = userAppApi.feignGetUserSimpleInfo(userAccountId, request.getHeader(TokenConstant.TOKEN));
......@@ -344,12 +356,12 @@ public class DynamicServiceImpl implements DynamicService {
if (gambitName!=null){
for (String s : gambitName) {
Integer integer = dynamicDao.gambitName(s);
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,integer);
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,integer,needSort);
}
}
// List<Integer> integers = dynamicDao.gambitName(gambitName);
if (gambitId!=null){
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,gambitId);
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,gambitId,needSort);
}
for (ForumDynamicDO forumDynamicDO : forumDynamicList) {
Integer dynamicId = forumDynamicDO.getDynamicId();
......
......@@ -470,8 +470,14 @@
<if test="userAccountIds!=null">
and fd.user_account_id=#{userAccountIds}
</if>
ORDER BY
fd.create_time DESC
<choose>
<when test="needSort != null">
order by likes_count desc
</when>
<otherwise>
order by create_time desc
</otherwise>
</choose>
LIMIT #{itemIndex}, #{pageSize}
</select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论