package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.AdRecordMapper;
import com.gxwebsoft.cms.service.AdRecordService;
import com.gxwebsoft.cms.entity.AdRecord;
import com.gxwebsoft.cms.param.AdRecordParam;
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-03-04 21:14:15
 */
@Service
public class AdRecordServiceImpl extends ServiceImpl<AdRecordMapper, AdRecord> implements AdRecordService {

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

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

    @Override
    public AdRecord getByIdRel(Integer adRecordId) {
        AdRecordParam param = new AdRecordParam();
        param.setAdRecordId(adRecordId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
