package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsAppSettingMapper;
import com.gxwebsoft.cms.service.CmsAppSettingService;
import com.gxwebsoft.cms.entity.CmsAppSetting;
import com.gxwebsoft.cms.param.CmsAppSettingParam;
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-02-19 01:35:44
 */
@Service
public class CmsAppSettingServiceImpl extends ServiceImpl<CmsAppSettingMapper, CmsAppSetting> implements CmsAppSettingService {

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

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

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

}
