From 98b84aefd546f7452540ef327e7f16f089fde741 Mon Sep 17 00:00:00 2001
From: Himit_ZH <372347736@qq.com>
Date: Fri, 18 Jun 2021 22:57:25 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
hoj-springboot/.gitignore | 1 -
hoj-springboot/DataBackup/pom.xml | 6 --
.../exception/GlobalExceptionHandler.java | 36 +++++++++---
.../hoj/controller/oj/CommentController.java | 7 +--
.../hoj/service/impl/ProblemServiceImpl.java | 11 ++--
.../hoj/service/impl/ScheduleServiceImpl.java | 8 +--
hoj-vue/src/App.vue | 7 ++-
hoj-vue/src/views/admin/problem/Problem.vue | 57 +++++++++++++++----
.../views/oj/discussion/discussionList.vue | 10 +++-
9 files changed, 97 insertions(+), 46 deletions(-)
diff --git a/hoj-springboot/.gitignore b/hoj-springboot/.gitignore
index 443def43..24cbb6dd 100644
--- a/hoj-springboot/.gitignore
+++ b/hoj-springboot/.gitignore
@@ -34,4 +34,3 @@ pnpm-debug.log*
*.njsproj
*.sln
*.sw?
-
diff --git a/hoj-springboot/DataBackup/pom.xml b/hoj-springboot/DataBackup/pom.xml
index 8786f216..dc2c6891 100644
--- a/hoj-springboot/DataBackup/pom.xml
+++ b/hoj-springboot/DataBackup/pom.xml
@@ -188,12 +188,6 @@
jsoup
1.13.1
-
-
- com.github.binarywang
- java-emoji-converter
- 1.0.1
-
diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/common/exception/GlobalExceptionHandler.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/common/exception/GlobalExceptionHandler.java
index 3440decc..b650aa4b 100644
--- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/common/exception/GlobalExceptionHandler.java
+++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/common/exception/GlobalExceptionHandler.java
@@ -31,7 +31,8 @@ import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import java.io.IOException;
-import java.sql.BatchUpdateException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.sql.SQLException;
import java.util.Set;
@@ -194,8 +195,8 @@ public class GlobalExceptionHandler {
*/
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(value = MessagingException.class)
- public CommonResult handler(MessagingException e) throws Exception {
- log.error("邮箱系统异常-------------->{}", e.getMessage());
+ public CommonResult handler(MessagingException e){
+ log.error("邮箱系统异常-------------->{}", getMessage(e));
return CommonResult.errorResponse("服务器异常,请稍后尝试!", CommonResult.STATUS_ERROR);
}
@@ -205,7 +206,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(ServiceException.class)
public CommonResult handleServiceException(ServiceException e) {
- log.error("业务逻辑异常-------------->{}", e.getMessage());
+ log.error("业务逻辑异常-------------->{}", getMessage(e));
return CommonResult.errorResponse("服务器异常,请稍后尝试!", CommonResult.STATUS_ERROR);
}
@@ -215,7 +216,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(DataIntegrityViolationException.class)
public CommonResult handleDataIntegrityViolationException(DataIntegrityViolationException e) {
- log.error("操作数据库出现异常-------------->{}", e.getMessage());
+ log.error("操作数据库出现异常-------------->{}", getMessage(e));
return CommonResult.errorResponse("服务器异常,请稍后尝试!", CommonResult.STATUS_ERROR);
}
@@ -226,7 +227,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(SQLException.class)
public CommonResult handleSQLException(SQLException e) {
- log.error("操作数据库出现异常-------------->{}", e.getMessage());
+ log.error("操作数据库出现异常-------------->{}", getMessage(e));
return CommonResult.errorResponse("操作失败!错误提示:" + e.getMessage(), CommonResult.STATUS_ERROR);
}
@@ -236,7 +237,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(PersistenceException.class)
public CommonResult handleBatchUpdateException(PersistenceException e) {
- log.error("操作数据库出现异常-------------->{}", e.getMessage());
+ log.error("操作数据库出现异常-------------->{}", getMessage(e));
return CommonResult.errorResponse("操作失败!请检查数据是否准确!可能原因:数据重复冲突,外键冲突!", CommonResult.STATUS_ERROR);
}
@@ -246,7 +247,26 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public CommonResult handleException(Exception e) {
- log.error("系统通用异常-------------->{}", e.getMessage());
+ log.error("系统通用异常-------------->{}", getMessage(e));
return CommonResult.errorResponse("服务器异常,请稍后尝试!", CommonResult.STATUS_ERROR);
}
+
+
+ /**
+ * 打印异常信息
+ */
+ public static String getMessage(Exception e) {
+ String swStr = null;
+ try (StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw)) {
+ e.printStackTrace(pw);
+ pw.flush();
+ sw.flush();
+ swStr = sw.toString();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ log.error(ex.getMessage());
+ }
+ return swStr;
+ }
}
diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/oj/CommentController.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/oj/CommentController.java
index a40e25da..dd79b5ae 100644
--- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/oj/CommentController.java
+++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/oj/CommentController.java
@@ -1,10 +1,10 @@
package top.hcode.hoj.controller.oj;
import cn.hutool.core.map.MapUtil;
+import cn.hutool.extra.emoji.EmojiUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.github.binarywang.java.emoji.EmojiConverter;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@@ -45,7 +45,6 @@ public class CommentController {
@Autowired
private ReplyServiceImpl replyService;
- private static EmojiConverter emojiConverter = EmojiConverter.getInstance();
@GetMapping("/comments")
public CommonResult getComments(@RequestParam(value = "cid", required = false) Long cid,
@@ -113,7 +112,7 @@ public class CommentController {
}
// 带有表情的字符串转换为编码
- comment.setContent(emojiConverter.toHtml(comment.getContent()));
+ comment.setContent(EmojiUtil.toHtml(comment.getContent()));
boolean isOk = commentService.saveOrUpdate(comment);
@@ -240,7 +239,7 @@ public class CommentController {
reply.setFromRole("user");
}
// 带有表情的字符串转换为编码
- reply.setContent(emojiConverter.toHtml(reply.getContent()));
+ reply.setContent(EmojiUtil.toHtml(reply.getContent()));
boolean isOk = replyService.saveOrUpdate(reply);
diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ProblemServiceImpl.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ProblemServiceImpl.java
index 2267f6f1..eac180d2 100644
--- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ProblemServiceImpl.java
+++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ProblemServiceImpl.java
@@ -35,10 +35,7 @@ import top.hcode.hoj.utils.Constants;
import java.io.File;
import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -260,7 +257,8 @@ public class ProblemServiceImpl extends ServiceImpl impl
!oldProblemCase.getOutput().equals(problemCase.getOutput())) {
needUpdateProblemCaseList.add(problemCase);
} else if (problem.getType().intValue() == Constants.Contest.TYPE_OI.getCode()) {
- if (oldProblemCase.getScore().intValue() != problemCase.getScore()) {
+ // 分数变动
+ if (!Objects.equals(oldProblemCase.getScore(), problemCase.getScore())) {
needUpdateProblemCaseList.add(problemCase);
}
}
@@ -451,7 +449,7 @@ public class ProblemServiceImpl extends ServiceImpl impl
jsonObject.set("inputName", problemCase.getInput());
jsonObject.set("outputName", problemCase.getOutput());
// 读取输出文件
- FileReader readFile = new FileReader(testCasesDir + File.separator + problemCase.getOutput(), CharsetUtil.UTF_8);
+ FileReader readFile = new FileReader(testCasesDir + File.separator + problemCase.getOutput(), CharsetUtil.UTF_8);
String output = readFile.readString().replaceAll("\r\n", "\n");
// spj是根据特判程序输出判断结果,所以无需初始化测试数据
@@ -485,7 +483,6 @@ public class ProblemServiceImpl extends ServiceImpl impl
List problemCaseList) {
JSONObject result = new JSONObject();
- System.out.println(isSpj);
result.set("isSpj", isSpj);
result.set("version", version);
result.set("testCasesSize", problemCaseList.size());
diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ScheduleServiceImpl.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ScheduleServiceImpl.java
index 65d51d8c..ba681127 100644
--- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ScheduleServiceImpl.java
+++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/impl/ScheduleServiceImpl.java
@@ -84,7 +84,7 @@ public class ScheduleServiceImpl implements ScheduleService {
}
List idLists = new LinkedList<>();
for (File file : files) {
- if(file.getDelete()) {
+ if (file.getDelete()) {
boolean delSuccess = FileUtil.del(file.getFilePath());
if (delSuccess) {
idLists.add(file.getId());
@@ -111,8 +111,8 @@ public class ScheduleServiceImpl implements ScheduleService {
@Override
public void deleteTestCase() {
boolean result = FileUtil.del(Constants.File.TESTCASE_TMP_FOLDER.getPath());
- if (!result){
- log.error("每日定时任务异常------------------------>{}","清除本地的题目测试数据失败!");
+ if (!result) {
+ log.error("每日定时任务异常------------------------>{}", "清除本地的题目测试数据失败!");
}
}
@@ -214,7 +214,7 @@ public class ScheduleServiceImpl implements ScheduleService {
// 用户信息存放在result列表中的第0个
JSONObject cfUserInfo = resultObject.getJSONArray("result").getJSONObject(0);
// 获取cf的分数
- int cfRating = cfUserInfo.getInt("rating");
+ Integer cfRating = cfUserInfo.getInt("rating", null);
UpdateWrapper userRecordUpdateWrapper = new UpdateWrapper<>();
// 将对应的cf分数修改
userRecordUpdateWrapper.eq("uid", uuid).set("rating", cfRating);
diff --git a/hoj-vue/src/App.vue b/hoj-vue/src/App.vue
index e947a4bb..0a05570e 100644
--- a/hoj-vue/src/App.vue
+++ b/hoj-vue/src/App.vue
@@ -57,8 +57,11 @@