You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.5 KiB
121 lines
4.5 KiB
package com.aurora.service.impl;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.aurora.enums.CommentTypeEnum;
|
|
import com.aurora.model.dto.CommentCountDTO;
|
|
import com.aurora.model.dto.TalkAdminDTO;
|
|
import com.aurora.model.dto.TalkDTO;
|
|
import com.aurora.entity.Talk;
|
|
import com.aurora.exception.BizException;
|
|
import com.aurora.mapper.CommentMapper;
|
|
import com.aurora.mapper.TalkMapper;
|
|
import com.aurora.service.TalkService;
|
|
|
|
import com.aurora.util.BeanCopyUtil;
|
|
import com.aurora.util.CommonUtil;
|
|
import com.aurora.util.PageUtil;
|
|
import com.aurora.util.UserUtil;
|
|
import com.aurora.model.vo.ConditionVO;
|
|
import com.aurora.model.dto.PageResultDTO;
|
|
import com.aurora.model.vo.TalkVO;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
|
|
import static com.aurora.enums.TalkStatusEnum.PUBLIC;
|
|
|
|
|
|
@Service
|
|
public class TalkServiceImpl extends ServiceImpl<TalkMapper, Talk> implements TalkService {
|
|
|
|
@Autowired
|
|
private TalkMapper talkMapper;
|
|
|
|
@Autowired
|
|
private CommentMapper commentMapper;
|
|
|
|
@Override
|
|
public PageResultDTO<TalkDTO> listTalks() {
|
|
Integer count = talkMapper.selectCount((new LambdaQueryWrapper<Talk>()
|
|
.eq(Talk::getStatus, PUBLIC.getStatus())));
|
|
if (count == 0) {
|
|
return new PageResultDTO<>();
|
|
}
|
|
List<TalkDTO> talkDTOs = talkMapper.listTalks(PageUtil.getLimitCurrent(), PageUtil.getSize());
|
|
List<Integer> talkIds = talkDTOs.stream()
|
|
.map(TalkDTO::getId)
|
|
.collect(Collectors.toList());
|
|
Map<Integer, Integer> commentCountMap = commentMapper.listCommentCountByTypeAndTopicIds(CommentTypeEnum.TALK.getType(), talkIds)
|
|
.stream()
|
|
.collect(Collectors.toMap(CommentCountDTO::getId, CommentCountDTO::getCommentCount));
|
|
talkDTOs.forEach(item -> {
|
|
item.setCommentCount(commentCountMap.get(item.getId()));
|
|
if (Objects.nonNull(item.getImages())) {
|
|
item.setImgs(CommonUtil.castList(JSON.parseObject(item.getImages(), List.class), String.class));
|
|
}
|
|
});
|
|
return new PageResultDTO<>(talkDTOs, count);
|
|
}
|
|
|
|
@Override
|
|
public TalkDTO getTalkById(Integer talkId) {
|
|
TalkDTO talkDTO = talkMapper.getTalkById(talkId);
|
|
if (Objects.isNull(talkDTO)) {
|
|
throw new BizException("说说不存在");
|
|
}
|
|
if (Objects.nonNull(talkDTO.getImages())) {
|
|
talkDTO.setImgs(CommonUtil.castList(JSON.parseObject(talkDTO.getImages(), List.class), String.class));
|
|
}
|
|
CommentCountDTO commentCountDTO = commentMapper.listCommentCountByTypeAndTopicId(CommentTypeEnum.TALK.getType(), talkId);
|
|
if (Objects.nonNull(commentCountDTO)) {
|
|
talkDTO.setCommentCount(commentCountDTO.getCommentCount());
|
|
}
|
|
return talkDTO;
|
|
}
|
|
|
|
@Override
|
|
public void saveOrUpdateTalk(TalkVO talkVO) {
|
|
Talk talk = BeanCopyUtil.copyObject(talkVO, Talk.class);
|
|
talk.setUserId(UserUtil.getUserDetailsDTO().getUserInfoId());
|
|
this.saveOrUpdate(talk);
|
|
}
|
|
|
|
@Override
|
|
public void deleteTalks(List<Integer> talkIds) {
|
|
talkMapper.deleteBatchIds(talkIds);
|
|
}
|
|
|
|
@Override
|
|
public PageResultDTO<TalkAdminDTO> listBackTalks(ConditionVO conditionVO) {
|
|
Integer count = talkMapper.selectCount(new LambdaQueryWrapper<Talk>()
|
|
.eq(Objects.nonNull(conditionVO.getStatus()), Talk::getStatus, conditionVO.getStatus()));
|
|
if (count == 0) {
|
|
return new PageResultDTO<>();
|
|
}
|
|
List<TalkAdminDTO> talkDTOs = talkMapper.listTalksAdmin(PageUtil.getLimitCurrent(), PageUtil.getSize(), conditionVO);
|
|
talkDTOs.forEach(item -> {
|
|
if (Objects.nonNull(item.getImages())) {
|
|
item.setImgs(CommonUtil.castList(JSON.parseObject(item.getImages(), List.class), String.class));
|
|
}
|
|
});
|
|
return new PageResultDTO<>(talkDTOs, count);
|
|
}
|
|
|
|
@Override
|
|
public TalkAdminDTO getBackTalkById(Integer talkId) {
|
|
TalkAdminDTO talkBackDTO = talkMapper.getTalkByIdAdmin(talkId);
|
|
if (Objects.nonNull(talkBackDTO.getImages())) {
|
|
talkBackDTO.setImgs(CommonUtil.castList(JSON.parseObject(talkBackDTO.getImages(), List.class), String.class));
|
|
}
|
|
return talkBackDTO;
|
|
}
|
|
|
|
}
|
|
|