package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.UserGradeMapper;
import com.gxwebsoft.common.system.service.UserGradeService;
import com.gxwebsoft.common.system.entity.UserGrade;
import com.gxwebsoft.common.system.param.UserGradeParam;
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 2023-10-07 22:51:17
 */
@Service
public class UserGradeServiceImpl extends ServiceImpl<UserGradeMapper, UserGrade> implements UserGradeService {

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

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

    @Override
    public UserGrade getByIdRel(Integer gradeId) {
        UserGradeParam param = new UserGradeParam();
        param.setGradeId(gradeId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
