package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.MpMenuMapper;
import com.gxwebsoft.cms.service.MpMenuService;
import com.gxwebsoft.cms.entity.MpMenu;
import com.gxwebsoft.cms.param.MpMenuParam;
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-05-02 12:22:25
 */
@Service
public class MpMenuServiceImpl extends ServiceImpl<MpMenuMapper, MpMenu> implements MpMenuService {

    @Override
    public PageResult<MpMenu> pageRel(MpMenuParam param) {
        PageParam<MpMenu, MpMenuParam> page = new PageParam<>(param);
        page.setDefaultOrder("rows asc, sort_number asc, menu_id asc");
        List<MpMenu> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<MpMenu> listRel(MpMenuParam param) {
        List<MpMenu> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<MpMenu, MpMenuParam> page = new PageParam<>();
        page.setDefaultOrder("rows asc, sort_number asc, menu_id asc");
        return page.sortRecords(list);
    }

    @Override
    public MpMenu getByIdRel(Integer menuId) {
        MpMenuParam param = new MpMenuParam();
        param.setMenuId(menuId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
