package com.hfkj.service.spread.impl;

import com.hfkj.dao.BsUserSpreadAccountTransferMapper;
import com.hfkj.entity.BsUserSpreadAccountTransfer;
import com.hfkj.entity.BsUserSpreadAccountTransferExample;
import com.hfkj.service.spread.BsUserSpreadAccountTransferService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @className: BsUserSpreadAccountTransferServiceImpl
 * @author: HuRui
 * @date: 2025/4/10
 **/
@Service("userSpreadAccountTransferService")
public class BsUserSpreadAccountTransferServiceImpl implements BsUserSpreadAccountTransferService {
    @Resource
    private BsUserSpreadAccountTransferMapper userSpreadAccountTransferMapper;

    @Override
    public void editData(BsUserSpreadAccountTransfer data) {
        data.setUpdateTime(new Date());
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            userSpreadAccountTransferMapper.insert(data);
        } else {
            userSpreadAccountTransferMapper.updateByPrimaryKey(data);
        }
    }

    @Override
    public BsUserSpreadAccountTransfer getDetailByOutBillNo(String outBillNo) {
        BsUserSpreadAccountTransferExample example = new BsUserSpreadAccountTransferExample();
        example.createCriteria().andOutBillNoEqualTo(outBillNo).andStatusNotEqualTo(0);
        List<BsUserSpreadAccountTransfer> list = userSpreadAccountTransferMapper.selectByExample(example);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public int withdrawChance(Long userId) {
        return 0;
    }
}
