package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.DesignCategoryMapper;
import com.gxwebsoft.cms.service.DesignCategoryService;
import com.gxwebsoft.cms.entity.DesignCategory;
import com.gxwebsoft.cms.param.DesignCategoryParam;
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-10 09:23:25
 */
@Service
public class DesignCategoryServiceImpl extends ServiceImpl<DesignCategoryMapper, DesignCategory> implements DesignCategoryService {

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

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

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

}
