package com.mcwl.myInvitation.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.myInvitation.domain.Commission;
import com.mcwl.myInvitation.domain.vo.CommissionVo;
import com.mcwl.myInvitation.mapper.CommissionMapper;
import com.mcwl.myInvitation.service.CommissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commission> implements CommissionService {


    @Override
    public TableDataInfo getWalletIncomeRecord(PageDomain pageDomain) {

        Page<Commission> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());

        baseMapper.selectPage(page, new LambdaQueryWrapper<Commission>()
                .eq(Commission::getUserId, SecurityUtils.getUserId()));

        List<Commission> commissionList = page.getRecords();
        List<CommissionVo> commissionVoList = BeanUtil.copyToList(commissionList, CommissionVo.class);

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