Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Smith-Cruise committed Feb 8, 2018
1 parent 128b309 commit 24e94c7
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 58 deletions.
50 changes: 27 additions & 23 deletions design/database.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
* @author Smith
Expand Down Expand Up @@ -87,7 +88,12 @@ public ResponseEntity getMeInfo(@PathVariable("gid") int gid,
@PathVariable("uid") int uid) {
GroupEntity groupEntity = groupService.getGroup(gid);
accessToEditOwnInfo(uid, groupEntity);
return new ResponseEntity(groupUserService.getGroupUserInfo(gid, uid));
try {
Map<String, Object> groupUser = groupUserService.getGroupUserInfo(gid, uid);
return new ResponseEntity(groupUser);
} catch (Exception e) {
return new ResponseEntity(null);
}
}

@ApiOperation("创建小组")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eagleoj.web.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.eagleoj.judge.ResultEnum;

/**
Expand All @@ -12,6 +13,9 @@ public class ContestProblemUserEntity {

private Integer uid;

@JSONField(name = "wrong_times")
private Integer wrongTimes;

private Integer score;

private ResultEnum status;
Expand Down Expand Up @@ -75,4 +79,12 @@ public Long getUsedTime() {
public void setUsedTime(Long usedTime) {
this.usedTime = usedTime;
}

public Integer getWrongTimes() {
return wrongTimes;
}

public void setWrongTimes(Integer wrongTimes) {
this.wrongTimes = wrongTimes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public class ContestUserEntity {

private Integer uid;

@JSONField(name = "total_used_time")
private Long totalUsedTime;

@JSONField(name = "total_score")
private Integer totalScore;

@JSONField(name = "total_wrong_times")
private Integer totalWrongTimes;

@JSONField(name = "submit_times")
private Integer submitTimes;

Expand Down Expand Up @@ -113,4 +122,28 @@ public Long getJoinTime() {
public void setJoinTime(Long joinTime) {
this.joinTime = joinTime;
}

public Long getTotalUsedTime() {
return totalUsedTime;
}

public void setTotalUsedTime(Long totalUsedTime) {
this.totalUsedTime = totalUsedTime;
}

public Integer getTotalScore() {
return totalScore;
}

public void setTotalScore(Integer totalScore) {
this.totalScore = totalScore;
}

public Integer getTotalWrongTimes() {
return totalWrongTimes;
}

public void setTotalWrongTimes(Integer totalWrongTimes) {
this.totalWrongTimes = totalWrongTimes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public List<Map<String, Object>> listContestProblems (int cid, int uid) {

@Override
public void saveContestProblem(int cid, int pid, int displayId, int score) {
ProblemEntity problemEntity = problemService.getProblem(cid);
WebUtil.assertNotNull(problemEntity, "题目不存在");
try {
ProblemEntity problemEntity = problemService.getProblem(pid);
} catch (Exception e) {
throw new WebErrorException("不存在此题目");
}

boolean flag = displayIdIsDuplicate(cid, displayId);
if (flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public void save(int cid, int pid, int uid, int score, ResultEnum status, long s
entity.setCid(cid);
entity.setPid(pid);
entity.setUid(uid);
if (status != ResultEnum.AC) {
entity.setWrongTimes(1);
}
entity.setScore(score);
entity.setStatus(status);
entity.setSolvedTime(solvedTimes);
Expand All @@ -55,6 +58,9 @@ public void save(int cid, int pid, int uid, int score, ResultEnum status, long s
public boolean update(int cid, int pid, int uid, int score, ResultEnum status,
long solvedTime, long usedTime) {
ContestProblemUserEntity entity = new ContestProblemUserEntity();
if (status != ResultEnum.AC) {
entity.setWrongTimes(1);
}
entity.setScore(score);
entity.setStatus(status);
entity.setSolvedTime(solvedTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ public void joinContest(int cid, int uid, String password) {
WebUtil.assertNull(contestUserEntity, "你已经加入比赛");

ContestEntity contestEntity = contestService.getContest(cid);
if (contestEntity.getStatus() != ContestStatus.USING.getNumber()) {
throw new WebErrorException("当前比赛不得加入");
if (contestEntity.getStatus() == ContestStatus.EDITING.getNumber()) {
throw new WebErrorException("当前比赛尚未开启");
}
if (contestEntity.getStatus() == ContestStatus.CLOSED.getNumber()) {
throw new WebErrorException("当前比赛已经关闭");
}
if (contestEntity.getGroup() > 0) {
// 小组赛
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void saveContestCode(ContestJudgeTask task, ResponseEntity response, int
}

updateContestProblemTimes(cid, pid, result);
updateContestUserTimes(cid, owner, result);
updateContestUserTimes(cid, owner, usedTime, score, result);
updateProblemTimes(pid, result);

if (task.getContestEntity().getOfficial() == 1) {
Expand Down Expand Up @@ -278,24 +278,30 @@ private void updateContestProblemTimes(int cid, int pid, ResultEnum result) {
contestProblemService.updateContestProblemTimes(cid, pid, contestProblemEntity);
}

private void updateContestUserTimes(int cid, int uid, ResultEnum result) {
private void updateContestUserTimes(int cid, int uid, long usedTime, int score, ResultEnum result) {
ContestUserEntity contestUserEntity = new ContestUserEntity();
contestUserEntity.setSubmitTimes(1);
switch (result) {
case AC:
contestUserEntity.setTotalUsedTime(usedTime);
contestUserEntity.setTotalScore(score);
contestUserEntity.setFinishedProblems(1);
contestUserEntity.setACTimes(1);
break;
case TLE:
contestUserEntity.setTotalWrongTimes(1);
contestUserEntity.setTLETimes(1);
break;
case RTE:
contestUserEntity.setTotalWrongTimes(1);
contestUserEntity.setRTETimes(1);
break;
case WA:
contestUserEntity.setTotalWrongTimes(1);
contestUserEntity.setWATimes(1);
break;
case CE:
contestUserEntity.setTotalWrongTimes(1);
contestUserEntity.setCETimes(1);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<insert id="save">
INSERT INTO `contest_problem_user`
(`cid`,`pid`,`uid`,`score`,`status`,`solved_time`,`used_time`)
VALUES (#{cid},#{pid}, #{uid},#{score},#{status},#{solvedTime},#{usedTime})
(`cid`,`pid`,`uid`,`wrong_times`,`score`,`status`,`solved_time`,`used_time`)
VALUES (#{cid},#{pid}, #{uid},#{wrongTimes},#{score},#{status},#{solvedTime},#{usedTime})
</insert>

<select id="getByCidPidUid" resultMap="contestProblemUserMap">
Expand Down Expand Up @@ -37,6 +37,9 @@
<update id="updateByCidPidUid">
UPDATE `contest_problem_user`
<set>
<if test="data.wrongTimes != null">
wrong_times = wrong_times + 1,
</if>
<if test="data.score != null">
score = #{data.score},
</if>
Expand All @@ -57,6 +60,7 @@
<id column="cid" property="cid"/>
<id column="pid" property="pid"/>
<id column="uid" property="uid"/>
<result column="wrong_times" property="wrongTimes"/>
<result column="score" property="score"/>
<result column="status" property="status"/>
<result column="solved_time" property="solvedTime"/>
Expand Down
12 changes: 12 additions & 0 deletions eagle-oj-web/src/main/resources/mapping/ContestUserMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
<update id="updateByCidUid">
UPDATE contest_user
<set>
<if test="data.totalUsedTime != null">
total_used_time = total_used_time + #{data.totalUsedTime},
</if>
<if test="data.totalScore != null">
total_score = total_score + #{data.totalScore},
</if>
<if test="data.totalWrongTimes != null">
total_wrong_times = total_wrong_times + #{data.totalWrongTimes},
</if>
<if test="data.submitTimes != null">
submit_times = submit_times + 1,
</if>
Expand Down Expand Up @@ -57,6 +66,9 @@
<resultMap id="contestUserMap" type="ContestUserEntity">
<id column="cid" property="cid"/>
<id column="uid" property="uid"/>
<result column="total_used_time" property="totalUsedTime"/>
<result column="total_score" property="totalScore"/>
<result column="total_wrong_times" property="totalWrongTimes"/>
<result column="submit_times" property="submitTimes"/>
<result column="finished_problems" property="finishedProblems"/>
<result column="ac_times" property="ACTimes"/>
Expand Down
42 changes: 16 additions & 26 deletions eagle-oj-web/src/main/resources/mapping/LeaderboardMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,38 @@

<select id="listOIRankByCid" resultType="HashMap">
SELECT
contest_problem_user.uid,
contest_user.uid,
contest_user.submit_times,
contest_user.ac_times,
contest_user.finished_problems,
SUM(score) AS score,
SUM(used_time) AS used_time,
contest_user.total_score,
contest_user.total_used_time,
nickname,
avatar
FROM
contest_problem_user
LEFT JOIN
user ON contest_problem_user.uid = user.uid
LEFT JOIN
contest_user ON contest_problem_user.uid = contest_user.uid
AND contest_problem_user.cid = contest_user.cid
WHERE
contest_problem_user.cid = 10
GROUP BY contest_problem_user.uid
ORDER BY score DESC , used_time ASC
FROM contest_user
LEFT JOIN user ON contest_user.uid = user.uid
WHERE cid = #{cid}
ORDER BY total_score DESC , total_used_time ASC
</select>

<select id="listACMRankByCid" resultType="HashMap">
SELECT
contest_problem_user.uid,
contest_user.uid,
contest_user.submit_times,
contest_user.ac_times,
contest_user.finished_problems,
SUM(score) AS score,
SUM(used_time) AS used_time,
(contest_user.submit_times - contest_user.ac_times) * 60 * 1000 * #{penalty} AS penalty_time,
contest_user.total_score,
contest_user.total_used_time,
contest_user.total_wrong_times,
total_wrong_times * 60 * 1000 * #{penalty} AS penalty_time,
nickname,
avatar
FROM
contest_problem_user
LEFT JOIN
user ON contest_problem_user.uid = user.uid
contest_user
LEFT JOIN
contest_user ON contest_problem_user.cid = contest_user.cid
AND contest_problem_user.uid = contest_user.uid
user ON contest_user.uid = user.uid
WHERE
contest_problem_user.cid = #{cid}
GROUP BY contest_problem_user.uid
ORDER BY score DESC , (used_time + penalty_time) ASC
contest_user.cid = #{cid}
ORDER BY total_score DESC , (total_used_time + penalty_time) ASC
</select>
</mapper>

0 comments on commit 24e94c7

Please sign in to comment.