package com.eactive.eai.rms.data.entity.onl.company;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.data.jpa.AbstractDataService;
import com.eactive.eai.rms.onl.manage.serviceinfo.company.CompanyUISearch;
import com.querydsl.core.types.dsl.BooleanExpression;

@Service
@Transactional
public class CompanyService extends AbstractDataService<Company, CompanyId, CompanyRepository> {

	public Page<Company> findPageWithSearch(Pageable pageable, CompanyUISearch companyUISearch) {

		QCompany qCompany = QCompany.company;

		BooleanExpression predicate = qCompany.companyName.containsIgnoreCase(companyUISearch.getSearchCompanyName())
								.and(qCompany.id.companyCode.containsIgnoreCase(companyUISearch.getSearchCompanyCode())
								.and(qCompany.id.appCode.containsIgnoreCase(companyUISearch.getSearchAppCode()))
								.and(qCompany.id.bzwkDstCode.contains(companyUISearch.getSearchBzwkDstcode())));

		return repository.findAll(predicate, pageable);
	}
}
