Search in sources :

Example 21 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project yshopmall by guchengwuyue.

the class BaseServiceImpl method setPageParam.

protected Page setPageParam(QueryParam queryParam, OrderItem defaultOrder) {
    Page page = new Page();
    // 设置当前页码
    page.setCurrent(queryParam.getPage());
    // 设置页大小
    page.setSize(queryParam.getLimit());
    /**
     * 如果是queryParam是OrderQueryParam,并且不为空,则使用前端排序
     * 否则使用默认排序
     */
    if (queryParam instanceof OrderQueryParam) {
        OrderQueryParam orderQueryParam = (OrderQueryParam) queryParam;
        List<OrderItem> orderItems = orderQueryParam.getOrders();
        if (CollectionUtil.isEmpty(orderItems)) {
            page.setOrders(Arrays.asList(defaultOrder));
        } else {
            page.setOrders(orderItems);
        }
    } else {
        page.setOrders(Arrays.asList(defaultOrder));
    }
    return page;
}
Also used : OrderQueryParam(co.yixiang.common.web.param.OrderQueryParam) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 22 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project video-spider by zc-libre.

the class VideoServiceImpl method getOrders.

private List<Sort.Order> getOrders(PageDTO<Video> page) {
    List<Sort.Order> orders = Lists.newArrayList();
    List<OrderItem> orderItems = page.getOrders();
    if (CollectionUtil.isEmpty(orderItems)) {
        Sort.Order createTime = Order.by("publishTime").with(Sort.Direction.DESC);
        Sort.Order lookNum = Order.by("lookNum").with(Sort.Direction.DESC);
        orders.add(createTime);
        orders.add(lookNum);
    }
    for (OrderItem orderItem : orderItems) {
        String column = orderItem.getColumn();
        boolean asc = orderItem.isAsc();
        Sort.Order order = Order.by(column);
        if (!asc) {
            order.with(Sort.Direction.DESC);
        }
        orders.add(order);
    }
    return orders;
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Sort(org.springframework.data.domain.Sort)

Example 23 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project PornTube by PuZhiweizuishuai.

the class ArticleServiceImpl method queryPage.

@Override
public PageUtils queryPage(Map<String, Object> params) {
    QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>();
    wrapper.eq("status", ArticleStatusEnum.NORMAL.getCode());
    wrapper.eq("examine_status", ExamineTypeEnum.SUCCESS.getCode());
    wrapper.orderByDesc("create_time");
    IPage<ArticleEntity> page = this.page(new Query<ArticleEntity>().getPage(params), wrapper);
    Set<Long> userIdList = page.getRecords().stream().map(ArticleEntity::getUserId).collect(Collectors.toSet());
    if (userIdList.size() == 0) {
        return null;
    }
    Map<Long, UserEntity> userEntityMap = userService.userMapList(userIdList);
    List<ArticleViewData> articleViewData = new ArrayList<>();
    page.getRecords().forEach(a -> {
        ArticleViewData viewData = new ArticleViewData();
        UserEntity userEntity = userEntityMap.get(a.getUserId());
        BeanUtils.copyProperties(a, viewData);
        viewData.setUsername(userEntity.getUsername());
        viewData.setAvatarUrl(userEntity.getAvatarUrl());
        articleViewData.add(viewData);
    });
    IPage<ArticleViewData> viewDataIPage = new IPage<ArticleViewData>() {

        @Override
        public List<OrderItem> orders() {
            return null;
        }

        @Override
        public List<ArticleViewData> getRecords() {
            return articleViewData;
        }

        @Override
        public IPage<ArticleViewData> setRecords(List<ArticleViewData> records) {
            return null;
        }

        @Override
        public long getTotal() {
            return page.getTotal();
        }

        @Override
        public IPage<ArticleViewData> setTotal(long total) {
            return null;
        }

        @Override
        public long getSize() {
            return page.getSize();
        }

        @Override
        public IPage<ArticleViewData> setSize(long size) {
            return null;
        }

        @Override
        public long getCurrent() {
            return page.getCurrent();
        }

        @Override
        public IPage<ArticleViewData> setCurrent(long current) {
            return null;
        }
    };
    return new PageUtils(viewDataIPage);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) IPage(com.baomidou.mybatisplus.core.metadata.IPage) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) ArticleViewData(com.buguagaoshu.porntube.vo.ArticleViewData) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)23 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)12 ArrayList (java.util.ArrayList)7 IPage (com.baomidou.mybatisplus.core.metadata.IPage)6 List (java.util.List)4 Collectors (java.util.stream.Collectors)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Map (java.util.Map)2 Sort (org.springframework.data.domain.Sort)2 OrderQueryParam (co.yixiang.common.web.param.OrderQueryParam)1 DbType (com.baomidou.mybatisplus.annotation.DbType)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 DefaultIdentifierGenerator (com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator)1 IdentifierGenerator (com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator)1 TableInfo (com.baomidou.mybatisplus.core.metadata.TableInfo)1 TableInfoHelper (com.baomidou.mybatisplus.core.metadata.TableInfoHelper)1 CollectionUtils (com.baomidou.mybatisplus.core.toolkit.CollectionUtils)1 StringUtils (com.baomidou.mybatisplus.core.toolkit.StringUtils)1 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)1 IDialect (com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect)1