package com.ssj.service.sys.parent.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.sys.parent.domain.SSJTermtrainQuestion;
import com.ssj.dao.sys.parent.dao.SSJTermtrainQuestionDao;
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.sys.parent.service.SSJTermtrainQuestionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service(version="1.0")
@Transactional
public class SSJTermtrainQuestionServiceImpl extends BaseServiceImpl<SSJTermtrainQuestion, String> implements SSJTermtrainQuestionService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SSJTermtrainQuestionDao dao;

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

    @Override
    public List<String> findDistinctBookName(String courseName, String grade) {
        return dao.findDistinctBookName(courseName, grade);
    }

    @Override
    public List<SSJTermtrainQuestion> findDistinctProvince(String courseName, String grade, String bookName) {
        return dao.findDistinctProvince(courseName, grade, bookName);
    }

    @Override
    public List<SSJTermtrainQuestion> findDistinctCity(String courseName, String grade, String bookName, String province) {
        return dao.findDistinctCity(courseName, grade, bookName, province);
    }

    @Override
    public List<SSJTermtrainQuestion> findDistinctArea(String courseName, String grade, String bookName, String province, String city) {
        return dao.findDistinctArea(courseName, grade, bookName, province, city);
    }

    @Override
    public List<SSJTermtrainQuestion> findDistinctYear(String courseName, String grade, String bookName, String province, String city, String area) {
        return dao.findDistinctYear(courseName, grade, bookName, province, city, area);
    }

    @Override
    public List<SSJTermtrainQuestion> findList(String courseName, String grade, String bookName, String province, String city, String area, String year) {
        return dao.findByCourseNameAndGradeAndBookNameAndProvinceAndCityAndAreaAndYear(courseName, grade, bookName, province, city, area, year);
    }

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