package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.UserGradeLogMapper;
import com.gxwebsoft.shop.service.UserGradeLogService;
import com.gxwebsoft.shop.entity.UserGradeLog;
import com.gxwebsoft.shop.param.UserGradeLogParam;
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-06-20 16:33:06
 */
@Service
public class UserGradeLogServiceImpl extends ServiceImpl<UserGradeLogMapper, UserGradeLog> implements UserGradeLogService {

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

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

    @Override
    public UserGradeLog getByIdRel(Integer logId) {
        UserGradeLogParam param = new UserGradeLogParam();
        param.setLogId(logId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
