package com.ningdatech.carapi.company.service.impl;

import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.carapi.company.entity.CompanyCertificate;
import com.ningdatech.carapi.company.mapper.CompanyCertificateMapper;
import com.ningdatech.carapi.company.service.ICompanyCertificateService;
import com.ningdatech.carapi.datascope.aop.LambdaDataScope;
import com.ningdatech.carapi.datascope.contants.LambdaDataScopeTypeEnum;

/**
 * <p>
 * 企业证书 服务实现类
 * </p>
 *
 * @author liushuai
 * @since 2022-10-25
 */
@Service
public class CompanyCertificateServiceImpl extends ServiceImpl<CompanyCertificateMapper, CompanyCertificate> implements ICompanyCertificateService {
    @Override
    public Page<CompanyCertificate> getCertificates(Page<CompanyCertificate> page, Long companyId) {
        LambdaQueryWrapper<CompanyCertificate> wrapper = Wrappers.lambdaQuery(CompanyCertificate.class);
        CompanyCertificateServiceImpl context = (CompanyCertificateServiceImpl) AopContext.currentProxy();
        context.buildQuery(wrapper, companyId);
        return page(page,wrapper);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildQuery(LambdaQueryWrapper<CompanyCertificate> wrapper, Long companyId) {
        wrapper.eq(CompanyCertificate::getCompanyId,companyId);
    }
}
