Skip to content

Commit

Permalink
完善小组功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Smith-Cruise committed Mar 6, 2018
1 parent c729452 commit 420a6d2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* @author Smith
Expand Down Expand Up @@ -157,7 +158,6 @@ public ResponseEntity getGroupContests(@PathVariable int gid) {
@PostMapping("/{gid}/enter")
public ResponseEntity enterGroup(@PathVariable("gid") int gid,
@RequestBody @Valid EnterGroupFormat format) {

groupUserService.joinGroup(gid, SessionHelper.get().getUid(), format.getPassword());
return new ResponseEntity("小组加入成功");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
**/
@Repository
public interface LeaderboardMapper {
List<Map<String, Object>> listOIRankByCid(@Param("cid") int cid, @Param("except") int exceptUser);
List<Map<String, Object>> listOIRankByCid(@Param("cid") int cid, @Param("gid") int groupId, @Param("except") int exceptUser);

List<Map<String, Object>> listACMRankByCid(@Param("cid") int cid, @Param("penalty") int penalty, @Param("except") int exceptUser);
List<Map<String, Object>> listACMRankByCid(@Param("cid") int cid, @Param("penalty") int penalty,@Param("gid") int groupId ,@Param("except") int exceptUser);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* @author Smith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* @author Smith
Expand Down Expand Up @@ -100,6 +101,9 @@ public void joinGroup(int gid, int uid, String password) {
GroupEntity groupEntity = groupService.getGroup(gid);
// 密码校对
if (groupEntity.getPassword() != null) {
if (password == null) {
throw new WebErrorException("密码不得为空");
}
if (! password.equals(groupEntity.getPassword())) {
throw new WebErrorException("密码错误");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void refreshContestLeaderboard(int cid) {
public List<Map<String, Object>> getContestLeaderboard(int cid) {
ContestEntity contestEntity = contestService.getContest(cid);
int type = contestEntity.getType();
int gid = contestEntity.getGroup();
boolean isACM = false;
Cache<Integer, Object> leaderboard = CacheController.getLeaderboard();
List<Map<String, Object>> list = (List<Map<String, Object>>) leaderboard.get(cid);
Expand All @@ -57,10 +58,10 @@ public List<Map<String, Object>> getContestLeaderboard(int cid) {
if (type == ContestTypeStatus.OI_CONTEST_NORMAL_TIME.getNumber()
|| type == ContestTypeStatus.OI_CONTEST_LIMIT_TIME.getNumber()) {
// OI比赛
list = leaderboardMapper.listOIRankByCid(cid, contestEntity.getOwner());
list = leaderboardMapper.listOIRankByCid(cid, gid,contestEntity.getOwner());
} else {
// ACM
list = leaderboardMapper.listACMRankByCid(cid, DefaultConfig.ACM_PENALTY_TIME, contestEntity.getOwner());
list = leaderboardMapper.listACMRankByCid(cid,DefaultConfig.ACM_PENALTY_TIME, gid,contestEntity.getOwner());
isACM = true;
}
// 存放本次生成的基本信息
Expand Down
43 changes: 32 additions & 11 deletions eagle-oj-web/src/main/resources/mapping/LeaderboardMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@
contest_user.finished_problems,
contest_user.total_score,
contest_user.total_used_time,
nickname,
avatar
<if test="gid == 0">
user.nickname
</if>
<if test="gid > 0">
group_user.group_name as nickname
</if>
FROM contest_user
LEFT JOIN user ON contest_user.uid = user.uid
<if test="gid == 0">
LEFT JOIN user ON contest_user.uid = user.uid
</if>
<if test="gid > 0">
LEFT JOIN group_user ON contest_user.uid = group_user.uid
</if>
WHERE cid = #{cid} AND contest_user.uid != #{except}
<if test="gid > 0">
AND group_user.gid=#{gid}
</if>
ORDER BY total_score DESC , total_used_time ASC
</select>

Expand All @@ -30,14 +42,23 @@
contest_user.total_used_time,
contest_user.total_wrong_times,
total_wrong_times * 60 * 1000 * #{penalty} AS penalty_time,
nickname,
avatar
FROM
contest_user
LEFT JOIN
user ON contest_user.uid = user.uid
WHERE
contest_user.cid = #{cid} AND contest_user.uid != #{except}
<if test="gid == 0">
user.nickname
</if>
<if test="gid > 0">
group_user.group_name as nickname
</if>
FROM contest_user
<if test="gid == 0">
LEFT JOIN user ON contest_user.uid = user.uid
</if>
<if test="gid > 0">
LEFT JOIN group_user ON contest_user.uid = group_user.uid
</if>
WHERE contest_user.cid = #{cid} AND contest_user.uid != #{except}
<if test="gid > 0">
AND group_user.gid=#{gid}
</if>
ORDER BY total_score DESC , (total_used_time + penalty_time) ASC
</select>
</mapper>

0 comments on commit 420a6d2

Please sign in to comment.