package com.kym.service.miniapp.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.kym.entity.miniapp.WalletDetail;
import com.kym.mapper.miniapp.WalletDetailMapper;
import com.kym.service.miniapp.WalletDetailService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户账户表 服务实现类
 * </p>
 *
 * @author skyline
 * @since 2023-08-09
 */
@Service
@DS("db-miniapp")
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();
        }

    }

}
