package cn.lili.modules.lmk.service.impl;
|
|
import cn.lili.common.security.AuthUser;
|
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.sensitive.SensitiveWordsFilter;
|
import cn.lili.modules.lmk.domain.vo.CollectTypeNumVO;
|
import cn.lili.modules.lmk.enums.general.VideoCommentStatusEnum;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import cn.lili.modules.lmk.domain.entity.VideoComment;
|
import cn.lili.modules.lmk.mapper.VideoCommentMapper;
|
import cn.lili.modules.lmk.service.VideoCommentService;
|
import cn.lili.base.Result;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import cn.lili.modules.lmk.domain.form.VideoCommentForm;
|
import cn.lili.modules.lmk.domain.vo.VideoCommentVO;
|
import cn.lili.modules.lmk.domain.query.VideoCommentQuery;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import lombok.RequiredArgsConstructor;
|
import cn.lili.utils.PageUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.Assert;
|
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 视频评论 服务实现类
|
*
|
* @author xp
|
* @since 2025-05-27
|
*/
|
@Service
|
@RequiredArgsConstructor
|
public class VideoCommentServiceImpl extends ServiceImpl<VideoCommentMapper, VideoComment> implements VideoCommentService {
|
|
private final VideoCommentMapper videoCommentMapper;
|
|
/**
|
* 添加
|
* @param form
|
* @return
|
*/
|
@Override
|
public Result comment(VideoCommentForm form) {
|
// 监测内容是否包含敏感词
|
if (SensitiveWordsFilter.includeSentenceWord(form.getCommentContent())) {
|
return Result.error("评论含敏感内容");
|
}
|
if (StringUtils.isNotBlank(form.getReplyId())) {
|
VideoComment beReplyComment = baseMapper.selectById(form.getReplyId());
|
if (Objects.isNull(beReplyComment)) {
|
throw new RuntimeException("您回复的评论已被删除");
|
} else if (VideoCommentStatusEnum.INVALID.getValue().equals(beReplyComment.getStatus())) {
|
throw new RuntimeException("您回复的评论已失效");
|
}
|
}
|
VideoComment entity = VideoCommentForm.getEntityByForm(form, null);
|
entity.setStatus(VideoCommentStatusEnum.AUDITING.getValue());
|
|
AuthUser currentUser = UserContext.getCurrentUser();
|
entity.setUserNickname(currentUser.getNickName());
|
entity.setUserAvatar(currentUser.getFace());
|
|
baseMapper.insert(entity);
|
return Result.ok("添加成功").data(this.detail(entity.getId()).get("data"));
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@Override
|
public Result remove(List<String> ids) {
|
baseMapper.deleteBatchIds(ids);
|
return Result.ok("删除成功");
|
}
|
|
/**
|
* id删除
|
* @param id
|
* @return
|
*/
|
@Override
|
public Result removeById(String id) {
|
baseMapper.deleteById(id);
|
return Result.ok("删除成功");
|
}
|
|
/**
|
* 分页查询
|
* @param query
|
* @return
|
*/
|
@Override
|
public Result page(VideoCommentQuery query) {
|
IPage<VideoCommentVO> page = PageUtil.getPage(query, VideoCommentVO.class);
|
baseMapper.getPage(page, query);
|
return Result.ok().data(page.getRecords()).total(page.getTotal());
|
}
|
|
/**
|
* 根据id查找
|
* @param id
|
* @return
|
*/
|
@Override
|
public Result detail(String id) {
|
VideoCommentVO vo = baseMapper.getById(id);
|
Assert.notNull(vo, "记录不存在");
|
return Result.ok().data(vo);
|
}
|
|
/**
|
* 列表
|
* @return
|
*/
|
@Override
|
public Result all() {
|
List<VideoComment> entities = baseMapper.selectList(null);
|
List<VideoCommentVO> vos = entities.stream()
|
.map(entity -> VideoCommentVO.getVoByEntity(entity, null))
|
.collect(Collectors.toList());
|
return Result.ok().data(vos);
|
}
|
|
@Override
|
public Result wxPage(VideoCommentQuery query) {
|
IPage<VideoCommentVO> page = PageUtil.getPage(query, VideoCommentVO.class);
|
if (StringUtils.isNotBlank(query.getMasterCommentId())) {
|
// 加载子评论的情况
|
baseMapper.replyCommentPage(page, query);
|
return Result.ok().data(page.getRecords());
|
} else {
|
// 加载主评论的情况。主评论id = masterCommentId
|
baseMapper.masterCommentPage(page, query);
|
}
|
return Result.ok().data(page.getRecords()).total(page.getTotal());
|
}
|
|
|
@Override
|
public List<CollectTypeNumVO> countNumGroupByVideo() {
|
return baseMapper.countNumGroupByVideo();
|
}
|
}
|