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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.UserBalanceLog;
import com.gxwebsoft.common.system.mapper.UserBalanceLogMapper;
import com.gxwebsoft.common.system.param.UserBalanceLogParam;
import com.gxwebsoft.common.system.service.UserBalanceLogService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户余额变动明细表Service实现
 *
 * @author 科技小王子
 * @since 2023-04-21 15:59:09
 */
@Service
public class UserBalanceLogServiceImpl extends ServiceImpl<UserBalanceLogMapper, UserBalanceLog> implements UserBalanceLogService {

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

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

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

}
