package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsStatisticsMapper;
import com.gxwebsoft.cms.service.CmsStatisticsService;
import com.gxwebsoft.cms.entity.CmsStatistics;
import com.gxwebsoft.cms.param.CmsStatisticsParam;
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-07-25 12:32:06
 */
@Service
public class CmsStatisticsServiceImpl extends ServiceImpl<CmsStatisticsMapper, CmsStatistics> implements CmsStatisticsService {

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

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

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

}
