package com.sckw.system.repository;

import com.baomidou.mybatisplus.core.metadata.IPage;
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.sckw.core.model.base.BaseModel;
import com.sckw.core.model.enums.ApprovalEnum;
import com.sckw.system.dao.KwsEnterpriseDao;
import com.sckw.system.model.KwsEnterprise;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author PC
 */
@Repository
public class KwsEnterpriseRepository extends ServiceImpl<KwsEnterpriseDao,KwsEnterprise>{
    public IPage<KwsEnterprise> pageEnt(int pageNum, int pageSize, Long entId) {
        return page(new Page<>(pageNum, pageSize), Wrappers.<KwsEnterprise>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .eq(BaseModel::getStatus,0)
                .eq(Objects.nonNull(entId),KwsEnterprise::getId, entId));
    }

    public List<KwsEnterprise> queryByEntIdAndName(String entId, String entName) {
        return list(Wrappers.<KwsEnterprise>lambdaQuery()
                .eq(BaseModel::getDelFlag, 0)
                .eq(BaseModel::getStatus, 0)
                .eq(KwsEnterprise::getApproval, ApprovalEnum.OK.getCode())
                .eq(StringUtils.isNotBlank(entId), KwsEnterprise::getId, entId)
                .like(StringUtils.isNotBlank(entName), KwsEnterprise::getFirmName, entName));
    }

    public List<KwsEnterprise> queryByEntIds(Set<Long> entIds,String entName) {
        return list(Wrappers.<KwsEnterprise>lambdaQuery()
                .eq(BaseModel::getDelFlag, 0)
                .eq(BaseModel::getStatus, 0)
                .eq(KwsEnterprise::getApproval, ApprovalEnum.OK.getCode())
                .in(KwsEnterprise::getId, entIds)
                .like(StringUtils.isNotBlank(entName), KwsEnterprise::getFirmName, entName));
    }

    public List<KwsEnterprise> queryByParentEntIds(Set<Long> entIds) {
        return list(Wrappers.<KwsEnterprise>lambdaQuery()
                .eq(BaseModel::getDelFlag, 0)
                .eq(BaseModel::getStatus, 0)
                .eq(KwsEnterprise::getApproval, ApprovalEnum.OK.getCode())
                .in(KwsEnterprise::getPid, entIds));
    }
}
