package com.kym.service.impl;

import cn.dev33.satoken.stp.StpUtil;

import com.github.pagehelper.PageHelper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.kym.entity.WalletDetail;
import com.kym.entity.common.PageBean;
import com.kym.entity.queryParams.WalletDetailQueryParam;
import com.kym.entity.vo.WalletDetailVo;
import com.kym.mapper.WalletDetailMapper;
import com.kym.service.WalletDetailService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户账户表 服务实现类
 * </p>
 *
 * @author skyline
 * @since 2023-08-09
 */
@Service
public class WalletDetailServiceImpl extends MPJBaseServiceImpl<WalletDetailMapper, WalletDetail> implements WalletDetailService {


    @Override
    public WalletDetail getWalletDetailByOrderNo(String orderNo, Integer type) {
        return lambdaQuery().eq(WalletDetail::getOrderNo, orderNo).eq(WalletDetail::getType, type).one();
    }

    @Override
    public List<WalletDetail> listWalletDetail(int type) {
        var userId = StpUtil.getLoginIdAsLong();
        if (type > 0) {
            return lambdaQuery().eq(WalletDetail::getUserId, userId).eq(WalletDetail::getStatus, WalletDetail.STATUS_已确认).eq(WalletDetail::getType, type).orderByDesc(WalletDetail::getId).list();
        } else {
            return lambdaQuery().eq(WalletDetail::getUserId, userId).eq(WalletDetail::getStatus, WalletDetail.STATUS_已确认).orderByDesc(WalletDetail::getId).list();
        }

    }

    @Override
    public PageBean<WalletDetailVo> listAdminWalletDetail(WalletDetailQueryParam params) {
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        List<WalletDetailVo> list = baseMapper.listAdminWalletDetail(params);
        return new PageBean<>(list);
    }

}
