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

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SnowFlakeUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.transferDetail.domain.TransferDetail;
import com.ruoyi.ss.transferDetail.domain.TransferDetailQuery;
import com.ruoyi.ss.transferDetail.domain.TransferDetailVO;
import com.ruoyi.ss.transferDetail.mapper.TransferDetailMapper;
import com.ruoyi.ss.transferDetail.service.ITransferDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 转账明细Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@Service
public class TransferDetailServiceImpl implements ITransferDetailService
{
    @Autowired
    private TransferDetailMapper transferDetailMapper;

    /**
     * 查询转账明细
     *
     * @param detailId 转账明细主键
     * @return 转账明细
     */
    @Override
    public TransferDetailVO selectTransferDetailByDetailId(Long detailId)
    {
        return transferDetailMapper.selectTransferDetailByDetailId(detailId);
    }

    /**
     * 查询转账明细列表
     *
     * @param transferDetail 转账明细
     * @return 转账明细
     */
    @Override
    public List<TransferDetailVO> selectTransferDetailList(TransferDetailQuery transferDetail)
    {
        return transferDetailMapper.selectTransferDetailList(transferDetail);
    }

    /**
     * 新增转账明细
     *
     * @param transferDetail 转账明细
     * @return 结果
     */
    @Override
    public int insertTransferDetail(TransferDetail transferDetail)
    {
        setBaseInfo(transferDetail);
        return transferDetailMapper.insertTransferDetail(transferDetail);
    }

    /**
     * 修改转账明细
     *
     * @param transferDetail 转账明细
     * @return 结果
     */
    @Override
    public int updateTransferDetail(TransferDetail transferDetail)
    {
        return transferDetailMapper.updateTransferDetail(transferDetail);
    }

    /**
     * 批量删除转账明细
     *
     * @param detailIds 需要删除的转账明细主键
     * @return 结果
     */
    @Override
    public int deleteTransferDetailByDetailIds(Long[] detailIds)
    {
        return transferDetailMapper.deleteTransferDetailByDetailIds(detailIds);
    }

    /**
     * 删除转账明细信息
     *
     * @param detailId 转账明细主键
     * @return 结果
     */
    @Override
    public int deleteTransferDetailByDetailId(Long detailId)
    {
        return transferDetailMapper.deleteTransferDetailByDetailId(detailId);
    }

    @Override
    public int batchInsert(List<TransferDetailVO> list) {
        if (CollectionUtils.isEmptyElement(list)) {
            return 0;
        }
        for (TransferDetailVO detail : list) {
            this.setBaseInfo(detail);
        }
        return transferDetailMapper.batchInsert(list);
    }

    @Override
    public int updateByQuery(TransferDetail data, TransferDetailQuery query) {
        return transferDetailMapper.updateByQuery(data, query);
    }

    private void setBaseInfo(TransferDetail detail) {
        detail.setDetailNo(String.valueOf(SnowFlakeUtil.newId()));
        detail.setCreateTime(DateUtils.getNowDate());
    }
}
