|
@@ -1,20 +1,36 @@
|
|
package com.ssj.service.sys.homework.service.impl;
|
|
package com.ssj.service.sys.homework.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.ssj.bean.kmt.kmt.domain.KmtHomeworkWrongQuestion;
|
|
|
|
+import com.ssj.bean.kmt.kmt.domain.QuestionRecommendRecord;
|
|
import com.ssj.bean.sys.homework.domain.HomeworkPicture;
|
|
import com.ssj.bean.sys.homework.domain.HomeworkPicture;
|
|
import com.ssj.bean.sys.homework.domain.HomeworkPictureCorrect;
|
|
import com.ssj.bean.sys.homework.domain.HomeworkPictureCorrect;
|
|
import com.ssj.bean.sys.imlibuser.TbClassTeacher;
|
|
import com.ssj.bean.sys.imlibuser.TbClassTeacher;
|
|
|
|
+import com.ssj.bean.sys.picturepredeal.domain.PicturePreDeal;
|
|
import com.ssj.bean.weixin.libmy.domain.TbLibManager;
|
|
import com.ssj.bean.weixin.libmy.domain.TbLibManager;
|
|
|
|
+import com.ssj.dao.kmt.kmt.dao.KmtExerciseQuestionDao;
|
|
import com.ssj.dao.sys.homework.dao.HomeworkPictureDao;
|
|
import com.ssj.dao.sys.homework.dao.HomeworkPictureDao;
|
|
import com.ssj.dao.sys.homework.dao.HomeworkQueryDao;
|
|
import com.ssj.dao.sys.homework.dao.HomeworkQueryDao;
|
|
import com.ssj.dao.sys.homework.dao.HomeworkPictureQueryDao;
|
|
import com.ssj.dao.sys.homework.dao.HomeworkPictureQueryDao;
|
|
import com.ssj.framework.core.common.service.BaseServiceImpl;
|
|
import com.ssj.framework.core.common.service.BaseServiceImpl;
|
|
|
|
+import com.ssj.framework.core.util.ResponseEntity;
|
|
import com.ssj.framework.core.util.StringUtil;
|
|
import com.ssj.framework.core.util.StringUtil;
|
|
import com.ssj.framework.weixin.util.DateUtil;
|
|
import com.ssj.framework.weixin.util.DateUtil;
|
|
import com.ssj.service.kmt.correctsys.dto.HomeworkPictureDto;
|
|
import com.ssj.service.kmt.correctsys.dto.HomeworkPictureDto;
|
|
|
|
+import com.ssj.service.kmt.dto.ExerciseQuestionAnswer4CorrectDTO;
|
|
|
|
+import com.ssj.service.kmt.dto.ExerciseQuestionAnswerDto;
|
|
|
|
+import com.ssj.service.kmt.dto.ExerciseQuestionDto;
|
|
|
|
+import com.ssj.service.kmt.service.KmtHomeworkWrongQuestionService;
|
|
|
|
+import com.ssj.service.kmt.service.QuestionRecommendRecordService;
|
|
import com.ssj.service.sys.homework.service.HomeworkPictureCorrectService;
|
|
import com.ssj.service.sys.homework.service.HomeworkPictureCorrectService;
|
|
import com.ssj.service.sys.homework.service.HomeworkPictureService;
|
|
import com.ssj.service.sys.homework.service.HomeworkPictureService;
|
|
import com.ssj.service.sys.imlibuser.service.TbClassTeacherService;
|
|
import com.ssj.service.sys.imlibuser.service.TbClassTeacherService;
|
|
|
|
+import com.ssj.service.sys.picturepredeal.request.RecognitionResultReq;
|
|
|
|
+import com.ssj.service.sys.picturepredeal.service.PicturePreDealService;
|
|
import com.ssj.service.weixin.library.service.IBookManagerService;
|
|
import com.ssj.service.weixin.library.service.IBookManagerService;
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
@@ -22,10 +38,8 @@ import org.springframework.data.repository.PagingAndSortingRepository;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author sh
|
|
* @author sh
|
|
@@ -54,6 +68,19 @@ public class HomeworkPictureServiceImpl extends BaseServiceImpl<HomeworkPicture,
|
|
@Autowired
|
|
@Autowired
|
|
private HomeworkQueryDao queryDao;
|
|
private HomeworkQueryDao queryDao;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private KmtHomeworkWrongQuestionService kmtHomeworkWrongQuestionService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuestionRecommendRecordService questionRecommendRecordService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private KmtExerciseQuestionDao kmtExerciseQuestionDao;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PicturePreDealService picturePreDealService;
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public PagingAndSortingRepository<HomeworkPicture, String> getDao() {
|
|
public PagingAndSortingRepository<HomeworkPicture, String> getDao() {
|
|
return homeworkPictureDao;
|
|
return homeworkPictureDao;
|
|
@@ -190,4 +217,220 @@ public class HomeworkPictureServiceImpl extends BaseServiceImpl<HomeworkPicture,
|
|
public List<Map<String, Object>> teacherStudentList(String teacherId) {
|
|
public List<Map<String, Object>> teacherStudentList(String teacherId) {
|
|
return queryDao.teacherStudentList(teacherId);
|
|
return queryDao.teacherStudentList(teacherId);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public Map<String, Object> findRecognitionResult(String pictureId) {
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ int discernType = 2;
|
|
|
|
+ String bookId = "";
|
|
|
|
+ String unitId = "";
|
|
|
|
+ String periodId = "";
|
|
|
|
+ Object [] questionIds = new Object[]{};
|
|
|
|
+ Object [] pageIndexs = new Object[]{};
|
|
|
|
+
|
|
|
|
+ PicturePreDeal picturePreDeal = picturePreDealService.findPreDealByHomeworkPictureId(pictureId);
|
|
|
|
+ if (picturePreDeal != null) {
|
|
|
|
+ //查询到识别记录
|
|
|
|
+ if (Objects.equals(1, picturePreDeal.getTaskStatus())) {
|
|
|
|
+ //ai已返回识别结果
|
|
|
|
+ if (picturePreDeal.getDealFlag() > 0) {
|
|
|
|
+ //匹配到练习册
|
|
|
|
+ discernType = 1;
|
|
|
|
+ bookId = picturePreDeal.getBookId();
|
|
|
|
+ unitId = picturePreDeal.getUnitId();
|
|
|
|
+ periodId = picturePreDeal.getModuleId();
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(picturePreDeal.getBookPageNo())) {
|
|
|
|
+ pageIndexs = JSON.parseArray(picturePreDeal.getBookPageNo()).toArray();
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotBlank(picturePreDeal.getQuestionIds())){
|
|
|
|
+ questionIds = JSON.parseArray(picturePreDeal.getQuestionIds()).toArray();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //未匹配到练习册
|
|
|
|
+ discernType = 3;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //识别中或识别失败
|
|
|
|
+ discernType = picturePreDeal.getTaskStatus();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (discernType != 1) {
|
|
|
|
+ //未从ai识别中获取到答案信息,校验是否学期回顾题目图片,如果是则尝试从题目推荐记录获取答案信息
|
|
|
|
+ HomeworkPicture homeworkPicture = this.getById(pictureId);
|
|
|
|
+ if (homeworkPicture != null && com.ssj.framework.basic.utils.StringUtils.isNotBlank(homeworkPicture.getQuestionRecommendRecordId())) {
|
|
|
|
+ QuestionRecommendRecord questionRecommendRecord =
|
|
|
|
+ questionRecommendRecordService.getById(homeworkPicture.getQuestionRecommendRecordId());
|
|
|
|
+ if (questionRecommendRecord != null) {
|
|
|
|
+ discernType = 1;
|
|
|
|
+ String questionIdListJson = Optional.ofNullable(questionRecommendRecord.getQuestionIdListJson())
|
|
|
|
+ .orElse("[]");
|
|
|
|
+ questionIds = JSON.parseArray(questionIdListJson).toArray();
|
|
|
|
+ bookId = "semester_review";
|
|
|
|
+ pageIndexs = new Object[]{1};
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resultMap.put("discernType", discernType);
|
|
|
|
+ resultMap.put("bookId", bookId);
|
|
|
|
+ resultMap.put("unitId", unitId);
|
|
|
|
+ resultMap.put("periodId", periodId);
|
|
|
|
+ resultMap.put("pageIndexs", pageIndexs);
|
|
|
|
+ resultMap.put("questionIds", questionIds);
|
|
|
|
+
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //unitId = this.getAnswerListQueryUnitId(bookId, unitId);
|
|
|
|
+ //return queryDao.findQuestionByBookIdAndPage(bookId, unitId, bookCourseId, pageIndex, bookYear);
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> pictureDetail(String pictureId) {
|
|
|
|
+
|
|
|
|
+ Map<String, Object> map = findRecognitionResult(pictureId);
|
|
|
|
+ if(MapUtils.getInteger(map,"discernType")!=1){
|
|
|
|
+ return new HashMap<>();
|
|
|
|
+ }
|
|
|
|
+ String bookId = MapUtils.getString(map,"bookId");
|
|
|
|
+ String unitId = MapUtils.getString(map,"unitId");
|
|
|
|
+ String periodId = MapUtils.getString(map,"periodId");
|
|
|
|
+ Object [] questionIds = (Object[]) map.get("questionIds");
|
|
|
|
+ Object [] pageIndexs =(Object[]) map.get("pageIndexs");
|
|
|
|
+ List resultList= Arrays.asList(questionIds);
|
|
|
|
+ List resultList2= Arrays.asList(pageIndexs);
|
|
|
|
+ HomeworkPicture homeworkPicture;
|
|
|
|
+ QuestionRecommendRecord questionRecommendRecord = null;
|
|
|
|
+ if (StringUtils.isNotBlank(pictureId)) {
|
|
|
|
+ homeworkPicture = this.getById(pictureId);
|
|
|
|
+ if (homeworkPicture != null && StringUtils.isNotBlank(homeworkPicture.getQuestionRecommendRecordId())) {
|
|
|
|
+ questionRecommendRecord = questionRecommendRecordService.getById(homeworkPicture.getQuestionRecommendRecordId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int bookYear = 0;
|
|
|
|
+ List<ExerciseQuestionDto> exerciseQuestionDtoList;
|
|
|
|
+ if (questionRecommendRecord == null) {
|
|
|
|
+ Integer by = kmtExerciseQuestionDao.getBookYear(bookId);
|
|
|
|
+ if (by != null){
|
|
|
|
+ bookYear = by;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (questionRecommendRecord != null) {
|
|
|
|
+ //如果是推荐题目拍照的作业图片则,直接从题目推荐记录里获取答案
|
|
|
|
+ exerciseQuestionDtoList = JSON.parseArray(questionRecommendRecord.getQuestionAnswerListJson(), ExerciseQuestionDto.class);
|
|
|
|
+// } else if(CollectionUtils.isNotEmpty(request.getQuestionIds())){
|
|
|
|
+// exerciseQuestionDtoList = this.findQuestionByQuestionIds(request.getQuestionIds());
|
|
|
|
+// logger.debug("查询答案------5");
|
|
|
|
+ } else if (resultList2 != null && resultList2.size() > 0){
|
|
|
|
+ resultList2.sort(Comparator.comparingInt(Integer::intValue));
|
|
|
|
+
|
|
|
|
+ exerciseQuestionDtoList = queryDao.findQuestionByBookIdAndPage(bookId, unitId, "", resultList2, bookYear);
|
|
|
|
+ } else {
|
|
|
|
+ exerciseQuestionDtoList =this.findAnswerByExerciseBookCourseId(periodId, bookYear);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotBlank(pictureId)){
|
|
|
|
+ List<KmtHomeworkWrongQuestion> list = kmtHomeworkWrongQuestionService.findList(pictureId, false);
|
|
|
|
+
|
|
|
|
+ if (list != null){
|
|
|
|
+ for (KmtHomeworkWrongQuestion wq : list){
|
|
|
|
+ for (ExerciseQuestionDto answer : exerciseQuestionDtoList){
|
|
|
|
+ //对错记录与答案记录匹配
|
|
|
|
+ if (wq.getQuestionId().equals(answer.getQuestionId())){
|
|
|
|
+ //对错记录与答案记录匹配
|
|
|
|
+ if (StringUtils.isBlank(wq.getSpaceIndex())) {
|
|
|
|
+ if (StringUtils.isBlank(wq.getCorrectSpaceIndex())){
|
|
|
|
+ for (ExerciseQuestionAnswerDto dto : answer.getAnswers()) {
|
|
|
|
+ dto.setSelectedType(wq.getType());
|
|
|
|
+ }
|
|
|
|
+ answer.setAllAnswerSelectedType(wq.getType());
|
|
|
|
+ } else {
|
|
|
|
+ String[] correctSpaceIndexArray = wq.getCorrectSpaceIndex().split("、");
|
|
|
|
+ for (String index : correctSpaceIndexArray) {
|
|
|
|
+ int i = Integer.parseInt(index);
|
|
|
|
+ if (i >= 1 && answer.getAnswers() != null && i <= answer.getAnswers().size()) {
|
|
|
|
+ ExerciseQuestionAnswerDto dto = answer.getAnswers().get(i - 1);
|
|
|
|
+ dto.setSelectedType(2);
|
|
|
|
+ }
|
|
|
|
+ answer.setAnswerSelectedType(Integer.parseInt(index), 2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String[] answerArray = wq.getSpaceIndex().split("、");
|
|
|
|
+ //所有答案先设置为对的
|
|
|
|
+ for (String index : answerArray) {
|
|
|
|
+ int i = Integer.parseInt(index);
|
|
|
|
+ if (i >= 1 && answer.getAnswers() != null && i <= answer.getAnswers().size()) {
|
|
|
|
+ ExerciseQuestionAnswerDto dto = answer.getAnswers().get(i - 1);
|
|
|
|
+ dto.setSelectedType(1);
|
|
|
|
+ }
|
|
|
|
+ answer.setAnswerSelectedType(Integer.parseInt(index), 1);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(wq.getCorrectSpaceIndex())){
|
|
|
|
+ String[] correctSpaceIndexArray = wq.getCorrectSpaceIndex().split("、");
|
|
|
|
+ for (String index : correctSpaceIndexArray) {
|
|
|
|
+ int i = Integer.parseInt(index);
|
|
|
|
+ if (i >= 1 && answer.getAnswers() != null && i <= answer.getAnswers().size()) {
|
|
|
|
+ ExerciseQuestionAnswerDto dto = answer.getAnswers().get(i - 1);
|
|
|
|
+ dto.setSelectedType(2);
|
|
|
|
+ }
|
|
|
|
+ answer.setAnswerSelectedType(Integer.parseInt(index), 2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Map<String, Map<String,List<ExerciseQuestionDto>>> temp1 = exerciseQuestionDtoList.stream().collect(Collectors.groupingBy(ExerciseQuestionDto::getBookCourseId, LinkedHashMap::new,
|
|
|
|
+ Collectors.groupingBy(ExerciseQuestionDto::getBigQuestionIndex, LinkedHashMap::new, Collectors.toList())));
|
|
|
|
+ List<ExerciseQuestionAnswer4CorrectDTO> exerciseQuestionAnswer4CorrectDTOList = new ArrayList<>();
|
|
|
|
+ int startIndex = -1;
|
|
|
|
+ int i = -1;
|
|
|
|
+ for (Map.Entry<String, Map<String,List<ExerciseQuestionDto>>> map1 : temp1.entrySet()){
|
|
|
|
+ for (Map.Entry<String,List<ExerciseQuestionDto>> map2 : map1.getValue().entrySet()) {
|
|
|
|
+ i = i + 1;
|
|
|
|
+ if (startIndex == -1 && CollectionUtils.isNotEmpty(resultList)){
|
|
|
|
+ if (isBigQuestionExists(resultList, map2.getValue())){
|
|
|
|
+ startIndex = i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ExerciseQuestionAnswer4CorrectDTO exerciseQuestionAnswer4CorrectDTO = new ExerciseQuestionAnswer4CorrectDTO();
|
|
|
|
+ exerciseQuestionAnswer4CorrectDTO.setBigQuestionIndex(map2.getKey());
|
|
|
|
+ exerciseQuestionAnswer4CorrectDTO.setQuestionList(map2.getValue());
|
|
|
|
+ exerciseQuestionAnswer4CorrectDTOList.add(exerciseQuestionAnswer4CorrectDTO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ startIndex = startIndex < 0 ? 0 : startIndex;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
+ result.put("startIndex", startIndex);
|
|
|
|
+ result.put("list", exerciseQuestionAnswer4CorrectDTOList);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private boolean isBigQuestionExists (List<String> questionIds, List<ExerciseQuestionDto> questionDtoList){
|
|
|
|
+ boolean result = false;
|
|
|
|
+ for (ExerciseQuestionDto question : questionDtoList){
|
|
|
|
+ if (questionIds.contains(question.getQuestionId())){
|
|
|
|
+ result = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<ExerciseQuestionDto> findAnswerByExerciseBookCourseId(
|
|
|
|
+ String exerciseBookCourseId, int bookYear) {
|
|
|
|
+ //调用es前的方法,2020年2月19日16:46:55
|
|
|
|
+ return queryDao.findAnswerByExerciseBookCourseId(exerciseBookCourseId, bookYear) ;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|