package com.mindskip.xzs.service.impl; import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.mindskip.xzs.context.WebContext; import com.mindskip.xzs.domain.Feedback; import com.mindskip.xzs.domain.Notify; import com.mindskip.xzs.domain.enums.NotifyRefType; import com.mindskip.xzs.domain.question.QuestionObject; import com.mindskip.xzs.domain.vo.FeedbackVO; import com.mindskip.xzs.repository.FeedbackMapper; import com.mindskip.xzs.repository.UserMapper; import com.mindskip.xzs.service.FeedbackService; import com.mindskip.xzs.service.NotifyService; import com.mindskip.xzs.utility.JsonUtil; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.Date; import java.util.stream.Collectors; /** * @author gonghl * @description 针对表【t_feedback(错题反馈)】的数据库操作Service实现 * @createDate 2024-05-07 15:52:33 */ @Service @RequiredArgsConstructor public class FeedbackServiceImpl extends ServiceImpl implements FeedbackService { private final FeedbackMapper feedbackMapper; private final WebContext webContext; private final NotifyService notifyService; @Override @Transactional(rollbackFor = Exception.class) public void saveFeedback(FeedbackVO feedbackVO) { Feedback feedback = new Feedback(); BeanUtils.copyProperties(feedbackVO, feedback); feedbackMapper.insert(feedback); // 添加通知 Notify notify = new Notify(); notify.setCreateTime(new Date()); notify.setReadStatus(2); notify.setRefId(feedback.getId()); notify.setRefType(NotifyRefType.FEEDBACK.getValue()); notify.setCreateUserId(webContext.getCurrentUser().getId()); notifyService.add(notify); } @Override public PageInfo feedbackPage(FeedbackVO feedbackVO) { return PageHelper.startPage(feedbackVO.getPageIndex(), feedbackVO.getPageSize()).doSelectPageInfo(() -> feedbackMapper.feedbackPage().stream().peek(f -> f.setQuestionTitle(JsonUtil.toJsonObject(f.getQuestionTitle(), QuestionObject.class).getTitleContent())).collect(Collectors.toList())); } @Override public void settleFeedback(Integer id) { new LambdaUpdateChainWrapper<>(feedbackMapper) .set(Feedback::getFix, true) .set(Feedback::getFixTime, LocalDateTime.now()) .eq(Feedback::getId, id) .update(); } }