|
|
@@ -1,24 +1,17 @@
|
|
|
-package com.es.demo;
|
|
|
+package com.seec.bok.back.controller;
|
|
|
|
|
|
-import com.es.demo.back.ChoiceQuestion;
|
|
|
-import com.es.demo.back.TQRepository;
|
|
|
+import com.seec.bok.back.entity.ChoiceQuestion;
|
|
|
+import com.seec.bok.back.repository.TQRepository;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
|
|
-import org.springframework.data.elasticsearch.core.query.GetQuery;
|
|
|
-import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
|
|
-import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import sun.security.util.Length;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @ClassName WebRestfulController
|
|
|
@@ -31,20 +24,27 @@ import java.util.stream.Stream;
|
|
|
@RestController
|
|
|
@RequestMapping("/rest")
|
|
|
public class WebRestfulController {
|
|
|
- private ElasticsearchOperations elasticsearchOperations;
|
|
|
@Autowired
|
|
|
@Qualifier("TQRepositoryImp")
|
|
|
private TQRepository tqRepository;
|
|
|
@Autowired
|
|
|
- public WebRestfulController(ElasticsearchOperations elasticsearchOperations) {
|
|
|
- this.elasticsearchOperations = elasticsearchOperations;
|
|
|
- }
|
|
|
+ public WebRestfulController() { }
|
|
|
|
|
|
@PostMapping("/tq")
|
|
|
public String save(@RequestBody ChoiceQuestion person) {
|
|
|
return saveChoiceQuestion(person);
|
|
|
}
|
|
|
private String saveChoiceQuestion(ChoiceQuestion tq){
|
|
|
+ if(tq.getAnswer()!=null){
|
|
|
+ tq.setAnswer(tq.getAnswer().replaceAll("【答案】",""));
|
|
|
+ }
|
|
|
+ if(tq.getAnalysis()!=null){
|
|
|
+ tq.setAnalysis(tq.getAnalysis().replaceAll("【解析】",""));
|
|
|
+ }
|
|
|
+ if(tq.getKey_points()!=null){
|
|
|
+ tq.setKey_points(tq.getKey_points().replaceAll("【考点】",""));
|
|
|
+ }
|
|
|
+
|
|
|
System.out.println("save:"+tq.toString());
|
|
|
return tqRepository.save(tq).toString();
|
|
|
}
|
|
|
@@ -60,8 +60,8 @@ public class WebRestfulController {
|
|
|
return all;
|
|
|
}
|
|
|
@GetMapping("/tq/{id}")
|
|
|
- public ChoiceQuestion findById(@PathVariable("id") Long id) {
|
|
|
- ChoiceQuestion tq = tqRepository.findById(id.intValue()).orElseThrow(()->{return new RuntimeException("not found id:"+id);});
|
|
|
+ public ChoiceQuestion findById(@PathVariable("id") Integer id) {
|
|
|
+ ChoiceQuestion tq = tqRepository.findById(id).orElseThrow(()->{return new RuntimeException("not found id:"+id);});
|
|
|
return tq;
|
|
|
}
|
|
|
|
|
|
@@ -69,7 +69,7 @@ public class WebRestfulController {
|
|
|
@RequestMapping(value="/postChapter",method = RequestMethod.POST,produces = "text/plain; charset=utf-8")
|
|
|
public String saveAll(@RequestParam String chapeter,@RequestBody String content) {
|
|
|
try {
|
|
|
- Map<Integer,ChoiceQuestion> questions=new LinkedHashMap<>();
|
|
|
+ Map<Integer, ChoiceQuestion> questions=new LinkedHashMap<>();
|
|
|
final int answerStartPos = content.lastIndexOf("## 参考答案与解析");
|
|
|
final int choiceStartPos = content.lastIndexOf("## 单项选择题");
|
|
|
final int completionStartPos = content.lastIndexOf("## 填空题");
|
|
|
@@ -87,9 +87,10 @@ public class WebRestfulController {
|
|
|
|
|
|
|
|
|
String answerContent=content.substring(answerStartPos);
|
|
|
+// System.out.println(answerContent);
|
|
|
SetAnswer(chapeter, answerContent, questions);
|
|
|
|
|
|
- System.out.println(questions.toString());
|
|
|
+// System.out.println(questions.toString());
|
|
|
questions.forEach((k,v)->{
|
|
|
if(v.questionIsLegal()){
|
|
|
saveChoiceQuestion(v);
|
|
|
@@ -104,7 +105,7 @@ public class WebRestfulController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void SetQuestion(String chapeter,String content, Map<Integer, ChoiceQuestion> questions) {
|
|
|
+ private void SetQuestion(String chapeter, String content, Map<Integer, ChoiceQuestion> questions) {
|
|
|
int num=1;
|
|
|
String type="choice";
|
|
|
while (true){
|
|
|
@@ -114,7 +115,7 @@ public class WebRestfulController {
|
|
|
if(startPos==-1){ break;}
|
|
|
content = content.substring(startPos);
|
|
|
int endPos=getEndPos(num,content);
|
|
|
- Integer id=Integer.valueOf(chapeter)*1000+num;
|
|
|
+ Integer id=Integer.valueOf(String.valueOf(Long.valueOf(chapeter)*1000+num));
|
|
|
String problem=content.substring(startTag.length(),endPos);
|
|
|
int A_Pos=0;
|
|
|
int firstA=problem.indexOf("\nA.");
|
|
|
@@ -154,7 +155,7 @@ public class WebRestfulController {
|
|
|
}
|
|
|
System.out.println(questions);
|
|
|
}
|
|
|
- private void SetAnswer(String chapeter,String content, Map<Integer, ChoiceQuestion> questions) {
|
|
|
+ private void SetAnswer(String chapeter, String content, Map<Integer, ChoiceQuestion> questions) {
|
|
|
int num=1;
|
|
|
while (true){
|
|
|
String startTag="\n"+num+".";
|
|
|
@@ -163,7 +164,7 @@ public class WebRestfulController {
|
|
|
if(startPos==-1){ break;}
|
|
|
content = content.substring(startPos);
|
|
|
int endPos=getEndPos(num,content);
|
|
|
- Integer id=Integer.valueOf(chapeter)*1000+num;
|
|
|
+ Long id=Long.valueOf(chapeter)*1000+num;
|
|
|
String solve = content.substring(0, endPos);
|
|
|
int answerStart=solve.indexOf("【答案】");
|
|
|
int keyPointsStart=solve.indexOf("【考点】");
|