use of com.baomidou.mybatisplus.core.metadata.IPage in project PornTube by PuZhiweizuishuai.
the class PlayRecordingWithArticleServiceImpl method playRecordingList.
@Override
public PageUtils playRecordingList(Map<String, Object> params, HttpServletRequest request) {
IPage<PlayRecordingEntity> page = playRecordingService.queryPage(params, request);
Set<Long> aids = page.getRecords().stream().map(PlayRecordingEntity::getArticleId).collect(Collectors.toSet());
List<ArticleEntity> articleEntities = articleService.listByIds(aids);
List<PlayRecordingWithArticleVo> play = new LinkedList<>();
if (articleEntities != null && articleEntities.size() != 0) {
Map<Long, ArticleEntity> articleEntityMap = articleEntities.stream().collect(Collectors.toMap(ArticleEntity::getId, a -> a));
for (PlayRecordingEntity playRecordingEntity : page.getRecords()) {
PlayRecordingWithArticleVo playRecordingWithArticleVo = new PlayRecordingWithArticleVo();
playRecordingWithArticleVo.setPlayRecordingEntity(playRecordingEntity);
ArticleEntity articleEntity = articleEntityMap.get(playRecordingEntity.getArticleId());
playRecordingWithArticleVo.setArticleEntity(articleEntity);
play.add(playRecordingWithArticleVo);
}
}
IPage<PlayRecordingWithArticleVo> iPage = new IPage<PlayRecordingWithArticleVo>() {
@Override
public List<OrderItem> orders() {
return null;
}
@Override
public List<PlayRecordingWithArticleVo> getRecords() {
return play;
}
@Override
public IPage<PlayRecordingWithArticleVo> setRecords(List<PlayRecordingWithArticleVo> records) {
return null;
}
@Override
public long getTotal() {
return page.getTotal();
}
@Override
public IPage<PlayRecordingWithArticleVo> setTotal(long total) {
return null;
}
@Override
public long getSize() {
return page.getSize();
}
@Override
public IPage<PlayRecordingWithArticleVo> setSize(long size) {
return null;
}
@Override
public long getCurrent() {
return page.getCurrent();
}
@Override
public IPage<PlayRecordingWithArticleVo> setCurrent(long current) {
return null;
}
};
return new PageUtils(iPage);
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project dolphinscheduler by apache.
the class ProcessDefinitionService method queryProcessDefinitionListPaging.
/**
* query process definition list paging
*
* @param loginUser login user
* @param projectName project name
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
* @param userId user id
* @return process definition page
*/
public Map<String, Object> queryProcessDefinitionListPaging(User loginUser, String projectName, String searchVal, Integer pageNo, Integer pageSize, Integer userId) {
Map<String, Object> result = new HashMap<>(5);
Project project = projectMapper.queryByName(projectName);
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
}
Page<ProcessDefinition> page = new Page(pageNo, pageSize);
IPage<ProcessDefinition> processDefinitionIPage = processDefineMapper.queryDefineListPaging(page, searchVal, userId, project.getId(), isAdmin(loginUser));
PageInfo pageInfo = new PageInfo<ProcessData>(pageNo, pageSize);
pageInfo.setTotalCount((int) processDefinitionIPage.getTotal());
pageInfo.setLists(processDefinitionIPage.getRecords());
result.put(Constants.DATA_LIST, pageInfo);
putMsg(result, Status.SUCCESS);
return result;
}
use of com.baomidou.mybatisplus.core.metadata.IPage 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 com.baomidou.mybatisplus.core.metadata.IPage 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 com.baomidou.mybatisplus.core.metadata.IPage in project HOJ by HimitZH.
the class TrainingRecordServiceImpl method getTrainingRank.
@Override
public IPage<TrainingRankVo> getTrainingRank(Long tid, String username, int currentPage, int limit) {
Map<Long, String> tpIdMapDisplayId = getTPIdMapDisplayId(tid);
List<TrainingRecordVo> trainingRecordVoList = trainingRecordMapper.getTrainingRecord(tid);
List<UserInfo> superAdminList = userInfoMapper.getSuperAdminList();
List<String> superAdminUidList = superAdminList.stream().map(UserInfo::getUuid).collect(Collectors.toList());
List<TrainingRankVo> result = new ArrayList<>();
HashMap<String, Integer> uidMapIndex = new HashMap<>();
int pos = 0;
for (TrainingRecordVo trainingRecordVo : trainingRecordVoList) {
// 超级管理员和训练创建者的提交不入排行榜
if (username.equals(trainingRecordVo.getUsername()) || superAdminUidList.contains(trainingRecordVo.getUid())) {
continue;
}
TrainingRankVo trainingRankVo;
Integer index = uidMapIndex.get(trainingRecordVo.getUid());
if (index == null) {
trainingRankVo = new TrainingRankVo();
trainingRankVo.setRealname(trainingRecordVo.getRealname()).setAvatar(trainingRecordVo.getAvatar()).setSchool(trainingRecordVo.getSchool()).setGender(trainingRecordVo.getGender()).setUid(trainingRecordVo.getUid()).setUsername(trainingRecordVo.getUsername()).setNickname(trainingRecordVo.getNickname()).setAc(0).setTotalRunTime(0);
HashMap<String, HashMap<String, Object>> submissionInfo = new HashMap<>();
trainingRankVo.setSubmissionInfo(submissionInfo);
result.add(trainingRankVo);
uidMapIndex.put(trainingRecordVo.getUid(), pos);
pos++;
} else {
trainingRankVo = result.get(index);
}
String displayId = tpIdMapDisplayId.get(trainingRecordVo.getTpid());
HashMap<String, Object> problemSubmissionInfo = trainingRankVo.getSubmissionInfo().getOrDefault(displayId, new HashMap<>());
// 如果该题目已经AC过了,只比较运行时间取最小
if ((Boolean) problemSubmissionInfo.getOrDefault("isAC", false)) {
if (trainingRecordVo.getStatus().intValue() == Constants.Judge.STATUS_ACCEPTED.getStatus()) {
int runTime = (int) problemSubmissionInfo.getOrDefault("runTime", 0);
if (runTime > trainingRecordVo.getUseTime()) {
trainingRankVo.setTotalRunTime(trainingRankVo.getTotalRunTime() - runTime + trainingRecordVo.getUseTime());
problemSubmissionInfo.put("runTime", trainingRecordVo.getUseTime());
}
}
continue;
}
problemSubmissionInfo.put("status", trainingRecordVo.getStatus());
problemSubmissionInfo.put("score", trainingRecordVo.getScore());
// 通过的话
if (trainingRecordVo.getStatus().intValue() == Constants.Judge.STATUS_ACCEPTED.getStatus()) {
// 总解决题目次数ac+1
trainingRankVo.setAc(trainingRankVo.getAc() + 1);
problemSubmissionInfo.put("isAC", true);
problemSubmissionInfo.put("runTime", trainingRecordVo.getUseTime());
trainingRankVo.setTotalRunTime(trainingRankVo.getTotalRunTime() + trainingRecordVo.getUseTime());
}
trainingRankVo.getSubmissionInfo().put(displayId, problemSubmissionInfo);
}
List<TrainingRankVo> orderResultList = result.stream().sorted(// 先以总ac数降序
Comparator.comparing(TrainingRankVo::getAc, Comparator.reverseOrder()).thenComparing(// 再以总耗时升序
TrainingRankVo::getTotalRunTime)).collect(Collectors.toList());
// 计算好排行榜,然后进行分页
Page<TrainingRankVo> page = new Page<>(currentPage, limit);
int count = orderResultList.size();
List<TrainingRankVo> pageList = new ArrayList<>();
// 计算当前页第一条数据的下标
int currId = currentPage > 1 ? (currentPage - 1) * limit : 0;
for (int i = 0; i < limit && i < count - currId; i++) {
pageList.add(orderResultList.get(currId + i));
}
page.setSize(limit);
page.setCurrent(currentPage);
page.setTotal(count);
page.setRecords(pageList);
return page;
}
Aggregations