package com.jeesharp.business.modules.finance.profitsharing.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeesharp.business.modules.finance.profitsharing.entity.ProfitSharingReceiver;
import com.jeesharp.business.modules.finance.profitsharing.mapper.ProfitSharingReceiverMapper;
import com.jeesharp.business.modules.finance.profitsharing.service.ProfitSharingReceiverService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * 分账接收方明细领域服务实现。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ProfitSharingReceiverServiceImpl implements ProfitSharingReceiverService {

    private final ProfitSharingReceiverMapper profitSharingReceiverMapper;

    @Override
    @Transactional(readOnly = false)
    public void saveReceiver(ProfitSharingReceiver receiver) {
        profitSharingReceiverMapper.insert(receiver);
    }

    @Override
    public List<ProfitSharingReceiver> listByProfitSharingOrderId(String profitSharingOrderId) {
        if (StrUtil.isBlank(profitSharingOrderId)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<ProfitSharingReceiver> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProfitSharingReceiver::getProfitSharingOrderId, profitSharingOrderId.trim());
        return profitSharingReceiverMapper.selectList(wrapper);
    }
}
