package com.sqx.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.modules.app.entity.UserMoney;
import com.sqx.modules.sys.dao.SysUserMoneyDao;
import com.sqx.modules.sys.entity.SysUserMoney;
import com.sqx.modules.sys.service.SysUserMoneyService;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.Map;

@Service
public class SysUserMoneyServiceImpl extends ServiceImpl<SysUserMoneyDao, SysUserMoney> implements SysUserMoneyService {

    @Override
    public void updateSysMoney(int i, Long userId, double money) {
        selectSysUserMoneyByUserId(userId);
        baseMapper.updateSysMoney(i, userId, money);
    }

    @Override
    public SysUserMoney selectSysUserMoneyByUserId(Long userId) {
        SysUserMoney userMoney = baseMapper.selectOne(new QueryWrapper<SysUserMoney>().eq("user_id", userId));
        if (userMoney == null) {
            userMoney = new SysUserMoney();
            userMoney.setUserId(userId);
            userMoney.setMoney(new BigDecimal("0.00"));
            baseMapper.insert(userMoney);
        }
        return userMoney;
    }
}

