|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.examwork.api.controller;
|
|
package cn.com.qmth.examcloud.core.examwork.api.controller;
|
|
|
|
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
@@ -249,13 +250,15 @@ public class NoticeController extends ControllerSupport {
|
|
}
|
|
}
|
|
String content = addNoticeDomain.getContent();
|
|
String content = addNoticeDomain.getContent();
|
|
// 普通文本内容不允许超过500个字
|
|
// 普通文本内容不允许超过500个字
|
|
- if (getSimpleTextLength(content) > 500) {
|
|
|
|
- throw new StatusException("500010", "通知内容不得超过500个字符");
|
|
|
|
|
|
+ int simpleTextLength=getSimpleTextLength(content);
|
|
|
|
+ if (simpleTextLength > 500) {
|
|
|
|
+ throw new StatusException("500010", "通知内容不得超过500个字符,当前字数为:"+simpleTextLength);
|
|
}
|
|
}
|
|
// 图片总大小不得超过2M
|
|
// 图片总大小不得超过2M
|
|
int imgSize = getImageSize(content);
|
|
int imgSize = getImageSize(content);
|
|
if (imgSize > (2 << 20)) {
|
|
if (imgSize > (2 << 20)) {
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
|
+ decimalFormat.setRoundingMode(RoundingMode.DOWN);//windows系统默认采用的是舍弃法,所以和它保持一致
|
|
String currentLength = decimalFormat
|
|
String currentLength = decimalFormat
|
|
.format(((double) imgSize / (double) 1024 / (double) 1024));
|
|
.format(((double) imgSize / (double) 1024 / (double) 1024));
|
|
throw new StatusException("500011", "图片大小不得超过2MB,当前大小为:" + currentLength + "MB");
|
|
throw new StatusException("500011", "图片大小不得超过2MB,当前大小为:" + currentLength + "MB");
|
|
@@ -314,13 +317,15 @@ public class NoticeController extends ControllerSupport {
|
|
}
|
|
}
|
|
String content = updateNoticeDomain.getContent();
|
|
String content = updateNoticeDomain.getContent();
|
|
// 普通文本内容不允许超过500个字
|
|
// 普通文本内容不允许超过500个字
|
|
- if (getSimpleTextLength(content) > 500) {
|
|
|
|
- throw new StatusException("500012", "通知内容不得超过500个字符");
|
|
|
|
|
|
+ int simpleTextLength=getSimpleTextLength(content);
|
|
|
|
+ if (simpleTextLength > 500) {
|
|
|
|
+ throw new StatusException("500010", "通知内容不得超过500个字符,当前字数为:"+simpleTextLength);
|
|
}
|
|
}
|
|
// 图片总大小不得超过2M
|
|
// 图片总大小不得超过2M
|
|
int imgSize = getImageSize(content);
|
|
int imgSize = getImageSize(content);
|
|
if (imgSize > (2 << 20)) {
|
|
if (imgSize > (2 << 20)) {
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
|
+ decimalFormat.setRoundingMode(RoundingMode.DOWN);
|
|
String currentLength = decimalFormat
|
|
String currentLength = decimalFormat
|
|
.format(((double) imgSize / (double) 1024 / (double) 1024));
|
|
.format(((double) imgSize / (double) 1024 / (double) 1024));
|
|
throw new StatusException("500015", "图片总大小不得超过2MB,当前大小为:" + currentLength + "MB");
|
|
throw new StatusException("500015", "图片总大小不得超过2MB,当前大小为:" + currentLength + "MB");
|
|
@@ -412,7 +417,4 @@ public class NoticeController extends ControllerSupport {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|