|
@@ -10,6 +10,11 @@ import java.util.Map.Entry;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.jsoup.Jsoup;
|
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
|
+import org.jsoup.safety.Whitelist;
|
|
|
|
+import org.jsoup.select.Elements;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -302,18 +307,41 @@ public class ExamServiceImpl implements ExamService {
|
|
}
|
|
}
|
|
|
|
|
|
String beforeExamRemark = properties.get("BEFORE_EXAM_REMARK");
|
|
String beforeExamRemark = properties.get("BEFORE_EXAM_REMARK");
|
|
- if (null != beforeExamRemark && beforeExamRemark.length() > 250000) {
|
|
|
|
- throw new StatusException("001002", "考前说明内容过大");
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (null != beforeExamRemark) {
|
|
|
|
+ String simpleText = Jsoup.clean(beforeExamRemark, Whitelist.simpleText());
|
|
|
|
+ if (simpleText.length() > 800) {
|
|
|
|
+ throw new StatusException("001002", "考前说明内容不得超过800个字符");
|
|
|
|
+ }
|
|
|
|
+ long imgsize=getImgSizeByBase64String(beforeExamRemark);
|
|
|
|
+ if(imgsize>150*1024) {
|
|
|
|
+ throw new StatusException("001002", "考前说明图片总大小不得超过150KB");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
String afterExamRemark = properties.get("AFTER_EXAM_REMARK");
|
|
String afterExamRemark = properties.get("AFTER_EXAM_REMARK");
|
|
- if (null != afterExamRemark && afterExamRemark.length() > 250000) {
|
|
|
|
- throw new StatusException("001002", "考后说明内容过大");
|
|
|
|
|
|
+ if (null != afterExamRemark ) {
|
|
|
|
+ String simpleText = Jsoup.clean(afterExamRemark, Whitelist.simpleText());
|
|
|
|
+ if (simpleText.length() > 800) {
|
|
|
|
+ throw new StatusException("001002", "考后说明内容不得超过800个字符");
|
|
|
|
+ }
|
|
|
|
+ long imgsize=getImgSizeByBase64String(afterExamRemark);
|
|
|
|
+ if(imgsize>150*1024) {
|
|
|
|
+ throw new StatusException("001002", "考后说明图片总大小不得超过150KB");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
String cheatingRemark = properties.get("CHEATING_REMARK");
|
|
String cheatingRemark = properties.get("CHEATING_REMARK");
|
|
- if (null != cheatingRemark && cheatingRemark.length() > 250000) {
|
|
|
|
- throw new StatusException("001002", "作弊说明内容过大");
|
|
|
|
|
|
+ if (null != cheatingRemark) {
|
|
|
|
+ String simpleText = Jsoup.clean(cheatingRemark, Whitelist.simpleText());
|
|
|
|
+ if (simpleText.length() > 800) {
|
|
|
|
+ throw new StatusException("001002", "作弊说明内容不得超过800个字符");
|
|
|
|
+ }
|
|
|
|
+ long imgsize=getImgSizeByBase64String(cheatingRemark);
|
|
|
|
+ if(imgsize>150*1024) {
|
|
|
|
+ throw new StatusException("001002", "作弊说明图片总大小不得超过150KB");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 校验机构权限
|
|
// 校验机构权限
|
|
@@ -343,6 +371,30 @@ public class ExamServiceImpl implements ExamService {
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param content 内容
|
|
|
|
+ * @return 内容中图片文件总大小
|
|
|
|
+ */
|
|
|
|
+ private long getImgSizeByBase64String(String content) {
|
|
|
|
+ long size=0;
|
|
|
|
+ if(StringUtils.isNoneEmpty(content)) {
|
|
|
|
+ Document doc = Jsoup.parse(content);
|
|
|
|
+ Elements imgs=doc.getElementsByTag("img");
|
|
|
|
+ if(imgs!=null) {
|
|
|
|
+ for(Element img:imgs) {
|
|
|
|
+ String src=img.attr("src");
|
|
|
|
+ String base64=src.split(",")[1];
|
|
|
|
+ int equalIndex= base64.indexOf("=");
|
|
|
|
+ if(equalIndex>0){
|
|
|
|
+ base64=base64.substring(0, equalIndex);
|
|
|
|
+ }
|
|
|
|
+ long fileSize=base64.length()-(base64.length()/8)*2;
|
|
|
|
+ size=size+fileSize;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return size;
|
|
|
|
+ }
|
|
/*
|
|
/*
|
|
* 实现
|
|
* 实现
|
|
*
|
|
*
|