package com.seer.teach.pay.app.wallet.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.pay.entity.PayCoinAccountTradeLogEntity;
import com.seer.teach.pay.mapper.PayCoinAccountTradeLogMapper;
import com.seer.teach.pay.app.wallet.req.CoinAccountTradeLogReq;
import com.seer.teach.pay.app.wallet.service.IAppUserCoinAccountTradeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 用户账户交易明细表 服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-06-25 16:25:06
 */
@Slf4j
@Service
public class AppUserCoinAccountTradeLogServiceImpl extends ServiceImpl<PayCoinAccountTradeLogMapper, PayCoinAccountTradeLogEntity> implements IAppUserCoinAccountTradeLogService {

    @Override
    public IPage<PayCoinAccountTradeLogEntity> myCoinAccountTradePageList(CoinAccountTradeLogReq params) {
        int userId = StpUtil.getLoginIdAsInt();
        log.info("用户[{}]查询用户账户交易明细表列表，分页参数：size={}, current={}, tradeType={}", userId, params.getPage(), params.getLimits(), params.getTradeType());
        IPage<PayCoinAccountTradeLogEntity> pageParams = new Page<>(params.getPage(), params.getLimits());
        IPage<PayCoinAccountTradeLogEntity> pageResult = super.page(pageParams, new LambdaQueryWrapper<PayCoinAccountTradeLogEntity>()
                .eq(Objects.nonNull(params.getTradeType()), PayCoinAccountTradeLogEntity::getTradeType, params.getTradeType())
                .eq(PayCoinAccountTradeLogEntity::getUserId, userId)
                .orderByDesc(PayCoinAccountTradeLogEntity::getId));
        if(log.isDebugEnabled()){
            log.debug("用户[{}]查询用户账户交易明细表列表，分页参数：{}", userId, pageParams);
        }
        return pageResult;
    }
}