package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.MpAdMapper;
import com.gxwebsoft.cms.service.MpAdService;
import com.gxwebsoft.cms.entity.MpAd;
import com.gxwebsoft.cms.param.MpAdParam;
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-07-23 01:53:01
 */
@Service
public class MpAdServiceImpl extends ServiceImpl<MpAdMapper, MpAd> implements MpAdService {

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

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

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

}
