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

动态投票

parent efd33ffe
...@@ -183,7 +183,7 @@ public class MobileTokenHelper { ...@@ -183,7 +183,7 @@ public class MobileTokenHelper {
* *
* @return 用户名 * @return 用户名
*/ */
public static String getUsername() { public static String getUserName() {
try { try {
String username = getTokenPayloads().getStr("userName"); String username = getTokenPayloads().getStr("userName");
if (StrUtil.isNotBlank(username)) { if (StrUtil.isNotBlank(username)) {
...@@ -198,4 +198,25 @@ public class MobileTokenHelper { ...@@ -198,4 +198,25 @@ public class MobileTokenHelper {
} }
} }
/**
* 获取当前用户姓名
*
* @return 用户名
*/
public static String getNikeName() {
try {
String nikeName = getTokenPayloads().getStr("nikeName");
if (StrUtil.isNotBlank(nikeName)) {
return nikeName;
} else {
throw new Mobile401Exception("身份认证失败,未获取到当前用户身份信息。");
}
} catch (Mobile401Exception e) {
throw e;
} catch (Exception e) {
throw new Mobile401Exception("获取当前用户身份信息获取失败。");
}
}
} }
...@@ -38,7 +38,7 @@ public class MobileAuthInterceptor implements HandlerInterceptor { ...@@ -38,7 +38,7 @@ public class MobileAuthInterceptor implements HandlerInterceptor {
return true; return true;
} }
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
log.info("=> 当前移动端请求用户:{}", username); log.info("=> 当前移动端请求用户:{}", username);
return true; return true;
} }
......
...@@ -5,11 +5,16 @@ import com.tangguo.common.mauth.MobileAuth; ...@@ -5,11 +5,16 @@ import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.mauth.MobileTokenHelper; import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.PageUtils; import com.tangguo.common.utils.PageUtils;
import com.tangguo.common.utils.ValidateOperations; import com.tangguo.common.utils.ValidateOperations;
import com.tangguo.domain.bo.CommentMomentBO;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.bo.LikeMomentBO; import com.tangguo.domain.bo.LikeMomentBO;
import com.tangguo.domain.bo.VoteMomentBO; import com.tangguo.domain.bo.VoteMomentBO;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.domain.vo.BbsMomentListVO; import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsVoteVO;
import com.tangguo.service.IBbsMomentCommentService;
import com.tangguo.service.IBbsMomentService; import com.tangguo.service.IBbsMomentService;
import com.tangguo.service.IBbsMomentVoteService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -28,6 +33,12 @@ public class MBbsMomentController { ...@@ -28,6 +33,12 @@ public class MBbsMomentController {
@Resource @Resource
private IBbsMomentService momentService; private IBbsMomentService momentService;
@Resource
private IBbsMomentCommentService momentCommentService;
@Resource
private IBbsMomentVoteService momentVoteService;
/** /**
* 查询动态列表 * 查询动态列表
...@@ -37,13 +48,27 @@ public class MBbsMomentController { ...@@ -37,13 +48,27 @@ public class MBbsMomentController {
@MobileAuth @MobileAuth
@GetMapping("/moments") @GetMapping("/moments")
public AjaxResult getUserMoments(String content) { public AjaxResult getUserMoments(String content) {
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
PageUtils.clearPage(); PageUtils.clearPage();
List<BbsMomentListVO> moments = this.momentService.getMoments(username, content); List<BbsMomentListVO> moments = this.momentService.getMoments(username, content);
return AjaxResult.success(moments); return AjaxResult.success(moments);
} }
/**
* 查询动态详情
*
* @return 动态
*/
@MobileAuth
@GetMapping("/{id}")
public AjaxResult getUserMoment(@PathVariable Long id) {
String username = MobileTokenHelper.getUserName();
BbsMomentListVO dbMoment = this.momentService.getMoment(id, username);
return AjaxResult.success(dbMoment);
}
/** /**
* 创建动态 * 创建动态
* *
...@@ -105,4 +130,51 @@ public class MBbsMomentController { ...@@ -105,4 +130,51 @@ public class MBbsMomentController {
} }
} }
/**
* 动态投票记录
*
* @param momentId 动态Id
* @return 投票记录
*/
@MobileAuth
@GetMapping("/votes")
public AjaxResult getMomentVotes(@RequestParam Long momentId, @RequestParam String optionCode) {
PageUtils.startPage();
List<BbsVoteVO> dbVotes = this.momentVoteService.getMomentVotes(momentId, optionCode);
return AjaxResult.success(dbVotes);
}
/**
* 评论动态
*
* @param bo 动态
* @return 投票结果
*/
@MobileAuth
@PostMapping("/comment")
public AjaxResult commentMoment(@RequestBody CommentMomentBO bo) {
ValidateOperations.generalValidate(bo);
synchronized (String.valueOf(bo.getMomentId()).intern()) {
this.momentService.userCommentMoment(bo);
return AjaxResult.success();
}
}
/**
* 查询动态评论
*
* @return 动态
*/
@MobileAuth
@GetMapping("/comments")
public AjaxResult getMomentComments(@RequestParam Long momentId) {
String userName = MobileTokenHelper.getUserName();
PageUtils.clearPage();
List<BbsCommentDetailVO> dbComments = this.momentCommentService.getMomentComments(momentId, userName);
return AjaxResult.success(dbComments);
}
} }
...@@ -66,7 +66,7 @@ public class MBbsUserController { ...@@ -66,7 +66,7 @@ public class MBbsUserController {
@MobileAuth @MobileAuth
@GetMapping("/moment/count") @GetMapping("/moment/count")
public AjaxResult getUserMomentCount() { public AjaxResult getUserMomentCount() {
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
BbsUserMomentCountVO momentCount = this.momentService.getUserMomentCount(username); BbsUserMomentCountVO momentCount = this.momentService.getUserMomentCount(username);
return AjaxResult.success(momentCount); return AjaxResult.success(momentCount);
} }
...@@ -80,7 +80,7 @@ public class MBbsUserController { ...@@ -80,7 +80,7 @@ public class MBbsUserController {
@MobileAuth @MobileAuth
@GetMapping("/moments") @GetMapping("/moments")
public AjaxResult getUserMoments(String content) { public AjaxResult getUserMoments(String content) {
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
PageUtils.clearPage(); PageUtils.clearPage();
List<BbsMomentListVO> moments = this.momentService.getUserMoments(username, content); List<BbsMomentListVO> moments = this.momentService.getUserMoments(username, content);
return AjaxResult.success(moments); return AjaxResult.success(moments);
......
...@@ -5,7 +5,9 @@ import com.tangguo.common.core.controller.BaseController; ...@@ -5,7 +5,9 @@ import com.tangguo.common.core.controller.BaseController;
import com.tangguo.common.core.domain.AjaxResult; import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo; import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType; import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.BbsMoment; import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.service.IBbsMomentService; import com.tangguo.service.IBbsMomentService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -50,8 +52,8 @@ public class BbsMomentController extends BaseController { ...@@ -50,8 +52,8 @@ public class BbsMomentController extends BaseController {
@PreAuthorize("@ss.hasPermi('bbs:moment:query')") @PreAuthorize("@ss.hasPermi('bbs:moment:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) { public AjaxResult getInfo(@PathVariable("id") Long id) {
BbsMoment moment = this.bbsMomentService.getById(id); BbsMomentListVO dbMoment = this.bbsMomentService.getMoment(id, SecurityUtils.getUsername());
return success(moment); return success(dbMoment);
} }
......
package com.tangguo.domain.bo;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
*
*
* @author 谈笑
* @createTime 2025-09-04 15:28:48 星期四
*/
@Data
public class CommentMomentBO {
/**
* 动态Id
*/
@NotNull(message = "动态Id不能为空")
private Long momentId;
/**
* 回复评论Id
*/
private Long parentId;
/**
* 评论内容
*/
@NotBlank(message = "评论内容不能为空")
@Length(max = 200, message = "评论内容字符长度错误")
private String content;
}
package com.tangguo.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
*
*
* @author 谈笑
* @createTime 2025-09-03 17:56:47 星期三
*/
@Data
public class BbsCommentDetailVO {
/** 评论Id */
private Long id;
/** 评论时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 评论用户姓名 */
private String nikeName;
/** 评论用户名 */
private String userName;
/** 回复评论用户名 */
private String replyNikeName;
/** 回复评论内容 */
private String replyContent;
/** 评论(回复)内容 */
private String content;
/** 是否本人评论:0 否、1 是 */
private Integer isSelf;
}
package com.tangguo.domain.vo; package com.tangguo.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.util.Date;
/** /**
* *
* *
...@@ -14,6 +17,10 @@ public class BbsCommentVO { ...@@ -14,6 +17,10 @@ public class BbsCommentVO {
/** 评论Id */ /** 评论Id */
private Long id; private Long id;
/** 评论时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 评论用户姓名 */ /** 评论用户姓名 */
private String nikeName; private String nikeName;
......
package com.tangguo.domain.vo;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
*
*
* @author 谈笑
* @createTime 2025-09-03 15:42:59 星期三
*/
@Data
public class BbsMomentDetailVO {
/** 发布时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 动态Id */
private Long id;
/** 发布人用户姓名 */
private String nikeName;
/** 发布人用户名 */
private String userName;
/** 动态内容 */
private String content;
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态 */
private String type;
/** 话题名称 */
private List<String> topicNames;
/** 话题Ids */
private List<String> topicIds;
/** 外部链接地址 */
private String linkUrl;
/** 是否开启评论:0 否、1 是 */
private Integer isEnableComment;
/** 是否精选评论:0 否、1 是 */
private Integer isEnableFeaturedComment;
/** 是否开启投票:0 否、1 是 */
private Integer isEnableVote;
/** 投票标题 */
private String voteTitle;
/** 投票选项类型:TEXT 文字、IMAGE 图片 */
private String voteOptionType;
/** 动态点赞人数 */
private Integer likeCount;
/** 动态评论人数 */
private Integer commentCount;
/** 动态投票人数 */
private Integer voteCount;
/** 当前是否点赞:0 未点赞、1 已点赞 */
private Integer isLike;
/** 当前是否投票:0 未投票、1 已投票 */
private Integer isVote;
/** 是否本人动态:0 否、1 是 */
private Integer isSelf;
/** 动态附件 */
private List<BbsAttachmentVO> attachments;
/** 动态投票选项 */
private List<BbsVoteOptionVO> voteOptions;
/** 动态附件 */
private List<BbsCommentVO> comments;
/**
* 处理主题名称
*/
public void setTopicNames(String topicNames) {
if (StrUtil.isNotBlank(topicNames)) {
this.topicNames = Arrays.asList(topicNames.split(","));
}
}
/**
* 处理主题Id
*/
public void setTopicIds(String topicIds) {
if (StrUtil.isNotBlank(topicIds)) {
this.topicIds = Arrays.asList(topicIds.split(","));
}
}
}
...@@ -84,7 +84,7 @@ public class BbsMomentListVO { ...@@ -84,7 +84,7 @@ public class BbsMomentListVO {
/** 动态投票选项 */ /** 动态投票选项 */
private List<BbsVoteOptionVO> voteOptions; private List<BbsVoteOptionVO> voteOptions;
/** 动态附件 */ /** 动态评论 */
private List<BbsCommentVO> comments; private List<BbsCommentVO> comments;
......
package com.tangguo.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
*
*
* @author 谈笑
* @createTime 2025-09-04 18:32:42 星期四
*/
@Data
public class BbsVoteVO {
/** 投票时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 用户姓名 */
private String nikeName;
}
...@@ -2,6 +2,8 @@ package com.tangguo.mapper; ...@@ -2,6 +2,8 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsMomentComment; import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.domain.vo.BbsCommentVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
...@@ -23,4 +25,7 @@ public interface BbsMomentCommentMapper extends BaseMapper<BbsMomentComment> { ...@@ -23,4 +25,7 @@ public interface BbsMomentCommentMapper extends BaseMapper<BbsMomentComment> {
List<BbsMomentComment> selectComments(@Param("momentIds") List<Long> momentIds, @Param("rows") int rows); List<BbsMomentComment> selectComments(@Param("momentIds") List<Long> momentIds, @Param("rows") int rows);
List<BbsCommentDetailVO> selectMomentComments(@Param("momentId") Long momentId, @Param("userName") String userName);
} }
...@@ -27,4 +27,7 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> { ...@@ -27,4 +27,7 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> {
List<BbsMomentListVO> selectMoments(@Param("userName") String userName, @Param("content") String content); List<BbsMomentListVO> selectMoments(@Param("userName") String userName, @Param("content") String content);
BbsMomentListVO selectMoment(@Param("momentId") Long momentId, @Param("userName") String userName);
} }
...@@ -2,6 +2,10 @@ package com.tangguo.mapper; ...@@ -2,6 +2,10 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsMomentVote; import com.tangguo.domain.BbsMomentVote;
import com.tangguo.domain.vo.BbsVoteVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 动态投票记录Mapper接口 * 动态投票记录Mapper接口
...@@ -10,4 +14,7 @@ import com.tangguo.domain.BbsMomentVote; ...@@ -10,4 +14,7 @@ import com.tangguo.domain.BbsMomentVote;
* @date 2025-09-01 * @date 2025-09-01
*/ */
public interface BbsMomentVoteMapper extends BaseMapper<BbsMomentVote> { public interface BbsMomentVoteMapper extends BaseMapper<BbsMomentVote> {
List<BbsVoteVO> selectVotes(@Param("momentId") Long momentId, @Param("optionCode") String optionCode);
} }
...@@ -3,6 +3,8 @@ package com.tangguo.service; ...@@ -3,6 +3,8 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMomentComment; import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.BbsMomentVoteOption; import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.domain.vo.BbsCommentVO;
import java.util.List; import java.util.List;
...@@ -48,4 +50,14 @@ public interface IBbsMomentCommentService extends IService<BbsMomentComment> { ...@@ -48,4 +50,14 @@ public interface IBbsMomentCommentService extends IService<BbsMomentComment> {
*/ */
void deleteComment(Long commentId); void deleteComment(Long commentId);
/**
* 查询动态评论
*
* @param momentId 动态Id
* @param userName 用户名
* @return 评论
*/
List<BbsCommentDetailVO> getMomentComments(Long momentId, String userName);
} }
...@@ -2,6 +2,7 @@ package com.tangguo.service; ...@@ -2,6 +2,7 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMoment; import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.bo.CommentMomentBO;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.bo.LikeMomentBO; import com.tangguo.domain.bo.LikeMomentBO;
import com.tangguo.domain.bo.VoteMomentBO; import com.tangguo.domain.bo.VoteMomentBO;
...@@ -63,6 +64,16 @@ public interface IBbsMomentService extends IService<BbsMoment> { ...@@ -63,6 +64,16 @@ public interface IBbsMomentService extends IService<BbsMoment> {
List<BbsMomentListVO> getMoments(String userName, String content); List<BbsMomentListVO> getMoments(String userName, String content);
/**
* 查询动态详情
*
* @param momentId 动态Id
* @param userName 用户名
* @return 动态列表
*/
BbsMomentListVO getMoment(Long momentId, String userName);
/** /**
* 创建动态 * 创建动态
* *
...@@ -94,4 +105,12 @@ public interface IBbsMomentService extends IService<BbsMoment> { ...@@ -94,4 +105,12 @@ public interface IBbsMomentService extends IService<BbsMoment> {
*/ */
void userVoteMoment(VoteMomentBO bo); void userVoteMoment(VoteMomentBO bo);
/**
* 评论动态
*
* @param bo 动态
*/
void userCommentMoment(CommentMomentBO bo);
} }
...@@ -7,6 +7,7 @@ import com.tangguo.domain.bo.CreateMomentBO; ...@@ -7,6 +7,7 @@ import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.vo.BbsVoteOptionVO; import com.tangguo.domain.vo.BbsVoteOptionVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 动态投票选项Service接口 * 动态投票选项Service接口
......
...@@ -2,6 +2,9 @@ package com.tangguo.service; ...@@ -2,6 +2,9 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMomentVote; import com.tangguo.domain.BbsMomentVote;
import com.tangguo.domain.vo.BbsVoteVO;
import java.util.List;
/** /**
* 动态投票记录Service接口 * 动态投票记录Service接口
...@@ -30,4 +33,14 @@ public interface IBbsMomentVoteService extends IService<BbsMomentVote> { ...@@ -30,4 +33,14 @@ public interface IBbsMomentVoteService extends IService<BbsMomentVote> {
*/ */
void addMomentVoteCount(Long momentId, String userName, String optionCode); void addMomentVoteCount(Long momentId, String userName, String optionCode);
/**
* 查询投票记录列表
*
* @param momentId 动态Id
* @param optionCode 投票选项编码
* @return 投票记录
*/
List<BbsVoteVO> getMomentVotes(Long momentId, String optionCode);
} }
...@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -5,6 +5,8 @@ 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.exception.ServiceException; import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsMomentComment; import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.domain.vo.BbsCommentVO;
import com.tangguo.enums.CommentStatus; import com.tangguo.enums.CommentStatus;
import com.tangguo.mapper.BbsMomentCommentMapper; import com.tangguo.mapper.BbsMomentCommentMapper;
import com.tangguo.service.IBbsMomentCommentService; import com.tangguo.service.IBbsMomentCommentService;
...@@ -93,4 +95,17 @@ public class BbsMomentCommentServiceImpl extends ServiceImpl<BbsMomentCommentMap ...@@ -93,4 +95,17 @@ public class BbsMomentCommentServiceImpl extends ServiceImpl<BbsMomentCommentMap
this.updateById(updComment); this.updateById(updComment);
} }
/**
* 查询动态评论
*
* @param momentId 动态Id
* @param userName 用户名
* @return 评论
*/
@Override
public List<BbsCommentDetailVO> getMomentComments(Long momentId, String userName) {
return this.baseMapper.selectMomentComments(momentId, userName);
}
} }
...@@ -7,14 +7,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -7,14 +7,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.exception.ServiceException; import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.mauth.MobileTokenHelper; import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.domain.*; import com.tangguo.domain.*;
import com.tangguo.domain.bo.CommentMomentBO;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.bo.LikeMomentBO; import com.tangguo.domain.bo.LikeMomentBO;
import com.tangguo.domain.bo.VoteMomentBO; import com.tangguo.domain.bo.VoteMomentBO;
import com.tangguo.domain.vo.*; import com.tangguo.domain.vo.*;
import com.tangguo.enums.EnableStatus; import com.tangguo.enums.*;
import com.tangguo.enums.LikeStatus;
import com.tangguo.enums.MomentType;
import com.tangguo.enums.VoteOptionType;
import com.tangguo.mapper.BbsMomentMapper; import com.tangguo.mapper.BbsMomentMapper;
import com.tangguo.service.*; import com.tangguo.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -23,10 +21,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -23,10 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -124,6 +119,22 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -124,6 +119,22 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
} }
/**
* 查询动态详情
*
* @param momentId 动态Id
* @param userName 用户名
* @return 动态列表
*/
@Override
public BbsMomentListVO getMoment(Long momentId, String userName) {
BbsMomentListVO dbMoment = this.baseMapper.selectMoment(momentId, userName);
this.fillMoment(Collections.singletonList(dbMoment));
dbMoment.setComments(null);
return dbMoment;
}
/** /**
* 创建动态 * 创建动态
* *
...@@ -133,7 +144,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -133,7 +144,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
@Override @Override
public void userCreateMoment(CreateMomentBO bo) { public void userCreateMoment(CreateMomentBO bo) {
// 添加动态 // 添加动态
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
BbsMoment newMoment = this.buildMoment(bo); BbsMoment newMoment = this.buildMoment(bo);
newMoment.setUserName(username); newMoment.setUserName(username);
this.save(newMoment); this.save(newMoment);
...@@ -160,7 +171,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -160,7 +171,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void userDeleteMoment(Long momentId) { public void userDeleteMoment(Long momentId) {
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
BbsMoment dbMoment = this.getOne( BbsMoment dbMoment = this.getOne(
Wrappers.lambdaQuery(BbsMoment.class) Wrappers.lambdaQuery(BbsMoment.class)
.select(BbsMoment::getId).eq(BbsMoment::getUserName, username).eq(BbsMoment::getId, momentId) .select(BbsMoment::getId).eq(BbsMoment::getUserName, username).eq(BbsMoment::getId, momentId)
...@@ -186,7 +197,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -186,7 +197,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("点赞失败,未查询到当前动态数据。"); throw new ServiceException("点赞失败,未查询到当前动态数据。");
} }
String userName = MobileTokenHelper.getUsername(); String userName = MobileTokenHelper.getUserName();
long likeStatus = this.likeService.getUserMomentLikeCount(dbMoment.getId(), userName); long likeStatus = this.likeService.getUserMomentLikeCount(dbMoment.getId(), userName);
int likeCount = dbMoment.getLikeCount(); int likeCount = dbMoment.getLikeCount();
...@@ -230,7 +241,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -230,7 +241,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("投票失败,当前动态未开启投票。"); throw new ServiceException("投票失败,当前动态未开启投票。");
} }
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
long voteCount = this.voteService.getUserMomentVoteCount(dbMoment.getId(), username); long voteCount = this.voteService.getUserMomentVoteCount(dbMoment.getId(), username);
if (voteCount > 0) { if (voteCount > 0) {
throw new ServiceException("投票失败,已对当前动态投票。"); throw new ServiceException("投票失败,已对当前动态投票。");
...@@ -259,6 +270,53 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -259,6 +270,53 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
} }
/**
* 评论动态
*
* @param bo 动态
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void userCommentMoment(CommentMomentBO bo) {
BbsMoment dbMoment = this.getById(bo.getMomentId());
if (Objects.isNull(dbMoment)) {
throw new ServiceException("评论失败,未查询到当前动态数据。");
}
if (EnableStatus.QY.getStatus() != dbMoment.getIsEnableComment()) {
throw new ServiceException("评论失败,当前动态未开启评论。");
}
BbsMomentComment dbParentComment = null;
if (Objects.nonNull(bo.getParentId())) {
dbParentComment = this.commentService.getById(bo.getParentId());
if (Objects.isNull(dbParentComment)) {
throw new ServiceException("回复失败,未查询到回复的评论数据");
}
}
// 添加动态评论
BbsMomentComment newComment = new BbsMomentComment();
newComment.setMomentId(dbMoment.getId());
newComment.setUserName(MobileTokenHelper.getUserName());
newComment.setNikeName(MobileTokenHelper.getNikeName());
newComment.setContent(bo.getContent());
newComment.setStatus(CommentStatus.ZC.getStatus());
newComment.setIsFeatured(1);
this.commentService.save(newComment);
// 更新动态评论
BbsMomentComment updComment = new BbsMomentComment();
updComment.setId(newComment.getId());
if (Objects.nonNull(dbParentComment)) {
updComment.setParentId(dbParentComment.getId());
updComment.setReplyNikeName(dbParentComment.getNikeName());
updComment.setAncestorPath(dbParentComment.getAncestorPath() + "," + newComment.getId());
} else {
updComment.setAncestorPath(String.valueOf(newComment.getId()));
}
this.commentService.updateById(updComment);
}
/** /**
* 构建动态实体 * 构建动态实体
...@@ -415,6 +473,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment ...@@ -415,6 +473,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
for (BbsMomentComment c : cs) { for (BbsMomentComment c : cs) {
BbsCommentVO cv = new BbsCommentVO(); BbsCommentVO cv = new BbsCommentVO();
cv.setId(c.getId()); cv.setId(c.getId());
cv.setCreateTime(c.getCreateTime());
cv.setNikeName(c.getNikeName()); cv.setNikeName(c.getNikeName());
cv.setUserName(c.getUserName()); cv.setUserName(c.getUserName());
cv.setContent(c.getContent()); cv.setContent(c.getContent());
......
...@@ -3,11 +3,14 @@ package com.tangguo.service.impl; ...@@ -3,11 +3,14 @@ package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.domain.BbsMomentVote; import com.tangguo.domain.BbsMomentVote;
import com.tangguo.domain.vo.BbsVoteVO;
import com.tangguo.mapper.BbsMomentVoteMapper; import com.tangguo.mapper.BbsMomentVoteMapper;
import com.tangguo.service.IBbsMomentVoteService; import com.tangguo.service.IBbsMomentVoteService;
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.List;
/** /**
* 动态投票记录Service业务层处理 * 动态投票记录Service业务层处理
...@@ -55,4 +58,17 @@ public class BbsMomentVoteServiceImpl extends ServiceImpl<BbsMomentVoteMapper, B ...@@ -55,4 +58,17 @@ public class BbsMomentVoteServiceImpl extends ServiceImpl<BbsMomentVoteMapper, B
this.save(newVote); this.save(newVote);
} }
/**
* 查询投票记录列表
*
* @param momentId 动态Id
* @param optionCode 投票选项编码
* @return 投票记录
*/
@Override
public List<BbsVoteVO> getMomentVotes(Long momentId, String optionCode) {
return this.baseMapper.selectVotes(momentId, optionCode);
}
} }
...@@ -194,7 +194,7 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i ...@@ -194,7 +194,7 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
} }
BbsTopic newTopic = new BbsTopic(); BbsTopic newTopic = new BbsTopic();
newTopic.setCreateBy(MobileTokenHelper.getUsername()); newTopic.setCreateBy(MobileTokenHelper.getUserName());
newTopic.setSource("移动端用户"); newTopic.setSource("移动端用户");
newTopic.setName(bo.getName()); newTopic.setName(bo.getName());
this.save(newTopic); this.save(newTopic);
......
...@@ -53,8 +53,9 @@ public class BbsUserService { ...@@ -53,8 +53,9 @@ public class BbsUserService {
QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(userName); QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(userName);
if (Objects.nonNull(dbUser)) { if (Objects.nonNull(dbUser)) {
Map<String, Object> payloads = new LinkedHashMap<>(1); Map<String, Object> payloads = new LinkedHashMap<>(2);
payloads.put("userName", dbUser.getUserName()); payloads.put("userName", dbUser.getUserName());
payloads.put("nikeName", dbUser.getNikeName());
return MobileTokenHelper.createDetailToken(payloads); return MobileTokenHelper.createDetailToken(payloads);
} else { } else {
throw new ServiceException("登录失败,未查询到当前登录用户数据。"); throw new ServiceException("登录失败,未查询到当前登录用户数据。");
...@@ -68,7 +69,7 @@ public class BbsUserService { ...@@ -68,7 +69,7 @@ public class BbsUserService {
* @return 用户信息 * @return 用户信息
*/ */
public Map<String, Object> getUserProfile() { public Map<String, Object> getUserProfile() {
String username = MobileTokenHelper.getUsername(); String username = MobileTokenHelper.getUserName();
QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(username); QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(username);
if (Objects.nonNull(dbUser)) { if (Objects.nonNull(dbUser)) {
return BeanUtil.beanToMap(dbUser, false, false); return BeanUtil.beanToMap(dbUser, false, false);
......
...@@ -43,7 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -43,7 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SELECT c.* FROM ( SELECT c.* FROM (
SELECT SELECT
*, *,
ROW_NUMBER() OVER (PARTITION BY moment_id ORDER BY create_time DESC) AS rn ROW_NUMBER() OVER (PARTITION BY moment_id ORDER BY create_time) AS rn
FROM FROM
bbs_moment_comment bbs_moment_comment
WHERE WHERE
...@@ -56,5 +56,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -56,5 +56,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) AS c ) AS c
WHERE rn &lt;= #{rows}; WHERE rn &lt;= #{rows};
</select> </select>
<select id="selectMomentComments" resultType="com.tangguo.domain.vo.BbsCommentDetailVO">
SELECT
c.id,
c.create_time,
c.moment_id,
c.nike_name,
c.user_name,
c.content,
c.parent_id,
c.reply_nike_name,
IF(c.user_name = #{userName}, 1, 0) AS is_self
FROM
bbs_moment_comment c
WHERE
c.moment_id = 1 AND c.`status` = 1
ORDER BY
c.create_time
</select>
</mapper> </mapper>
...@@ -112,5 +112,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -112,5 +112,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY ORDER BY
m.create_time DESC m.create_time DESC
</select> </select>
<select id="selectMoment" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT
m.*,
uv.nike_name,
IF(l.id IS NOT NULL, 1, 0) AS is_like,
IF(v.id IS NOT NULL, 1, 0) AS is_vote,
IF(m.user_name = #{userName}, 1, 0) AS is_self
FROM
bbs_moment m
LEFT JOIN
qwmh_sys_user_view uv ON uv.user_name = m.user_name
LEFT JOIN
(
SELECT
id, moment_id
FROM
bbs_moment_like
WHERE
user_name = #{userName}
) l ON l.moment_id = m.id
LEFT JOIN
(
SELECT
id, moment_id
FROM
bbs_moment_vote
WHERE
user_name = #{userName}
) v ON v.moment_id = m.id
WHERE
m.id = #{momentId}
ORDER BY
m.create_time DESC
</select>
</mapper> </mapper>
...@@ -3,5 +3,19 @@ ...@@ -3,5 +3,19 @@
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.BbsMomentVoteMapper"> <mapper namespace="com.tangguo.mapper.BbsMomentVoteMapper">
<select id="selectVotes" resultType="com.tangguo.domain.vo.BbsVoteVO">
SELECT
v.create_time,
uv.nike_name
FROM
bbs_moment_vote v
LEFT JOIN
qwmh_sys_user_view uv ON uv.user_name = v.user_name
WHERE
v.moment_id = #{momentId} AND v.option_code = #{optionCode}
ORDER BY
v.create_time
</select>
</mapper> </mapper>
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