package com.leromro.core.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leromro.core.domain.ClientAccount;
import com.leromro.core.domain.VolunteerAccount;
import com.leromro.core.mapper.ClientAccountMapper;
import com.leromro.core.service.IClientAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class ClientAccountServiceImpl extends ServiceImpl<ClientAccountMapper, ClientAccount> implements IClientAccountService {
    @Autowired
    private ClientAccountMapper clientAccountMapper;

    @Override
    public void insertVolunteerAccount(Long userId) {
        //如果存在账户则不创建
        ClientAccount clientAccount = this.getOne(new LambdaQueryWrapper<ClientAccount>()
                .eq(ClientAccount::getUserId, userId));
        if (ObjectUtil.isNull(clientAccount)){
            this.save(ClientAccount.builder()
                    .userId(userId)
                    .balance(BigDecimal.ZERO)
                    .build());
        }
    }
}
