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

动态查询

parent 6eed8780
......@@ -19,7 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
*/
@RestController
@RequestMapping("/bbs/mobile/common")
public class MCommonController {
public class MBbsCommonController {
/**
* 通用上传请求(单个)
......
......@@ -31,7 +31,21 @@ public class MBbsMomentController {
@MobileAuth
@PostMapping("/create")
public AjaxResult createMoment(@RequestBody CreateMomentBO bo) {
this.momentService.createMoment(bo);
this.momentService.userCreateMoment(bo);
return AjaxResult.success();
}
/**
* 删除动态
*
* @param momentId 动态Id
* @return 删除结果
*/
@MobileAuth
@DeleteMapping("/delete/{momentId}")
public AjaxResult createMoment(@PathVariable Long momentId) {
this.momentService.userDeleteMoment(momentId);
return AjaxResult.success();
}
......
package com.tangguo.controller.mobile;
import com.github.pagehelper.PageHelper;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.utils.PageUtils;
import com.tangguo.domain.BbsTopic;
import com.tangguo.domain.bo.CreateTopicBO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsTopicListVO;
import com.tangguo.service.IBbsMomentService;
import com.tangguo.service.IBbsTopicService;
import org.springframework.web.bind.annotation.*;
......@@ -53,8 +50,8 @@ public class MBbsTopicController {
@MobileAuth
@PostMapping("/create")
public AjaxResult createTopic(@RequestBody CreateTopicBO bo) {
this.topicService.createTopic(bo);
return AjaxResult.success();
BbsTopicListVO topic = this.topicService.createTopic(bo);
return AjaxResult.success(topic);
}
......
......@@ -2,13 +2,17 @@ package com.tangguo.controller.mobile;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.PageUtils;
import com.tangguo.domain.bo.CodeLoginBO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
import com.tangguo.service.IBbsMomentService;
import com.tangguo.service.impl.BbsUserService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
......@@ -61,9 +65,25 @@ public class MBbsUserController {
*/
@MobileAuth
@GetMapping("/moment/count")
public AjaxResult userMomentCount() {
BbsUserMomentCountVO momentCount = this.momentService.getUserMomentCount();
public AjaxResult getUserMomentCount() {
String username = MobileTokenHelper.getUsername();
BbsUserMomentCountVO momentCount = this.momentService.getUserMomentCount(username);
return AjaxResult.success(momentCount);
}
/**
* 查询动态列表
*
* @return 动态
*/
@MobileAuth
@GetMapping("/moments")
public AjaxResult getUserMoments(String content) {
String username = MobileTokenHelper.getUsername();
PageUtils.clearPage();
List<BbsMomentListVO> moments = this.momentService.getMoments(username, content);
return AjaxResult.success(moments);
}
}
......@@ -46,19 +46,19 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("动态内容")
private String content;
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态 */
@Excel(name = "动态类型:IMAGE 图片动态、VIDEO 视频动态")
@ApiModelProperty("动态类型:IMAGE 图片动态、VIDEO 视频动态")
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态 */
@Excel(name = "动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态")
@ApiModelProperty("动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态")
private String type;
/** 话题名称(号分割) */
@Excel(name = "话题名称", readConverterExp = "逗=号分割")
@ApiModelProperty("话题名称(逗号分割)")
/** 话题名称(|号分割) */
@Excel(name = "话题名称", readConverterExp = "|号分割")
@ApiModelProperty("话题名称(|分割)")
private String topicNames;
/** 话题Ids(号分割) */
@Excel(name = "话题Ids", readConverterExp = "逗=号分割")
@ApiModelProperty("话题Ids(逗号分割)")
/** 话题Ids(|号分割) */
@Excel(name = "话题Ids", readConverterExp = "|分割")
@ApiModelProperty("话题Ids(|分割)")
private String topicIds;
/** 外部链接地址 */
......@@ -66,9 +66,9 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("外部链接地址")
private String linkUrl;
/** 附件地址(号分割) */
@Excel(name = "附件地址(逗号分割)")
@ApiModelProperty("附件地址(逗号分割)")
/** 附件地址(|号分割) */
@Excel(name = "附件地址(|分割)")
@ApiModelProperty("附件地址(|分割)")
private String attachmentUrls;
/** 是否开启评论:0 否、1 是 */
......
package com.tangguo.domain.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
*
*
* @author 谈笑
* @createTime 2025-09-03 15:42:59 星期三
*/
@Data
public class BbsMomentListDTO {
/**
* 发布时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 动态Id */
private Long id;
/** 发布人用户名 */
private String userName;
/** 动态内容 */
private String content;
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态 */
private String type;
/** 话题名称 */
private String topicNames;
/** 话题Ids */
private String topicIds;
/** 外部链接地址 */
private String linkUrl;
/** 附件地址 */
private String attachmentUrls;
/** 是否开启评论:0 否、1 是 */
private Integer isEnableComment;
/** 是否精选评论:0 否、1 是 */
private Integer isEnableFeaturedComment;
/** 是否开启投票:0 否、1 是 */
private Integer isEnableVote;
/** 投票标题 */
private String voteTitle;
/** 投票选项类型:TEXT 文字、IMAGE 图片 */
private String voteOptionType;
/** 投票选项JSON */
private String voteOptions;
/** 动态点赞人数 */
private Integer likeCount;
/** 动态评论人数 */
private Integer commentCount;
/** 动态投票人数 */
private Integer voteCount;
/** 当前是否点赞:0 未点赞、1 已点赞 */
private Integer isLike;
/** 当前是否投票:0 未投票、1 已投票 */
private Integer isVote;
}
package com.tangguo.domain.vo;
import lombok.Data;
/**
*
*
* @author 谈笑
* @createTime 2025-09-03 17:56:47 星期三
*/
@Data
public class BbsCommentVO {
/** 评论Id */
private Long id;
/** 评论用户姓名 */
private String nikeName;
/** 评论用户名 */
private String userName;
/** 回复的用户姓名 */
private String replyNikeName;
/** 回复的用户姓名 */
private String replyUserName;
/** 评论回复内容 */
private String content;
}
package com.tangguo.domain.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tangguo.common.annotation.Excel;
import com.tangguo.domain.bo.CreateMomentBO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
......@@ -20,6 +15,10 @@ import java.util.List;
@Data
public class BbsMomentListVO {
/** 发布时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 动态Id */
private Long id;
......@@ -29,7 +28,7 @@ public class BbsMomentListVO {
/** 动态内容 */
private String content;
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态 */
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态 */
private String type;
/** 话题名称 */
......@@ -71,4 +70,13 @@ public class BbsMomentListVO {
/** 动态投票人数 */
private Integer voteCount;
/** 当前是否点赞:0 未点赞、1 已点赞 */
private Integer isLike;
/** 当前是否投票:0 未投票、1 已投票 */
private Integer isVote;
/** 是否本人动态:0 否、1 是 */
private Integer isSelf;
}
package com.tangguo.domain.vo;
import com.tangguo.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
......
......@@ -2,6 +2,7 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.dto.BbsMomentListDTO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
import org.apache.ibatis.annotations.Param;
......@@ -20,4 +21,10 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> {
BbsUserMomentCountVO selectUserMomentCount(@Param("userName") String userName);
List<BbsMomentListDTO> selectUserMoments(@Param("userName") String userName, @Param("content") String content);
List<BbsMomentListDTO> selectMoments(@Param("userName") String userName, @Param("content") String content);
}
......@@ -3,6 +3,7 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
import java.util.List;
......@@ -24,12 +25,41 @@ public interface IBbsMomentService extends IService<BbsMoment> {
List<BbsMoment> selectBbsMomentList(BbsMoment bbsMoment);
/**
* 删除动态
*
* @param id 动态Id
*/
void deleteMoment(Long id);
/**
* 查询用户动态相关统计数据
*
* @param userName 用户名
* @return 动态统计数据
*/
BbsUserMomentCountVO getUserMomentCount();
BbsUserMomentCountVO getUserMomentCount(String userName);
/**
* 查询用户动态列表
*
* @param userName 用户名
* @param content 动态内容
* @return 动态列表
*/
List<BbsMomentListVO> getUserMoments(String userName, String content);
/**
* 查询动态列表
*
* @param userName 用户名
* @param content 动态内容
* @return 动态列表
*/
List<BbsMomentListVO> getMoments(String userName, String content);
/**
......@@ -37,6 +67,14 @@ public interface IBbsMomentService extends IService<BbsMoment> {
*
* @param bo 动态
*/
void createMoment(CreateMomentBO bo);
void userCreateMoment(CreateMomentBO bo);
/**
* 删除动态
*
* @param momentId 动态Id
*/
void userDeleteMoment(Long momentId);
}
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMomentAttachment;
import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.enums.VoteOptionType;
import java.util.List;
......
......@@ -88,6 +88,6 @@ public interface IBbsTopicService extends IService<BbsTopic> {
*
* @param bo 话题
*/
void createTopic(CreateTopicBO bo);
BbsTopicListVO createTopic(CreateTopicBO bo);
}
......@@ -12,7 +12,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
......
......@@ -3,11 +3,14 @@ package com.tangguo.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.dto.BbsMomentListDTO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
import com.tangguo.enums.EnableStatus;
import com.tangguo.enums.MomentType;
......@@ -20,6 +23,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
......@@ -54,15 +59,55 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
}
/**
* 删除动态
*
* @param id 动态Id
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteMoment(Long id) {
this.removeById(id);
}
/**
* 查询用户动态相关统计数据
*
* @param userName 用户名
* @return 动态统计数据
*/
@Override
public BbsUserMomentCountVO getUserMomentCount() {
String username = MobileTokenHelper.getUsername();
return this.baseMapper.selectUserMomentCount(username);
public BbsUserMomentCountVO getUserMomentCount(String userName) {
return this.baseMapper.selectUserMomentCount(userName);
}
/**
* 查询动态列表
*
* @param userName 用户名
* @param content 动态内容
* @return 动态列表
*/
@Override
public List<BbsMomentListVO> getUserMoments(String userName, String content) {
List<BbsMomentListDTO> dbMoments = this.baseMapper.selectUserMoments(userName, content);
return this.buildMomentListVO(dbMoments);
}
/**
* 查询动态列表
*
* @param userName 用户名
* @param content 动态内容
* @return 动态列表
*/
@Override
public List<BbsMomentListVO> getMoments(String userName, String content) {
List<BbsMomentListDTO> dbMoments = this.baseMapper.selectMoments(userName, content);
return this.buildMomentListVO(dbMoments);
}
......@@ -73,10 +118,10 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void createMoment(CreateMomentBO bo) {
public void userCreateMoment(CreateMomentBO bo) {
// 添加动态
String username = MobileTokenHelper.getUsername();
BbsMoment newMoment = this.buildBbsMoment(bo);
BbsMoment newMoment = this.buildMoment(bo);
newMoment.setUserName(username);
this.save(newMoment);
......@@ -88,13 +133,34 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
}
/**
* 删除动态
*
* @param momentId 动态Id
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void userDeleteMoment(Long momentId) {
String username = MobileTokenHelper.getUsername();
BbsMoment dbMoment = this.getOne(
Wrappers.lambdaQuery(BbsMoment.class)
.select(BbsMoment::getId).eq(BbsMoment::getUserName, username).eq(BbsMoment::getId, momentId)
);
if (Objects.isNull(dbMoment)) {
throw new ServiceException("删除失败,未查询到当前动态数据。");
}
this.removeById(dbMoment.getId());
}
/**
* 构建动态实体
*
* @param bo 动态
* @return 动态实体
*/
private BbsMoment buildBbsMoment(CreateMomentBO bo) {
private BbsMoment buildMoment(CreateMomentBO bo) {
final String separator = "|";
// 动态类型
......@@ -141,42 +207,77 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
if (Objects.isNull(optionType)) {
throw new ServiceException("发布失败,动态投票选项类型错误。");
}
List<CreateMomentBO.VoteOption> options = bo.getVoteOptions();
if (CollUtil.isEmpty(options)) {
throw new ServiceException("发布失败,动态投票选项不能为空。");
}
for (int i = 0; i < options.size(); i++) {
CreateMomentBO.VoteOption option = options.get(i);
long optionCount = options.stream().filter(o -> o.getName().equals(option.getName())).count();
if (optionCount > 1) {
throw new ServiceException("发布失败,动态投票选项重复。");
}
int optionIndex = i + 1;
option.setType(optionType.name());
option.setCode(String.valueOf(optionIndex));
option.setSort(optionIndex);
}
newMoment.setVoteTitle(bo.getVoteTitle());
newMoment.setVoteOptionType(optionType.name());
String optionsJson = this.buildVoteOptionsJson(optionType, options);
newMoment.setVoteOptions(optionsJson);
newMoment.setVoteOptions(JSONUtil.toJsonStr(options));
}
return newMoment;
}
/**
* 构建动态投票选项Json
* 构建动态列表
*
* @param type 选项类型
* @param options 选项
* @return 选项Json
* @param dbMoments 动态
* @return 动态列表
*/
public String buildVoteOptionsJson(VoteOptionType type, List<CreateMomentBO.VoteOption> options) {
if (CollUtil.isEmpty(options)) {
throw new ServiceException("发布失败,动态投票选项不能为空。");
}
for (int i = 0; i < options.size(); i++) {
CreateMomentBO.VoteOption option = options.get(i);
long optionCount = options.stream().filter(o -> o.getName().equals(option.getName())).count();
if (optionCount > 1) {
throw new ServiceException("发布失败,动态投票选项重复。");
private List<BbsMomentListVO> buildMomentListVO(List<BbsMomentListDTO> dbMoments) {
List<BbsMomentListVO> moments = new ArrayList<>(dbMoments.size());
for (BbsMomentListDTO dbMoment : dbMoments) {
BbsMomentListVO moment = new BbsMomentListVO();
moment.setCreateTime(dbMoment.getCreateTime());
moment.setId(dbMoment.getId());
moment.setUserName(dbMoment.getUserName());
moment.setContent(dbMoment.getContent());
moment.setType(dbMoment.getType());
String topicNames = dbMoment.getTopicNames();
if (StrUtil.isNotBlank(topicNames)) {
moment.setTopicNames(Arrays.asList(topicNames.split("\\|")));
}
String topicIds = dbMoment.getTopicIds();
if (StrUtil.isNotBlank(topicNames)) {
moment.setTopicIds(Arrays.asList(topicIds.split("\\|")));
}
option.setType(type.name());
int optionIndex = i + 1;
option.setCode(String.valueOf(optionIndex));
option.setSort(optionIndex);
String attachmentUrls = dbMoment.getAttachmentUrls();
if (StrUtil.isNotBlank(attachmentUrls)) {
moment.setAttachmentUrls(Arrays.asList(attachmentUrls.split("\\|")));
}
moment.setLinkUrl(dbMoment.getLinkUrl());
moment.setIsEnableComment(dbMoment.getIsEnableComment());
moment.setIsEnableFeaturedComment(dbMoment.getIsEnableFeaturedComment());
moment.setIsEnableVote(dbMoment.getIsEnableVote());
moment.setVoteTitle(dbMoment.getVoteTitle());
moment.setVoteOptionType(dbMoment.getVoteOptionType());
moment.setVoteOptions(dbMoment.getVoteOptions());
moment.setLikeCount(dbMoment.getLikeCount());
moment.setCommentCount(dbMoment.getCommentCount());
moment.setVoteCount(dbMoment.getVoteCount());
moment.setIsLike(dbMoment.getIsLike());
moment.setIsVote(dbMoment.getIsVote());
moments.add(moment);
}
return JSONUtil.toJsonStr(options);
return moments;
}
}
package com.tangguo.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.enums.VoteOptionType;
import com.tangguo.mapper.BbsMomentVoteOptionMapper;
import com.tangguo.service.IBbsMomentVoteOptionService;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
......
......@@ -184,7 +184,7 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
* @param bo 话题
*/
@Override
public void createTopic(CreateTopicBO bo) {
public BbsTopicListVO createTopic(CreateTopicBO bo) {
synchronized (bo.getName().intern()) {
long nameCount = this.count(
Wrappers.lambdaQuery(BbsTopic.class).eq(BbsTopic::getName, bo.getName())
......@@ -198,6 +198,11 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
newTopic.setSource("移动端用户");
newTopic.setName(bo.getName());
this.save(newTopic);
BbsTopicListVO topicVO = new BbsTopicListVO();
topicVO.setId(newTopic.getId());
topicVO.setName(newTopic.getName());
return topicVO;
}
}
......
......@@ -35,5 +35,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(SELECT COUNT(*) FROM bbs_moment_comment WHERE user_name = #{userName}) AS comment_count,
(SELECT COUNT(*) FROM bbs_moment_like WHERE user_name = #{userName}) AS like_count
</select>
<select id="selectUserMoments" resultType="com.tangguo.domain.dto.BbsMomentListDTO">
SELECT
m.*,
IF(l.id IS NOT NULL AND l.like_status = 1, 1, 0) AS is_like,
IF(v.id IS NOT NULL, 1, 0) AS is_vote
FROM
bbs_moment m
LEFT JOIN
(
SELECT
id, moment_id, like_status
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>
<if test="1==1">
m.user_name = #{userName}
</if>
<if test="content != null and content != ''">
AND m.content LIKE CONCAT('%', #{content}, '%')
</if>
</where>
ORDER BY
m.create_time DESC
</select>
<select id="selectMoments" resultType="com.tangguo.domain.dto.BbsMomentListDTO">
SELECT
m.*,
IF(l.id IS NOT NULL AND l.like_status = 1, 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
(
SELECT
id, moment_id, like_status
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>
<if test="content != null and content != ''">
m.content LIKE CONCAT('%', #{content}, '%')
</if>
</where>
ORDER BY
m.create_time DESC
</select>
</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