| package com.dsh.course.service.impl; | 
|   | 
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
| import com.dsh.course.entity.Problem; | 
| import com.dsh.course.entity.SensitiveWords; | 
| import com.dsh.course.mapper.ProblemMapper; | 
| import com.dsh.course.mapper.SensitiveWordsMapper; | 
| import com.dsh.course.service.IProblemService; | 
| import com.dsh.guns.modular.system.util.ResultUtil; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.StringUtils; | 
|   | 
| import javax.annotation.Resource; | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
|   | 
| @Service | 
| public class ProblemServiceImpl extends ServiceImpl<ProblemMapper, Problem> implements IProblemService { | 
|   | 
|     @Resource | 
|     private ProblemMapper problemMapper; | 
|   | 
|     @Resource | 
|     private SensitiveWordsMapper sensitiveWordsMapper; | 
|   | 
|   | 
|   | 
|     /** | 
|      * 添加留言 | 
|      * @param content | 
|      * @param uid | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Override | 
|     public ResultUtil leaveMessage(String content, Integer uid) throws Exception { | 
|         if(!StringUtils.isEmpty(content)){ | 
|             if(content.length() > 200){ | 
|                 return ResultUtil.error("留言内容过长"); | 
|             } | 
|             List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null); | 
|             for(SensitiveWords s : sensitiveWords){ | 
|                 content = content.replaceAll(s.getContent(), "***"); | 
|             } | 
|         } | 
|   | 
|         Problem problem = new Problem(); | 
|         problem.setContent(content); | 
|         problem.setUserId(uid); | 
|         problem.setInsertTime(new Date()); | 
|         problem.setState(1); | 
|         this.baseMapper.insert(problem); | 
|         return ResultUtil.success(); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取提交的留言 | 
|      * @param pageNum | 
|      * @param size | 
|      * @param uid | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Override | 
|     public List<Map<String, Object>> queryProblems(Integer pageNum, Integer size, Integer uid) throws Exception { | 
|         pageNum = (pageNum - 1) * size; | 
|         return problemMapper.queryProblems(pageNum, size, uid); | 
|     } | 
| } |