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;
}
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);
}
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());
}
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;
}
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;
}
Aggregations