package com.ruoyi.task.snapshot;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ruoyi.bst.snapshot.domain.enums.SnapshotType;
import com.ruoyi.bst.snapshot.service.SnapshotService;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.system.user.domain.UserQuery;
import com.ruoyi.system.user.service.UserDashboard;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class SnapshotTask {

    @Autowired
    private SnapshotService snapshotService;

    @Autowired
    private UserDashboard userDashboard;

    /**
     * 记录用户余额
     */
    public void snapshotUserBalance() {
        BigDecimal balance = userDashboard.selectSumOfBalance(new UserQuery());
        int rows = snapshotService.record(SnapshotType.USER_BALANCE, balance.toString());
        ServiceUtil.assertion(rows != 1, "记录用户余额失败");
    }
    
}
