package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.MpMapper;
import com.gxwebsoft.cms.service.MpService;
import com.gxwebsoft.cms.entity.Mp;
import com.gxwebsoft.cms.param.MpParam;
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 00:09:11
 */
@Service
public class MpServiceImpl extends ServiceImpl<MpMapper, Mp> implements MpService {

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

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

    @Override
    public Mp getByIdRel(Integer mpId) {
        MpParam param = new MpParam();
        param.setMpId(mpId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
