|
@@ -0,0 +1,127 @@
|
|
|
+package cn.com.qmth.am.controller;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.util.IOUtils;
|
|
|
+import com.qmth.boot.api.annotation.Aac;
|
|
|
+import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+
|
|
|
+import cn.com.qmth.am.config.SysProperty;
|
|
|
+import cn.com.qmth.am.entity.QuestionEntity;
|
|
|
+import cn.com.qmth.am.enums.DataStatus;
|
|
|
+import cn.com.qmth.am.enums.ImportFileName;
|
|
|
+import cn.com.qmth.am.service.QuestionService;
|
|
|
+import cn.com.qmth.am.service.StudentScoreService;
|
|
|
+import cn.com.qmth.am.service.StudentService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin")
|
|
|
+@Aac(strict = false, auth = false)
|
|
|
+public class AdminController{
|
|
|
+ @Autowired
|
|
|
+ private QuestionService questionService;
|
|
|
+ @Autowired
|
|
|
+ private StudentService studentService;
|
|
|
+ @Autowired
|
|
|
+ private StudentScoreService studentScoreService;
|
|
|
+ @Autowired
|
|
|
+ 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();
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), old);
|
|
|
+ } catch (IOException e) {
|
|
|
+ return "上传失败,"+e.getMessage();
|
|
|
+ }finally {
|
|
|
+ if(in!=null) {
|
|
|
+ try {
|
|
|
+ in.close();
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|