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

优化动态

parent a98f658f
......@@ -51,14 +51,14 @@ public class BbsMoment extends BaseEntity {
@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,11 +66,6 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("外部链接地址")
private String linkUrl;
/** 附件地址(|号分割) */
@Excel(name = "附件地址(|分割)")
@ApiModelProperty("附件地址(|分割)")
private String attachmentUrls;
/** 是否开启评论:0 否、1 是 */
@Excel(name = "是否开启评论:0 否、1 是")
@ApiModelProperty("是否开启评论:0 否、1 是")
......@@ -108,11 +103,6 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("投票结束时间")
private Date voteEndTime;
/** 投票选项JSON */
@Excel(name = "投票选项JSON")
@ApiModelProperty("投票选项JSON")
private String voteOptions;
/** 动态点赞人数 */
@Excel(name = "动态点赞人数")
@ApiModelProperty("动态点赞人数")
......
......@@ -57,9 +57,4 @@ public class BbsMomentAttachment extends BaseEntity {
@ApiModelProperty("附件预览地址")
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 {
/** 外部链接地址 */
private String linkUrl;
/** 动态附件地址 */
private List<String> attachmentUrls;
/** 是否开启评论:0 否、1 是 */
private Integer isEnableComment;
......@@ -46,6 +43,9 @@ public class CreateMomentBO {
/** 投票选项类型:TEXT 文字、IMAGE 图片 */
private String voteOptionType;
/** 动态附件 */
private List<Attachment> attachments;
/** 动态投票选项 */
private List<VoteOption> voteOptions;
......@@ -59,15 +59,9 @@ public class CreateMomentBO {
/** 附件名称 */
private String name;
/** 附件类型:图片 IMAGE、视频 VIDEO */
private String type;
/** 附件预览地址 */
private String url;
/** 文件扩展名:PNG、JPG、MP4 */
private String fileExt;
}
/**
......@@ -76,21 +70,12 @@ public class CreateMomentBO {
@Data
public static class VoteOption {
/** 选项类型:TEXT 文字、IMAGE 图片 */
private String type;
/** 选项名称 */
private String name;
/** 选项编码 */
private String code;
/** 图片地址 */
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 {
/** 外部链接地址 */
private String linkUrl;
/** 附件地址 */
private List<String> attachmentUrls;
/** 是否开启评论:0 否、1 是 */
private Integer isEnableComment;
......@@ -58,9 +55,6 @@ public class BbsMomentListVO {
/** 投票选项类型:TEXT 文字、IMAGE 图片 */
private String voteOptionType;
/** 投票选项JSON */
private String voteOptions;
/** 动态点赞人数 */
private Integer likeCount;
......@@ -79,4 +73,51 @@ public class BbsMomentListVO {
/** 是否本人动态:0 否、1 是 */
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;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.dto.BbsMomentListDTO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
import org.apache.ibatis.annotations.Param;
......@@ -22,9 +22,9 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> {
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;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.BbsMomentAttachment;
import com.tangguo.domain.bo.CreateMomentBO;
......@@ -23,14 +24,22 @@ public interface IBbsMomentAttachmentService extends IService<BbsMomentAttachmen
List<BbsMomentAttachment> getAttachments(Long momentId);
/**
* 查询动态附件
*
* @param momentIds 动态Ids
* @return 附件
*/
List<BbsMomentAttachment> getAttachments(List<Long> momentIds);
/**
* 添加动态附件
*
* @param userName 用户名
* @param momentId 动态Id
* @param moment 动态
* @param attachments 动态附件
*/
void addAttachments(String userName, Long momentId, List<CreateMomentBO.Attachment> attachments);
void addAttachments(BbsMoment moment, List<CreateMomentBO.Attachment> attachments);
/**
......
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.bo.CreateMomentBO;
......@@ -23,13 +24,22 @@ public interface IBbsMomentVoteOptionService extends IService<BbsMomentVoteOptio
List<BbsMomentVoteOption> getVoteOptions(Long momentId);
/**
* 查询动态投票选项
*
* @param momentIds 动态Ids
* @return 投票选项
*/
List<BbsMomentVoteOption> getVoteOptions(List<Long> momentIds);
/**
* 添加动态投票选项
*
* @param momentId 动态Id
* @param moment 动态
* @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;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.BbsMomentAttachment;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.mapper.BbsMomentAttachmentMapper;
......@@ -36,31 +37,48 @@ public class BbsMomentAttachmentServiceImpl extends ServiceImpl<BbsMomentAttachm
@Override
public List<BbsMomentAttachment> getAttachments(Long momentId) {
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 momentId 动态Id
* @param moment 动态
* @param attachments 动态附件
*/
@Transactional(rollbackFor = Exception.class)
@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)) {
List<BbsMomentAttachment> newAttachments = new ArrayList<>(attachments.size());
for (CreateMomentBO.Attachment attachment : attachments) {
BbsMomentAttachment newAttachment = new BbsMomentAttachment();
newAttachment.setMomentId(momentId);
newAttachment.setUserName(userName);
newAttachment.setMomentId(moment.getId());
newAttachment.setUserName(moment.getUserName());
newAttachment.setName(attachment.getName());
newAttachment.setType(attachment.getType());
newAttachment.setType(moment.getType());
newAttachment.setUrl(attachment.getUrl());
newAttachment.setFileExt(attachment.getFileExt());
newAttachments.add(newAttachment);
}
this.saveBatch(newAttachments);
......@@ -76,7 +94,8 @@ public class BbsMomentAttachmentServiceImpl extends ServiceImpl<BbsMomentAttachm
@Override
public void deleteAttachments(Long momentId) {
this.remove(
Wrappers.lambdaQuery(BbsMomentAttachment.class).eq(BbsMomentAttachment::getMomentId, momentId)
Wrappers.lambdaQuery(BbsMomentAttachment.class)
.eq(BbsMomentAttachment::getMomentId, momentId)
);
}
......
......@@ -2,14 +2,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.BbsMomentAttachment;
import com.tangguo.domain.BbsMomentVoteOption;
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;
......@@ -19,14 +19,17 @@ import com.tangguo.mapper.BbsMomentMapper;
import com.tangguo.service.IBbsMomentAttachmentService;
import com.tangguo.service.IBbsMomentService;
import com.tangguo.service.IBbsMomentVoteOptionService;
import lombok.extern.slf4j.Slf4j;
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.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* 动态Service业务层处理
......@@ -34,6 +37,7 @@ import java.util.Objects;
* @author ruoyi
* @date 2025-09-01
*/
@Slf4j
@Service
public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment> implements IBbsMomentService {
......@@ -91,8 +95,9 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
*/
@Override
public List<BbsMomentListVO> getUserMoments(String userName, String content) {
List<BbsMomentListDTO> dbMoments = this.baseMapper.selectUserMoments(userName, content);
return this.buildMomentListVO(dbMoments);
List<BbsMomentListVO> dbMoments = this.baseMapper.selectUserMoments(userName, content);
this.fillMoment(dbMoments);
return dbMoments;
}
......@@ -105,8 +110,9 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
*/
@Override
public List<BbsMomentListVO> getMoments(String userName, String content) {
List<BbsMomentListDTO> dbMoments = this.baseMapper.selectMoments(userName, content);
return this.buildMomentListVO(dbMoments);
List<BbsMomentListVO> dbMoments = this.baseMapper.selectMoments(userName, content);
this.fillMoment(dbMoments);
return dbMoments;
}
......@@ -124,10 +130,16 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
newMoment.setUserName(username);
this.save(newMoment);
// 添加动态附件
MomentType momentType = MomentType.getMomentType(bo.getType());
if (MomentType.IMAGE == momentType || MomentType.VIDEO == momentType) {
this.attachmentsService.addAttachments(newMoment, bo.getAttachments());
}
// 添加动态投票选项
if (EnableStatus.QY.getStatus() == bo.getIsEnableVote()) {
List<CreateMomentBO.VoteOption> voteOptions = bo.getVoteOptions();
this.voteOptionService.addVoteOptions(newMoment.getId(), voteOptions);
this.voteOptionService.addVoteOptions(newMoment, voteOptions);
}
}
......@@ -160,8 +172,6 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
* @return 动态实体
*/
private BbsMoment buildMoment(CreateMomentBO bo) {
final String separator = "|";
// 动态类型
MomentType momentType = MomentType.getMomentType(bo.getType());
if (Objects.isNull(momentType)) {
......@@ -169,24 +179,24 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
}
// 动态附件
List<String> attachmentUrls = bo.getAttachmentUrls();
BbsMoment newMoment = new BbsMoment();
List<CreateMomentBO.Attachment> attachments = bo.getAttachments();
String linkUrl = bo.getLinkUrl();
if (MomentType.IMAGE == momentType || MomentType.VIDEO == momentType) {
if (CollUtil.isEmpty(attachmentUrls)) {
if (CollUtil.isEmpty(attachments)) {
throw new ServiceException("发布失败,动态附件不能为空。");
}
}
else if (MomentType.URL == momentType) {
if (StrUtil.isBlank(linkUrl)) {
throw new ServiceException("发布失败,动态链接不能为空。");
} else {
newMoment.setLinkUrl(linkUrl);
}
}
BbsMoment newMoment = new BbsMoment();
newMoment.setType(momentType.name());
newMoment.setContent(bo.getContent());
newMoment.setLinkUrl(linkUrl);
newMoment.setAttachmentUrls(String.join(separator, attachmentUrls));
newMoment.setIsEnableComment(bo.getIsEnableComment());
newMoment.setIsEnableFeaturedComment(bo.getIsEnableFeaturedComment());
......@@ -194,90 +204,103 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
List<String> topicNames = bo.getTopicNames();
List<String> topicIds = bo.getTopicIds();
if (CollUtil.isNotEmpty(topicNames) && CollUtil.isNotEmpty(topicIds)) {
newMoment.setTopicIds(String.join(separator, topicIds));
newMoment.setTopicNames(String.join(separator, topicNames));
newMoment.setTopicIds(String.join(",", topicIds));
newMoment.setTopicNames(String.join(",", topicNames));
}
// 动态投票
Integer isEnableVote = bo.getIsEnableVote();
newMoment.setIsEnableVote(isEnableVote);
if (EnableStatus.QY.getStatus() == isEnableVote) {
newMoment.setVoteTitle(bo.getVoteTitle());
VoteOptionType optionType = VoteOptionType.getVoteOptionType(bo.getVoteOptionType());
if (Objects.isNull(optionType)) {
throw new ServiceException("发布失败,动态投票选项类型错误。");
}
newMoment.setVoteOptionType(optionType.name());
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();
for (CreateMomentBO.VoteOption option : options) {
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());
newMoment.setVoteOptions(JSONUtil.toJsonStr(options));
}
return newMoment;
}
/**
* 构建动态列表
* 填充动态附件和投票选项
*
* @param dbMoments 动态
* @return 动态列表
* @param moments 动态
*/
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("\\|")));
private void fillMoment(List<BbsMomentListVO> moments) {
List<Long> momentIds = moments.stream().map(BbsMomentListVO::getId).collect(Collectors.toList());
if (CollUtil.isEmpty(momentIds)) {
return;
}
String topicIds = dbMoment.getTopicIds();
if (StrUtil.isNotBlank(topicNames)) {
moment.setTopicIds(Arrays.asList(topicIds.split("\\|")));
try {
// 查询动态附件
CompletableFuture<Map<Long, List<BbsMomentAttachment>>> af = CompletableFuture.supplyAsync(() -> {
List<BbsMomentAttachment> atts = this.attachmentsService.getAttachments(momentIds);
return atts.stream().collect(Collectors.groupingBy(BbsMomentAttachment::getMomentId));
});
// 查询动态投票选项
CompletableFuture<Map<Long, List<BbsMomentVoteOption>>> of = CompletableFuture.supplyAsync(() -> {
List<BbsMomentVoteOption> opts = this.voteOptionService.getVoteOptions(momentIds);
return opts.stream().collect(Collectors.groupingBy(BbsMomentVoteOption::getMomentId));
});
// 等待全部任务处理完毕
CompletableFuture.allOf(af, of).join();
Map<Long, List<BbsMomentAttachment>> attsMap = af.join();
Map<Long, List<BbsMomentVoteOption>> optsMap = of.join();
// 填充动态
for (BbsMomentListVO m : moments) {
// 填充动态附件
List<BbsMomentAttachment> as = attsMap.get(m.getId());
if (CollUtil.isNotEmpty(as)) {
List<BbsMomentListVO.Attachment> avs = new ArrayList<>(as.size());
for (BbsMomentAttachment a : as) {
BbsMomentListVO.Attachment av = new BbsMomentListVO.Attachment();
av.setName(a.getName());
av.setUrl(a.getUrl());
avs.add(av);
}
m.setAttachments(avs);
}
String attachmentUrls = dbMoment.getAttachmentUrls();
if (StrUtil.isNotBlank(attachmentUrls)) {
moment.setAttachmentUrls(Arrays.asList(attachmentUrls.split("\\|")));
// 填充动态投票选项
List<BbsMomentVoteOption> os = optsMap.get(m.getId());
if (CollUtil.isNotEmpty(os)) {
List<BbsMomentListVO.VoteOption> ovs = new ArrayList<>(os.size());
for (BbsMomentVoteOption o : os) {
BbsMomentListVO.VoteOption ov = new BbsMomentListVO.VoteOption();
ov.setType(o.getType());
ov.setName(o.getName());
ov.setCode(o.getCode());
ov.setImageUrl(o.getImageUrl());
ov.setSort(o.getSort());
ov.setVoteCount(o.getVoteCount());
ovs.add(ov);
}
m.setVoteOptions(ovs);
}
}
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());
moment.setIsSelf(dbMoment.getIsSelf());
moments.add(moment);
} catch (Exception e) {
log.error("=> 填充动态附件和投票选项失败:", e);
}
return moments;
}
}
......@@ -3,8 +3,10 @@ package com.tangguo.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.domain.BbsMoment;
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.stereotype.Service;
......@@ -36,33 +38,57 @@ public class BbsMomentVoteOptionServiceImpl extends ServiceImpl<BbsMomentVoteOpt
@Override
public List<BbsMomentVoteOption> getVoteOptions(Long momentId) {
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 投票选项
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void addVoteOptions(Long momentId, List<CreateMomentBO.VoteOption> voteOptions) {
public void addVoteOptions(BbsMoment moment, List<CreateMomentBO.VoteOption> voteOptions) {
if (CollUtil.isNotEmpty(voteOptions)) {
List<BbsMomentVoteOption> newVoteOptions = new ArrayList<>(voteOptions.size());
for (CreateMomentBO.VoteOption voteOption : voteOptions) {
BbsMomentVoteOption newVoteOption = new BbsMomentVoteOption();
newVoteOption.setMomentId(momentId);
newVoteOption.setType(voteOption.getType());
newVoteOption.setName(voteOption.getName());
newVoteOption.setCode(voteOption.getCode());
newVoteOption.setImageUrl(voteOption.getImageUrl());
newVoteOption.setSort(voteOption.getSort());
newVoteOptions.add(newVoteOption);
List<BbsMomentVoteOption> newOptions = new ArrayList<>(voteOptions.size());
for (int i = 0; i < voteOptions.size(); i++) {
CreateMomentBO.VoteOption option = voteOptions.get(i);
BbsMomentVoteOption newOption = new BbsMomentVoteOption();
newOption.setMomentId(moment.getId());
VoteOptionType optionType = VoteOptionType.getVoteOptionType(moment.getVoteOptionType());
newOption.setType(optionType.name());
newOption.setName(option.getName());
int optionIndex = i + 1;
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"
</select>
<select id="selectUserMoments" resultType="com.tangguo.domain.dto.BbsMomentListDTO">
<select id="selectUserMoments" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT
m.*,
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"
</select>
<select id="selectMoments" resultType="com.tangguo.domain.dto.BbsMomentListDTO">
<select id="selectMoments" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT
m.*,
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