xiatian 1 rok temu
rodzic
commit
669720edb2

+ 10 - 0
db/am_db.sql

@@ -1,3 +1,13 @@
+CREATE DATABASE IF NOT EXISTS ai_marking_db default character set utf8mb4 collate utf8mb4_general_ci;
+
+CREATE USER IF NOT EXISTS 'ai_marking'@'%' IDENTIFIED BY 'ai_marking';
+
+GRANT ALL PRIVILEGES  ON `ai_marking_db`.* TO 'ai_marking'@'localhost' IDENTIFIED BY 'ai_marking';
+
+FLUSH  PRIVILEGES;
+
+USE ai_marking_db;
+
 DROP TABLE IF EXISTS `am_question`;
 DROP TABLE IF EXISTS `am_question`;
 CREATE TABLE `am_question` (
 CREATE TABLE `am_question` (
   `id` bigint NOT NULL AUTO_INCREMENT,
   `id` bigint NOT NULL AUTO_INCREMENT,

+ 102 - 73
src/main/java/cn/com/qmth/am/controller/AdminController.java

@@ -22,11 +22,13 @@ import org.springframework.web.multipart.MultipartFile;
 import com.alibaba.fastjson.util.IOUtils;
 import com.alibaba.fastjson.util.IOUtils;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.core.concurrent.service.ConcurrentService;
 
 
 import cn.com.qmth.am.config.SysProperty;
 import cn.com.qmth.am.config.SysProperty;
 import cn.com.qmth.am.entity.QuestionEntity;
 import cn.com.qmth.am.entity.QuestionEntity;
 import cn.com.qmth.am.enums.DataStatus;
 import cn.com.qmth.am.enums.DataStatus;
 import cn.com.qmth.am.enums.ImportFileName;
 import cn.com.qmth.am.enums.ImportFileName;
+import cn.com.qmth.am.enums.LockType;
 import cn.com.qmth.am.service.QuestionService;
 import cn.com.qmth.am.service.QuestionService;
 import cn.com.qmth.am.service.StudentScoreService;
 import cn.com.qmth.am.service.StudentScoreService;
 import cn.com.qmth.am.service.StudentService;
 import cn.com.qmth.am.service.StudentService;
@@ -35,7 +37,7 @@ import io.swagger.annotations.ApiOperation;
 @RestController
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin")
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin")
 @Aac(strict = false, auth = false)
 @Aac(strict = false, auth = false)
-public class AdminController{
+public class AdminController {
 	@Autowired
 	@Autowired
 	private QuestionService questionService;
 	private QuestionService questionService;
 	@Autowired
 	@Autowired
@@ -44,84 +46,111 @@ public class AdminController{
 	private StudentScoreService studentScoreService;
 	private StudentScoreService studentScoreService;
 	@Autowired
 	@Autowired
 	private SysProperty sysProperty;
 	private SysProperty sysProperty;
-    @ApiOperation(value = "进度详情")
-    @RequestMapping(value = "info", method = RequestMethod.GET)
-    public void info(HttpServletResponse response,@RequestParam Long examId) {
-    	StringBuilder sb=new StringBuilder();
-    	List<QuestionEntity> qs=questionService.findByExamId(examId);
-    	int qstotal=0;
-    	int qsCourse=0;
-    	if(CollectionUtils.isNotEmpty(qs)) {
-    		Set<String> cset=new HashSet<>();
-    		qstotal=qs.size();
-    		for(QuestionEntity q:qs) {
-    			cset.add(q.getSubjectCode());
-    		}
-    		qsCourse=cset.size();
-    	}
-    	sb.append("试卷科目总数:"+qsCourse+"\r\n");
-    	sb.append("试卷小题总数:"+qstotal+"\r\n");
-    	int total=studentService.countBy(examId,null);
-    	if(total==0) {
-    		sb.append("考生总数:0");
-    		returnJson(sb.toString(), response);
-    		return;
-    	}
-    	sb.append("考生总数:"+total+"\r\n");
-    	int suc=studentService.countBy(examId,DataStatus.SUCCESS);
-    	sb.append("考生处理成功总数:"+suc+"\r\n");
-    	int failed=studentService.countBy(examId,DataStatus.FAILED);
-    	sb.append("考生处理失败总数:"+failed+"\r\n");
-    	int qtotal=studentScoreService.countBy(examId,null);
-    	if(qtotal==0) {
-    		sb.append("试题总数:0");
-    		returnJson(sb.toString(), response);
-    		return;
-    	}
-    	sb.append("考生试题总数:"+qtotal+"\r\n");
-    	int qsuc=studentScoreService.countBy(examId,DataStatus.SUCCESS);
-    	sb.append("考生试题处理成功总数:"+qsuc+"\r\n");
-    	int qfailed=studentScoreService.countBy(examId,DataStatus.FAILED);
-    	sb.append("考生试题处理失败总数:"+qfailed+"\r\n");
-    	returnJson(sb.toString(), response);
-    }
-    
-    @ApiOperation(value = "上传导入文件")
-    @RequestMapping(value = "upload", method = RequestMethod.POST)
-    public String upload(@RequestParam MultipartFile file) {
-    	if(ImportFileName.getByName(file.getOriginalFilename())==null) {
-    		return "上传失败,文件名错误";
-    	}
-    	File old=new File(sysProperty.getDataDir()+"/"+file.getOriginalFilename());
-    	if(old.exists()) {
-    		return "上传失败,有正在处理的文件";
-    	}
-    	InputStream in=null;
-    	try {
-    		in=file.getInputStream();
+	@Autowired
+	private ConcurrentService concurrentService;
+
+	@ApiOperation(value = "进度详情")
+	@RequestMapping(value = "info", method = RequestMethod.GET)
+	public void info(HttpServletResponse response, @RequestParam Long examId) {
+		StringBuilder sb = new StringBuilder();
+		List<QuestionEntity> qs = questionService.findByExamId(examId);
+		int qstotal = 0;
+		int qsCourse = 0;
+		if (CollectionUtils.isNotEmpty(qs)) {
+			Set<String> cset = new HashSet<>();
+			qstotal = qs.size();
+			for (QuestionEntity q : qs) {
+				cset.add(q.getSubjectCode());
+			}
+			qsCourse = cset.size();
+		}
+		sb.append("试卷科目总数:" + qsCourse + "\r\n");
+		sb.append("试卷小题总数:" + qstotal + "\r\n");
+		int total = studentService.countBy(examId, null);
+		if (total == 0) {
+			sb.append("考生总数:0");
+			returnJson(sb.toString(), response);
+			return;
+		}
+		sb.append("考生总数:" + total + "\r\n");
+		int suc = studentService.countBy(examId, DataStatus.SUCCESS);
+		sb.append("考生处理成功总数:" + suc + "\r\n");
+		int failed = studentService.countBy(examId, DataStatus.FAILED);
+		sb.append("考生处理失败总数:" + failed + "\r\n");
+		int qtotal = studentScoreService.countBy(examId, null);
+		if (qtotal == 0) {
+			sb.append("试题总数:0");
+			returnJson(sb.toString(), response);
+			return;
+		}
+		sb.append("考生试题总数:" + qtotal + "\r\n");
+		int qsuc = studentScoreService.countBy(examId, DataStatus.SUCCESS);
+		sb.append("考生试题处理成功总数:" + qsuc + "\r\n");
+		int qfailed = studentScoreService.countBy(examId, DataStatus.FAILED);
+		sb.append("考生试题处理失败总数:" + qfailed + "\r\n");
+		returnJson(sb.toString(), response);
+	}
+
+	@ApiOperation(value = "上传导入文件")
+	@RequestMapping(value = "upload", method = RequestMethod.POST)
+	public String upload(@RequestParam MultipartFile file) {
+		if (ImportFileName.getByName(file.getOriginalFilename()) == null) {
+			return "上传失败,文件名错误";
+		}
+		File old = new File(sysProperty.getDataDir() + "/" + file.getOriginalFilename());
+		if (old.exists()) {
+			return "上传失败,有正在处理的文件";
+		}
+		InputStream in = null;
+		try {
+			in = file.getInputStream();
 			FileUtils.copyInputStreamToFile(file.getInputStream(), old);
 			FileUtils.copyInputStreamToFile(file.getInputStream(), old);
 		} catch (IOException e) {
 		} catch (IOException e) {
-			return "上传失败,"+e.getMessage();
-		}finally {
-			if(in!=null) {
+			return "上传失败," + e.getMessage();
+		} finally {
+			if (in != null) {
 				try {
 				try {
 					in.close();
 					in.close();
 				} catch (IOException e) {
 				} catch (IOException e) {
 				}
 				}
 			}
 			}
 		}
 		}
-    	return "上传成功";
-    }
-    
-    private void returnJson(String body, HttpServletResponse response) {
-        response.setContentType("application/json;charset=utf-8");
-        PrintWriter writer = null;
-        try {
-            writer = response.getWriter();
-            writer.write(body);
-        } catch (IOException e) {
-        } finally {
-            IOUtils.close(writer);
-        }
-    }
+		return "上传成功";
+	}
+	
+	@ApiOperation(value = "重置数据")
+	@RequestMapping(value = "reset", method = RequestMethod.GET)
+	public String reset(@RequestParam Long examId,@RequestParam(required = false) String subjectCode) {
+		boolean lock1 = concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().tryLock();
+		if(!lock1) {
+			return "重置失败,有任务正在处理,请稍后 再试";
+		}
+		boolean lock2 = concurrentService.getReadWriteLock(LockType.OCR.name()).writeLock().tryLock();
+		if(!lock2) {
+			return "重置失败,有任务正在处理,请稍后 再试";
+		}
+		try {
+			studentService.reset(examId, subjectCode);
+			return "重置成功";
+		} finally {
+			if (lock2) {
+				concurrentService.getReadWriteLock(LockType.OCR.name()).writeLock().unlock();
+			}
+			if (lock1) {
+				concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().unlock();
+			}
+		}
+	}
+
+	private void returnJson(String body, HttpServletResponse response) {
+		response.setContentType("application/json;charset=utf-8");
+		PrintWriter writer = null;
+		try {
+			writer = response.getWriter();
+			writer.write(body);
+		} catch (IOException e) {
+		} finally {
+			IOUtils.close(writer);
+		}
+	}
 }
 }

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

@@ -39,4 +39,6 @@ public interface StudentScoreService  extends IService<StudentScoreEntity> {
 
 
 	int countBy(Long examId, DataStatus success);
 	int countBy(Long examId, DataStatus success);
 
 
+	void removeBy(Long examId, String subjectCode);
+
 }
 }

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

@@ -36,5 +36,7 @@ public interface StudentService  extends IService<StudentEntity> {
 
 
 	int countBy(Long examId, DataStatus success);
 	int countBy(Long examId, DataStatus success);
 
 
+	void reset(Long examId, String subjectCode);
+
 
 
 }
 }

+ 12 - 0
src/main/java/cn/com/qmth/am/service/impl/StudentScoreServiceImpl.java

@@ -640,4 +640,16 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 		lw.eq(StudentScoreEntity::getExamId, examId);
 		lw.eq(StudentScoreEntity::getExamId, examId);
 		return this.count(wrapper);
 		return this.count(wrapper);
 	}
 	}
+
+	@Transactional
+	@Override
+	public void removeBy(Long examId, String subjectCode) {
+		QueryWrapper<StudentScoreEntity> wrapper = new QueryWrapper<>();
+		LambdaQueryWrapper<StudentScoreEntity> lw = wrapper.lambda();
+		if(subjectCode!=null) {
+			lw.eq(StudentScoreEntity::getSubjectCode, subjectCode);
+		}
+		lw.eq(StudentScoreEntity::getExamId, examId);
+		this.remove(wrapper);
+	}
 }
 }

+ 14 - 0
src/main/java/cn/com/qmth/am/service/impl/StudentServiceImpl.java

@@ -338,4 +338,18 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 		lw.eq(StudentEntity::getExamId, examId);
 		lw.eq(StudentEntity::getExamId, examId);
 		return this.count(wrapper);
 		return this.count(wrapper);
 	}
 	}
+
+	@Transactional
+	@Override
+	public void reset(Long examId, String subjectCode) {
+		studentScoreService.removeBy(examId,subjectCode);
+		UpdateWrapper<StudentEntity> wrapper = new UpdateWrapper<>();
+		LambdaUpdateWrapper<StudentEntity> lw = wrapper.lambda();
+		lw.set(StudentEntity::getDataStatus, DataStatus.WAITING);
+		if(subjectCode!=null) {
+			lw.eq(StudentEntity::getSubjectCode, subjectCode);
+		}
+		lw.eq(StudentEntity::getExamId, examId);
+		this.update(wrapper);
+	}
 }
 }

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

@@ -22,12 +22,16 @@ public class AiMarkingJob {
 
 
 	@Scheduled(fixedDelay = 5 * 1000, initialDelay = 20 * 1000)
 	@Scheduled(fixedDelay = 5 * 1000, initialDelay = 20 * 1000)
 	public void doJob() {
 	public void doJob() {
+		List<StudentScoreEntity> scores = studentScoreService.findAllToAiMarking();
+		if (CollectionUtils.isEmpty(scores)) {
+			return;
+		}
 		boolean lock = concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().tryLock();
 		boolean lock = concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().tryLock();
 		try {
 		try {
 			if (!lock) {
 			if (!lock) {
 				return;
 				return;
 			}
 			}
-			this.dispose();
+			this.dispose(scores);
 		} finally {
 		} finally {
 			if (lock) {
 			if (lock) {
 				concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().unlock();
 				concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().unlock();
@@ -35,11 +39,7 @@ public class AiMarkingJob {
 		}
 		}
 	}
 	}
 
 
-	private void dispose() {
-		List<StudentScoreEntity> scores = studentScoreService.findAllToAiMarking();
-		if (CollectionUtils.isEmpty(scores)) {
-			return;
-		}
+	private void dispose(List<StudentScoreEntity> scores) {
 		for (StudentScoreEntity score : scores) {
 		for (StudentScoreEntity score : scores) {
 			studentScoreService.aiMarking(score);
 			studentScoreService.aiMarking(score);
 		}
 		}

+ 10 - 10
src/main/java/cn/com/qmth/am/task/BiuldImageJob.java

@@ -54,12 +54,20 @@ public class BiuldImageJob {
 
 
 	@Scheduled(fixedDelay = 5 * 1000, initialDelay = 20 * 1000)
 	@Scheduled(fixedDelay = 5 * 1000, initialDelay = 20 * 1000)
 	public void doJob() {
 	public void doJob() {
+		List<StudentEntity> stus = studentService.findToDispose();
+		if (CollectionUtils.isEmpty(stus)) {
+			return;
+		}
+		List<QuestionEntity> qs=questionService.list();
+		if (CollectionUtils.isEmpty(qs)) {
+			return;
+		}
 		boolean lock = concurrentService.getReadWriteLock(LockType.OCR.name()).writeLock().tryLock();
 		boolean lock = concurrentService.getReadWriteLock(LockType.OCR.name()).writeLock().tryLock();
 		try {
 		try {
 			if (!lock) {
 			if (!lock) {
 				return;
 				return;
 			}
 			}
-			this.dispose();
+			this.dispose(stus,qs);
 		} finally {
 		} finally {
 			if (lock) {
 			if (lock) {
 				concurrentService.getReadWriteLock(LockType.OCR.name()).writeLock().unlock();
 				concurrentService.getReadWriteLock(LockType.OCR.name()).writeLock().unlock();
@@ -67,15 +75,7 @@ public class BiuldImageJob {
 		}
 		}
 	}
 	}
 
 
-	private void dispose() {
-		List<StudentEntity> stus = studentService.findToDispose();
-		if (CollectionUtils.isEmpty(stus)) {
-			return;
-		}
-		List<QuestionEntity> qs=questionService.list();
-		if (CollectionUtils.isEmpty(qs)) {
-			return;
-		}
+	private void dispose(List<StudentEntity> stus,List<QuestionEntity> qs) {
 		Map<String,Map<Long,QuestionEntity>> qmap=new HashMap<>();
 		Map<String,Map<Long,QuestionEntity>> qmap=new HashMap<>();
 		for(QuestionEntity q:qs) {
 		for(QuestionEntity q:qs) {
 			String key=q.getExamId()+"-"+q.getSubjectCode();
 			String key=q.getExamId()+"-"+q.getSubjectCode();

+ 4 - 4
src/main/resources/application.properties

@@ -12,10 +12,10 @@ com.qmth.mybatis.block-attack=false
 # ********** db config **********
 # ********** db config **********
 #
 #
 db.host=localhost
 db.host=localhost
-db.port=3306
-db.database=ai_marking
-com.qmth.datasource.username=root
-com.qmth.datasource.password=123456
+db.port=3309
+db.database=ai_marking_db
+com.qmth.datasource.username=ai_marking
+com.qmth.datasource.password=ai_marking
 com.qmth.datasource.url=jdbc:mysql://${db.host}:${db.port}/${db.database}?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2b8&rewriteBatchedStatements=true
 com.qmth.datasource.url=jdbc:mysql://${db.host}:${db.port}/${db.database}?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2b8&rewriteBatchedStatements=true
 
 
 #
 #