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

import com.ssj.bean.sys.problem.domain.BanbenDetail;
import com.ssj.dao.sys.problem.dao.IBanbenDetalDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.sys.problem.service.IBanbenDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class BanbenDetailServiceImpl extends BaseServiceImpl<BanbenDetail,String> implements IBanbenDetailService {

    @Autowired
    private IBanbenDetalDao dao;

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

    @Override
    public BanbenDetail findBanbenByAnyParams(String courseName, String schoolId, String grade) {
        return dao.findBanbenByAnyParams(courseName,schoolId,grade);
    }

    @Override
    public int findBanbenByParams(String courseName, String schoolName, String grade,String area) {
        BanbenDetail detail = dao.findBanbenByParams(courseName,schoolName,grade,area);
        if(detail == null){
//            if(courseName.equals("语文")){
////                return  2;
////            }else if(courseName.equals("数学")){
////                return  2;
////            }else if(courseName.equals("英语")){
////                return  2;
////            }else{
////                return  2;
////            }
            return 2;
        }else {
            return detail.getBanben();
        }
    }

    @Override
    @Cacheable(value = "key", keyGenerator = "keyGenerator_Banben" , cacheManager="cacheManager")
    public int findBanben(String courseName, String schoolName, String grade) {
        BanbenDetail detail = dao.findBanbenByParams(courseName,schoolName,grade);
        if(detail == null){
//            if(courseName.equals("语文")){
////                return  2;
////            }else if(courseName.equals("数学")){
////                return  2;
////            }else if(courseName.equals("英语")){
////                return  2;
////            }else{
////                return  2;
////            }
            return 2;
        }else {
            return detail.getBanben();
        }
    }
}
