package com.gxwebsoft.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.project.mapper.ProjectCollectionMapper;
import com.gxwebsoft.project.service.ProjectCollectionService;
import com.gxwebsoft.project.entity.ProjectCollection;
import com.gxwebsoft.project.param.ProjectCollectionParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 我的收藏Service实现
 *
 * @author 科技小王子
 * @since 2025-03-16 12:12:13
 */
@Service
public class ProjectCollectionServiceImpl extends ServiceImpl<ProjectCollectionMapper, ProjectCollection> implements ProjectCollectionService {

    @Override
    public PageResult<ProjectCollection> pageRel(ProjectCollectionParam param) {
        PageParam<ProjectCollection, ProjectCollectionParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        List<ProjectCollection> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<ProjectCollection> listRel(ProjectCollectionParam param) {
        List<ProjectCollection> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<ProjectCollection, ProjectCollectionParam> page = new PageParam<>();
        page.setDefaultOrder("sort_number asc, create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public ProjectCollection getByIdRel(Integer id) {
        ProjectCollectionParam param = new ProjectCollectionParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
