package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.DesignRecordMapper;
import com.gxwebsoft.cms.service.DesignRecordService;
import com.gxwebsoft.cms.entity.DesignRecord;
import com.gxwebsoft.cms.param.DesignRecordParam;
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 20:34:14
 */
@Service
public class DesignRecordServiceImpl extends ServiceImpl<DesignRecordMapper, DesignRecord> implements DesignRecordService {

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

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

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

}
