package com.yida.data.device.consume.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.consume.EduStudentConsumeCard;
import com.yida.data.device.consume.mapper.EduStudentConsumeCardMapper;
import com.yida.data.device.consume.service.EduStudentConsumeCardService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 学生消费机信息管理Service实现
 *
 * @author ZYJ
 * @date 2023-03-20 15:02:20
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class EduStudentConsumeCardServiceImpl extends ServiceImpl
        <EduStudentConsumeCardMapper, EduStudentConsumeCard> implements EduStudentConsumeCardService {

    @Override
    public void saveConsumeCard(EduStudentConsumeCard eduStudentConsumeCard) {
        EduStudentConsumeCard consumeCard = getOne(Wrappers.lambdaQuery(new EduStudentConsumeCard())
                .eq(EduStudentConsumeCard::getStudentId, eduStudentConsumeCard.getStudentId()));
        if (Objects.isNull(consumeCard)) {
            eduStudentConsumeCard.setBalance(new BigDecimal("0.0"));
            save(eduStudentConsumeCard);
        }
    }
}
