|
|
@@ -0,0 +1,156 @@
|
|
|
+/*
|
|
|
+ * Copyright [2022] [https://www.xiaonuo.vip]
|
|
|
+ *
|
|
|
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
|
+ *
|
|
|
+ * 1.请不要删除和修改根目录下的LICENSE文件。
|
|
|
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
|
|
|
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
|
|
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
|
|
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
|
|
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
|
|
+ */
|
|
|
+package vip.xiaonuo.disk.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
+import vip.xiaonuo.common.exception.CommonException;
|
|
|
+import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
+import vip.xiaonuo.disk.domain.QuestionAnswer;
|
|
|
+import vip.xiaonuo.disk.domain.QuestionAnswerGive;
|
|
|
+import vip.xiaonuo.disk.mapper.QuestionAnswerGiveMapper;
|
|
|
+import vip.xiaonuo.disk.mapper.QuestionAnswerMapper;
|
|
|
+import vip.xiaonuo.disk.param.QuestionAnswerAddParam;
|
|
|
+import vip.xiaonuo.disk.param.QuestionAnswerEditParam;
|
|
|
+import vip.xiaonuo.disk.param.QuestionAnswerIdParam;
|
|
|
+import vip.xiaonuo.disk.param.QuestionAnswerPageParam;
|
|
|
+import vip.xiaonuo.disk.service.QuestionAnswerService;
|
|
|
+import vip.xiaonuo.disk.vo.questionanswer.QuestionAnswerVo;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * question_answerService接口实现类
|
|
|
+ *
|
|
|
+ * @author pans
|
|
|
+ * @date 2025/07/11 18:52
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class QuestionAnswerServiceImpl extends ServiceImpl<QuestionAnswerMapper, QuestionAnswer> implements QuestionAnswerService {
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private QuestionAnswerMapper questionAnswerMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private QuestionAnswerGiveMapper questionAnswerGiveMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<QuestionAnswerVo> page(QuestionAnswerPageParam questionAnswerPageParam) {
|
|
|
+ Page<QuestionAnswerVo> page=questionAnswerMapper.selectCommentPid(CommonPageRequest.defaultPage(),questionAnswerPageParam.getChapterId(), questionAnswerPageParam.getCourseId(),StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ List<QuestionAnswerVo> list=questionAnswerMapper.selectCommentNoPid(questionAnswerPageParam.getChapterId(), questionAnswerPageParam.getCourseId(),StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ page.getRecords().stream().forEach(item -> {
|
|
|
+ List<QuestionAnswerVo> child= list.stream().filter(itemchild-> itemchild.getPid().equals(item.getId())).collect(Collectors.toList());
|
|
|
+ item.setChild(child);
|
|
|
+ item.setChildSize(child.size());
|
|
|
+ });
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(QuestionAnswerAddParam questionAnswerAddParam) {
|
|
|
+ QuestionAnswer questionAnswer = BeanUtil.toBean(questionAnswerAddParam, QuestionAnswer.class);
|
|
|
+ questionAnswer.setUserId(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ questionAnswer.setTime(new Date());
|
|
|
+ this.save(questionAnswer);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(QuestionAnswerEditParam questionAnswerEditParam) {
|
|
|
+ QuestionAnswer questionAnswer = this.queryEntity(questionAnswerEditParam.getId());
|
|
|
+ BeanUtil.copyProperties(questionAnswerEditParam, questionAnswer);
|
|
|
+ questionAnswer.setUserId(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ questionAnswer.setTime(new Date());
|
|
|
+ this.updateById(questionAnswer);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(List<QuestionAnswerIdParam> questionAnswerIdParamList) {
|
|
|
+ // 执行删除
|
|
|
+ this.removeByIds(CollStreamUtil.toList(questionAnswerIdParamList, QuestionAnswerIdParam::getId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public QuestionAnswer detail(QuestionAnswerIdParam questionAnswerIdParam) {
|
|
|
+ return this.queryEntity(questionAnswerIdParam.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public QuestionAnswer queryEntity(Integer id) {
|
|
|
+ QuestionAnswer questionAnswer = this.getById(id);
|
|
|
+ if(ObjectUtil.isEmpty(questionAnswer)) {
|
|
|
+ throw new CommonException("question_answer不存在,id值为:{}", id);
|
|
|
+ }
|
|
|
+ return questionAnswer;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void give(Integer id) {
|
|
|
+ QuestionAnswer userComment=queryEntity(id);
|
|
|
+ if(ObjectUtil.isEmpty(userComment.getGiveNum())) {
|
|
|
+ userComment.setGiveNum(1);
|
|
|
+ }else{
|
|
|
+ userComment.setGiveNum(userComment.getGiveNum()+1);
|
|
|
+ }
|
|
|
+ this.updateById(userComment);
|
|
|
+ //添加点赞记录表
|
|
|
+ QuestionAnswerGive userCommentGive=new QuestionAnswerGive();
|
|
|
+ userCommentGive.setUserId(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ userCommentGive.setCreateUser(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ userCommentGive.setQuestionAnswerid(id);
|
|
|
+ userCommentGive.setCreateTime(new Date());
|
|
|
+ userCommentGive.setDeleteFlag("NOT_DELETE");
|
|
|
+ questionAnswerGiveMapper.insert(userCommentGive);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String giveCancel(Integer id) {
|
|
|
+ QuestionAnswer userComment=queryEntity(id);
|
|
|
+ if(userComment.getGiveNum()>0){
|
|
|
+ userComment.setGiveNum(userComment.getGiveNum()-1);
|
|
|
+ this.updateById(userComment);
|
|
|
+ //删除点赞记录表
|
|
|
+ QuestionAnswerGive userCommentGive=new QuestionAnswerGive();
|
|
|
+ userCommentGive.setQuestionAnswerid(id);
|
|
|
+ userCommentGive.setUserId(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ userCommentGive.setDeleteFlag("DELETED");
|
|
|
+ questionAnswerGiveMapper.updateQuestionAnswerGiveMapper(userCommentGive);
|
|
|
+ return "取消点赞成功!";
|
|
|
+ }else{
|
|
|
+ return "点赞数量为0,无法取消点赞!";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|