| | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.base.BaseApiController; |
| | | import com.mindskip.xzs.base.RestResponse; |
| | |
| | | questionService.insert(question); |
| | | |
| | | |
| | | // 查出所有的课目 |
| | | List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | |
| | | List<String> subjectNames = Arrays.asList(excelQuestion.getSubjectName().split(SPLIT)); |
| | | List<Subject> targetSubject = subjects.stream() |
| | | .filter(subject -> subjectNames.contains(subject.getName())) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(targetSubject)) { |
| | | // todo 记录这个错误 |
| | | continue; |
| | | List<Subject> subjects = subjectNames.stream().map(name -> { |
| | | // 判断课目是否存在于数据库,如果不存在则自动新增课目 |
| | | Subject byName = subjectMapper.getByName(name); |
| | | if (Objects.isNull(byName)) { |
| | | byName = new Subject(); |
| | | byName.setName(name); |
| | | byName.setDeleted(false); |
| | | subjectMapper.insert(byName); |
| | | } |
| | | return byName; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | // 构建课目-题目信息 |
| | | questionSubjectsList = targetSubject.stream() |
| | | questionSubjectsList = subjects.stream() |
| | | .filter(subject -> { |
| | | // 去重题目:题干+课目相同才算同一题 |
| | | List<QuestionSubjectVO> lists = questionService.countQuestionByTitleAndSubject(excelQuestion.getTitle(), subject.getId()); |
| | |
| | | questionSubjectService.saves(questionSubjectsList); |
| | | } |
| | | } else { |
| | | // 查出所有的课目 |
| | | List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | List<String> subjectNames = Arrays.asList(excelQuestion.getSubjectName().split(SPLIT)); |
| | | List<Subject> targetSubject = subjects.stream() |
| | | .filter(subject -> subjectNames.contains(subject.getName())) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(targetSubject)) { |
| | | // todo 记录这个错误 |
| | | continue; |
| | | List<Subject> subjects = subjectNames.stream().map(name -> { |
| | | // 判断课目是否存在于数据库,如果不存在则自动新增课目 |
| | | Subject byName = subjectMapper.getByName(name); |
| | | if (Objects.isNull(byName)) { |
| | | byName = new Subject(); |
| | | byName.setName(name); |
| | | byName.setDeleted(false); |
| | | subjectMapper.insert(byName); |
| | | } |
| | | return byName; |
| | | }).collect(Collectors.toList()); |
| | | // 构建课目-题目信息 |
| | | questionSubjectsList = targetSubject.stream() |
| | | questionSubjectsList = subjects.stream() |
| | | .filter(subject -> { |
| | | // 去重题目:题干+课目相同才算同一题 |
| | | List<QuestionSubjectVO> lists = questionService.countQuestionByTitleAndSubject(excelQuestion.getTitle(), subject.getId()); |