package com.ssj.service.conch.game.service.impl;

import com.ssj.bean.sys.game.domain.GameQuestion;
import com.ssj.dao.sys.game.dao.GameQuestionDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.persistence.DynamicSpecifications;
import com.ssj.framework.core.persistence.SearchFilter;
import com.ssj.service.conch.game.service.GameQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author Mount Liu
 * @date 2018/2/19
 */
@Service
@Transactional
public class GameQuestionServiceImpl extends BaseServiceImpl<GameQuestion, String> implements GameQuestionService {

    @Autowired
    private GameQuestionDao dao;

    @Override
    public PagingAndSortingRepository<GameQuestion, String> getDao() {
        return dao;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page<GameQuestion> findByPage(Map<String, Object> params, Pageable sp) {
        Map<String, SearchFilter> filters = SearchFilter.parse(params);
        Specification<GameQuestion> specification = DynamicSpecifications.bySearchFilter(filters.values(), GameQuestion.class);
        return dao.findAll(specification, sp);
    }
}
