|
@@ -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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|