package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.UserPointsLogMapper;
import com.gxwebsoft.shop.service.UserPointsLogService;
import com.gxwebsoft.shop.entity.UserPointsLog;
import com.gxwebsoft.shop.param.UserPointsLogParam;
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 2022-11-25 19:04:43
 */
@Service
public class UserPointsLogServiceImpl extends ServiceImpl<UserPointsLogMapper, UserPointsLog> implements UserPointsLogService {

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

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

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

}
