|
@@ -1,23 +1,37 @@
|
|
|
package com.yaoxiang.diagnosis.controller;
|
|
|
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
import com.yaoxiang.diagnosis.dao.OptionRepo;
|
|
|
import com.yaoxiang.diagnosis.dao.QuestionRepo;
|
|
|
+import com.yaoxiang.diagnosis.entity.Paper;
|
|
|
+import com.yaoxiang.diagnosis.entity.PaperCommit;
|
|
|
import com.yaoxiang.diagnosis.file.FileService;
|
|
|
import com.yaoxiang.diagnosis.entity.Question;
|
|
|
+import com.yaoxiang.diagnosis.model.AnswerContrast;
|
|
|
import com.yaoxiang.diagnosis.model.AuthUser;
|
|
|
+import com.yaoxiang.diagnosis.model.OptionPercentVo;
|
|
|
import com.yaoxiang.diagnosis.model.Result;
|
|
|
+import com.yaoxiang.diagnosis.service.CommitService;
|
|
|
+import com.yaoxiang.diagnosis.service.PaperService;
|
|
|
import com.yaoxiang.diagnosis.service.SpecialKnowledgeService;
|
|
|
-import com.yaoxiang.diagnosis.util.SecurityUtil;
|
|
|
+import com.yaoxiang.diagnosis.util.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
|
|
|
@@ -37,12 +51,17 @@ public class TestController {
|
|
|
@Resource
|
|
|
private SpecialKnowledgeService specialKnowledgeService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private CommitService commitService;
|
|
|
+ @Resource
|
|
|
+ private PaperService paperService;
|
|
|
+
|
|
|
private AtomicLong visitCount = new AtomicLong();
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TestController.class);
|
|
|
|
|
|
@GetMapping("/")
|
|
|
- public String index(){
|
|
|
+ public String index() {
|
|
|
return "hello";
|
|
|
}
|
|
|
|
|
@@ -120,7 +139,91 @@ public class TestController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("syncKnowledgeToSpecial")
|
|
|
- public boolean syncKnowledgeToSpecial(Long subjectId,String grade,Long pid){
|
|
|
- return specialKnowledgeService.syncKnowledgeToSpecial(subjectId,grade,pid);
|
|
|
+ public boolean syncKnowledgeToSpecial(Long subjectId, String grade, Long pid) {
|
|
|
+ return specialKnowledgeService.syncKnowledgeToSpecial(subjectId, grade, pid);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("optionPercent")
|
|
|
+ @ApiOperation("导出试卷每张选项的选中率")
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "pid", value = "pid", paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "startTime", value = "startTime", paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "endTime", value = "endTime", paramType = "query")})
|
|
|
+ public void exportOptionPercent(Long pid, HttpServletResponse response,
|
|
|
+ @RequestParam(defaultValue = "1584107900000") Long startTime,
|
|
|
+ @RequestParam(required = false) Long endTime) throws IOException {
|
|
|
+ logger.info("start {}", new Date(startTime));
|
|
|
+ if (endTime == null) {
|
|
|
+ endTime = DateUtil.getLastTimeOfDay(new Date()).getTime();
|
|
|
+ }
|
|
|
+ logger.info("end {}", new Date(endTime));
|
|
|
+ List<PaperCommit> list = commitService.listPaperCommit(pid, startTime, endTime);
|
|
|
+ Paper p = paperService.getOnePaper(pid);
|
|
|
+ byte[] data = calc1(list, p);
|
|
|
+ logger.info("commit size {},", list.size());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ response.setHeader("Content-Disposition", "attachment;fileName=xxx.xlsx");
|
|
|
+ response.getOutputStream().write(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public byte[] calc1(List<PaperCommit> list, Paper p) {
|
|
|
+
|
|
|
+ Map<Integer, Map<String, Integer>> mapCount = new LinkedHashMap<>();
|
|
|
+ Map<Integer, String> collects = new LinkedHashMap<>();
|
|
|
+ for (int i = 1; i <= p.getQuestionNum(); i++) {
|
|
|
+ LinkedHashMap<String, Integer> linkedHashMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ linkedHashMap.put("A", 0);
|
|
|
+ linkedHashMap.put("B", 0);
|
|
|
+ linkedHashMap.put("C", 0);
|
|
|
+ linkedHashMap.put("D", 0);
|
|
|
+ linkedHashMap.put("E", 0);
|
|
|
+ linkedHashMap.put("blank", 0);
|
|
|
+ mapCount.put(i, linkedHashMap);
|
|
|
+ }
|
|
|
+ for (Question q : p.getQuestions()) {
|
|
|
+ collects.put(q.getNumber(), q.getAnswer());
|
|
|
+ }
|
|
|
+ for (PaperCommit commit : list) {
|
|
|
+ String jsonAnswer = commit.getJsonAns();
|
|
|
+ List<AnswerContrast> contrasts = convertAnswerContrast(jsonAnswer);
|
|
|
+ for (AnswerContrast contrast : contrasts) {
|
|
|
+ String options = contrast.getOptions();
|
|
|
+ Map<String, Integer> os = mapCount.get(contrast.getNumber());
|
|
|
+ if (StringUtils.isBlank(options)) {
|
|
|
+ options = "blank";
|
|
|
+ }
|
|
|
+ int c = os.get(options);
|
|
|
+ os.put(options, c + 1);
|
|
|
+ mapCount.put(contrast.getNumber(), os);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<OptionPercentVo> vos = new ArrayList<>();
|
|
|
+ for (Map.Entry<Integer, Map<String, Integer>> entry : mapCount.entrySet()) {
|
|
|
+ int number = entry.getKey();
|
|
|
+ Map<String, Integer> os = entry.getValue();
|
|
|
+ OptionPercentVo vo = new OptionPercentVo();
|
|
|
+ vo.setNumber(number);
|
|
|
+ vo.setAnswer(collects.get(number));
|
|
|
+ vo.setA(NumberUtil.format(os.get("A") * 100.0 / list.size()));
|
|
|
+ vo.setB(NumberUtil.format(os.get("B") * 100.0 / list.size()));
|
|
|
+ vo.setC(NumberUtil.format(os.get("C") * 100.0 / list.size()));
|
|
|
+ vo.setD(NumberUtil.format(os.get("D") * 100.0 / list.size()));
|
|
|
+ vo.setE(NumberUtil.format(os.get("E") * 100.0 / list.size()));
|
|
|
+ vo.setBlank(NumberUtil.format(os.get("blank") * 100.0 / list.size()));
|
|
|
+ logger.info(vo.toString());
|
|
|
+ vos.add(vo);
|
|
|
+ }
|
|
|
+ return ExportUtil.export1(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AnswerContrast> convertAnswerContrast(String json) {
|
|
|
+ return ObjectUtil.getGson().fromJson(json, new TypeToken<List<AnswerContrast>>() {
|
|
|
+ }.getType());
|
|
|
}
|
|
|
}
|