|
@@ -41,7 +41,7 @@ import cn.com.qmth.am.service.QuestionService;
|
|
|
|
|
|
@Service
|
|
|
public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity> implements QuestionService {
|
|
|
- private Pattern scoreRex = Pattern.compile("\\[\\[([0-9](.[0-9]+){0,1})分\\]\\]");
|
|
|
+ private Pattern scoreRex = Pattern.compile("\\[\\[([0-9][0-9]*(.[0-9]+){0,1})分\\]\\]");
|
|
|
private static final String[] EXCEL_HEADER = new String[] { "考试ID", "科目代码", "科目名称", "大题号", "小题号", "满分", "试题内容",
|
|
|
"试题答案", "作答坐标" };
|
|
|
@Autowired
|
|
@@ -351,30 +351,38 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
|
if (StringUtils.isBlank(s)) {
|
|
|
return null;
|
|
|
}
|
|
|
- try {
|
|
|
- List<StandardAnswer> list = new ArrayList<>();
|
|
|
- Matcher matcher = scoreRex.matcher(s);
|
|
|
- int start=0;
|
|
|
- String score = null;
|
|
|
- while (matcher.find()) {
|
|
|
- if(start!=0) {
|
|
|
- StandardAnswer a=new StandardAnswer();
|
|
|
- list.add(a);
|
|
|
- a.setScore(score);
|
|
|
- a.setContent(s.substring(start,matcher.start()));
|
|
|
- }
|
|
|
- score=matcher.group(1);
|
|
|
- start=matcher.end();
|
|
|
- }
|
|
|
- if(start<s.length()) {
|
|
|
+ List<StandardAnswer> list = new ArrayList<>();
|
|
|
+ Matcher matcher = scoreRex.matcher(s);
|
|
|
+ int start=0;
|
|
|
+ Double score = null;
|
|
|
+ while (matcher.find()) {
|
|
|
+ if(start!=0) {
|
|
|
StandardAnswer a=new StandardAnswer();
|
|
|
list.add(a);
|
|
|
a.setScore(score);
|
|
|
- a.setContent(s.substring(start,s.length()));
|
|
|
+ a.setContent(s.substring(start,matcher.start()));
|
|
|
}
|
|
|
- return list;
|
|
|
- } catch (Exception e) {
|
|
|
- return null;
|
|
|
+ try {
|
|
|
+ score=Double.valueOf(matcher.group(1));
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new StatusException("分数格式有误");
|
|
|
+ }
|
|
|
+ checkScore(score);
|
|
|
+ start=matcher.end();
|
|
|
+ }
|
|
|
+ if(start<s.length()) {
|
|
|
+ StandardAnswer a=new StandardAnswer();
|
|
|
+ list.add(a);
|
|
|
+ a.setScore(score);
|
|
|
+ checkScore(score);
|
|
|
+ a.setContent(s.substring(start,s.length()));
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkScore(Double score) {
|
|
|
+ if(score==null) {
|
|
|
+ throw new StatusException("分数不能为空");
|
|
|
}
|
|
|
}
|
|
|
|