package com.ssj.service.sys.opentest;

import com.ssj.bean.sys.opentest.OpenTestUnit;
import com.ssj.dao.sys.opentest.OpenTestUnitDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Mount Liu
 * @date 2020/5/15
 */
@Service
@Transactional
public class OpenTestUnitServiceImpl extends BaseServiceImpl<OpenTestUnit, String> implements OpenTestUnitService {

    @Autowired
    private OpenTestUnitDao dao;

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

    @Override
    public List<OpenTestUnit> findUnit(boolean isAll, int type) {
        if (isAll) {
            return dao.findAllUnit(type);
        }
        return dao.findValidUnit(type);
    }

    @Override
    public List<OpenTestUnit> findUnit(String grade, String subject, String versionName, String unit) {
        return dao.findByGradeAndSubjectAndVersionNameAndUnit(grade, subject, versionName, unit);
    }

    @Override
    public List<OpenTestUnit> findUnit(String grade, String subject, String versionName, String unit, String semester, int type) {
        int semesterType = "第一学期".equals(semester) ? 1 : 2;
        if (type == 2) {
            return dao.findUnit(grade, subject, versionName, unit, semesterType, type);
        } else {
            return dao.findUnit(grade, subject, versionName, semesterType, type);
        }
    }


    @Override
    public List<OpenTestUnit> findUnit(String grade, String subject, String versionName, String unit, String semester, int type, int isValid) {
        int semesterType = "第一学期".equals(semester) ? 1 : 2;
        if (type == 2) {
            //单元测评
            return dao.findByGradeAndSubjectAndVersionNameAndUnitAndIsValidAndSemesterAndType(grade, subject, versionName, unit, isValid, semesterType, type);
        } else {
            return dao.findByGradeAndSubjectAndVersionNameAndIsValidAndSemesterAndType(grade, subject, versionName, isValid, semesterType, type);
        }
    }


}
