/**
 * @filename:/rderIncomeAssociationServiceImpl 2024-11-04
 * @project KJT v1.1.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.service.finance.paymentcollection.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trade.service.business.separateaccounts.domain.SeparateAccounts;
import com.trade.service.business.separateaccounts.domain.SeparateAccountsInfo;
import com.trade.service.business.separateaccounts.service.SeparateAccountsInfoService;
import com.trade.service.business.separateaccounts.service.SeparateAccountsService;
import com.trade.service.finance.paymentcollection.domain.OrderIncomeAssociation;
import com.trade.service.finance.paymentcollection.mapper.OrderIncomeAssociationMapper;
import com.trade.service.finance.paymentcollection.service.OrderIncomeAssociationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description:订单与入账关联表服务实现
 * @version: v1.1.0
 * @author: wanglang
 */
@Service
public class OrderIncomeAssociationServiceImpl extends ServiceImpl<OrderIncomeAssociationMapper, OrderIncomeAssociation> implements OrderIncomeAssociationService {

    @Resource
    private SeparateAccountsInfoService separateAccountsInfoService;
    @Resource
    private SeparateAccountsService separateAccountsService;

    @Override
    public OrderIncomeAssociation getByBillingIncomeIdId(Long billingIncomeId) {
        return this.lambdaQuery().eq(OrderIncomeAssociation::getBillingIncomeId, billingIncomeId).one();
    }

    @Override
    public OrderIncomeAssociation getOrderIncomeAssociation(Long separateAccountsInfoId) {
        SeparateAccountsInfo separateAccountsInfo = separateAccountsInfoService.getById(separateAccountsInfoId);
        if (separateAccountsInfo == null) {
            return null;
        }
        SeparateAccounts separateAccounts = separateAccountsService
                .getById(separateAccountsInfo.getSeparateAccountsId());
        if (separateAccounts == null) {
            return null;
        }
        return getByBillingIncomeIdId(separateAccounts.getBillingIncomeId());
    }
}
