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

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.entity.onl.routing.QRouting;
import com.eactive.eai.data.entity.onl.routing.Routing;
import com.eactive.eai.data.jpa.AbstractDataService;
import com.querydsl.core.types.dsl.BooleanExpression;

@Service
@Transactional
public class RoutingService extends AbstractDataService<Routing, String, RoutingEMSRepository> {
	public Page<Routing> findAll(Pageable pageable, RoutingSearch routingSearch) {
		QRouting qRouting = QRouting.routing;

		BooleanExpression predicate = qRouting.routname.containsIgnoreCase(routingSearch.getSearchRoutName())
				.and(qRouting.motivrouturiname.contains(routingSearch.getSearchSyncUri()))
				.and(qRouting.nonmotivrouturiname.contains(routingSearch.getSearchAsynUri()));

		return repository.findAll(predicate, pageable);
	}

	public Iterable<Routing> findByLayerdstcd(String layerdstcd) {
		QRouting qRouting = QRouting.routing;
		BooleanExpression predicate = qRouting.layerdstcd.eq(layerdstcd);
		return repository.findAll(predicate, qRouting.routname.asc());
	}
}
