package com.ym.mec.biz.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.TeacherDefaultMusicGroupSalaryDao;
import com.ym.mec.biz.dal.entity.TeacherDefaultMusicGroupSalary;
import com.ym.mec.biz.dal.enums.ClassGroupTypeEnum;
import com.ym.mec.biz.dal.enums.YesOrNoEnum;
import com.ym.mec.biz.service.TeacherDefaultMusicGroupSalaryService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

import java.util.Date;
import java.util.List;

@Service
public class TeacherDefaultMusicGroupSalaryServiceImpl extends BaseServiceImpl<Long, TeacherDefaultMusicGroupSalary>  implements TeacherDefaultMusicGroupSalaryService {
	
	@Autowired
	private TeacherDefaultMusicGroupSalaryDao teacherDefaultMusicGroupSalaryDao;

	@Override
	public BaseDAO<Long, TeacherDefaultMusicGroupSalary> getDAO() {
		return teacherDefaultMusicGroupSalaryDao;
	}

	@Override
    public TeacherDefaultMusicGroupSalary getTeacherSalaryByUserIdAndType(int userId,ClassGroupTypeEnum classGroupType) {
        return teacherDefaultMusicGroupSalaryDao.getTeacherSalaryByUserIdAndType(userId, classGroupType);
    }

	@Override
	public void batchUpset(List<TeacherDefaultMusicGroupSalary> teacherDefaultMusicGroupSalaries) {
		if(teacherDefaultMusicGroupSalaries != null && teacherDefaultMusicGroupSalaries.size() > 0){
			Date date = new Date();
			teacherDefaultMusicGroupSalaries.forEach(e->{
				if(e.getId() == null){
					teacherDefaultMusicGroupSalaryDao.insert(e);
				}else{
					if(e.getDelFlag() == YesOrNoEnum.YES){
						teacherDefaultMusicGroupSalaryDao.delete(e.getId());
					}else {
						e.setUpdateTime(date);
						teacherDefaultMusicGroupSalaryDao.update(e);
					}
				}
			});
		}
	}
}