use of top.hcode.hoj.pojo.entity.user.UserInfo in project HOJ by HimitZH.
the class AdminUserController method editUser.
@PutMapping("/edit-user")
@RequiresPermissions("user_admin")
@RequiresAuthentication
@Transactional(rollbackFor = Exception.class)
public CommonResult editUser(@RequestBody Map<String, Object> params, HttpServletRequest request) {
String username = (String) params.get("username");
String uid = (String) params.get("uid");
String realname = (String) params.get("realname");
String email = (String) params.get("email");
String password = (String) params.get("password");
int type = (int) params.get("type");
int status = (int) params.get("status");
boolean setNewPwd = (boolean) params.get("setNewPwd");
UpdateWrapper<UserInfo> updateWrapper1 = new UpdateWrapper<>();
updateWrapper1.eq("uuid", uid).set("username", username).set("realname", realname).set("email", email).set(setNewPwd, "password", SecureUtil.md5(password)).set("status", status);
boolean result1 = userInfoService.update(updateWrapper1);
QueryWrapper<UserRole> userRoleQueryWrapper = new QueryWrapper<>();
userRoleQueryWrapper.eq("uid", uid);
UserRole userRole = userRoleService.getOne(userRoleQueryWrapper, false);
boolean result2 = false;
int oldType = userRole.getRoleId().intValue();
if (userRole.getRoleId().intValue() != type) {
userRole.setRoleId(Long.valueOf(type));
result2 = userRoleService.updateById(userRole);
}
if (result1) {
// 需要重新登录
userRoleService.deleteCache(uid, true);
} else if (result2) {
// 需要重新授权
userRoleService.deleteCache(uid, false);
}
if (result2) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
String title = "权限变更通知(Authority Change Notice)";
String content = userRoleService.getAuthChangeContent(oldType, type);
adminSysNoticeService.addSingleNoticeToUser(userRolesVo.getUid(), uid, title, content, "Sys");
}
return CommonResult.successResponse(null, "修改成功!");
}
use of top.hcode.hoj.pojo.entity.user.UserInfo in project HOJ by HimitZH.
the class RankController method getRankList.
/**
* @MethodName get-rank-list
* @Params * @param null
* @Description 获取排行榜数据
* @Return CommonResult
* @Since 2020/10/27
*/
@GetMapping("/get-rank-list")
public CommonResult getRankList(@RequestParam(value = "limit", required = false) Integer limit, @RequestParam(value = "currentPage", required = false) Integer currentPage, @RequestParam(value = "searchUser", required = false) String searchUser, @RequestParam(value = "type", required = true) Integer type) {
// 页数,每页题数若为空,设置默认值
if (currentPage == null || currentPage < 1)
currentPage = 1;
if (limit == null || limit < 1)
limit = 30;
List<String> uidList = null;
if (!StringUtils.isEmpty(searchUser)) {
QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();
userInfoQueryWrapper.and(wrapper -> wrapper.like("username", searchUser).or().like("nickname", searchUser).or().like("realname", searchUser));
userInfoQueryWrapper.eq("status", 0);
uidList = userInfoService.list(userInfoQueryWrapper).stream().map(UserInfo::getUuid).collect(Collectors.toList());
}
IPage rankList = null;
// 根据type查询不同类型的排行榜
if (type.intValue() == Constants.Contest.TYPE_ACM.getCode()) {
rankList = userRecordService.getACMRankList(limit, currentPage, uidList);
} else if (type.intValue() == Constants.Contest.TYPE_OI.getCode()) {
rankList = userRecordService.getOIRankList(limit, currentPage, uidList);
} else {
return CommonResult.errorResponse("比赛类型代码不正确!");
}
if (rankList != null && rankList.getTotal() == 0) {
return CommonResult.successResponse(rankList, "暂无数据");
} else {
return CommonResult.successResponse(rankList, "获取成功");
}
}
use of top.hcode.hoj.pojo.entity.user.UserInfo in project HOJ by HimitZH.
the class ContestRecordServiceImpl method getACInfo.
@Override
public IPage<ContestRecord> getACInfo(Integer currentPage, Integer limit, Integer status, Long cid, String contestCreatorId) {
List<ContestRecord> acInfo = contestRecordMapper.getACInfo(status, cid);
HashMap<Long, String> pidMapUidAndPid = new HashMap<>(12);
HashMap<String, Long> UidAndPidMapTime = new HashMap<>(12);
List<UserInfo> superAdminList = getSuperAdminList();
List<String> superAdminUidList = superAdminList.stream().map(UserInfo::getUuid).collect(Collectors.toList());
List<ContestRecord> userACInfo = new LinkedList<>();
for (ContestRecord contestRecord : acInfo) {
if (contestRecord.getUid().equals(contestCreatorId) || superAdminUidList.contains(contestRecord.getUid())) {
// 超级管理员和比赛创建者的提交跳过
continue;
}
contestRecord.setFirstBlood(false);
String uidAndPid = pidMapUidAndPid.get(contestRecord.getPid());
if (uidAndPid == null) {
pidMapUidAndPid.put(contestRecord.getPid(), contestRecord.getUid() + contestRecord.getPid());
UidAndPidMapTime.put(contestRecord.getUid() + contestRecord.getPid(), contestRecord.getTime());
} else {
Long firstTime = UidAndPidMapTime.get(uidAndPid);
Long tmpTime = contestRecord.getTime();
if (tmpTime < firstTime) {
pidMapUidAndPid.put(contestRecord.getPid(), contestRecord.getUid() + contestRecord.getPid());
UidAndPidMapTime.put(contestRecord.getUid() + contestRecord.getPid(), tmpTime);
}
}
userACInfo.add(contestRecord);
}
List<ContestRecord> pageList = new ArrayList<>();
int count = userACInfo.size();
// 计算当前页第一条数据的下标
int currId = currentPage > 1 ? (currentPage - 1) * limit : 0;
for (int i = 0; i < limit && i < count - currId; i++) {
ContestRecord contestRecord = userACInfo.get(currId + i);
if (pidMapUidAndPid.get(contestRecord.getPid()).equals(contestRecord.getUid() + contestRecord.getPid())) {
contestRecord.setFirstBlood(true);
}
pageList.add(contestRecord);
}
Page<ContestRecord> page = new Page<>(currentPage, limit);
page.setSize(limit);
page.setCurrent(currentPage);
page.setTotal(count);
page.setRecords(pageList);
return page;
}
use of top.hcode.hoj.pojo.entity.user.UserInfo in project HOJ by HimitZH.
the class ContestRecordServiceImpl method calcACMRank.
/**
* @param isOpenSealRank 是否是查询封榜后的数据
* @param removeStar 是否需要移除打星队伍
* @param contest 比赛实体信息
* @param contestRecordList 比赛记录数据
* @param currentUserId 当前查看榜单的用户uuid,不为空则将该数据复制一份放置列表最前
* @param concernedList 关注的用户(uuid)列表
* @MethodName calcACMRank
* @Description TODO
* @Return
* @Since 2021/12/10
*/
public List<ACMContestRankVo> calcACMRank(boolean isOpenSealRank, boolean removeStar, Contest contest, List<ContestRecordVo> contestRecordList, String currentUserId, List<String> concernedList) {
List<UserInfo> superAdminList = getSuperAdminList();
List<String> superAdminUidList = superAdminList.stream().map(UserInfo::getUuid).collect(Collectors.toList());
List<ACMContestRankVo> result = new ArrayList<>();
HashMap<String, Integer> uidMapIndex = new HashMap<>();
int index = 0;
HashMap<String, Long> firstACMap = new HashMap<>();
for (ContestRecordVo contestRecord : contestRecordList) {
if (superAdminUidList.contains(contestRecord.getUid())) {
// 超级管理员的提交不入排行榜
continue;
}
ACMContestRankVo ACMContestRankVo;
if (!uidMapIndex.containsKey(contestRecord.getUid())) {
// 如果该用户信息没还记录
// 初始化参数
ACMContestRankVo = new ACMContestRankVo();
ACMContestRankVo.setRealname(contestRecord.getRealname()).setAvatar(contestRecord.getAvatar()).setSchool(contestRecord.getSchool()).setGender(contestRecord.getGender()).setUid(contestRecord.getUid()).setUsername(contestRecord.getUsername()).setNickname(contestRecord.getNickname()).setAc(0).setTotalTime(0L).setTotal(0);
HashMap<String, HashMap<String, Object>> submissionInfo = new HashMap<>();
ACMContestRankVo.setSubmissionInfo(submissionInfo);
result.add(ACMContestRankVo);
uidMapIndex.put(contestRecord.getUid(), index);
index++;
} else {
// 根据记录的index进行获取
ACMContestRankVo = result.get(uidMapIndex.get(contestRecord.getUid()));
}
HashMap<String, Object> problemSubmissionInfo = ACMContestRankVo.getSubmissionInfo().get(contestRecord.getDisplayId());
if (problemSubmissionInfo == null) {
problemSubmissionInfo = new HashMap<>();
problemSubmissionInfo.put("errorNum", 0);
}
ACMContestRankVo.setTotal(ACMContestRankVo.getTotal() + 1);
// 如果是当前是开启封榜的时段和同时该提交是处于封榜时段 尝试次数+1
if (isOpenSealRank && isInSealTimeSubmission(contest, contestRecord.getSubmitTime())) {
int tryNum = (int) problemSubmissionInfo.getOrDefault("tryNum", 0);
problemSubmissionInfo.put("tryNum", tryNum + 1);
} else {
// 如果该题目已经AC过了,其它都不记录了
if ((Boolean) problemSubmissionInfo.getOrDefault("isAC", false)) {
continue;
}
// 通过的话
if (contestRecord.getStatus().intValue() == Constants.Contest.RECORD_AC.getCode()) {
// 总解决题目次数ac+1
ACMContestRankVo.setAc(ACMContestRankVo.getAc() + 1);
// 判断是不是first AC
boolean isFirstAC = false;
Long time = firstACMap.getOrDefault(contestRecord.getDisplayId(), null);
if (time == null) {
isFirstAC = true;
firstACMap.put(contestRecord.getDisplayId(), contestRecord.getTime());
} else {
// 相同提交时间也是first AC
if (time.longValue() == contestRecord.getTime().longValue()) {
isFirstAC = true;
}
}
int errorNumber = (int) problemSubmissionInfo.getOrDefault("errorNum", 0);
problemSubmissionInfo.put("isAC", true);
problemSubmissionInfo.put("isFirstAC", isFirstAC);
problemSubmissionInfo.put("ACTime", contestRecord.getTime());
problemSubmissionInfo.put("errorNum", errorNumber);
// 同时计算总耗时,总耗时加上 该题目未AC前的错误次数*20*60+题目AC耗时
ACMContestRankVo.setTotalTime(ACMContestRankVo.getTotalTime() + errorNumber * 20 * 60 + contestRecord.getTime());
// 未通过同时需要记录罚时次数
} else if (contestRecord.getStatus().intValue() == Constants.Contest.RECORD_NOT_AC_PENALTY.getCode()) {
int errorNumber = (int) problemSubmissionInfo.getOrDefault("errorNum", 0);
problemSubmissionInfo.put("errorNum", errorNumber + 1);
} else {
int errorNumber = (int) problemSubmissionInfo.getOrDefault("errorNum", 0);
problemSubmissionInfo.put("errorNum", errorNumber);
}
}
ACMContestRankVo.getSubmissionInfo().put(contestRecord.getDisplayId(), problemSubmissionInfo);
}
List<ACMContestRankVo> orderResultList = result.stream().sorted(// 先以总ac数降序
Comparator.comparing(ACMContestRankVo::getAc, Comparator.reverseOrder()).thenComparing(// 再以总耗时升序
ACMContestRankVo::getTotalTime)).collect(Collectors.toList());
// 需要打星的用户名列表
HashMap<String, Boolean> starAccountMap = starAccountToMap(contest.getStarAccount());
// 如果选择了移除打星队伍,同时该用户属于打星队伍,则将其移除
if (removeStar) {
orderResultList.removeIf(acmContestRankVo -> starAccountMap.containsKey(acmContestRankVo.getUsername()));
}
// 记录当前用户排名数据和关注列表的用户排名数据
List<ACMContestRankVo> topACMRankVoList = new ArrayList<>();
boolean needAddConcernedUser = false;
if (!CollectionUtils.isEmpty(concernedList)) {
needAddConcernedUser = true;
// 移除关注列表与当前用户重复
concernedList.remove(currentUserId);
}
int rankNum = 1;
int len = orderResultList.size();
ACMContestRankVo lastACMRankVo = null;
for (int i = 0; i < len; i++) {
ACMContestRankVo currentACMRankVo = orderResultList.get(i);
if (starAccountMap.containsKey(currentACMRankVo.getUsername())) {
// 打星队伍排名为-1
currentACMRankVo.setRank(-1);
} else {
if (rankNum == 1) {
currentACMRankVo.setRank(rankNum);
} else {
// 当前用户的总罚时和AC数跟前一个用户一样的话,同时前一个不应该为打星,排名则一样
if (lastACMRankVo.getAc().equals(currentACMRankVo.getAc()) && lastACMRankVo.getTotalTime().equals(currentACMRankVo.getTotalTime())) {
currentACMRankVo.setRank(lastACMRankVo.getRank());
} else {
currentACMRankVo.setRank(rankNum);
}
}
lastACMRankVo = currentACMRankVo;
rankNum++;
}
if (!StringUtils.isEmpty(currentUserId) && currentACMRankVo.getUid().equals(currentUserId)) {
topACMRankVoList.add(currentACMRankVo);
}
// 需要添加关注用户
if (needAddConcernedUser) {
if (concernedList.contains(currentACMRankVo.getUid())) {
topACMRankVoList.add(currentACMRankVo);
}
}
}
topACMRankVoList.addAll(orderResultList);
return topACMRankVoList;
}
use of top.hcode.hoj.pojo.entity.user.UserInfo in project HOJ by HimitZH.
the class ContestRecordServiceImpl method calcOIRank.
/**
* @param removeStar 是否需要移除打星队伍
* @param contest 比赛实体信息
* @param oiContestRecord 比赛记录数据
* @param currentUserId 当前查看榜单的用户uuid,不为空则将该数据复制一份放置列表最前
* @param concernedList 关注的用户(uuid)列表
* @MethodName calcOIRank
* @Description TODO
* @Return
* @Since 2021/12/10
*/
public List<OIContestRankVo> calcOIRank(List<ContestRecordVo> oiContestRecord, Contest contest, Boolean removeStar, String currentUserId, List<String> concernedList) {
List<UserInfo> superAdminList = getSuperAdminList();
List<String> superAdminUidList = superAdminList.stream().map(UserInfo::getUuid).collect(Collectors.toList());
List<OIContestRankVo> result = new ArrayList<>();
HashMap<String, Integer> uidMapIndex = new HashMap<>();
HashMap<String, HashMap<String, Integer>> uidMapTime = new HashMap<>();
boolean isHighestRankScore = Constants.Contest.OI_RANK_HIGHEST_SCORE.getName().equals(contest.getOiRankScoreType());
int index = 0;
for (ContestRecordVo contestRecord : oiContestRecord) {
if (superAdminUidList.contains(contestRecord.getUid())) {
// 超级管理员的提交不入排行榜
continue;
}
if (contestRecord.getStatus().equals(Constants.Contest.RECORD_AC.getCode())) {
// AC
HashMap<String, Integer> pidMapTime = uidMapTime.get(contestRecord.getUid());
if (pidMapTime != null) {
Integer useTime = pidMapTime.get(contestRecord.getDisplayId());
if (useTime != null) {
if (useTime > contestRecord.getUseTime()) {
// 如果时间消耗比原来的少
pidMapTime.put(contestRecord.getDisplayId(), contestRecord.getUseTime());
}
} else {
pidMapTime.put(contestRecord.getDisplayId(), contestRecord.getUseTime());
}
} else {
HashMap<String, Integer> tmp = new HashMap<>();
tmp.put(contestRecord.getDisplayId(), contestRecord.getUseTime());
uidMapTime.put(contestRecord.getUid(), tmp);
}
}
OIContestRankVo oiContestRankVo;
if (!uidMapIndex.containsKey(contestRecord.getUid())) {
// 如果该用户信息没还记录
// 初始化参数
oiContestRankVo = new OIContestRankVo();
oiContestRankVo.setRealname(contestRecord.getRealname()).setUid(contestRecord.getUid()).setUsername(contestRecord.getUsername()).setSchool(contestRecord.getSchool()).setAvatar(contestRecord.getAvatar()).setGender(contestRecord.getGender()).setNickname(contestRecord.getNickname()).setTotalScore(0);
HashMap<String, Integer> submissionInfo = new HashMap<>();
oiContestRankVo.setSubmissionInfo(submissionInfo);
result.add(oiContestRankVo);
uidMapIndex.put(contestRecord.getUid(), index);
index++;
} else {
// 根据记录的index进行获取
oiContestRankVo = result.get(uidMapIndex.get(contestRecord.getUid()));
}
// 记录总分
HashMap<String, Integer> submissionInfo = oiContestRankVo.getSubmissionInfo();
Integer score = submissionInfo.get(contestRecord.getDisplayId());
if (isHighestRankScore) {
if (score == null) {
oiContestRankVo.setTotalScore(oiContestRankVo.getTotalScore() + contestRecord.getScore());
submissionInfo.put(contestRecord.getDisplayId(), contestRecord.getScore());
}
} else {
if (contestRecord.getScore() != null) {
if (score != null) {
// 为了避免同个提交时间的重复计算
oiContestRankVo.setTotalScore(oiContestRankVo.getTotalScore() - score + contestRecord.getScore());
} else {
oiContestRankVo.setTotalScore(oiContestRankVo.getTotalScore() + contestRecord.getScore());
}
}
submissionInfo.put(contestRecord.getDisplayId(), contestRecord.getScore());
}
}
for (OIContestRankVo oiContestRankVo : result) {
HashMap<String, Integer> pidMapTime = uidMapTime.get(oiContestRankVo.getUid());
int sumTime = 0;
if (pidMapTime != null) {
for (String key : pidMapTime.keySet()) {
Integer time = pidMapTime.get(key);
sumTime += time == null ? 0 : time;
}
}
oiContestRankVo.setTotalTime(sumTime);
oiContestRankVo.setTimeInfo(pidMapTime);
}
// 根据总得分进行降序,再根据总时耗升序排序
List<OIContestRankVo> orderResultList = result.stream().sorted(Comparator.comparing(OIContestRankVo::getTotalScore, Comparator.reverseOrder()).thenComparing(OIContestRankVo::getTotalTime, Comparator.naturalOrder())).collect(Collectors.toList());
// 需要打星的用户名列表
HashMap<String, Boolean> starAccountMap = starAccountToMap(contest.getStarAccount());
// 如果选择了移除打星队伍,同时该用户属于打星队伍,则将其移除
if (removeStar) {
orderResultList.removeIf(acmContestRankVo -> starAccountMap.containsKey(acmContestRankVo.getUsername()));
}
// 记录当前用户排名数据和关注列表的用户排名数据
List<OIContestRankVo> topOIRankVoList = new ArrayList<>();
boolean needAddConcernedUser = false;
if (!CollectionUtils.isEmpty(concernedList)) {
needAddConcernedUser = true;
// 移除关注列表与当前用户重复
concernedList.remove(currentUserId);
}
int rankNum = 1;
OIContestRankVo lastOIRankVo = null;
int len = orderResultList.size();
for (int i = 0; i < len; i++) {
OIContestRankVo currentOIRankVo = orderResultList.get(i);
if (starAccountMap.containsKey(currentOIRankVo.getUsername())) {
// 打星队伍排名为-1
currentOIRankVo.setRank(-1);
} else {
if (rankNum == 1) {
currentOIRankVo.setRank(rankNum);
} else {
// 当前用户的程序总运行时间和总得分跟前一个用户一样的话,同时前一个不应该为打星用户,排名则一样
if (lastOIRankVo.getTotalScore().equals(currentOIRankVo.getTotalScore()) && lastOIRankVo.getTotalTime().equals(currentOIRankVo.getTotalTime())) {
currentOIRankVo.setRank(lastOIRankVo.getRank());
} else {
currentOIRankVo.setRank(rankNum);
}
}
lastOIRankVo = currentOIRankVo;
rankNum++;
}
if (!StringUtils.isEmpty(currentUserId) && currentOIRankVo.getUid().equals(currentUserId)) {
topOIRankVoList.add(currentOIRankVo);
}
// 需要添加关注用户
if (needAddConcernedUser) {
if (concernedList.contains(currentOIRankVo.getUid())) {
topOIRankVoList.add(currentOIRankVo);
}
}
}
topOIRankVoList.addAll(orderResultList);
return topOIRankVoList;
}
Aggregations