package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ComponentsMapper;
import com.gxwebsoft.cms.service.ComponentsService;
import com.gxwebsoft.cms.entity.Components;
import com.gxwebsoft.cms.param.ComponentsParam;
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-08-25 19:00:41
 */
@Service
public class ComponentsServiceImpl extends ServiceImpl<ComponentsMapper, Components> implements ComponentsService {

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

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

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

}
