package com.sunxung.factoring.service.tradingPlatform.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.tradingPlatform.Platform;
import com.sunxung.factoring.entity.tradingPlatform.TradingPlatformInvoiceInfo;
import com.sunxung.factoring.mapper.tradingPlatform.TradingPlatformInvoiceInfoMapper;
import com.sunxung.factoring.service.tradingPlatform.PlatformService;
import com.sunxung.factoring.service.tradingPlatform.TradingPlatformInvoiceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Yafan Wang
 * @Date 2023/3/9 14:12
 */
@Service
public class TradingPlatformInvoiceInfoServiceImpl extends ServiceImpl<TradingPlatformInvoiceInfoMapper, TradingPlatformInvoiceInfo> implements TradingPlatformInvoiceInfoService {

    @Autowired
    private PlatformService platformService;

    @Override
    public TradingPlatformInvoiceInfo findByPlatformId(Long platformId) {
        TradingPlatformInvoiceInfo platformInvoiceInfo = getOne(new QueryWrapper<TradingPlatformInvoiceInfo>().eq("trading_platform_id", platformId));
        if (platformInvoiceInfo == null) {
            platformInvoiceInfo = new TradingPlatformInvoiceInfo();
            Platform platform = platformService.getById(platformId);
            if (platform != null) {
                platformInvoiceInfo.setSocialCreditCode(platform.getSocialCreditCode());
            }
        }
        return platformInvoiceInfo;
    }
}
