package com.ruoyi.bst.balanceLog.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.balanceLog.domain.BalanceLog;
import com.ruoyi.bst.balanceLog.domain.BalanceLogQuery;
import com.ruoyi.bst.balanceLog.domain.BalanceLogVO;
import com.ruoyi.bst.balanceLog.mapper.BalanceLogMapper;
import com.ruoyi.bst.balanceLog.service.BalanceLogService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 余额日志Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-14
 */
@Service
public class BalanceLogServiceImpl implements BalanceLogService
{
    @Autowired
    private BalanceLogMapper balanceLogMapper;

    /**
     * 查询余额日志
     *
     * @param id 余额日志主键
     * @return 余额日志
     */
    @Override
    public BalanceLogVO selectBalanceLogById(Long id, boolean scope) {
        if (id == null) {
            return null;
        }

        BalanceLogQuery query = new BalanceLogQuery();
        query.setId(id);
        query.setScope(scope);
        return this.selectOne(query);
    }

    private BalanceLogVO selectOne(BalanceLogQuery query) {
        PageHelper.startPage(1, 1);
        List<BalanceLogVO> list = balanceLogMapper.selectBalanceLogList(query);
        return CollectionUtils.firstElement(list);
    }

    /**
     * 查询余额日志列表
     *
     * @param balanceLog 余额日志
     * @return 余额日志
     */
    @Override
    public List<BalanceLogVO> selectBalanceLogList(BalanceLogQuery balanceLog)
    {
        return balanceLogMapper.selectBalanceLogList(balanceLog);
    }

    /**
     * 新增余额日志
     *
     * @param balanceLog 余额日志
     * @return 结果
     */
    @Override
    public int insertBalanceLog(BalanceLog balanceLog)
    {
        balanceLog.setCreateTime(DateUtils.getNowDate());
        return balanceLogMapper.insertBalanceLog(balanceLog);
    }

    /**
     * 修改余额日志
     *
     * @param balanceLog 余额日志
     * @return 结果
     */
    @Override
    public int updateBalanceLog(BalanceLog balanceLog)
    {
        return balanceLogMapper.updateBalanceLog(balanceLog);
    }

    /**
     * 批量删除余额日志
     *
     * @param ids 需要删除的余额日志主键
     * @return 结果
     */
    @Override
    public int deleteBalanceLogByIds(Long[] ids)
    {
        return balanceLogMapper.deleteBalanceLogByIds(ids);
    }

    /**
     * 删除余额日志信息
     *
     * @param id 余额日志主键
     * @return 结果
     */
    @Override
    public int deleteBalanceLogById(Long id)
    {
        return balanceLogMapper.deleteBalanceLogById(id);
    }
}
