Skip to content

Commit

Permalink
完善代码查看机制
Browse files Browse the repository at this point in the history
  • Loading branch information
Smith-Cruise committed Feb 12, 2018
1 parent 24e94c7 commit ed3df74
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public class AdminController {
@RequiresRoles(value = {"8", "9"}, logical = Logical.OR)
@GetMapping("/overview")
public ResponseEntity getOverview() {
Map<String, Integer> data = new HashMap<>(4);
Map<String, Integer> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<UserLogEntity> tempList;
Expand Down Expand Up @@ -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<Map<String, Object>> list = problemUserService.listUserProblemHistory(uid);
return new ResponseEntity(WebUtil.generatePageData(pager, list));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface ProblemMapper {

int count();

int countAuditing();

int getRandomPid();

ProblemEntity getByPid(int pid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface SubmissionMapper {

int countByPid(int pid);

List<Map<String, Object>> listSubmissionsByOwnerPidCid(@Param("owner") int owner,
@Param("pid") int pid,
@Param("cid") int cid);
List<Map<String, Object>> listSubmissionsByOwnerPidCid(@Param("owner") Integer owner,
@Param("pid") Integer pid,
@Param("cid") Integer cid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
@Service
public class JudgerDispatcher {

private List<JudgerEntity> judgerList;

@Autowired
private JudgerService judgerService;

private List<JudgerEntity> judgerList;

public void refresh() {
judgerList = judgerService.listJudger();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ void save(int owner, int pid, int cid, int gid, int sourceCode, LanguageEnum lan

int countProblemSubmissions(int pid);

List<Map<String, Object>> listSubmissions(int owner, int pid, int cid);
List<Map<String, Object>> listOwnSubmissions(Integer owner, Integer pid, Integer cid);

List<Map<String, Object>> listProblemSubmissions(Integer pid, Integer cid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public int countProblems() {
return problemMapper.count();
}

@Override
public int countAuditingProblems() {
return problemMapper.countAuditing();
}

@Override
public int getRandomPid() {
return problemMapper.getRandomPid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public int countProblemSubmissions(int pid) {
}

@Override
public List<Map<String, Object>> listSubmissions(int owner, int pid, int cid) {
public List<Map<String, Object>> listOwnSubmissions(Integer owner, Integer pid, Integer cid) {
return submissionMapper.listSubmissionsByOwnerPidCid(owner, pid, cid);
}

@Override
public List<Map<String, Object>> listProblemSubmissions(Integer pid, Integer cid) {
return submissionMapper.listSubmissionsByOwnerPidCid(null, pid, cid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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("本场比赛不属于该小组");
}
// 检查用户是否在小组中
Expand Down
4 changes: 4 additions & 0 deletions eagle-oj-web/src/main/resources/mapping/ProblemMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
SELECT count(*) FROM problem
</select>

<select id="countAuditing" resultType="Integer">
SELECT count(*) FROM problem WHERE status=1
</select>

<select id="getRandomPid" resultType="Integer">
SELECT problem.pid FROM problem
WHERE problem.status=2
Expand Down
20 changes: 16 additions & 4 deletions eagle-oj-web/src/main/resources/mapping/SubmissionMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@
</select>

<select id="listSubmissionsByOwnerPidCid" resultType="HashMap">
SELECT * FROM submission LEFT JOIN attachment ON submission.source_code=attachment.aid
WHERE submission.owner=#{owner} AND pid=#{pid}
<if test="cid != 0">
AND cid=#{cid}
SELECT submission.*, attachment.url
<if test="owner == null">
, user.nickname
</if>
FROM submission
LEFT JOIN attachment ON submission.source_code=attachment.aid
<if test="owner == null">
LEFT JOIN user on submission.owner=user.uid
</if>
WHERE pid=#{pid}
<if test="owner != null">
AND submission.owner = #{owner}
</if>
<if test="cid != null">
AND cid = #{cid}
</if>

ORDER BY submit_time DESC
</select>

Expand Down

0 comments on commit ed3df74

Please sign in to comment.