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

优化动态

parent a98f658f
...@@ -51,14 +51,14 @@ public class BbsMoment extends BaseEntity { ...@@ -51,14 +51,14 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态") @ApiModelProperty("动态类型:IMAGE 图片动态、VIDEO 视频动态、URL 链接动态")
private String type; private String type;
/** 话题名称(|号分割) */ /** 话题名称(号分割) */
@Excel(name = "话题名称", readConverterExp = "|号分割") @Excel(name = "话题名称", readConverterExp = "号分割")
@ApiModelProperty("话题名称(|分割)") @ApiModelProperty("话题名称(逗号分割)")
private String topicNames; private String topicNames;
/** 话题Ids(|号分割) */ /** 话题Ids(号分割) */
@Excel(name = "话题Ids", readConverterExp = "|分割") @Excel(name = "话题Ids", readConverterExp = "逗号分割")
@ApiModelProperty("话题Ids(|分割)") @ApiModelProperty("话题Ids(逗号分割)")
private String topicIds; private String topicIds;
/** 外部链接地址 */ /** 外部链接地址 */
...@@ -66,11 +66,6 @@ public class BbsMoment extends BaseEntity { ...@@ -66,11 +66,6 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("外部链接地址") @ApiModelProperty("外部链接地址")
private String linkUrl; private String linkUrl;
/** 附件地址(|号分割) */
@Excel(name = "附件地址(|分割)")
@ApiModelProperty("附件地址(|分割)")
private String attachmentUrls;
/** 是否开启评论:0 否、1 是 */ /** 是否开启评论:0 否、1 是 */
@Excel(name = "是否开启评论:0 否、1 是") @Excel(name = "是否开启评论:0 否、1 是")
@ApiModelProperty("是否开启评论:0 否、1 是") @ApiModelProperty("是否开启评论:0 否、1 是")
...@@ -108,11 +103,6 @@ public class BbsMoment extends BaseEntity { ...@@ -108,11 +103,6 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("投票结束时间") @ApiModelProperty("投票结束时间")
private Date voteEndTime; private Date voteEndTime;
/** 投票选项JSON */
@Excel(name = "投票选项JSON")
@ApiModelProperty("投票选项JSON")
private String voteOptions;
/** 动态点赞人数 */ /** 动态点赞人数 */
@Excel(name = "动态点赞人数") @Excel(name = "动态点赞人数")
@ApiModelProperty("动态点赞人数") @ApiModelProperty("动态点赞人数")
......
...@@ -57,9 +57,4 @@ public class BbsMomentAttachment extends BaseEntity { ...@@ -57,9 +57,4 @@ public class BbsMomentAttachment extends BaseEntity {
@ApiModelProperty("附件预览地址") @ApiModelProperty("附件预览地址")
private String url; private String url;
/** 文件扩展名:PNG、JPG、MP4 */
@Excel(name = "文件扩展名:PNG、JPG、MP4")
@ApiModelProperty("文件扩展名:PNG、JPG、MP4")
private String fileExt;
} }
...@@ -28,9 +28,6 @@ public class CreateMomentBO { ...@@ -28,9 +28,6 @@ public class CreateMomentBO {
/** 外部链接地址 */ /** 外部链接地址 */
private String linkUrl; private String linkUrl;
/** 动态附件地址 */
private List<String> attachmentUrls;
/** 是否开启评论:0 否、1 是 */ /** 是否开启评论:0 否、1 是 */
private Integer isEnableComment; private Integer isEnableComment;
...@@ -46,6 +43,9 @@ public class CreateMomentBO { ...@@ -46,6 +43,9 @@ public class CreateMomentBO {
/** 投票选项类型:TEXT 文字、IMAGE 图片 */ /** 投票选项类型:TEXT 文字、IMAGE 图片 */
private String voteOptionType; private String voteOptionType;
/** 动态附件 */
private List<Attachment> attachments;
/** 动态投票选项 */ /** 动态投票选项 */
private List<VoteOption> voteOptions; private List<VoteOption> voteOptions;
...@@ -59,15 +59,9 @@ public class CreateMomentBO { ...@@ -59,15 +59,9 @@ public class CreateMomentBO {
/** 附件名称 */ /** 附件名称 */
private String name; private String name;
/** 附件类型:图片 IMAGE、视频 VIDEO */
private String type;
/** 附件预览地址 */ /** 附件预览地址 */
private String url; private String url;
/** 文件扩展名:PNG、JPG、MP4 */
private String fileExt;
} }
/** /**
...@@ -76,21 +70,12 @@ public class CreateMomentBO { ...@@ -76,21 +70,12 @@ public class CreateMomentBO {
@Data @Data
public static class VoteOption { public static class VoteOption {
/** 选项类型:TEXT 文字、IMAGE 图片 */
private String type;
/** 选项名称 */ /** 选项名称 */
private String name; private String name;
/** 选项编码 */
private String code;
/** 图片地址 */ /** 图片地址 */
private String imageUrl; private String imageUrl;
/** 排序值 */
private Integer sort;
} }
} }
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;
/** 是否本人动态:0 否、1 是 */
private Integer isSelf;
}
...@@ -40,9 +40,6 @@ public class BbsMomentListVO { ...@@ -40,9 +40,6 @@ public class BbsMomentListVO {
/** 外部链接地址 */ /** 外部链接地址 */
private String linkUrl; private String linkUrl;
/** 附件地址 */
private List<String> attachmentUrls;
/** 是否开启评论:0 否、1 是 */ /** 是否开启评论:0 否、1 是 */
private Integer isEnableComment; private Integer isEnableComment;
...@@ -58,9 +55,6 @@ public class BbsMomentListVO { ...@@ -58,9 +55,6 @@ public class BbsMomentListVO {
/** 投票选项类型:TEXT 文字、IMAGE 图片 */ /** 投票选项类型:TEXT 文字、IMAGE 图片 */
private String voteOptionType; private String voteOptionType;
/** 投票选项JSON */
private String voteOptions;
/** 动态点赞人数 */ /** 动态点赞人数 */
private Integer likeCount; private Integer likeCount;
...@@ -79,4 +73,51 @@ public class BbsMomentListVO { ...@@ -79,4 +73,51 @@ public class BbsMomentListVO {
/** 是否本人动态:0 否、1 是 */ /** 是否本人动态:0 否、1 是 */
private Integer isSelf; private Integer isSelf;
/** 动态附件 */
private List<Attachment> attachments;
/** 动态投票选项 */
private List<VoteOption> voteOptions;
/**
* 动态附件
*/
@Data
public static class Attachment {
/** 附件名称 */
private String name;
/** 附件预览地址 */
private String url;
}
/**
* 动态投票选项
*/
@Data
public static class VoteOption {
/** 选项类型:TEXT 文字、IMAGE 图片 */
private String type;
/** 选项名称 */
private String name;
/** 选项编码 */
private String code;
/** 图片地址 */
private String imageUrl;
/** 排序值 */
private Integer sort;
/** 投票人数 */
private Integer voteCount;
}
} }
...@@ -2,7 +2,7 @@ package com.tangguo.mapper; ...@@ -2,7 +2,7 @@ package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsMoment; import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.dto.BbsMomentListDTO; import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO; import com.tangguo.domain.vo.BbsUserMomentCountVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -22,9 +22,9 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> { ...@@ -22,9 +22,9 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> {
BbsUserMomentCountVO selectUserMomentCount(@Param("userName") String userName); BbsUserMomentCountVO selectUserMomentCount(@Param("userName") String userName);
List<BbsMomentListDTO> selectUserMoments(@Param("userName") String userName, @Param("content") String content); List<BbsMomentListVO> selectUserMoments(@Param("userName") String userName, @Param("content") String content);
List<BbsMomentListDTO> selectMoments(@Param("userName") String userName, @Param("content") String content); List<BbsMomentListVO> selectMoments(@Param("userName") String userName, @Param("content") String content);
} }
package com.tangguo.service; 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.BbsMomentAttachment; import com.tangguo.domain.BbsMomentAttachment;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
...@@ -23,14 +24,22 @@ public interface IBbsMomentAttachmentService extends IService<BbsMomentAttachmen ...@@ -23,14 +24,22 @@ public interface IBbsMomentAttachmentService extends IService<BbsMomentAttachmen
List<BbsMomentAttachment> getAttachments(Long momentId); List<BbsMomentAttachment> getAttachments(Long momentId);
/**
* 查询动态附件
*
* @param momentIds 动态Ids
* @return 附件
*/
List<BbsMomentAttachment> getAttachments(List<Long> momentIds);
/** /**
* 添加动态附件 * 添加动态附件
* *
* @param userName 用户名 * @param moment 动态
* @param momentId 动态Id
* @param attachments 动态附件 * @param attachments 动态附件
*/ */
void addAttachments(String userName, Long momentId, List<CreateMomentBO.Attachment> attachments); void addAttachments(BbsMoment moment, List<CreateMomentBO.Attachment> attachments);
/** /**
......
package com.tangguo.service; 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.BbsMomentVoteOption; import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
...@@ -23,13 +24,22 @@ public interface IBbsMomentVoteOptionService extends IService<BbsMomentVoteOptio ...@@ -23,13 +24,22 @@ public interface IBbsMomentVoteOptionService extends IService<BbsMomentVoteOptio
List<BbsMomentVoteOption> getVoteOptions(Long momentId); List<BbsMomentVoteOption> getVoteOptions(Long momentId);
/**
* 查询动态投票选项
*
* @param momentIds 动态Ids
* @return 投票选项
*/
List<BbsMomentVoteOption> getVoteOptions(List<Long> momentIds);
/** /**
* 添加动态投票选项 * 添加动态投票选项
* *
* @param momentId 动态Id * @param moment 动态
* @param voteOptions 投票选项 * @param voteOptions 投票选项
*/ */
void addVoteOptions(Long momentId, List<CreateMomentBO.VoteOption> voteOptions); void addVoteOptions(BbsMoment moment, List<CreateMomentBO.VoteOption> voteOptions);
/** /**
......
...@@ -3,6 +3,7 @@ package com.tangguo.service.impl; ...@@ -3,6 +3,7 @@ package com.tangguo.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
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.BbsMoment;
import com.tangguo.domain.BbsMomentAttachment; import com.tangguo.domain.BbsMomentAttachment;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.mapper.BbsMomentAttachmentMapper; import com.tangguo.mapper.BbsMomentAttachmentMapper;
...@@ -36,31 +37,48 @@ public class BbsMomentAttachmentServiceImpl extends ServiceImpl<BbsMomentAttachm ...@@ -36,31 +37,48 @@ public class BbsMomentAttachmentServiceImpl extends ServiceImpl<BbsMomentAttachm
@Override @Override
public List<BbsMomentAttachment> getAttachments(Long momentId) { public List<BbsMomentAttachment> getAttachments(Long momentId) {
return this.list( return this.list(
Wrappers.lambdaQuery(BbsMomentAttachment.class).eq(BbsMomentAttachment::getMomentId, momentId) Wrappers.lambdaQuery(BbsMomentAttachment.class)
.eq(BbsMomentAttachment::getMomentId, momentId)
); );
} }
/**
* 查询动态附件
*
* @param momentIds 动态Ids
* @return 附件
*/
@Override
public List<BbsMomentAttachment> getAttachments(List<Long> momentIds) {
List<BbsMomentAttachment> dbAttachments = new ArrayList<>(9);
if (CollUtil.isNotEmpty(momentIds)) {
dbAttachments = this.list(
Wrappers.lambdaQuery(BbsMomentAttachment.class).in(BbsMomentAttachment::getMomentId, momentIds)
);
}
return dbAttachments;
}
/** /**
* 添加动态附件 * 添加动态附件
* *
* @param userName 用户名 * @param moment 动态
* @param momentId 动态Id
* @param attachments 动态附件 * @param attachments 动态附件
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void addAttachments(String userName, Long momentId, List<CreateMomentBO.Attachment> attachments) { public void addAttachments(BbsMoment moment, List<CreateMomentBO.Attachment> attachments) {
if (CollUtil.isNotEmpty(attachments)) { if (CollUtil.isNotEmpty(attachments)) {
List<BbsMomentAttachment> newAttachments = new ArrayList<>(attachments.size()); List<BbsMomentAttachment> newAttachments = new ArrayList<>(attachments.size());
for (CreateMomentBO.Attachment attachment : attachments) { for (CreateMomentBO.Attachment attachment : attachments) {
BbsMomentAttachment newAttachment = new BbsMomentAttachment(); BbsMomentAttachment newAttachment = new BbsMomentAttachment();
newAttachment.setMomentId(momentId); newAttachment.setMomentId(moment.getId());
newAttachment.setUserName(userName); newAttachment.setUserName(moment.getUserName());
newAttachment.setName(attachment.getName()); newAttachment.setName(attachment.getName());
newAttachment.setType(attachment.getType()); newAttachment.setType(moment.getType());
newAttachment.setUrl(attachment.getUrl()); newAttachment.setUrl(attachment.getUrl());
newAttachment.setFileExt(attachment.getFileExt());
newAttachments.add(newAttachment); newAttachments.add(newAttachment);
} }
this.saveBatch(newAttachments); this.saveBatch(newAttachments);
...@@ -76,7 +94,8 @@ public class BbsMomentAttachmentServiceImpl extends ServiceImpl<BbsMomentAttachm ...@@ -76,7 +94,8 @@ public class BbsMomentAttachmentServiceImpl extends ServiceImpl<BbsMomentAttachm
@Override @Override
public void deleteAttachments(Long momentId) { public void deleteAttachments(Long momentId) {
this.remove( this.remove(
Wrappers.lambdaQuery(BbsMomentAttachment.class).eq(BbsMomentAttachment::getMomentId, momentId) Wrappers.lambdaQuery(BbsMomentAttachment.class)
.eq(BbsMomentAttachment::getMomentId, momentId)
); );
} }
......
...@@ -3,8 +3,10 @@ package com.tangguo.service.impl; ...@@ -3,8 +3,10 @@ package com.tangguo.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
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.BbsMoment;
import com.tangguo.domain.BbsMomentVoteOption; import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.bo.CreateMomentBO; import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.enums.VoteOptionType;
import com.tangguo.mapper.BbsMomentVoteOptionMapper; import com.tangguo.mapper.BbsMomentVoteOptionMapper;
import com.tangguo.service.IBbsMomentVoteOptionService; import com.tangguo.service.IBbsMomentVoteOptionService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -36,33 +38,57 @@ public class BbsMomentVoteOptionServiceImpl extends ServiceImpl<BbsMomentVoteOpt ...@@ -36,33 +38,57 @@ public class BbsMomentVoteOptionServiceImpl extends ServiceImpl<BbsMomentVoteOpt
@Override @Override
public List<BbsMomentVoteOption> getVoteOptions(Long momentId) { public List<BbsMomentVoteOption> getVoteOptions(Long momentId) {
return this.list( return this.list(
Wrappers.lambdaQuery(BbsMomentVoteOption.class).eq(BbsMomentVoteOption::getMomentId, momentId) Wrappers.lambdaQuery(BbsMomentVoteOption.class)
.eq(BbsMomentVoteOption::getMomentId, momentId)
); );
} }
/**
* 查询动态投票选项
*
* @param momentIds 动态Ids
* @return 投票选项
*/
@Override
public List<BbsMomentVoteOption> getVoteOptions(List<Long> momentIds) {
List<BbsMomentVoteOption> dbOptions = new ArrayList<>(2);
if (CollUtil.isNotEmpty(momentIds)) {
dbOptions = this.list(
Wrappers.lambdaQuery(BbsMomentVoteOption.class).in(BbsMomentVoteOption::getMomentId, momentIds)
);
}
return dbOptions;
}
/** /**
* 添加动态投票选项 * 添加动态投票选项
* *
* @param momentId 动态Id * @param moment 动态
* @param voteOptions 投票选项 * @param voteOptions 投票选项
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void addVoteOptions(Long momentId, List<CreateMomentBO.VoteOption> voteOptions) { public void addVoteOptions(BbsMoment moment, List<CreateMomentBO.VoteOption> voteOptions) {
if (CollUtil.isNotEmpty(voteOptions)) { if (CollUtil.isNotEmpty(voteOptions)) {
List<BbsMomentVoteOption> newVoteOptions = new ArrayList<>(voteOptions.size()); List<BbsMomentVoteOption> newOptions = new ArrayList<>(voteOptions.size());
for (CreateMomentBO.VoteOption voteOption : voteOptions) { for (int i = 0; i < voteOptions.size(); i++) {
BbsMomentVoteOption newVoteOption = new BbsMomentVoteOption(); CreateMomentBO.VoteOption option = voteOptions.get(i);
newVoteOption.setMomentId(momentId); BbsMomentVoteOption newOption = new BbsMomentVoteOption();
newVoteOption.setType(voteOption.getType()); newOption.setMomentId(moment.getId());
newVoteOption.setName(voteOption.getName()); VoteOptionType optionType = VoteOptionType.getVoteOptionType(moment.getVoteOptionType());
newVoteOption.setCode(voteOption.getCode()); newOption.setType(optionType.name());
newVoteOption.setImageUrl(voteOption.getImageUrl()); newOption.setName(option.getName());
newVoteOption.setSort(voteOption.getSort()); int optionIndex = i + 1;
newVoteOptions.add(newVoteOption); newOption.setCode(String.valueOf(optionIndex));
newOption.setSort(optionIndex);
if (VoteOptionType.IMAGE == optionType) {
newOption.setImageUrl(option.getImageUrl());
}
newOptions.add(newOption);
} }
this.saveBatch(newVoteOptions); this.saveBatch(newOptions);
} }
} }
......
...@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserMoments" resultType="com.tangguo.domain.dto.BbsMomentListDTO"> <select id="selectUserMoments" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT SELECT
m.*, m.*,
IF(l.id IS NOT NULL AND l.like_status = 1, 1, 0) AS is_like, IF(l.id IS NOT NULL AND l.like_status = 1, 1, 0) AS is_like,
...@@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectMoments" resultType="com.tangguo.domain.dto.BbsMomentListDTO"> <select id="selectMoments" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT SELECT
m.*, m.*,
IF(l.id IS NOT NULL AND l.like_status = 1, 1, 0) AS is_like, IF(l.id IS NOT NULL AND l.like_status = 1, 1, 0) AS is_like,
......
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