Search in sources :

Example 11 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project RuoYi-Cloud-Plus by JavaLionLi.

the class PageQuery method build.

public <T> Page<T> build() {
    Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);
    Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
    if (pageNum <= 0) {
        pageNum = DEFAULT_PAGE_NUM;
    }
    Page<T> page = new Page<>(pageNum, pageSize);
    OrderItem orderItem = buildOrderItem();
    if (ObjectUtil.isNotNull(orderItem)) {
        page.addOrder(orderItem);
    }
    return page;
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 12 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem 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 13 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project platform by elveahuang.

the class MyBatisPlusUtils method toSpringDataPage.

/**
 * 把MyBatis-Plus的分页对象转换成为Spring-Data的分页对象
 */
public static <T> Page<T> toSpringDataPage(IPage<T> mybatisPlusPage) {
    // Spring Data Pageable 目前只支持 int 类型的 page 和 size
    int page = Math.toIntExact(mybatisPlusPage.getCurrent() - 1);
    int size = Math.toIntExact(mybatisPlusPage.getSize());
    List<Sort.Order> orderList = Lists.newArrayList();
    if (!CollectionUtils.isEmpty(mybatisPlusPage.orders())) {
        for (OrderItem item : mybatisPlusPage.orders()) {
            if (item.isAsc()) {
                orderList.add(Sort.Order.asc(item.getColumn()));
            } else {
                orderList.add(Sort.Order.desc(item.getColumn()));
            }
        }
    }
    // 转换分页对象
    Pageable pageable = PageRequest.of(page, size, Sort.by(orderList));
    return new PageImpl<>(mybatisPlusPage.getRecords(), pageable, mybatisPlusPage.getTotal());
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem)

Example 14 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project jeebiz-boot by Jeebiz.

the class BaseServiceImpl method getPagedList.

/**
 * 分页查询
 *
 * @param t
 * @return
 */
@Override
public Page<T> getPagedList(PaginationEntity<T> model) {
    Page<T> page = new Page<T>(model.getPageNo(), model.getLimit());
    if (!CollectionUtils.isEmpty(model.getOrders())) {
        for (OrderItem orderBy : model.getOrders()) {
            page.addOrder(orderBy);
        }
    }
    List<T> records = getBaseMapper().getPagedList(page, model);
    page.setRecords(records);
    return page;
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 15 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project atjob by 1-2-3.

the class MybatisUtil method getOrderItemList.

/**
 * 生成用于 Mybatis plus 排序的 OrderItem 列表.
 *
 * @param sort 排序字符串,格式类似:userName.ascend-userAgd.decend
 * @param clazz 要进行排序的实体类型
 * @param isAppendPkOrder 是否追加主键作为第二排序字段。当使用分页排序时,如果第一排序字段有大量相同值,不追加一个唯一字段作为第二排序字段将导致分页数据混乱。
 * @return
 */
public static List<OrderItem> getOrderItemList(String sort, Class<?> clazz, Boolean isAppendPkOrder) {
    // 属性名 -> 字段名 映射
    TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
    Map<String, String> fieldsMap = tableInfo.getFieldList().stream().collect(Collectors.toMap(fieldInfo -> fieldInfo.getProperty(), fieldInfo -> fieldInfo.getColumn()));
    List<OrderItem> result = new ArrayList<OrderItem>();
    if (StringUtils.isNotBlank(sort)) {
        result = Stream.of(sort.split("-")).map(t -> {
            var sortSpec = t.split("[.]");
            var propName = sortSpec[0];
            var direction = sortSpec[1];
            return StringUtils.equals(direction, "ascend") ? OrderItem.asc(fieldsMap.get(propName)) : OrderItem.desc(fieldsMap.get(propName));
        }).collect(Collectors.toList());
    }
    if (isAppendPkOrder) {
        result.add(OrderItem.asc(tableInfo.getKeyColumn()));
    }
    return result;
}
Also used : DefaultIdentifierGenerator(com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) TableInfoHelper(com.baomidou.mybatisplus.core.metadata.TableInfoHelper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) List(java.util.List) TableInfo(com.baomidou.mybatisplus.core.metadata.TableInfo) Stream(java.util.stream.Stream) IdentifierGenerator(com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator) Map(java.util.Map) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) ArrayList(java.util.ArrayList) TableInfo(com.baomidou.mybatisplus.core.metadata.TableInfo)

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