Search in sources :

Example 61 with IPage

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);
}
Also used : PageUtils(com.buguagaoshu.porntube.utils.PageUtils) ArticleService(com.buguagaoshu.porntube.service.ArticleService) ArticleEntity(com.buguagaoshu.porntube.entity.ArticleEntity) PlayRecordingWithArticleVo(com.buguagaoshu.porntube.vo.PlayRecordingWithArticleVo) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) PlayRecordingService(com.buguagaoshu.porntube.service.PlayRecordingService) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Collectors(java.util.stream.Collectors) PlayRecordingEntity(com.buguagaoshu.porntube.entity.PlayRecordingEntity) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlayRecordingWithArticleService(com.buguagaoshu.porntube.service.PlayRecordingWithArticleService) LinkedList(java.util.LinkedList) IPage(com.baomidou.mybatisplus.core.metadata.IPage) PlayRecordingWithArticleVo(com.buguagaoshu.porntube.vo.PlayRecordingWithArticleVo) LinkedList(java.util.LinkedList) PlayRecordingEntity(com.buguagaoshu.porntube.entity.PlayRecordingEntity) IPage(com.baomidou.mybatisplus.core.metadata.IPage) PageUtils(com.buguagaoshu.porntube.utils.PageUtils) ArticleEntity(com.buguagaoshu.porntube.entity.ArticleEntity) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) List(java.util.List) LinkedList(java.util.LinkedList)

Example 62 with 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;
}
Also used : Status(org.apache.dolphinscheduler.api.enums.Status) Project(org.apache.dolphinscheduler.dao.entity.Project) PageInfo(org.apache.dolphinscheduler.api.utils.PageInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) ProcessDefinition(org.apache.dolphinscheduler.dao.entity.ProcessDefinition) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 63 with IPage

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, "获取成功");
    }
}
Also used : IPage(com.baomidou.mybatisplus.core.metadata.IPage) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) UserInfo(top.hcode.hoj.pojo.entity.user.UserInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 64 with IPage

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;
}
Also used : ContestRecord(top.hcode.hoj.pojo.entity.contest.ContestRecord) UserInfo(top.hcode.hoj.pojo.entity.user.UserInfo) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 65 with IPage

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;
}
Also used : TrainingRankVo(top.hcode.hoj.pojo.vo.TrainingRankVo) UserInfo(top.hcode.hoj.pojo.entity.user.UserInfo) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) TrainingRecordVo(top.hcode.hoj.pojo.vo.TrainingRecordVo)

Aggregations

IPage (com.baomidou.mybatisplus.core.metadata.IPage)197 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)152 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)73 ApiOperation (io.swagger.annotations.ApiOperation)28 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 PageDTO (com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 LoginUser (org.jeecg.common.system.vo.LoginUser)16 JSONObject (com.alibaba.fastjson.JSONObject)15 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 PageInfo (org.apache.dolphinscheduler.api.utils.PageInfo)13 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)11 Result (org.jeecg.common.api.vo.Result)10 List (java.util.List)9 User (org.apache.dolphinscheduler.dao.entity.User)9 Field (java.lang.reflect.Field)8 Date (java.util.Date)8 Collectors (java.util.stream.Collectors)7 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)7