package com.qnfhq.modules.c2c.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qnfhq.common.service.impl.BaseServiceImpl;
import com.qnfhq.common.service.impl.CrudServiceImpl;
import com.qnfhq.modules.c2c.dao.C2cUserReceiptDao;
import com.qnfhq.modules.c2c.dto.C2cMyReceiptDTO;
import com.qnfhq.modules.c2c.dto.C2cUserReceiptDTO;
import com.qnfhq.modules.c2c.entity.C2cUserReceiptEntity;
import com.qnfhq.modules.c2c.service.C2cUserReceiptService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * c2c用户收款信息
 *
 * @author yelz 30262728@qq.com
 * @since 1.0.0 2025-11-17
 */
@Service
public class C2cUserReceiptServiceImpl extends BaseServiceImpl<C2cUserReceiptDao, C2cUserReceiptEntity> implements C2cUserReceiptService {


    private QueryWrapper<C2cUserReceiptEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<C2cUserReceiptEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public List<C2cUserReceiptEntity> selectListMyReceipt(C2cMyReceiptDTO dto) {
        QueryWrapper<C2cUserReceiptEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(dto.getUserId()), "user_id", dto.getUserId());
        wrapper.eq(Objects.nonNull(dto.getType()), "type", dto.getType());
        return baseDao.selectList(wrapper);
    }

    @Override
    public C2cUserReceiptEntity selectOneMyReceipt(Long userId,Integer type) {
        return baseDao.selectOne(new LambdaQueryWrapper<C2cUserReceiptEntity>()
                .eq(Objects.nonNull(userId), C2cUserReceiptEntity::getUserId, userId)
                .eq(Objects.nonNull(type), C2cUserReceiptEntity::getType, type)
                .last(" limit 1"));
    }


}