package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.AdMapper;
import com.gxwebsoft.cms.service.AdService;
import com.gxwebsoft.cms.entity.Ad;
import com.gxwebsoft.cms.param.AdParam;
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 AdServiceImpl extends ServiceImpl<AdMapper, Ad> implements AdService {

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

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

    @Override
    public Ad getByIdRel(Integer adId) {
        AdParam param = new AdParam();
        param.setAdId(adId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
