package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.DesignCollectMapper;
import com.gxwebsoft.cms.service.DesignCollectService;
import com.gxwebsoft.cms.entity.DesignCollect;
import com.gxwebsoft.cms.param.DesignCollectParam;
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 2024-10-08 15:21:56
 */
@Service
public class DesignCollectServiceImpl extends ServiceImpl<DesignCollectMapper, DesignCollect> implements DesignCollectService {

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

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

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

}
