package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.MpOfficialMenuMapper;
import com.gxwebsoft.cms.service.MpOfficialMenuService;
import com.gxwebsoft.cms.entity.MpOfficialMenu;
import com.gxwebsoft.cms.param.MpOfficialMenuParam;
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-09-15 13:12:38
 */
@Service
public class MpOfficialMenuServiceImpl extends ServiceImpl<MpOfficialMenuMapper, MpOfficialMenu> implements MpOfficialMenuService {

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

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

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

}
