New file |
| | |
| | | package com.qxueyou.scc.Sensitive; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | |
| | | //敏感词过滤器:利用DFA算法 进行敏感词过滤 |
| | | |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | public class SensitiveFilterService { |
| | | |
| | | |
| | | private Map sensitiveWordMap = null; |
| | | |
| | | |
| | | // 最小匹配规则 |
| | | public static int minMatchTYpe = 1; |
| | | |
| | | |
| | | // 最大匹配规则 |
| | | public static int maxMatchType = 2; |
| | | |
| | | |
| | | // 单例 |
| | | private static SensitiveFilterService instance = null; |
| | | |
| | | |
| | | // 构造函数,初始化敏感词库 |
| | | private SensitiveFilterService() { |
| | | |
| | | |
| | | sensitiveWordMap = new SensitiveWordInit().initKeyWord(); |
| | | } |
| | | |
| | | |
| | | // 获取单例 |
| | | public static SensitiveFilterService getInstance() { |
| | | if (null == instance) { |
| | | instance = new SensitiveFilterService(); |
| | | } |
| | | return instance; |
| | | } |
| | | |
| | | |
| | | // 获取文字中的敏感词 |
| | | |
| | | |
| | | public Set<String> getSensitiveWord(String txt, int matchType) { |
| | | Set<String> sensitiveWordList = new HashSet<String>(); |
| | | |
| | | |
| | | for (int i = 0; i < txt.length(); i++) { |
| | | |
| | | |
| | | // 判断是否包含敏感字符 |
| | | int length = CheckSensitiveWord(txt, i, matchType); |
| | | |
| | | // 存在,加入list中 |
| | | if (length > 0) { |
| | | sensitiveWordList.add(txt.substring(i, i + length)); |
| | | |
| | | // 减1的原因,是因为for会自增 |
| | | i = i + length - 1; |
| | | } |
| | | } |
| | | |
| | | return sensitiveWordList; |
| | | } |
| | | // 替换敏感字字符 |
| | | |
| | | public String replaceSensitiveWord(String txt, int matchType, |
| | | String replaceChar) { |
| | | String resultTxt = txt; |
| | | // 获取所有的敏感词 |
| | | Set<String> set = getSensitiveWord(txt, matchType); |
| | | Iterator<String> iterator = set.iterator(); |
| | | String word = null; |
| | | String replaceString = null; |
| | | while (iterator.hasNext()) { |
| | | word = iterator.next(); |
| | | replaceString = getReplaceChars(replaceChar, word.length()); |
| | | resultTxt = resultTxt.replaceAll(word, replaceString); |
| | | } |
| | | return resultTxt; |
| | | } |
| | | |
| | | /** |
| | | * 返回 字符串含有的拦截词 逗号隔开 |
| | | * |
| | | * @param txt |
| | | * @return |
| | | */ |
| | | public String returnSensitiveWord(String txt) { |
| | | String resultTxt = txt; |
| | | StringBuilder sensitiveWord = new StringBuilder(""); |
| | | // 获取所有的敏感词 |
| | | Set<String> set = getSensitiveWord(txt, 1); |
| | | Iterator<String> iterator = set.iterator(); |
| | | String word = null; |
| | | String replaceString = null; |
| | | while (iterator.hasNext()) { |
| | | String str = resultTxt; |
| | | word = iterator.next(); |
| | | replaceString = getReplaceChars("*", word.length()); |
| | | resultTxt = resultTxt.replaceAll(word, replaceString); |
| | | if (!resultTxt.equals(str)){ |
| | | sensitiveWord.append(word); |
| | | sensitiveWord.append(","); |
| | | } |
| | | } |
| | | return sensitiveWord.toString(); |
| | | } |
| | | /** |
| | | * 获取替换字符串 |
| | | |
| | | * |
| | | * @param replaceChar |
| | | * @param length |
| | | * @return |
| | | */ |
| | | private String getReplaceChars(String replaceChar, int length) { |
| | | String resultReplace = replaceChar; |
| | | for (int i = 1; i < length; i++) { |
| | | resultReplace += replaceChar; |
| | | } |
| | | |
| | | return resultReplace; |
| | | } |
| | | |
| | | /** |
| | | * 判断文本中包含敏感词个数 |
| | | * @param |
| | | */ |
| | | public static boolean checkContainCount(String txt) { |
| | | SensitiveFilterService filter = SensitiveFilterService.getInstance(); |
| | | Set<java.lang.String> hou = filter.getSensitiveWord(txt, 1); |
| | | return hou.size() > 0; |
| | | } |
| | | /** |
| | | |
| | | * 检查文字中是否包含敏感字符,检查规则如下:<br> |
| | | * 如果存在,则返回敏感词字符的长度,不存在返回0 |
| | | * |
| | | * @param txt |
| | | * @param beginIndex |
| | | * @param matchType |
| | | * @return |
| | | */ |
| | | public int CheckSensitiveWord(String txt, int beginIndex, int matchType) { |
| | | |
| | | // 敏感词结束标识位:用于敏感词只有1位的情况 |
| | | boolean flag = false; |
| | | |
| | | // 匹配标识数默认为0 |
| | | int matchFlag = 0; |
| | | Map nowMap = sensitiveWordMap; |
| | | for (int i = beginIndex; i < txt.length(); i++) { |
| | | char word = txt.charAt(i); |
| | | // 获取指定key |
| | | nowMap = (Map) nowMap.get(word); |
| | | |
| | | // 存在,则判断是否为最后一个 |
| | | if (nowMap != null) { |
| | | |
| | | // 找到相应key,匹配标识+1 |
| | | matchFlag++; |
| | | |
| | | // 如果为最后一个匹配规则,结束循环,返回匹配标识数 |
| | | if ("1".equals(nowMap.get("isEnd"))) { |
| | | |
| | | // 结束标志位为true |
| | | flag = true; |
| | | |
| | | // 最小规则,直接返回,最大规则还需继续查找 |
| | | if (SensitiveFilterService.minMatchTYpe == matchType) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 不存在,直接返回 |
| | | else { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (matchFlag < 2 && !flag) { // 长度必须大于等于1,为词 |
| | | matchFlag = 0; |
| | | } |
| | | return matchFlag; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.Sensitive; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | |
| | | //屏蔽敏感词初始化 |
| | | |
| | | |
| | | @SuppressWarnings({"rawtypes", "unchecked"}) |
| | | public class SensitiveWordInit { |
| | | // 字符编码 |
| | | private String ENCODING = "UTF-8"; |
| | | |
| | | // 初始化敏感字库 |
| | | public Map initKeyWord() { |
| | | // 读取敏感词库 ,存入Set中 |
| | | Set<String> wordSet = readSensitiveWordFile(); |
| | | // 将敏感词库加入到HashMap中//确定有穷自动机DFA |
| | | return addSensitiveWordToHashMap(wordSet); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 读取敏感词库,将敏感词放入HashSet中,构建一个DFA算法模型:<br> |
| | | * 中 = { |
| | | * isEnd = 0 |
| | | * 国 = { |
| | | * isEnd = 1 |
| | | * 人 = {isEnd = 0 |
| | | * 民 = {isEnd = 1} |
| | | * } |
| | | * 男 = { |
| | | * isEnd = 0 |
| | | * 人 = { |
| | | * isEnd = 1 |
| | | * } |
| | | * } |
| | | * } |
| | | * } |
| | | * 五 = { |
| | | * isEnd = 0 |
| | | * 星 = { |
| | | * isEnd = 0 |
| | | * 红 = { |
| | | * isEnd = 0 |
| | | * 旗 = { |
| | | * isEnd = 1 |
| | | * } |
| | | * } |
| | | * } |
| | | * } |
| | | */ |
| | | |
| | | |
| | | // 读取敏感词库 ,存入HashMap中 |
| | | private Set<String> readSensitiveWordFile() { |
| | | |
| | | |
| | | Set<String> wordSet = null; |
| | | // app为项目地址 |
| | | /* |
| | | * String app = System.getProperty("user.dir"); System.out.println(app); |
| | | * URL resource = Thread.currentThread().getContextClassLoader() |
| | | * .getResource("/"); String path = resource.getPath().substring(1); |
| | | * System.out.println(path); File file = new File(path + |
| | | * "censorwords.txt"); |
| | | */ |
| | | |
| | | |
| | | //敏感词库 |
| | | File file = new File( |
| | | "src/main/resources/SensitiveWordList.txt"); |
| | | try { |
| | | // 读取文件输入流 |
| | | InputStreamReader read = new InputStreamReader(new FileInputStream( |
| | | file), ENCODING); |
| | | |
| | | // 文件是否是文件 和 是否存在 |
| | | if (file.isFile() && file.exists()) { |
| | | |
| | | wordSet = new HashSet<String>(); |
| | | // StringBuffer sb = new StringBuffer(); |
| | | // BufferedReader是包装类,先把字符读到缓存里,到缓存满了,再读入内存,提高了读的效率。 |
| | | BufferedReader br = new BufferedReader(read); |
| | | String txt = null; |
| | | |
| | | |
| | | // 读取文件,将文件内容放入到set中 |
| | | while ((txt = br.readLine()) != null) { |
| | | wordSet.add(txt); |
| | | } |
| | | |
| | | |
| | | br.close(); |
| | | |
| | | |
| | | /* |
| | | * String str = sb.toString(); String[] ss = str.split(","); for |
| | | * (String s : ss) { wordSet.add(s); } |
| | | */ |
| | | } |
| | | |
| | | |
| | | // 关闭文件流 |
| | | read.close(); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | return wordSet; |
| | | } |
| | | |
| | | |
| | | // 将HashSet中的敏感词,存入HashMap中 |
| | | private Map addSensitiveWordToHashMap(Set<String> wordSet) { |
| | | |
| | | |
| | | // 初始化敏感词容器,减少扩容操作 |
| | | Map wordMap = new HashMap(wordSet.size()); |
| | | |
| | | |
| | | for (String word : wordSet) { |
| | | Map nowMap = wordMap; |
| | | for (int i = 0; i < word.length(); i++) { |
| | | // 转换成char型 |
| | | char keyChar = word.charAt(i); |
| | | // 获取 |
| | | Object tempMap = nowMap.get(keyChar); |
| | | // 如果存在该key,直接赋值 |
| | | if (tempMap != null) { |
| | | nowMap = (Map) tempMap; |
| | | } |
| | | // 不存在则,则构建一个map,同时将isEnd设置为0,因为他不是最后一个 |
| | | else { |
| | | // 设置标志位 |
| | | Map<String, String> newMap = new HashMap<String, String>(); |
| | | newMap.put("isEnd", "0"); |
| | | // 添加到集合 |
| | | nowMap.put(keyChar, newMap); |
| | | nowMap = newMap; |
| | | } |
| | | // 最后一个 |
| | | if (i == word.length() - 1) { |
| | | nowMap.put("isEnd", "1"); |
| | | } |
| | | } |
| | | } |
| | | return wordMap; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | List<Map<String, Object>> queryAllClassIdAndName(); |
| | | |
| | | ClsClass getReClass(String classTypes); |
| | | |
| | | List<ClsClass> getTeacherClassLst(String teacherId); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ClsClass> getTeacherClassLst(String teacherId) { |
| | | String sql = "select c.* " + |
| | | "from cls_class as c " + |
| | | "where c.DELETE_FLAG is false and c.CLASS_ID in " + |
| | | "(select cs.CLASS_ID " + |
| | | "from cls_class_re_subject as cs " + |
| | | "LEFT JOIN subject as s on s.SUBJECT_ID =cs.SUBJECT_ID " + |
| | | "where cs.DELETE_FLAG is false and s.DELETE_FLAG is false and s.TEACHER_ID=:teacherId )"; |
| | | List<Object[]> list = findByComplexSql(sql, CollectionUtils.newObjectMap("teacherId", teacherId), Object[].class); |
| | | List<ClsClass> clsClassList=new ArrayList<>(); |
| | | for (Object[] objects : list) { |
| | | ClsClass clsClass = new ClsClass(); |
| | | clsClass.setClassId(objects[0].toString()); |
| | | clsClassList.add(clsClass); |
| | | } |
| | | return clsClassList; |
| | | } |
| | | |
| | | @Override |
| | | public Result updateClass(String classId, String className, String classNumber, Date startTime, Date endTime, |
| | | String subjectId, boolean needJoinAudit, boolean needQuitAudit, boolean showAnalysisAfterExer, |
| | | boolean canMultiExer, boolean needForum, String teacherId, String chargeClassName) { |
| | |
| | | public Map<String, Object> getClassActivityInfo(String classId) { |
| | | |
| | | Map<String, Object> result = scoreService.queryClassHomeworkScoreInfo(classId); |
| | | result.putAll(scoreService.queryClassExamScoreInfo(classId)); |
| | | Map<String, Object> stringObjectMap = scoreService.queryClassExamScoreInfo(classId); |
| | | result.putAll(stringObjectMap); |
| | | |
| | | ClsClass cls = read(classId); |
| | | |
| | |
| | | |
| | | return this.findCount(hql, CollectionUtils.newList(classId)); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | String hql = "select count(distinct id.homeworkId) from HomeworkScoreV where classId=?"; |
| | | |
| | | return this.findCount(hql, CollectionUtils.newList(classId)); |
| | | return this.findCount(hql, CollectionUtils.newList(classId)); |
| | | } |
| | | |
| | | public int getHomeworkToAuditCount(String classId) { |
| | |
| | | import com.qxueyou.scc.exam.dao.ExamResultVDao; |
| | | import com.qxueyou.scc.exam.model.ExamResultV; |
| | | import com.qxueyou.scc.exercise.dao.ExerciseResultDAO; |
| | | import com.qxueyou.scc.exercise.model.ExerciseRecord; |
| | | import com.qxueyou.scc.exercise.model.ExerciseResultV; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | public Map<String,Object> queryClassExamScoreInfo(String classId) { |
| | | |
| | | return CollectionUtils.newObjectMap( |
| | | "examCount",examDao.getExamCount(classId), |
| | | "examHasAuditCount",examDao.getExamCount(classId), |
| | | "examToAuditCount",0, |
| | | "examNoSubmitCount",examDao.getToSubmitExamCount(classId) |
| | | "examCount",examResultVDao.getExamCount(classId),//考试次数 |
| | | "examHasAuditCount",getCommitExamCount(classId, Integer.parseInt(ExerciseRecord.STATUS_CHECK)),//已批阅 |
| | | "examToAuditCount",getCommitExamCount(classId, Integer.parseInt(ExerciseRecord.STATUS_SUBMIT)),//待批阅 |
| | | "examNoSubmitCount",getCommitExamCount(classId, Integer.parseInt(ExerciseRecord.STATUS_NOT_SUBMIT))//未提交 |
| | | ); |
| | | |
| | | } |
| | | |
| | | public int getUnCommitExamCount(String classId) { |
| | | String sql = "SELECT c.exam_id, c.exam_name, c.exam_batch_Id, c.start_Time, c.end_Time, " |
| | | + "c.class_id, d.exercise_Group_Id, d.score, d. STATUS FROM ( SELECT i.exam_Id, " |
| | | + "i.exam_Name, b.exam_Batch_Id, b.start_Time,b.end_Time, r.class_Id FROM Exam_Info i, " |
| | | + "Exam_Batch_Info b, Exam_Class_Re r WHERE i.exam_Id = b.exam_Id AND b.exam_Batch_Id " |
| | | + "= r.exam_Batch_Id AND r.class_Id =:classId AND i.exam_status = 1 AND b.delete_Flag" |
| | | + "= 0 AND r.delete_Flag = 0 ) c LEFT OUTER JOIN ( SELECT * FROM Exercise_Record " |
| | | + "d WHERE d.delete_Flag = 0 ) d ON c.exam_Batch_Id = d.exam_Batch_Id " |
| | | + "AND c.class_id = d.class_id where ifnull(d.status,0)= 0 and (c.end_Time - CURRENT_TIMESTAMP ()) < 0 "; |
| | | List<Object[]> list = findByComplexSql(sql, CollectionUtils.newObjectMap("classId", classId), |
| | | Object[].class); |
| | | return list.size(); |
| | | |
| | | } |
| | | |
| | | public int getCommitExamCount(String classId,Integer status) { |
| | | String sql = "SELECT c.exam_id, c.exam_name, c.exam_batch_Id, c.start_Time, c.end_Time, " |
| | | + "c.class_id, d.exercise_Group_Id, d.score, d. STATUS FROM ( SELECT i.exam_Id, " |
| | | + "i.exam_Name, b.exam_Batch_Id, b.start_Time,b.end_Time, r.class_Id FROM Exam_Info i, " |
| | | + "Exam_Batch_Info b, Exam_Class_Re r WHERE i.exam_Id = b.exam_Id AND b.exam_Batch_Id " |
| | | + "= r.exam_Batch_Id AND r.class_Id =:classId AND i.exam_status = 1 AND b.delete_Flag" |
| | | + "= 0 AND r.delete_Flag = 0 ) c LEFT OUTER JOIN ( SELECT * FROM Exercise_Record " |
| | | + "d WHERE d.delete_Flag = 0 ) d ON c.exam_Batch_Id = d.exam_Batch_Id " |
| | | + "AND c.class_id = d.class_id where d.status = :status "; |
| | | List<Object[]> list = findByComplexSql(sql, CollectionUtils.newObjectMap("classId", classId,"status",status), |
| | | Object[].class); |
| | | return list.size(); |
| | | } |
| | | @Override |
| | | public Map<String,Object> queryClassHomeworkScoreInfo(String classId) { |
| | | |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.qxueyou.scc.teach.student.model.StuStudent; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | |
| | | @Autowired |
| | | IClassLectureService clsLectureService; |
| | | |
| | | /** |
| | | * 获取正常班级列表 |
| | | * |
| | | * @param keyword |
| | | * @param limit |
| | | * @param pageNum |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "获取学生详情接口", notes = "") |
| | | @GetMapping(value = "/student/getStudentDetails") |
| | | public Result getStudentDetails() { |
| | | |
| | | StuStudent stu = this.studentService.getStudentDetails(ClientUtils.getUserId()); |
| | | return new Result(true, "success", stu); |
| | | } |
| | | //---------------------------------------------------------------------------------app接口--------------------------------------------------------------------------------------------------------------------/ |
| | | |
| | | /** |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | | import com.qxueyou.scc.admin.teacher.service.ITeacherService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | |
| | | |
| | | @Autowired |
| | | IClassService classService; |
| | | |
| | | @Autowired |
| | | private ITeacherService teacherService; |
| | | @Value("${server.context-index}") |
| | | private String WEB_INDEX; |
| | | |
| | |
| | | |
| | | // request.getSession().invalidate(); |
| | | // ClientUtils.isAdmin()=true; |
| | | String teacherId = ClientUtils.isAdmin()?null:ClientUtils.getUserId(); |
| | | |
| | | List<ClsClass> clsLst = classService.getClassLst("",teacherId, 2000, 1, 1); |
| | | |
| | | //判断是否是教师 |
| | | String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId()); |
| | | |
| | | List<ClsClass> clsLst = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(teacherId)) { |
| | | //获取该老师下发布的课程的所属班级 |
| | | clsLst = classService.getTeacherClassLst(teacherId); |
| | | }else{ |
| | | //管理员查询所有班级 |
| | | clsLst =classService.getClassLst("",teacherId, 2000, 1, 1); |
| | | } |
| | | List<Map<String,Object>> result = new ArrayList<Map<String,Object>>(clsLst.size()*2); |
| | | |
| | | for(ClsClass cls:clsLst) { |
| | | result.add(classService.getClassActivityInfo(cls.getClassId())); |
| | | Map<String, Object> classActivityInfo = classService.getClassActivityInfo(cls.getClassId()); |
| | | result.add(classActivityInfo); |
| | | } |
| | | |
| | | return new Result(true,null,result); |
| | |
| | | return this.find(hql,CollectionUtils.newList(classId),ExamResultV.class); |
| | | } |
| | | |
| | | public int getExamCount(String classId) { |
| | | //id. |
| | | String hql = "select count(distinct examId) from ExamResultV where class_Id=?"; |
| | | |
| | | return this.findCount(hql, CollectionUtils.newList(classId)); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | package com.qxueyou.scc.operation.topic.action; |
| | | |
| | | import com.qxueyou.scc.Sensitive.SensitiveFilterService; |
| | | import com.qxueyou.scc.Sensitive.SensitiveWordFilter; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @GetMapping(value = "addComment") |
| | | public Result addComment(String content, String commentObjectId, String commentParentId, String commentedId, |
| | | String commentedName) { |
| | | SensitiveWordFilter.loadWordFromFile("D:\\工作\\SensitiveWord\\SensitiveWordList.txt"); |
| | | String filter = SensitiveWordFilter.Filter(content); |
| | | return topicService.addComment(filter, commentObjectId, commentParentId, commentedId, commentedName); |
| | | // SensitiveWordFilter.loadWordFromFile("C:\\Users\\Administrator\\Desktop\\SensitiveWordList.txt"); |
| | | // String filter = SensitiveWordFilter.Filter(content); |
| | | SensitiveFilterService filter = SensitiveFilterService.getInstance(); |
| | | String filterContentHou = filter.replaceSensitiveWord(content, 1, "*"); |
| | | return topicService.addComment(filterContentHou, commentObjectId, commentParentId, commentedId, commentedName); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | StuStudent getStudentByNo(String studentNo); |
| | | |
| | | StuStudent getStudentDetails(String userId); |
| | | } |
| | |
| | | public StuStudent getStudentByNo(String studentNo) { |
| | | return this.findUnique("from StuStudent where studentNo=? ", CollectionUtils.newList(studentNo), StuStudent.class); |
| | | } |
| | | |
| | | @Override |
| | | public StuStudent getStudentDetails(String userId) { |
| | | return this.findUnique("from StuStudent where deleteFlag is false and userId=? ", CollectionUtils.newList(userId), StuStudent.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<StuStudent> getStudentByclassId(String classId) { |
| | | QStuStudent qClassStudent=QStuStudent.stuStudent; |