package com.bizzan.bitrade.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.bizzan.bitrade.dao.MemberFeedbackDao;
import com.bizzan.bitrade.entity.MemberFeedback;
import com.bizzan.bitrade.pagination.Criteria;
import com.bizzan.bitrade.pagination.Restrictions;
import com.querydsl.core.types.Predicate;

@Service
public class MemberFeedbackService {

	@Autowired
	private MemberFeedbackDao memberFeedbackDao;
	
	public MemberFeedback findOne(Long id) {
		return memberFeedbackDao.findOne(id);
	}
	
	public void save(MemberFeedback memberFeedback) {
		memberFeedbackDao.save(memberFeedback);
	}
	
	public void deleteBatch(Long[] array) {
        for (Long serialNumber : array) {
        	memberFeedbackDao.delete(serialNumber);
        }
    }
	
	public Page<MemberFeedback> findAll(Predicate predicate, Pageable pageable) {
        return memberFeedbackDao.findAll(predicate, pageable);
    }
	
	public Page<MemberFeedback> page(Integer pageNo, Integer pageSize, Criteria<MemberFeedback> specification) {
        //排序方式 (需要倒序 这样    Criteria.sort("id","createTime.desc") ) //参数实体类为字段名
        Sort orders = Criteria.sortStatic("id");
        //分页参数
        PageRequest pageRequest = new PageRequest(pageNo, pageSize, orders);
        return memberFeedbackDao.findAll(specification, pageRequest);
    }
    
	
	public Page<MemberFeedback> pageByMemberId(Integer pageNo, Integer pageSize, Long memberId) {
		Criteria<MemberFeedback> specification = new Criteria<MemberFeedback>();
        specification.add(Restrictions.eq("memberId", memberId, false));
        return this.page(pageNo, pageSize, specification);
	}
}
