|
@@ -1,15 +1,19 @@
|
|
|
package com.yaoxiang.diagnosis.word;
|
|
|
|
|
|
+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 java.io.ByteArrayInputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class KnowledgeUtil {
|
|
|
|
|
@@ -59,7 +63,7 @@ public class KnowledgeUtil {
|
|
|
for (int numRow = 2; numRow < sheet.getLastRowNum(); numRow++) {
|
|
|
XSSFRow xRow = sheet.getRow(numRow);
|
|
|
|
|
|
- if(xRow.getCell(3) == null){
|
|
|
+ if (xRow.getCell(3) == null) {
|
|
|
continue;
|
|
|
}
|
|
|
MatterVo vo = new MatterVo();
|
|
@@ -77,4 +81,147 @@ public class KnowledgeUtil {
|
|
|
System.out.println(result);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ public static List<SpecialKnowledge> importSpecialKnowledge(Long subjectId, String grade, byte[] data) throws Exception {
|
|
|
+ XSSFWorkbook book = new XSSFWorkbook(new ByteArrayInputStream(data));
|
|
|
+ XSSFSheet sheet = book.getSheet("知识点+编号");
|
|
|
+ List<SpecialKnowledge> result = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ SpecialKnowledge parent = null;
|
|
|
+
|
|
|
+ for (int i = 3; i <= 110; i++) {
|
|
|
+ XSSFRow row = sheet.getRow(i);
|
|
|
+
|
|
|
+ String content = row.getCell(0).getStringCellValue();
|
|
|
+ if (StringUtils.isNotBlank(content)) {
|
|
|
+ SpecialKnowledge knowledge = new SpecialKnowledge();
|
|
|
+ knowledge.setLevel(0);
|
|
|
+ knowledge.setContent(content);
|
|
|
+ knowledge.setSubjectId(subjectId);
|
|
|
+ knowledge.setGrade(grade);
|
|
|
+ parent = knowledge;
|
|
|
+ result.add(knowledge);
|
|
|
+ }
|
|
|
+ initKnowLedge(row, 1, row.getLastCellNum(), parent, result);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void initKnowLedge(XSSFRow row, int index, int max, SpecialKnowledge parent, List<SpecialKnowledge> result) {
|
|
|
+ if (index == max - 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ XSSFCell cell = row.getCell(index);
|
|
|
+ String value = cell.getStringCellValue();
|
|
|
+ SpecialKnowledge knowledge;
|
|
|
+ if (StringUtils.isNotBlank(value)) {
|
|
|
+ knowledge = new SpecialKnowledge();
|
|
|
+ knowledge.setGrade("6Y");
|
|
|
+ if (index == max - 2) {
|
|
|
+ knowledge.setCode(row.getCell(max - 1).getStringCellValue());
|
|
|
+ }
|
|
|
+ knowledge.setLevel(index);
|
|
|
+ knowledge.setContent(value);
|
|
|
+ knowledge.setParent(parent);
|
|
|
+ parent = knowledge;
|
|
|
+ result.add(knowledge);
|
|
|
+ }
|
|
|
+ initKnowLedge(row, index + 1, max, parent, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<SpecialKnowledge> importSpecialKnowledge1(Long subjectId, String grade, byte[] data) throws Exception {
|
|
|
+ XSSFWorkbook book = new XSSFWorkbook(new ByteArrayInputStream(data));
|
|
|
+ XSSFSheet sheet = book.getSheet("知识点+编号");
|
|
|
+ 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) {
|
|
|
+ k.setCode(row.getCell(j + 1).getStringCellValue());
|
|
|
+ }
|
|
|
+ k.setLevel(j);
|
|
|
+ k.setGrade(grade);
|
|
|
+ k.setSubjectId(subjectId);
|
|
|
+ k.setContent(content);
|
|
|
+ map.put(content,k);
|
|
|
+ result.add(k);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|