package com.uas.platform.b2b.history.service.impl;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.uas.platform.b2b.history.dao.PurchaseOrderChangeDao;
import com.uas.platform.b2b.history.model.PurchaseOrderChange;
import com.uas.platform.b2b.history.service.PurchaseOrderChangeService;
import com.uas.platform.core.model.PageInfo;

@Service("history.PurchaseOrderChangeService")
public class PurchaseOrderChangeServiceImpl implements PurchaseOrderChangeService {

	@Autowired
	private PurchaseOrderChangeDao purchaseOrderChangeDao;

	@Override
	public Page<PurchaseOrderChange> findAllByPageInfo(final PageInfo pageInfo) {
		return purchaseOrderChangeDao.findAll(new Specification<PurchaseOrderChange>() {

			public Predicate toPredicate(Root<PurchaseOrderChange> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
				query.where(pageInfo.getPredicates(root, query, builder));
				return null;
			}
		}, pageInfo);
	}

	@Override
	public PurchaseOrderChange findById(Long id) {
		return purchaseOrderChangeDao.findOne(id);
	}
}