package com.jkcredit.invoice.service.customer.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jkcredit.invoice.mapper.customer.CustomerRecMapper;
import com.jkcredit.invoice.model.entity.customer.CustomerRec;
import com.jkcredit.invoice.service.customer.CustomerRecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户信息维护接口实现类
 * @author mumuxigua
 */
@Service("customerRecService")
public class CustomerRecServiceImpl extends ServiceImpl<CustomerRecMapper, CustomerRec> implements CustomerRecService {
    @Autowired
    CustomerRecMapper customerRecMapper;

    /**
     * 查找所有备案信息
     *
     * @param page
     * @param customerRec
     * @return
     */
    @Override
    public IPage findAllCustomerRec(Page page, CustomerRec customerRec) {
        return customerRecMapper.selectAllByPage(page, customerRec);
    }


    /**
     * 查找所有备案信息(备案预警查询)
     *
     * @param page
     * @param customerRec
     * @return
     */
    @Override
    public IPage findAllCustomerRecWarning(Page page, CustomerRec customerRec) {
        return customerRecMapper.selectAllByPageWarning(page, customerRec);
    }


    /**
     * 客户信息导出
     *
     * @param customerRec
     * @return
     */
    @Override
    public List<CustomerRec> findAllCustomerRecForExport(CustomerRec customerRec) {
        return customerRecMapper.selectAllByPageExport(customerRec);
    }


    /**
     * 未在平台备案成功客户查询
     *
     * @param record
     * @return
     */
    @Override
    public synchronized CustomerRec selectByCustomerNameAndCompanyReference(CustomerRec record) {
        CustomerRec customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(record);
        if (customerRec == null || customerRec.getRecStatus() != 1) {
            customerRec = null;
        }
        return customerRec;
    }

    /**
     * 根据企业编码查询客户信息
     *
     * @param record
     * @return
     */
    @Override
    public synchronized CustomerRec selectByCustomerNameAndCompanyNum(CustomerRec record) {
        CustomerRec customerRec = customerRecMapper.selectByCustomerNameAndCompanyNum(record);
        if (customerRec == null || customerRec.getRecStatus() != 1) {
            customerRec = null;
        }
        return customerRec;
    }

    /**
     * 根据企业名称查询客户信息
     *
     * @param record
     * @return
     */
    @Override
    public CustomerRec selectByCustomerNameAndCompanyConcat(CustomerRec record) {
        return customerRecMapper.selectByCustomerNameAndCompanyConcat(record);
    }

    @Override
    public CustomerRec selectByCustomerNameAndCompany(CustomerRec customerRec) {
        return customerRecMapper.selectByCustomerNameAndCompany(customerRec);
    }

    /**
     * 查询有效的客户备案信息
     *
     * @param
     * @return java.util.List<com.jkcredit.invoice.model.entity.customer.CustomerRec>
     * @throws
     * @createDate 2024/4/4 上午11:21
     * @author mashengyi
     */
    @Override
    public List<CustomerRec> findAllCustomeRecQueryList() {
        return customerRecMapper.selectAllCustomeRecQueryList();
    }
}
