package com.mcwl.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.mcwl.common.constant.HttpStatus;
import com.mcwl.common.core.page.PageDomain;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.system.domain.SysUserPayAccount;
import com.mcwl.system.domain.SysUserPayAccountLog;
import com.mcwl.system.domain.dto.WithdrawalPageRes;
import com.mcwl.system.mapper.SysUserPayAccountLogMapper;
import com.mcwl.system.mapper.SysUserPayAccountMapper;
import com.mcwl.system.service.ISysUserPayAccountLogService;
import com.mcwl.system.service.ISysUserPayAccountService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 用户提现
 */
@Service
public class SysUserPayAccountLogServiceImpl extends ServiceImpl<SysUserPayAccountLogMapper, SysUserPayAccountLog> implements ISysUserPayAccountLogService {

    /**
     * 当前用户的提现记录
     * @param withdrawalPageRes 分页参数
     * @return TableDataInfo
     */
    @Override
    public TableDataInfo getWithdrawalRecord(WithdrawalPageRes withdrawalPageRes) {

        Long userId = withdrawalPageRes.getUserId();
        userId = Objects.isNull(userId) ? SecurityUtils.getUserId() : userId;

        Page<SysUserPayAccountLog> page = new Page<>(withdrawalPageRes.getPageNum(), withdrawalPageRes.getPageSize());

        baseMapper.selectPage(page, new LambdaQueryWrapper<SysUserPayAccountLog>()
                .select(SysUserPayAccountLog::getAmount, SysUserPayAccountLog::getAccount,
                        SysUserPayAccountLog::getWallet, SysUserPayAccountLog::getCreateTime)
                .eq(SysUserPayAccountLog::getUserId, userId)
                .orderByDesc(SysUserPayAccountLog::getCreateTime));

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(page.getRecords());
        rspData.setTotal(page.getTotal());
        return rspData;
    }
}
