package com.sunxung.factoring.service.businessmanagement.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.businessmanagement.BusinessBasicInfo;
import com.sunxung.factoring.entity.businessmanagement.BusinessSupplierInfo;
import com.sunxung.factoring.mapper.businessManagement.BusinessSupplierInfoMapper;
import com.sunxung.factoring.service.businessmanagement.BusinessBasicInfoService;
import com.sunxung.factoring.service.businessmanagement.BusinessSupplierInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liutao
 */
@Service
public class BusinessSupplierInfoServiceImpl extends ServiceImpl<BusinessSupplierInfoMapper, BusinessSupplierInfo> implements BusinessSupplierInfoService {

    @Autowired
    private BusinessBasicInfoService businessBasicInfoService;

    @Override
    public List<BusinessSupplierInfo> findByBasicInfoId(Long businessBasicInfoId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("business_basic_info_id", businessBasicInfoId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<BusinessSupplierInfo> getSupplierList(String businessNumber) {
        BusinessBasicInfo basicInfo = businessBasicInfoService.getByBusinessNumber(businessNumber);
        List<BusinessSupplierInfo> list = new ArrayList<>();
        if (basicInfo != null && basicInfo.getId() != null) {
            list = findByBasicInfoId(basicInfo.getId());
        }
        return list;
    }
}
