From ed3df74af32efaa6f12591be4d7259bd82f16049 Mon Sep 17 00:00:00 2001 From: Smith Date: Mon, 12 Feb 2018 23:00:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BB=A3=E7=A0=81=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/AdminController.java | 3 +- .../web/controller/CodeController.java | 2 +- .../web/controller/ProblemUserController.java | 44 ---------- .../web/controller/ProfileController.java | 2 + .../web/controller/SubmissionsController.java | 84 ++++++++++++++++++- .../web/controller/UserLogController.java | 21 ++++- .../com/eagleoj/web/dao/ProblemMapper.java | 2 + .../com/eagleoj/web/dao/SubmissionMapper.java | 6 +- .../eagleoj/web/judger/JudgerDispatcher.java | 4 +- .../eagleoj/web/service/ProblemService.java | 2 + .../web/service/SubmissionService.java | 4 +- .../web/service/async/AsyncJudgeService.java | 3 +- .../web/service/impl/ProblemServiceImpl.java | 5 ++ .../service/impl/SubmissionServiceImpl.java | 7 +- .../impl/async/AsyncJudgeServiceImpl.java | 7 +- .../main/resources/mapping/ProblemMapper.xml | 4 + .../resources/mapping/SubmissionMapper.xml | 20 ++++- 17 files changed, 153 insertions(+), 67 deletions(-) delete mode 100644 eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProblemUserController.java diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/AdminController.java b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/AdminController.java index 0ea49a0..5265d8b 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/AdminController.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/AdminController.java @@ -42,11 +42,12 @@ public class AdminController { @RequiresRoles(value = {"8", "9"}, logical = Logical.OR) @GetMapping("/overview") public ResponseEntity getOverview() { - Map data = new HashMap<>(4); + Map data = new HashMap<>(5); data.put("contests", contestService.countContests()); data.put("users", userService.countUsers()); data.put("groups", groupService.countGroups()); data.put("problems", problemService.countProblems()); + data.put("auditing_problems", problemService.countAuditingProblems()); return new ResponseEntity(data); } } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/CodeController.java b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/CodeController.java index 3f3ea53..1448f8e 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/CodeController.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/CodeController.java @@ -71,7 +71,7 @@ public ResponseEntity submitCode(@RequestBody @Valid UserSubmitCodeFormat format int owner = SessionHelper.get().getUid(); String id; if (gid != 0 && cid != 0) { - id = asyncJudgeService.addGroupJudge(sourceCode, lang, owner, pid, cid); + id = asyncJudgeService.addGroupJudge(sourceCode, lang, owner, pid, cid, gid); } else if (cid != 0) { id = asyncJudgeService.addContestJudge(sourceCode, lang, owner, pid, cid); } else { diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProblemUserController.java b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProblemUserController.java deleted file mode 100644 index 64cb8af..0000000 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProblemUserController.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.eagleoj.web.controller; - -import com.eagleoj.web.entity.ResponseEntity; -import com.eagleoj.web.service.ProblemUserService; -import com.eagleoj.web.util.WebUtil; -import com.github.pagehelper.Page; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageRowBounds; -import io.swagger.annotations.ApiOperation; -import com.eagleoj.web.entity.ResponseEntity; -import com.eagleoj.web.service.ProblemUserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Smith - **/ -@RestController -@Validated -@RequestMapping(value = "/problem_user", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) -public class ProblemUserController { - - @Autowired - private ProblemUserService problemUserService; - - @ApiOperation("获取最近10条用户做题记录") - @GetMapping - public ResponseEntity getProblemUser(@RequestParam("uid") int uid, - @RequestParam("page") int page, - @RequestParam("page_size") int pageSize) { - Page pager = PageHelper.startPage(page, pageSize); - List> list = problemUserService.listUserProblemHistory(uid); - return new ResponseEntity(WebUtil.generatePageData(pager, list)); - } -} diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProfileController.java b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProfileController.java index ae42892..fcea7eb 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProfileController.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/ProfileController.java @@ -35,6 +35,8 @@ public ResponseEntity getProfile(@PathVariable int uid) { UserEntity userEntity = userService.getUserByUid(uid); userEntity.setPassword(null); userEntity.setEmail(null); + userEntity.setRole(null); + userEntity.setPermission(null); return new ResponseEntity(userEntity); } } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/SubmissionsController.java b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/SubmissionsController.java index d34d244..f51e5d6 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/SubmissionsController.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/SubmissionsController.java @@ -1,13 +1,18 @@ package com.eagleoj.web.controller; +import com.eagleoj.judge.ResultEnum; +import com.eagleoj.web.data.status.RoleStatus; +import com.eagleoj.web.entity.ContestEntity; +import com.eagleoj.web.entity.ProblemEntity; +import com.eagleoj.web.service.*; import com.eagleoj.web.util.WebUtil; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.swagger.annotations.ApiOperation; +import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresAuthentication; import com.eagleoj.web.entity.ResponseEntity; import com.eagleoj.web.security.SessionHelper; -import com.eagleoj.web.service.SubmissionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; @@ -30,16 +35,87 @@ public class SubmissionsController { @Autowired private SubmissionService submissionService; + @Autowired + private ProblemUserService problemUserService; + + @Autowired + private ProblemService problemService; + + @Autowired + private ContestProblemUserService contestProblemUserService; + + @Autowired + private ContestService contestService; + @ApiOperation("获取用户的代码记录") @RequiresAuthentication @GetMapping - public ResponseEntity getUserSubmissions(@RequestParam("cid") int cid, - @RequestParam("pid") int pid, + public ResponseEntity getUserSubmissions(@RequestParam("pid") int pid, + @RequestParam("cid") Integer cid, @RequestParam("page") int page, @RequestParam("page_size") int pageSize) { Page pager = PageHelper.startPage(page, pageSize); int owner = SessionHelper.get().getUid(); + if (cid == 0) { + cid = null; + } return new ResponseEntity(WebUtil.generatePageData(pager, - submissionService.listSubmissions(owner, pid, cid))); + submissionService.listOwnSubmissions(owner, pid, cid))); + } + + @ApiOperation("获取本题的所有代码") + @RequiresAuthentication + @GetMapping("/all") + public ResponseEntity getProblemSubmissions(@RequestParam("pid") int pid, + @RequestParam("cid") int cid, + @RequestParam("page") int page, + @RequestParam("page_size") int pageSize) { + int uid = SessionHelper.get().getUid(); + int role = SessionHelper.get().getRole(); + ProblemEntity problemEntity = problemService.getProblem(pid); + + if (cid != 0) { + ContestEntity contestEntity = contestService.getContest(cid); + // 比赛管理者可以查看当前比赛此题的提交 + if (contestEntity.getOwner() == uid) { + return returnAllSubmissions(pid, cid, page, pageSize); + } + + // admin + if (role == RoleStatus.ADMIN.getNumber() || role == RoleStatus.ROOT.getNumber()) { + return returnAllSubmissions(pid, cid, page, pageSize); + } + + // AC + try { + if (contestProblemUserService.getByCidPidUid(cid, pid, uid).getStatus() == ResultEnum.AC) { + return returnAllSubmissions(pid, cid, page, pageSize); + } + } catch (Exception e) { } + } else { + // 出题者可以直接看 + if (problemEntity.getOwner() == uid) { + return returnAllSubmissions(pid, 0, page, pageSize); + } + + // admin + if (role == RoleStatus.ADMIN.getNumber() || role == RoleStatus.ROOT.getNumber()) { + return returnAllSubmissions(pid, 0, page, pageSize); + } + + // AC + try { + if (problemUserService.get(pid, uid).getStatus() == ResultEnum.AC) { + return returnAllSubmissions(pid, 0, page, pageSize); + } + } catch (Exception e) {} + } + + return new ResponseEntity("你暂时没有资格查看", null); + } + + private ResponseEntity returnAllSubmissions(int pid, int cid, int page, int pageSize) { + Page pager = PageHelper.startPage(page, pageSize); + return new ResponseEntity(WebUtil.generatePageData(pager, submissionService.listProblemSubmissions(pid, cid))); } } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/UserLogController.java b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/UserLogController.java index 9569490..8efe076 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/controller/UserLogController.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/controller/UserLogController.java @@ -2,6 +2,10 @@ import com.eagleoj.web.controller.exception.WebErrorException; import com.eagleoj.web.entity.ResponseEntity; +import com.eagleoj.web.service.ProblemUserService; +import com.eagleoj.web.util.WebUtil; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.swagger.annotations.ApiOperation; import com.eagleoj.web.entity.UserLogEntity; import com.eagleoj.web.service.UserLogService; @@ -25,8 +29,11 @@ public class UserLogController { @Autowired private UserLogService userLogService; - @ApiOperation("获取用户近期记录") - @GetMapping + @Autowired + private ProblemUserService problemUserService; + + @ApiOperation("获取用户敲代码近期记录") + @GetMapping("coding_frequency") public ResponseEntity getUserLog(@RequestParam("uid") int uid, @RequestParam("time") String time) { List tempList; @@ -66,4 +73,14 @@ public ResponseEntity getUserLog(@RequestParam("uid") int uid, } return new ResponseEntity(finalList); } + + @ApiOperation("获取最近用户做题记录") + @GetMapping("problem_history") + public ResponseEntity getProblemUser(@RequestParam("uid") int uid, + @RequestParam("page") int page, + @RequestParam("page_size") int pageSize) { + Page pager = PageHelper.startPage(page, pageSize); + List> list = problemUserService.listUserProblemHistory(uid); + return new ResponseEntity(WebUtil.generatePageData(pager, list)); + } } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/dao/ProblemMapper.java b/eagle-oj-web/src/main/java/com/eagleoj/web/dao/ProblemMapper.java index a63dbe8..4f17934 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/dao/ProblemMapper.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/dao/ProblemMapper.java @@ -18,6 +18,8 @@ public interface ProblemMapper { int count(); + int countAuditing(); + int getRandomPid(); ProblemEntity getByPid(int pid); diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/dao/SubmissionMapper.java b/eagle-oj-web/src/main/java/com/eagleoj/web/dao/SubmissionMapper.java index 25e4055..4b32f29 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/dao/SubmissionMapper.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/dao/SubmissionMapper.java @@ -17,7 +17,7 @@ public interface SubmissionMapper { int countByPid(int pid); - List> listSubmissionsByOwnerPidCid(@Param("owner") int owner, - @Param("pid") int pid, - @Param("cid") int cid); + List> listSubmissionsByOwnerPidCid(@Param("owner") Integer owner, + @Param("pid") Integer pid, + @Param("cid") Integer cid); } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/judger/JudgerDispatcher.java b/eagle-oj-web/src/main/java/com/eagleoj/web/judger/JudgerDispatcher.java index 808c56e..e5c68ad 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/judger/JudgerDispatcher.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/judger/JudgerDispatcher.java @@ -14,11 +14,11 @@ @Service public class JudgerDispatcher { - private List judgerList; - @Autowired private JudgerService judgerService; + private List judgerList; + public void refresh() { judgerList = judgerService.listJudger(); } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/service/ProblemService.java b/eagle-oj-web/src/main/java/com/eagleoj/web/service/ProblemService.java index ecd663a..8c9f6a5 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/service/ProblemService.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/service/ProblemService.java @@ -17,6 +17,8 @@ int save(JSONArray tags, int owner, String title, JSONObject description, JSONOb int countProblems(); + int countAuditingProblems(); + int getRandomPid(); void deleteProblem(int pid); diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/service/SubmissionService.java b/eagle-oj-web/src/main/java/com/eagleoj/web/service/SubmissionService.java index 0c1f583..3bf513c 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/service/SubmissionService.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/service/SubmissionService.java @@ -16,5 +16,7 @@ void save(int owner, int pid, int cid, int gid, int sourceCode, LanguageEnum lan int countProblemSubmissions(int pid); - List> listSubmissions(int owner, int pid, int cid); + List> listOwnSubmissions(Integer owner, Integer pid, Integer cid); + + List> listProblemSubmissions(Integer pid, Integer cid); } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/service/async/AsyncJudgeService.java b/eagle-oj-web/src/main/java/com/eagleoj/web/service/async/AsyncJudgeService.java index f6a760f..011b2db 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/service/async/AsyncJudgeService.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/service/async/AsyncJudgeService.java @@ -22,5 +22,6 @@ String addContestJudge(String sourceCode, LanguageEnum lang, String addGroupJudge(String sourceCode, LanguageEnum lang, int owner, int pid, - int cid); + int cid, + int gid); } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/ProblemServiceImpl.java b/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/ProblemServiceImpl.java index fabb7c2..bfa7dfe 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/ProblemServiceImpl.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/ProblemServiceImpl.java @@ -97,6 +97,11 @@ public int countProblems() { return problemMapper.count(); } + @Override + public int countAuditingProblems() { + return problemMapper.countAuditing(); + } + @Override public int getRandomPid() { return problemMapper.getRandomPid(); diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/SubmissionServiceImpl.java b/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/SubmissionServiceImpl.java index 4136289..2dd8f4c 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/SubmissionServiceImpl.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/SubmissionServiceImpl.java @@ -47,7 +47,12 @@ public int countProblemSubmissions(int pid) { } @Override - public List> listSubmissions(int owner, int pid, int cid) { + public List> listOwnSubmissions(Integer owner, Integer pid, Integer cid) { return submissionMapper.listSubmissionsByOwnerPidCid(owner, pid, cid); } + + @Override + public List> listProblemSubmissions(Integer pid, Integer cid) { + return submissionMapper.listSubmissionsByOwnerPidCid(null, pid, cid); + } } diff --git a/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/async/AsyncJudgeServiceImpl.java b/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/async/AsyncJudgeServiceImpl.java index f054dab..87c29f7 100644 --- a/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/async/AsyncJudgeServiceImpl.java +++ b/eagle-oj-web/src/main/java/com/eagleoj/web/service/impl/async/AsyncJudgeServiceImpl.java @@ -120,7 +120,8 @@ public String addContestJudge(String sourceCode, LanguageEnum lang, @Override public String addGroupJudge(String sourceCode, LanguageEnum lang, int owner, int pid, - int cid) { + int cid, + int gid) { ProblemEntity problemEntity = problemService.getProblem(pid); containLang(lang, problemEntity); ContestEntity contestEntity = contestService.getContest(cid); @@ -134,8 +135,8 @@ public String addGroupJudge(String sourceCode, LanguageEnum lang, ContestProblemEntity contestProblemEntity = contestProblemService.getContestProblem(cid, pid); // 检查是否为小组比赛 - int gid = contestEntity.getGroup(); - if (gid == 0) { + int tempGid = contestEntity.getGroup(); + if (tempGid != gid) { throw new WebErrorException("本场比赛不属于该小组"); } // 检查用户是否在小组中 diff --git a/eagle-oj-web/src/main/resources/mapping/ProblemMapper.xml b/eagle-oj-web/src/main/resources/mapping/ProblemMapper.xml index 3c36160..b0b9dce 100644 --- a/eagle-oj-web/src/main/resources/mapping/ProblemMapper.xml +++ b/eagle-oj-web/src/main/resources/mapping/ProblemMapper.xml @@ -14,6 +14,10 @@ SELECT count(*) FROM problem + +