xiatian 1 năm trước cách đây
mục cha
commit
2c7bb35b7c

+ 17 - 17
db/am_db.sql

@@ -3,15 +3,15 @@ CREATE TABLE `am_question` (
   `id` bigint NOT NULL AUTO_INCREMENT,
   `id` bigint NOT NULL AUTO_INCREMENT,
   `create_time` datetime DEFAULT NULL,
   `create_time` datetime DEFAULT NULL,
   `update_time` datetime DEFAULT NULL,
   `update_time` datetime DEFAULT NULL,
-  `answer` longtext COLLATE utf8mb4_bin NOT NULL,
-  `content` longtext COLLATE utf8mb4_bin NOT NULL,
   `exam_id` bigint NOT NULL,
   `exam_id` bigint NOT NULL,
-  `full_score` double NOT NULL,
-  `image_slice` varchar(1000) COLLATE utf8mb4_bin NOT NULL,
-  `main_number` int NOT NULL,
-  `sub_number` int NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
+  `main_number` int NOT NULL,
+  `sub_number` int NOT NULL,
+  `full_score` double NOT NULL,
+  `answer` longtext COLLATE utf8mb4_bin NOT NULL,
+  `content` longtext COLLATE utf8mb4_bin NOT NULL,
+  `image_slice` varchar(1000) COLLATE utf8mb4_bin NOT NULL,
   PRIMARY KEY (`id`),
   PRIMARY KEY (`id`),
   UNIQUE KEY `IDX_QUESTION_01` (`exam_id`, `subject_code`, `main_number`, `sub_number`)
   UNIQUE KEY `IDX_QUESTION_01` (`exam_id`, `subject_code`, `main_number`, `sub_number`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
@@ -21,10 +21,10 @@ CREATE TABLE `am_student` (
   `id` bigint NOT NULL AUTO_INCREMENT,
   `id` bigint NOT NULL AUTO_INCREMENT,
   `create_time` datetime DEFAULT NULL,
   `create_time` datetime DEFAULT NULL,
   `update_time` datetime DEFAULT NULL,
   `update_time` datetime DEFAULT NULL,
-  `data_status` varchar(255) NOT NULL,
   `exam_id` bigint NOT NULL,
   `exam_id` bigint NOT NULL,
-  `student_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
+  `student_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
+  `data_status` varchar(255) NOT NULL,
   `err_msg` varchar(2000) COLLATE utf8mb4_bin DEFAULT NULL,
   `err_msg` varchar(2000) COLLATE utf8mb4_bin DEFAULT NULL,
   PRIMARY KEY (`id`),
   PRIMARY KEY (`id`),
   UNIQUE KEY `IDX_STUDENT_01` (`exam_id`, `subject_code`, `student_code`)
   UNIQUE KEY `IDX_STUDENT_01` (`exam_id`, `subject_code`, `student_code`)
@@ -35,20 +35,20 @@ CREATE TABLE `am_student_score` (
   `id` bigint NOT NULL AUTO_INCREMENT,
   `id` bigint NOT NULL AUTO_INCREMENT,
   `create_time` datetime DEFAULT NULL,
   `create_time` datetime DEFAULT NULL,
   `update_time` datetime DEFAULT NULL,
   `update_time` datetime DEFAULT NULL,
-  `ai_score` double DEFAULT NULL,
-  `answer_status` varchar(255) NOT NULL,
-  `score_status` varchar(255) NOT NULL,
-  `answer` longtext COLLATE utf8mb4_bin DEFAULT NULL,
-  `err_msg` varchar(2000) COLLATE utf8mb4_bin DEFAULT NULL,
-  `main_number` int NOT NULL,
-  `marking_score` double DEFAULT NULL,
-  `score_ratio` double DEFAULT NULL,
   `student_id` bigint NOT NULL,
   `student_id` bigint NOT NULL,
   `question_id` bigint NOT NULL,
   `question_id` bigint NOT NULL,
   `exam_id` bigint NOT NULL,
   `exam_id` bigint NOT NULL,
-  `student_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
+  `student_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
+  `main_number` int NOT NULL,
   `sub_number` 	 varchar(255) NOT NULL,
   `sub_number` 	 varchar(255) NOT NULL,
+  `answer_status` varchar(255) NOT NULL,
+  `score_status` varchar(255) NOT NULL,
+  `answer` longtext COLLATE utf8mb4_bin DEFAULT NULL,
+  `ai_score` double DEFAULT NULL,
+  `score_ratio` double DEFAULT NULL,
+  `marking_score` double DEFAULT NULL,
+  `err_msg` varchar(2000) COLLATE utf8mb4_bin DEFAULT NULL,
   PRIMARY KEY (`id`),
   PRIMARY KEY (`id`),
   UNIQUE KEY `IDX_STUDENT_SCORE_01` (`student_id`, `question_id`),
   UNIQUE KEY `IDX_STUDENT_SCORE_01` (`student_id`, `question_id`),
   UNIQUE KEY `IDX_STUDENT_SCORE_02` (`exam_id`, `subject_code`, `student_code`,`main_number`, `sub_number`)
   UNIQUE KEY `IDX_STUDENT_SCORE_02` (`exam_id`, `subject_code`, `student_code`,`main_number`, `sub_number`)

+ 3 - 0
src/main/java/cn/com/qmth/am/entity/StudentScoreEntity.java

@@ -1,5 +1,7 @@
 package cn.com.qmth.am.entity;
 package cn.com.qmth.am.entity;
 
 
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 
 
 import cn.com.qmth.am.entity.base.IdEntity;
 import cn.com.qmth.am.entity.base.IdEntity;
@@ -33,6 +35,7 @@ public class StudentScoreEntity extends IdEntity {
 	private String answer;
 	private String answer;
 
 
 	//错误信息
 	//错误信息
+    @TableField(updateStrategy = FieldStrategy.IGNORED)
 	private String errMsg;
 	private String errMsg;
 
 
 	public Long getStudentId() {
 	public Long getStudentId() {

+ 3 - 3
src/main/java/cn/com/qmth/am/service/StudentScoreService.java

@@ -20,7 +20,7 @@ public interface StudentScoreService  extends IService<StudentScoreEntity> {
 
 
 	List<StudentScoreEntity> getByStudentId(Long id);
 	List<StudentScoreEntity> getByStudentId(Long id);
 
 
-	void add(StudentEntity student, Map<Long,QuestionEntity> quetions);
+	List<StudentScoreEntity> add(StudentEntity student, Map<Long,QuestionEntity> quetions);
 
 
 	void updateAnswerErr(Long id,String string);
 	void updateAnswerErr(Long id,String string);
 
 
@@ -30,10 +30,10 @@ public interface StudentScoreService  extends IService<StudentScoreEntity> {
 
 
 	void ocr(StudentScoreImageDto dto);
 	void ocr(StudentScoreImageDto dto);
 
 
-	StudentScoreEntity findOneToAiMarking();
-
 	void aiMarking(StudentScoreEntity score);
 	void aiMarking(StudentScoreEntity score);
 
 
 	void resetStatus();
 	void resetStatus();
 
 
+	List<StudentScoreEntity> findAllToAiMarking();
+
 }
 }

+ 1 - 1
src/main/java/cn/com/qmth/am/service/StudentService.java

@@ -30,7 +30,7 @@ public interface StudentService  extends IService<StudentEntity> {
 
 
 	void createSlice(StudentScoreEntity score, Map<Long, QuestionEntity> quetions,Map<Integer,AnswerImageDto> answerImages);
 	void createSlice(StudentScoreEntity score, Map<Long, QuestionEntity> quetions,Map<Integer,AnswerImageDto> answerImages);
 
 
-	void updateStatus(Long id, DataStatus from, DataStatus to);
+	void updateStatus(Long id,DataStatus to);
 
 
 	void resetStatus();
 	void resetStatus();
 
 

+ 11 - 8
src/main/java/cn/com/qmth/am/service/impl/StudentScoreServiceImpl.java

@@ -323,7 +323,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 
 
 	@Transactional
 	@Transactional
 	@Override
 	@Override
-	public void add(StudentEntity student, Map<Long, QuestionEntity> quetions) {
+	public List<StudentScoreEntity> add(StudentEntity student, Map<Long, QuestionEntity> quetions) {
 		List<StudentScoreEntity> adds = new ArrayList<>();
 		List<StudentScoreEntity> adds = new ArrayList<>();
 		for (QuestionEntity q : quetions.values()) {
 		for (QuestionEntity q : quetions.values()) {
 			StudentScoreEntity s = new StudentScoreEntity();
 			StudentScoreEntity s = new StudentScoreEntity();
@@ -339,6 +339,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 			s.setSubNumber(q.getSubNumber());
 			s.setSubNumber(q.getSubNumber());
 		}
 		}
 		this.saveBatch(adds);
 		this.saveBatch(adds);
+		return adds;
 	}
 	}
 
 
 	@Transactional
 	@Transactional
@@ -460,6 +461,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 		UpdateWrapper<StudentScoreEntity> wrapper = new UpdateWrapper<>();
 		UpdateWrapper<StudentScoreEntity> wrapper = new UpdateWrapper<>();
 		LambdaUpdateWrapper<StudentScoreEntity> lw = wrapper.lambda();
 		LambdaUpdateWrapper<StudentScoreEntity> lw = wrapper.lambda();
 		lw.set(StudentScoreEntity::getAnswerStatus, DataStatus.SUCCESS);
 		lw.set(StudentScoreEntity::getAnswerStatus, DataStatus.SUCCESS);
+		lw.set(StudentScoreEntity::getErrMsg, null);
 		lw.set(StudentScoreEntity::getAnswer, answer);
 		lw.set(StudentScoreEntity::getAnswer, answer);
 		lw.eq(StudentScoreEntity::getId, id);
 		lw.eq(StudentScoreEntity::getId, id);
 		this.update(wrapper);
 		this.update(wrapper);
@@ -495,17 +497,17 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 
 
 	private void ocrErr(StudentScoreImageDto dto, String err) {
 	private void ocrErr(StudentScoreImageDto dto, String err) {
 		updateAnswerErr(dto.getStudentScoreId(), err);
 		updateAnswerErr(dto.getStudentScoreId(), err);
-		studentService.updateStatus(dto.getStudentId(), DataStatus.PROCESSING, DataStatus.FAILED);
+		studentService.updateStatus(dto.getStudentId(), DataStatus.FAILED);
 	}
 	}
 
 
+	
 	@Override
 	@Override
-	public StudentScoreEntity findOneToAiMarking() {
+	public List<StudentScoreEntity> findAllToAiMarking() {
 		QueryWrapper<StudentScoreEntity> wrapper = new QueryWrapper<>();
 		QueryWrapper<StudentScoreEntity> wrapper = new QueryWrapper<>();
 		LambdaQueryWrapper<StudentScoreEntity> lw = wrapper.lambda();
 		LambdaQueryWrapper<StudentScoreEntity> lw = wrapper.lambda();
 		lw.eq(StudentScoreEntity::getAnswerStatus, DataStatus.SUCCESS);
 		lw.eq(StudentScoreEntity::getAnswerStatus, DataStatus.SUCCESS);
-		lw.eq(StudentScoreEntity::getScoreStatus, DataStatus.WAITING);
-		wrapper.last("LIMIT 1");
-		return this.getOne(wrapper);
+		lw.in(StudentScoreEntity::getScoreStatus, DataStatus.WAITING,DataStatus.FAILED);
+		return this.list(wrapper);
 	}
 	}
 
 
 	@Transactional
 	@Transactional
@@ -528,7 +530,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 			if (ret != null) {
 			if (ret != null) {
 				updateScore(score.getId(), Calculator.multiply(q.getFullScore(), ret),ret);
 				updateScore(score.getId(), Calculator.multiply(q.getFullScore(), ret),ret);
 				if (allSuccess(score.getStudentId())) {
 				if (allSuccess(score.getStudentId())) {
-					studentService.updateStatus(score.getStudentId(), DataStatus.PROCESSING, DataStatus.SUCCESS);
+					studentService.updateStatus(score.getStudentId(),DataStatus.SUCCESS);
 				}
 				}
 			} else {
 			} else {
 				aiScoreErr(dto, "aiScore异常");
 				aiScoreErr(dto, "aiScore异常");
@@ -585,13 +587,14 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 		lw.set(StudentScoreEntity::getScoreStatus, DataStatus.SUCCESS);
 		lw.set(StudentScoreEntity::getScoreStatus, DataStatus.SUCCESS);
 		lw.set(StudentScoreEntity::getAiScore, aiScore);
 		lw.set(StudentScoreEntity::getAiScore, aiScore);
 		lw.set(StudentScoreEntity::getScoreRatio, scoreRatio);
 		lw.set(StudentScoreEntity::getScoreRatio, scoreRatio);
+		lw.set(StudentScoreEntity::getErrMsg, null);
 		lw.eq(StudentScoreEntity::getId, id);
 		lw.eq(StudentScoreEntity::getId, id);
 		this.update(wrapper);
 		this.update(wrapper);
 	}
 	}
 
 
 	private void aiScoreErr(AiMarkingDto dto, String err) {
 	private void aiScoreErr(AiMarkingDto dto, String err) {
 		updateScoreErr(dto.getScoreInfo().getId(), err);
 		updateScoreErr(dto.getScoreInfo().getId(), err);
-		studentService.updateStatus(dto.getScoreInfo().getStudentId(), DataStatus.PROCESSING, DataStatus.FAILED);
+		studentService.updateStatus(dto.getScoreInfo().getStudentId(),DataStatus.FAILED);
 	}
 	}
 
 
 	private void updateScoreErr(Long id, String err) {
 	private void updateScoreErr(Long id, String err) {

+ 8 - 9
src/main/java/cn/com/qmth/am/service/impl/StudentServiceImpl.java

@@ -257,7 +257,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 	public List<StudentEntity> findToDispose() {
 	public List<StudentEntity> findToDispose() {
 		QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
 		QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
 		LambdaQueryWrapper<StudentEntity> lw = wrapper.lambda();
 		LambdaQueryWrapper<StudentEntity> lw = wrapper.lambda();
-		lw.eq(StudentEntity::getDataStatus, DataStatus.WAITING);
+		lw.in(StudentEntity::getDataStatus, DataStatus.WAITING,DataStatus.FAILED);
 		return this.list(wrapper);
 		return this.list(wrapper);
 	}
 	}
 
 
@@ -266,7 +266,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 		List<StudentScoreEntity> scores=studentService.getOrCreateScores(student, quetions);
 		List<StudentScoreEntity> scores=studentService.getOrCreateScores(student, quetions);
 		Map<Integer,AnswerImageDto> answerImages=new HashMap<>();
 		Map<Integer,AnswerImageDto> answerImages=new HashMap<>();
 		for(StudentScoreEntity score:scores) {
 		for(StudentScoreEntity score:scores) {
-			if(DataStatus.WAITING.equals(score.getAnswerStatus())) {
+			if(DataStatus.WAITING.equals(score.getAnswerStatus())||DataStatus.FAILED.equals(score.getAnswerStatus())) {
 				studentService.createSlice(score,quetions,answerImages);
 				studentService.createSlice(score,quetions,answerImages);
 			}
 			}
 		}
 		}
@@ -278,7 +278,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 		QuestionEntity q=quetions.get(score.getQuestionId());
 		QuestionEntity q=quetions.get(score.getQuestionId());
 		if(q==null) {
 		if(q==null) {
 			studentScoreService.updateAnswerErr(score.getId(),"未找到试题信息");
 			studentScoreService.updateAnswerErr(score.getId(),"未找到试题信息");
-			updateStatus(score.getStudentId(),DataStatus.PROCESSING,DataStatus.FAILED);
+			updateStatus(score.getStudentId(),DataStatus.FAILED);
 			return;
 			return;
 		}
 		}
 		try {
 		try {
@@ -286,11 +286,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 		} catch (Exception e) {
 		} catch (Exception e) {
 			if(e instanceof StatusException) {
 			if(e instanceof StatusException) {
 				studentScoreService.updateAnswerErr(score.getId(),e.getMessage());
 				studentScoreService.updateAnswerErr(score.getId(),e.getMessage());
-				updateStatus(score.getStudentId(),DataStatus.PROCESSING,DataStatus.FAILED);
+				updateStatus(score.getStudentId(),DataStatus.FAILED);
 			}else {
 			}else {
 				log.error("系统异常",e);
 				log.error("系统异常",e);
 				studentScoreService.updateAnswerErr(score.getId(),"系统异常");
 				studentScoreService.updateAnswerErr(score.getId(),"系统异常");
-				updateStatus(score.getStudentId(),DataStatus.PROCESSING,DataStatus.FAILED);
+				updateStatus(score.getStudentId(),DataStatus.FAILED);
 			}
 			}
 		}
 		}
 	}
 	}
@@ -300,20 +300,19 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 	public List<StudentScoreEntity> getOrCreateScores(StudentEntity student, Map<Long,QuestionEntity> quetions) {
 	public List<StudentScoreEntity> getOrCreateScores(StudentEntity student, Map<Long,QuestionEntity> quetions) {
 		List<StudentScoreEntity> scores=studentScoreService.getByStudentId(student.getId());
 		List<StudentScoreEntity> scores=studentScoreService.getByStudentId(student.getId());
 		if(CollectionUtils.isEmpty(scores)) {
 		if(CollectionUtils.isEmpty(scores)) {
-			studentScoreService.add(student,quetions);
+			scores=studentScoreService.add(student,quetions);
 		}
 		}
-		updateStatus(student.getId(),DataStatus.WAITING,DataStatus.PROCESSING);
+		updateStatus(student.getId(),DataStatus.PROCESSING);
 		return scores;
 		return scores;
 	}
 	}
 	
 	
 	@Transactional
 	@Transactional
 	@Override
 	@Override
-	public void updateStatus(Long id,DataStatus from,DataStatus to) {
+	public void updateStatus(Long id,DataStatus to) {
 		UpdateWrapper<StudentEntity> wrapper = new UpdateWrapper<>();
 		UpdateWrapper<StudentEntity> wrapper = new UpdateWrapper<>();
 		LambdaUpdateWrapper<StudentEntity> lw = wrapper.lambda();
 		LambdaUpdateWrapper<StudentEntity> lw = wrapper.lambda();
 		lw.set(StudentEntity::getDataStatus, to);
 		lw.set(StudentEntity::getDataStatus, to);
 		lw.eq(StudentEntity::getId, id);
 		lw.eq(StudentEntity::getId, id);
-		lw.eq(StudentEntity::getDataStatus, from);
 		this.update(wrapper);
 		this.update(wrapper);
 	}
 	}
 	
 	

+ 8 - 5
src/main/java/cn/com/qmth/am/task/AiMarkingJob.java

@@ -1,5 +1,8 @@
 package cn.com.qmth.am.task;
 package cn.com.qmth.am.task;
 
 
+import java.util.List;
+
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -33,11 +36,11 @@ public class AiMarkingJob {
 	}
 	}
 
 
 	private void dispose() {
 	private void dispose() {
-		for(;;) {
-			StudentScoreEntity score = studentScoreService.findOneToAiMarking();
-			if (score==null) {
-				return;
-			}
+		List<StudentScoreEntity> scores = studentScoreService.findAllToAiMarking();
+		if (CollectionUtils.isEmpty(scores)) {
+			return;
+		}
+		for (StudentScoreEntity score : scores) {
 			studentScoreService.aiMarking(score);
 			studentScoreService.aiMarking(score);
 		}
 		}
 	}
 	}