Browse Source

增加上传化学知识点接口,专项诊断报告将把题号关联到知识点列表中,不使用年级+科目的方式进行软绑定和不再在试卷中打上知识点标签。增加同步小升初数学的知识点绑定

4228306 5 years ago
parent
commit
69df0cbdc1

BIN
doc/化学中考专项诊断知识点列表.xlsx


+ 17 - 5
src/main/java/com/yaoxiang/diagnosis/controller/ExcelController.java

@@ -50,8 +50,8 @@ public class ExcelController {
                                @RequestBody MultipartFile file) throws Exception {
         byte[] data = file.getBytes();
         List<MatterVo> list = KnowledgeUtil.importMatter(subjectId, grade, data);
-        matterService.addBase(Constants.MATTER_EMOTION,"emotion");
-        matterService.addBase(Constants.MATTER_STUDY,"study");
+        matterService.addBase(Constants.MATTER_EMOTION, "emotion");
+        matterService.addBase(Constants.MATTER_STUDY, "study");
         matterService.addAll(list);
         return Result.ok(list);
     }
@@ -59,11 +59,23 @@ public class ExcelController {
     @PostMapping("/uploadSpecial")
     @ApiOperation("上传专项诊断知识点")
     public Result uploadSpecial(@RequestParam(defaultValue = "2") Long subjectId,
-        @RequestParam(defaultValue = "6Y") String grade,
-        @RequestBody MultipartFile file) throws Exception{
+                                @RequestParam(defaultValue = "6Y") String grade,
+                                @RequestBody MultipartFile file) throws Exception {
         byte[] data = file.getBytes();
-        List<SpecialKnowledge> list = KnowledgeUtil.importSpecialKnowledge1(subjectId,grade,data);
+        List<SpecialKnowledge> list = KnowledgeUtil.importSpecialKnowledge1(subjectId, grade, data);
         boolean result = specialKnowledgeService.add(list);
         return new Result(result);
     }
+
+    @PostMapping("/uploadSpecialChem")
+    @ApiOperation("上传专项诊断知识点")
+    public Result uploadSpecialChem(@RequestParam(defaultValue = "4") Long subjectId,
+                                    @RequestParam(defaultValue = "9Y") String grade,
+                                    @RequestParam(defaultValue = "5") Long pid,
+                                    @RequestBody MultipartFile file) throws Exception {
+        byte[] data = file.getBytes();
+        List<SpecialKnowledge> list = KnowledgeUtil.importSpecialKnowledge2(subjectId, grade, data,pid);
+        specialKnowledgeService.add(list);
+        return Result.ok(list);
+    }
 }

+ 1 - 4
src/main/java/com/yaoxiang/diagnosis/controller/SpecialDiagnosisController.java

@@ -3,10 +3,7 @@ package com.yaoxiang.diagnosis.controller;
 import com.yaoxiang.diagnosis.entity.SpecialKnowledge;
 import com.yaoxiang.diagnosis.service.SpecialKnowledgeService;
 import io.swagger.annotations.Api;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;

+ 7 - 0
src/main/java/com/yaoxiang/diagnosis/controller/TestController.java

@@ -6,6 +6,7 @@ import com.yaoxiang.diagnosis.file.FileService;
 import com.yaoxiang.diagnosis.entity.Question;
 import com.yaoxiang.diagnosis.model.AuthUser;
 import com.yaoxiang.diagnosis.model.Result;
+import com.yaoxiang.diagnosis.service.SpecialKnowledgeService;
 import com.yaoxiang.diagnosis.util.SecurityUtil;
 import io.swagger.annotations.Api;
 import org.slf4j.Logger;
@@ -33,6 +34,8 @@ public class TestController {
     private QuestionRepo questionRepo;
     @Resource
     private FileService fileService;
+    @Resource
+    private SpecialKnowledgeService specialKnowledgeService;
 
     private AtomicLong visitCount = new AtomicLong();
 
@@ -111,4 +114,8 @@ public class TestController {
         return Result.ok();
     }
 
+    @PostMapping("syncKnowledgeToSpecial")
+    public boolean syncKnowledgeToSpecial(Long subjectId,String grade,Long pid){
+        return specialKnowledgeService.syncKnowledgeToSpecial(subjectId,grade,pid);
+    }
 }

+ 23 - 0
src/main/java/com/yaoxiang/diagnosis/entity/SpecialKnowledge.java

@@ -74,6 +74,13 @@ public class SpecialKnowledge {
     @Transient
     private List<SpecialKnowledge> children;
 
+//    @Transient
+    @ApiModelProperty("该知识点所在的试卷")
+    private Long pid;
+//    @Transient
+    @ApiModelProperty("该知识点指向的题号 以,隔开")
+    private String qids;
+
     public Long getId() {
         return id;
     }
@@ -194,6 +201,22 @@ public class SpecialKnowledge {
         this.collectNum = collectNum;
     }
 
+    public Long getPid() {
+        return pid;
+    }
+
+    public void setPid(Long pid) {
+        this.pid = pid;
+    }
+
+    public String getQids() {
+        return qids;
+    }
+
+    public void setQids(String qids) {
+        this.qids = qids;
+    }
+
     @Override
     public String toString() {
         return "SpecialKnowledge{" +

+ 36 - 17
src/main/java/com/yaoxiang/diagnosis/service/SpecialKnowledgeService.java

@@ -1,7 +1,10 @@
 package com.yaoxiang.diagnosis.service;
 
 import com.yaoxiang.diagnosis.config.Constants;
+import com.yaoxiang.diagnosis.dao.PaperRepo;
 import com.yaoxiang.diagnosis.dao.SpecialKnowledgeRepo;
+import com.yaoxiang.diagnosis.entity.Paper;
+import com.yaoxiang.diagnosis.entity.Question;
 import com.yaoxiang.diagnosis.entity.SpecialKnowledge;
 import com.yaoxiang.diagnosis.model.Result;
 import com.yaoxiang.diagnosis.util.NumberUtil;
@@ -11,10 +14,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -23,6 +23,8 @@ public class SpecialKnowledgeService {
 
     @Resource
     private SpecialKnowledgeRepo specialKnowledgeRepo;
+    @Resource
+    private PaperService paperService;
 
     private static final Logger logger = LoggerFactory.getLogger(SpecialKnowledgeService.class);
 
@@ -69,45 +71,62 @@ public class SpecialKnowledgeService {
     }
 
     public void calcCount(List<SpecialKnowledge> list) {
-        Map<Integer,List<SpecialKnowledge>> group = list.stream().collect(Collectors.groupingBy(SpecialKnowledge::getLevel));
-        Map<Long,SpecialKnowledge> knowledgeMap = list.stream().collect(Collectors.toMap(SpecialKnowledge::getId,Function.identity()));
+        Map<Integer, List<SpecialKnowledge>> group = list.stream().collect(Collectors.groupingBy(SpecialKnowledge::getLevel));
+        Map<Long, SpecialKnowledge> knowledgeMap = list.stream().collect(Collectors.toMap(SpecialKnowledge::getId, Function.identity()));
         int max = group.keySet().stream().max(Comparator.naturalOrder()).orElse(0);
-        if(max ==0){
+        if (max == 0) {
             logger.warn("最大层级为0,请检查数据");
         }
-        for (int i = max; i>1 ;i--){
+        for (int i = max; i > 1; i--) {
             //全是同一级的
             List<SpecialKnowledge> ss = group.get(i);
             //找出同一个parentId的
-            Map<Long,List<SpecialKnowledge>> map = ss.stream().collect(Collectors.groupingBy(SpecialKnowledge::getParentId));
+            Map<Long, List<SpecialKnowledge>> map = ss.stream().collect(Collectors.groupingBy(SpecialKnowledge::getParentId));
             double rate = 0;
-            for (Map.Entry<Long,List<SpecialKnowledge>> entry:map.entrySet()){
+            for (Map.Entry<Long, List<SpecialKnowledge>> entry : map.entrySet()) {
                 int collectCount = 0;
                 int questionNum = 0;
                 List<SpecialKnowledge> specialKnowledges = entry.getValue();
-                for (SpecialKnowledge s:specialKnowledges){
-                    collectCount+= s.getCollectNum();
+                for (SpecialKnowledge s : specialKnowledges) {
+                    collectCount += s.getCollectNum();
                     questionNum += s.getQuestionNum();
                 }
                 //parent 不为null
-                if(specialKnowledges.size() > 0){
+                if (specialKnowledges.size() > 0) {
                     SpecialKnowledge parent = knowledgeMap.get(entry.getKey());
                     parent.setCollectNum(collectCount);
                     parent.setQuestionNum(questionNum);
                     //小于等于层级3
-                    if(i <= 4 && questionNum > 0){
+                    if (i <= 4 && questionNum > 0) {
                         double master = collectCount * 100.0 / questionNum;
                         parent.setMaster(NumberUtil.format(master));
-                        if(master < 0.8){
+                        if (master < 0.8) {
                             parent.setMasterStatus(Constants.SPECIAL_KNOWLEDGE_UNMASTER);
                         }
                     }
                 }
             }
 
-            if(i >= 3){
-                ss.forEach(s->s.setChildren(null));
+            if (i >= 3) {
+                ss.forEach(s -> s.setChildren(null));
             }
         }
     }
+
+    public boolean syncKnowledgeToSpecial(Long subjectId, String grade, Long pid) {
+        List<SpecialKnowledge> list = list(subjectId, grade);
+        Paper paper = paperService.getOnePaper(pid);
+        Map<String, List<Question>> group = paper.getQuestions().stream().collect(Collectors.groupingBy(Question::getTag));
+
+        for (SpecialKnowledge s : list) {
+            s.setPid(pid);
+            //编号不为null 并且 这个知识点有考
+            if (s.getCode() != null && group.get(s.getCode()) != null) {
+                List<Integer> numbers = group.get(s.getCode()).stream().map(Question::getNumber).collect(Collectors.toList());
+                s.setQids(StringUtils.join(numbers, ","));
+            }
+            specialKnowledgeRepo.save(s);
+        }
+        return true;
+    }
 }

+ 53 - 41
src/main/java/com/yaoxiang/diagnosis/word/KnowledgeUtil.java

@@ -4,10 +4,8 @@ import com.yaoxiang.diagnosis.entity.SpecialKnowledge;
 import com.yaoxiang.diagnosis.entity.SubjectKnowledge;
 import com.yaoxiang.diagnosis.model.MatterVo;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFRow;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.xssf.usermodel.*;
 
 import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
@@ -177,7 +175,7 @@ public class KnowledgeUtil {
             XSSFRow row = sheet.getRow(i);
             for (int j = 0; j < row.getLastCellNum() - 1; j++) {
                 String content = row.getCell(j).getStringCellValue();
-                if(map.containsKey(content)){
+                if (map.containsKey(content)) {
                     continue;
                 }
                 SpecialKnowledge k = new SpecialKnowledge();
@@ -188,49 +186,63 @@ public class KnowledgeUtil {
                 if (j == row.getLastCellNum() - 2) {
                     k.setCode(row.getCell(j + 1).getStringCellValue());
                 }
-//                if(j > 0){
-//                    k.setRoot1(row.getCell(0).getStringCellValue());
-//                }
-//                if(j > 1){
-//                    k.setRoot2(row.getCell(1).getStringCellValue());
-//                }
-//                if(j > 2){
-//                    k.setRoot3(row.getCell(2).getStringCellValue());
-//                }
-                k.setLevel(j);
+                //层级从第一级开始
+                k.setLevel(j + 1);
                 k.setGrade(grade);
                 k.setSubjectId(subjectId);
                 k.setContent(content);
-                map.put(content,k);
+                map.put(content, k);
                 result.add(k);
             }
         }
 
-        //一列一列来读取
-//        int colNum = sheet.getRow(3).getLastCellNum();
-//        for (int j = 0;j < colNum -1 ;j++){
-//            SpecialKnowledge p = queue.poll();
-//            for (int i=3;i<sheet.getLastRowNum();i++){
-//                String content = sheet.getRow(i).getCell(j).getStringCellValue();
-////                if(p != null && a != null && i == a + 1){
-////                    p = queue.poll();
-////                    a = index.poll();
-////                }
-//                if(StringUtils.isNotBlank(content)){
-//                    SpecialKnowledge k = new SpecialKnowledge();
-//                    k.setParent(p);
-//                    k.setLevel(j);
-//                    k.setGrade(grade);
-//                    k.setSubjectId(subjectId);
-//                    k.setContent(content);
-//                    result.add(k);
-//                    queue.add(k);
-//                    index.put(content,k);
-//                }
-//
-//            }
-//
-//        }
+        return result;
+    }
+
+    public static List<SpecialKnowledge> importSpecialKnowledge2(Long subjectId, String grade, byte[] data, Long pid) throws Exception {
+        XSSFWorkbook book = new XSSFWorkbook(new ByteArrayInputStream(data));
+        XSSFSheet sheet = book.getSheetAt(0);
+        List<SpecialKnowledge> result = new ArrayList<>();
+        for (int i = 3; i <= sheet.getLastRowNum(); i++) {
+            XSSFRow row = sheet.getRow(i);
+            for (int j = 0; j < row.getLastCellNum() - 1; j++) {
+                XSSFCell cell = row.getCell(j);
+                String content = cell.getStringCellValue();
+                if (StringUtils.isBlank(content)) {
+                    cell.setCellValue(sheet.getRow(i - 1).getCell(j).getStringCellValue());
+                }
+            }
+        }
+        Map<String, SpecialKnowledge> map = new HashMap<>();
+        for (int i = 3; i <= sheet.getLastRowNum(); i++) {
+            XSSFRow row = sheet.getRow(i);
+            for (int j = 0; j < row.getLastCellNum() - 1; j++) {
+                String content = row.getCell(j).getStringCellValue();
+                if (map.containsKey(content)) {
+                    continue;
+                }
+                SpecialKnowledge k = new SpecialKnowledge();
+                if (j > 0) {
+                    String parentContent = row.getCell(j - 1).getStringCellValue();
+                    k.setParent(map.get(parentContent));
+                }
+                if (j == row.getLastCellNum() - 2) {
+                    XSSFCell cell = row.getCell(j + 1);
+                    if (CellType.NUMERIC == cell.getCellTypeEnum()) {
+                        k.setQids(String.valueOf(cell.getNumericCellValue()));
+                    } else {
+                        k.setQids(cell.getStringCellValue());
+                    }
+                }
+                k.setLevel(j + 1);
+                k.setGrade(grade);
+                k.setPid(pid);
+                k.setSubjectId(subjectId);
+                k.setContent(content);
+                map.put(content, k);
+                result.add(k);
+            }
+        }
         return result;
     }