ResourceServiceImpl.java 1.17 KB
package vion.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.dto.ResourceDTO;
import vion.mapper.ResourceMapper;
import vion.model.Resource;
import vion.service.IResourceService;
import vion.vo.ResourceVO;

import java.util.List;

/**
 * @author HlQ
 * @date 2023/11/28
 */
@Service
@RequiredArgsConstructor
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements IResourceService {

    private final Converter converter;

    @Override
    public Page<ResourceVO> list(ResourceDTO dto) {
        Page<Resource> resourcePage = this
                .lambdaQuery(converter.convert(dto, new Resource()))
                .page(Page.of(dto.getPageNum(), dto.getPageSize()));
        List<ResourceVO> resourceVOList = converter.convert(resourcePage.getRecords(), ResourceVO.class);
        return Page.<ResourceVO>of(resourcePage.getCurrent(), resourcePage.getSize(), resourcePage.getTotal()).setRecords(resourceVOList);
    }
}