package com.ruoyi.ss.dividendRefund.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.dividendRefund.domain.DividendRefund;
import com.ruoyi.ss.dividendRefund.domain.DividendRefundQuery;
import com.ruoyi.ss.dividendRefund.domain.DividendRefundVO;
import com.ruoyi.ss.dividendRefund.mapper.DividendRefundMapper;
import com.ruoyi.ss.dividendRefund.service.DividendRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 分成退款记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-25
 */
@Service
public class DividendRefundServiceImpl implements DividendRefundService
{
    @Autowired
    private DividendRefundMapper dividendRefundMapper;

    /**
     * 查询分成退款记录
     *
     * @param id 分成退款记录主键
     * @return 分成退款记录
     */
    @Override
    public DividendRefundVO selectDividendRefundById(Long id)
    {
        return dividendRefundMapper.selectDividendRefundById(id);
    }

    /**
     * 查询分成退款记录列表
     *
     * @param dividendRefund 分成退款记录
     * @return 分成退款记录
     */
    @Override
    public List<DividendRefundVO> selectDividendRefundList(DividendRefundQuery dividendRefund)
    {
        return dividendRefundMapper.selectDividendRefundList(dividendRefund);
    }

    /**
     * 新增分成退款记录
     *
     * @param dividendRefund 分成退款记录
     * @return 结果
     */
    @Override
    public int insertDividendRefund(DividendRefund dividendRefund)
    {
        dividendRefund.setCreateTime(DateUtils.getNowDate());
        return dividendRefundMapper.insertDividendRefund(dividendRefund);
    }

    /**
     * 修改分成退款记录
     *
     * @param dividendRefund 分成退款记录
     * @return 结果
     */
    @Override
    public int updateDividendRefund(DividendRefund dividendRefund)
    {
        return dividendRefundMapper.updateDividendRefund(dividendRefund);
    }

    /**
     * 批量删除分成退款记录
     *
     * @param ids 需要删除的分成退款记录主键
     * @return 结果
     */
    @Override
    public int deleteDividendRefundByIds(Long[] ids)
    {
        return dividendRefundMapper.deleteDividendRefundByIds(ids);
    }

    /**
     * 删除分成退款记录信息
     *
     * @param id 分成退款记录主键
     * @return 结果
     */
    @Override
    public int deleteDividendRefundById(Long id)
    {
        return dividendRefundMapper.deleteDividendRefundById(id);
    }

    @Override
    public int batchInsert(List<DividendRefund> list) {
        if (CollectionUtils.isEmptyElement(list)) {
            return 0;
        }
        Date now = DateUtils.getNowDate();
        for (DividendRefund refund : list) {
            refund.setCreateTime(now);
        }
        return dividendRefundMapper.batchInsert(list);
    }

    @Override
    public BigDecimal selectSumOfAmount(DividendRefundQuery query) {
        return dividendRefundMapper.selectSumOfAmount(query);
    }
}
