package com.sunyard.ssp.modules.user.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunyard.ssp.modules.user.entity.ScRole;
import com.sunyard.ssp.modules.user.mapper.ScRoleMapper;
import com.sunyard.ssp.modules.user.service.IScRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tsz
 * @since 2020-03-11
 */
@Slf4j
@Service
@Transactional
public class ScRoleServiceImpl extends ServiceImpl<ScRoleMapper, ScRole> implements IScRoleService {

    @Override
    public Page findAll(Pageable pageable) {
        IPage page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        QueryWrapper wrapper = new QueryWrapper<>();
        if(!pageable.getSort().isEmpty()){
            for (Sort.Order order : pageable.getSort()) {
                wrapper.orderBy(true, Sort.Direction.ASC.equals(order.getDirection()), order.getProperty());
            }
        }
        IPage roleList = baseMapper.selectPage(page, wrapper);
        Page<ScRole> res = new PageImpl<ScRole>(roleList.getRecords(),pageable,roleList.getTotal());
        return res;
    }
}
