|
|
@@ -4605,7 +4605,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void getImageWordTwo(MultipartFile file, String major) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void getImageWordTwo(MultipartFile file, String major,String exam) {
|
|
|
OCRClient client = new OCRClient("de165480ad1fe94abd16f29a8897b7dd", "6904aae4f8e468d376a3a56f91398e78");
|
|
|
|
|
|
HashMap<String, Object> options = new HashMap<>();
|
|
|
@@ -4645,14 +4646,31 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
if (jsonNode.has("result") && jsonNode.get("result").has("markdown")) {
|
|
|
String markdown = jsonNode.get("result").get("markdown").asText();
|
|
|
List<String> strings = extractPureText(markdown);
|
|
|
- questionReset(strings,major);
|
|
|
+ questionReset(strings,major,exam);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void questionReset(List<String> questions,String majorName){
|
|
|
+
|
|
|
+ private void questionReset(List<String> questions,String majorName,String exam){
|
|
|
+
|
|
|
+ //题库业务层次
|
|
|
+ CourseEducationType educationType = iCourseEducationTypeService
|
|
|
+ .getOne(new LambdaQueryWrapper<CourseEducationType>().eq(CourseEducationType::getEducationName, "考前培训").eq(CourseEducationType::getStatus, 1).last("limit 1"));
|
|
|
+ Long eduId = educationType.getId();
|
|
|
+ CourseProjectType projectType = iCourseProjectTypeService
|
|
|
+ .getOne(new LambdaQueryWrapper<CourseProjectType>().eq(CourseProjectType::getProjectName, "施工现场专业人员").eq(CourseProjectType::getEducationId, eduId).eq(CourseProjectType::getStatus, 1).last("limit 1"));
|
|
|
+ Long proId = projectType.getId();
|
|
|
+ CourseBusiness business = iCourseBusinessService
|
|
|
+ .getOne(new LambdaQueryWrapper<CourseBusiness>().eq(CourseBusiness::getBusinessName, "七大员").eq(CourseBusiness::getProjectId, proId).eq(CourseBusiness::getStatus, 1).last("limit 1"));
|
|
|
+ Long businessId = business.getId();
|
|
|
+ List<CourseSubjectProject> list = iCourseSubjectProjectService.list(new LambdaQueryWrapper<CourseSubjectProject>().eq(CourseSubjectProject::getProjectId, proId));
|
|
|
+ List<Long> subIds = list.stream().map(CourseSubjectProject::getSubjectId).collect(Collectors.toList());
|
|
|
+ CourseSubject courseSubject = iCourseSubjectService.getOne(new LambdaQueryWrapper<CourseSubject>().in(CourseSubject::getId, subIds).eq(CourseSubject::getSubjectName, majorName).last("limit 1"));
|
|
|
+ Long subId = courseSubject.getId();
|
|
|
+
|
|
|
//题库ID
|
|
|
Long questionId = 0L;
|
|
|
//处理题库
|
|
|
@@ -4670,17 +4688,194 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
List<String> content = questions.subList(start + 1, end);
|
|
|
//获取第一个判断题型
|
|
|
String bt = content.get(0);
|
|
|
+ if (bt.contains("理解题")){
|
|
|
+ if (StringUtils.isBlank(exam)){
|
|
|
+ throw new CustomException("案例题需要补充试卷名称");
|
|
|
+ }
|
|
|
+ //就是案例题,分解获取案例题文本
|
|
|
+ Integer start1 = 0;
|
|
|
+ Integer end1 = 0;
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ String s = content.get(i);
|
|
|
+ List<String> list1 = Arrays.asList("多选题", "单选题", "判断题");
|
|
|
+ if (list1.stream().anyMatch(x -> s.contains(x))){
|
|
|
+ end1 = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //案例题文案
|
|
|
+ List<String> anLi = content.subList(start1, end1);
|
|
|
+ //提取文本
|
|
|
+ String anLiStr = "";
|
|
|
+ for (String text : anLi) {
|
|
|
+ // 排除条件(这些不是问题描述)
|
|
|
+ if (text.matches("^[0-9]{1,3}\\..*题$") || // 题号类型
|
|
|
+ text.matches(".*[0-9]分$") || // 简单分数
|
|
|
+ text.matches("^[A-E][|、::]?.*") || // 选项
|
|
|
+ text.length() < 10) { // 太短的文本
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ anLiStr = text;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(anLiStr)) {
|
|
|
+ throw new CustomException("案例题文案获取失败");
|
|
|
+ }
|
|
|
+ //案例题序号
|
|
|
+ String anLiXu = bt.replaceAll("^([0-9]+)、.*", "$1");
|
|
|
+ //检查是否已经存在
|
|
|
+ QuestionWaiBuBo bo = new QuestionWaiBuBo();
|
|
|
+ bo.setEduId(eduId);
|
|
|
+ bo.setProId(proId);
|
|
|
+ bo.setBusinessId(businessId);
|
|
|
+ bo.setSubId(subId);
|
|
|
+ String keyWord = String.format("[%s]案例题序号:%s",exam,anLiXu);
|
|
|
+ bo.setContent(keyWord);
|
|
|
+ Question entity = baseMapper.getQuestionByWaiBu(bo);
|
|
|
+ if (ObjectUtils.isNotNull(entity)){
|
|
|
+ //修改
|
|
|
+ entity.setContent(anLiStr);
|
|
|
+ updateById(entity);
|
|
|
+ }else {
|
|
|
+ //新增
|
|
|
+ Question question = new Question();
|
|
|
+ question.setContent(anLiStr);
|
|
|
+ question.setType(4);
|
|
|
+ question.setStatus(1);
|
|
|
+ question.setCreateTime(DateUtils.getNowTime());
|
|
|
+ question.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ question.setCode(ServletUtils.getEncoded("TM"));
|
|
|
+ question.setPrefixName(String.format("外部系统拉取(%s)[%s]案例题序号:%s",DateUtils.getDate(),exam,anLiXu));
|
|
|
+ question.setPublishStatus(1);
|
|
|
+ question.setFromPlat(1);
|
|
|
+ save(question);
|
|
|
+ QuestionBusiness questionBusiness = new QuestionBusiness();
|
|
|
+ questionBusiness.setEducationTypeId(eduId);
|
|
|
+ questionBusiness.setProjectId(proId);
|
|
|
+ questionBusiness.setBusinessId(businessId);
|
|
|
+ questionBusiness.setSubjectId(subId);
|
|
|
+ questionBusiness.setType(1);
|
|
|
+ questionBusiness.setMajorId(question.getQuestionId());
|
|
|
+ iQuestionBusinessService.save(questionBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ //案例题小题
|
|
|
+ content = content.subList(end1,content.size());
|
|
|
+ bt = content.get(0);
|
|
|
+ }
|
|
|
// 匹配带小数的数字
|
|
|
Pattern pattern = Pattern.compile("\\d+(\\.\\d+)");
|
|
|
Matcher matcher = pattern.matcher(bt);
|
|
|
if (matcher.find()){
|
|
|
+ if (StringUtils.isBlank(exam)){
|
|
|
+ throw new CustomException("案例题需要补充试卷名称");
|
|
|
+ }
|
|
|
//带有小数点是案例题
|
|
|
String group = matcher.group(0);
|
|
|
- List<String> list = Arrays.asList(group.split("\\."));
|
|
|
+ List<String> list1 = Arrays.asList(group.split("\\."));
|
|
|
//案例序号
|
|
|
- String xuh = list.get(0);
|
|
|
+ String xuh = list1.get(0);
|
|
|
//案例小题序号
|
|
|
- String xuxh = list.get(1);
|
|
|
+ String xuxh = list1.get(1);
|
|
|
+ String content2 = String.format("[%s]案例题序号:%s",exam, xuh);
|
|
|
+
|
|
|
+ //解析题库
|
|
|
+ List<QuestionInfoVo> infoVoList = new ArrayList<>();
|
|
|
+ if (bt.contains("单选题")){
|
|
|
+ List<String> questionList = filterContent(content);
|
|
|
+ //第一个是标题
|
|
|
+ String s = questionList.get(0);
|
|
|
+ QuestionInfoVo infoVo = new QuestionInfoVo();
|
|
|
+ infoVo.setContent(s);
|
|
|
+ infoVo.setType(1);
|
|
|
+ infoVo.setWaiBuSort(Integer.valueOf(xuxh));
|
|
|
+ List<QuestionDetailVo> detailVoList = new ArrayList<>();
|
|
|
+ for (int i = 1; i < questionList.size(); i++) {
|
|
|
+ String s1 = questionList.get(i);
|
|
|
+ QuestionDetailVo detailVo = new QuestionDetailVo();
|
|
|
+ detailVo.setContent(s1);
|
|
|
+ detailVo.setOptionsId(i);
|
|
|
+ detailVoList.add(detailVo);
|
|
|
+ }
|
|
|
+ infoVo.setOptionsList(detailVoList);
|
|
|
+ //分解答案
|
|
|
+ String answer = getAnswer(questions);
|
|
|
+ infoVo.setAnswerQuestion(simpleConvert(answer));
|
|
|
+ infoVoList.add(infoVo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bt.contains("多选题")){
|
|
|
+ List<String> questionList = filterContent(content);
|
|
|
+ //第一个是标题
|
|
|
+ String s = questionList.get(0);
|
|
|
+ QuestionInfoVo infoVo = new QuestionInfoVo();
|
|
|
+ infoVo.setContent(s);
|
|
|
+ infoVo.setType(2);
|
|
|
+ infoVo.setWaiBuSort(Integer.valueOf(xuxh));
|
|
|
+ List<QuestionDetailVo> detailVoList = new ArrayList<>();
|
|
|
+ for (int i = 1; i < questionList.size(); i++) {
|
|
|
+ String s1 = questionList.get(i);
|
|
|
+ QuestionDetailVo detailVo = new QuestionDetailVo();
|
|
|
+ detailVo.setContent(s1);
|
|
|
+ detailVo.setOptionsId(i);
|
|
|
+ detailVoList.add(detailVo);
|
|
|
+ }
|
|
|
+ infoVo.setOptionsList(detailVoList);
|
|
|
+ //分解答案
|
|
|
+ String answer = getAnswer(questions);
|
|
|
+ infoVo.setAnswerQuestion(simpleConvert(answer));
|
|
|
+ infoVoList.add(infoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bt.contains("判断题")){
|
|
|
+ List<String> questionList = filterContent(content);
|
|
|
+ //第一个是标题
|
|
|
+ String s = questionList.get(0);
|
|
|
+ QuestionInfoVo infoVo = new QuestionInfoVo();
|
|
|
+ infoVo.setContent(s);
|
|
|
+ infoVo.setType(3);
|
|
|
+ infoVo.setWaiBuSort(Integer.valueOf(xuxh));
|
|
|
+ //分解答案
|
|
|
+ String answer = getAnswer(questions);
|
|
|
+ infoVo.setAnswerQuestion(answer.contains("错") ? "0":"1");
|
|
|
+ infoVoList.add(infoVo);
|
|
|
+ }
|
|
|
+ //判断是否已经在
|
|
|
+ QuestionWaiBuBo bo = new QuestionWaiBuBo();
|
|
|
+ bo.setEduId(eduId);
|
|
|
+ bo.setProId(proId);
|
|
|
+ bo.setBusinessId(businessId);
|
|
|
+ bo.setSubId(subId);
|
|
|
+ bo.setContent(content2);
|
|
|
+ Question entity = baseMapper.getQuestionByWaiBu(bo);
|
|
|
+ if (ObjectUtils.isNotNull(entity)){
|
|
|
+ //已存在,添加案例小题
|
|
|
+ String jsonStr = entity.getJsonStr();
|
|
|
+ if (StringUtils.isNotBlank(jsonStr)){
|
|
|
+ List<QuestionInfoVo> infoVoList1 = JSONArray.parseArray(jsonStr, QuestionInfoVo.class);
|
|
|
+ infoVoList1.addAll(infoVoList);
|
|
|
+ List<QuestionInfoVo> collect = infoVoList1.stream().sorted(Comparator.comparingInt(QuestionInfoVo::getWaiBuSort)).collect(Collectors.toList());
|
|
|
+ entity.setJsonStr(JSONArray.toJSONString(collect));
|
|
|
+ }else {
|
|
|
+ entity.setJsonStr(JSONArray.toJSONString(infoVoList));
|
|
|
+ }
|
|
|
+ updateById(entity);
|
|
|
+ questionId = entity.getQuestionId();
|
|
|
+ }else {
|
|
|
+ //新增
|
|
|
+ Question question = new Question();
|
|
|
+ question.setContent(content2);
|
|
|
+ question.setType(4);
|
|
|
+ question.setStatus(1);
|
|
|
+ question.setCreateTime(DateUtils.getNowTime());
|
|
|
+ question.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ question.setCode(ServletUtils.getEncoded("TM"));
|
|
|
+ question.setPrefixName(String.format("外部系统拉取(%s)[%s]案例题序号:%s",DateUtils.getDate(),exam,xuh));
|
|
|
+ question.setPublishStatus(1);
|
|
|
+ question.setFromPlat(1);
|
|
|
+ question.setJsonStr(JSONArray.toJSONString(infoVoList));
|
|
|
+ save(question);
|
|
|
+ questionId = question.getQuestionId();
|
|
|
+ }
|
|
|
|
|
|
}else {
|
|
|
//判断题,多选题,单选题
|
|
|
@@ -4770,20 +4965,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
throw new CustomException("题库解析失败");
|
|
|
}
|
|
|
|
|
|
- //题库业务层次
|
|
|
- CourseEducationType educationType = iCourseEducationTypeService
|
|
|
- .getOne(new LambdaQueryWrapper<CourseEducationType>().eq(CourseEducationType::getEducationName, "考前培训").eq(CourseEducationType::getStatus, 1).last("limit 1"));
|
|
|
- Long eduId = educationType.getId();
|
|
|
- CourseProjectType projectType = iCourseProjectTypeService
|
|
|
- .getOne(new LambdaQueryWrapper<CourseProjectType>().eq(CourseProjectType::getProjectName, "施工现场专业人员").eq(CourseProjectType::getEducationId, eduId).eq(CourseProjectType::getStatus, 1).last("limit 1"));
|
|
|
- Long proId = projectType.getId();
|
|
|
- CourseBusiness business = iCourseBusinessService
|
|
|
- .getOne(new LambdaQueryWrapper<CourseBusiness>().eq(CourseBusiness::getBusinessName, "七大员").eq(CourseBusiness::getProjectId, proId).eq(CourseBusiness::getStatus, 1).last("limit 1"));
|
|
|
- Long businessId = business.getId();
|
|
|
- List<CourseSubjectProject> list = iCourseSubjectProjectService.list(new LambdaQueryWrapper<CourseSubjectProject>().eq(CourseSubjectProject::getProjectId, proId));
|
|
|
- List<Long> subIds = list.stream().map(CourseSubjectProject::getSubjectId).collect(Collectors.toList());
|
|
|
- CourseSubject courseSubject = iCourseSubjectService.getOne(new LambdaQueryWrapper<CourseSubject>().in(CourseSubject::getId, subIds).eq(CourseSubject::getSubjectName, majorName).last("limit 1"));
|
|
|
- Long subId = courseSubject.getId();
|
|
|
QuestionBusiness questionBusiness = new QuestionBusiness();
|
|
|
questionBusiness.setEducationTypeId(eduId);
|
|
|
questionBusiness.setProjectId(proId);
|
|
|
@@ -4809,14 +4990,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
|
|
|
private String getAnswer(List<String> question){
|
|
|
+ //找正确答案
|
|
|
Integer index =0;
|
|
|
for (int i = 0; i < question.size(); i++) {
|
|
|
String s = question.get(i);
|
|
|
- if (s.contains("X") || s.contains("x")){
|
|
|
+ if (s.equals("正确答案")){
|
|
|
index = i;
|
|
|
}
|
|
|
}
|
|
|
- return question.get(index+1);
|
|
|
+ return question.get(index+3);
|
|
|
}
|
|
|
|
|
|
private List<String> filterContent(List<String> lines) {
|
|
|
@@ -4843,6 +5025,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
trimmed = trimmed.substring(1).trim();
|
|
|
}
|
|
|
|
|
|
+ //去除首字母或者| 这种符号
|
|
|
+ trimmed = trimmed.replaceAll("^[A-E][\\||]?", "");
|
|
|
// 去除结尾的括号
|
|
|
// trimmed = trimmed.replaceAll("[()()]+$", "");
|
|
|
|
|
|
@@ -4854,7 +5038,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 提取纯文本信息,过滤掉所有链接、HTML标签和Markdown符号
|
|
|
*/
|