package com.keao.edu.user.service.impl;

import com.keao.edu.common.dal.BaseDAO;
import com.keao.edu.common.exception.BizException;
import com.keao.edu.common.service.impl.BaseServiceImpl;
import com.keao.edu.user.dao.MusicTheoryDao;
import com.keao.edu.user.entity.MusicTheory;
import com.keao.edu.user.service.MusicTheoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class MusicTheoryServiceImpl extends BaseServiceImpl<Integer, MusicTheory> implements MusicTheoryService {
	
	@Autowired
	private MusicTheoryDao musicTheoryDao;

	@Override
	public BaseDAO<Integer, MusicTheory> getDAO() {
		return musicTheoryDao;
	}

	@Override
	public void addMusicTheory(MusicTheory musicTheory) {
		if(Objects.isNull(musicTheory.getLevel())){
			throw new BizException("请设置乐理级别");
		}
		if(Objects.isNull(musicTheory.getFee())){
			throw new BizException("请设置乐理费用");
		}
		MusicTheory existsMusicTheory = musicTheoryDao.getWithTenantAndLevel(musicTheory.getTenantId(), musicTheory.getLevel());
		if(Objects.nonNull(existsMusicTheory)){
			throw new BizException("乐理级别重复");
		}
		musicTheoryDao.insert(musicTheory);
	}
}
