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

import com.ym.mec.biz.dal.dao.CourseScheduleTeacherSalaryDao;
import com.ym.mec.biz.dal.dao.TeacherSalaryModifyLogDao;
import com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary;
import com.ym.mec.biz.dal.entity.TeacherSalaryModifyLog;
import com.ym.mec.biz.service.CourseScheduleTeacherSalaryService;
import com.ym.mec.biz.service.TeacherSalaryModifyLogService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TeacherSalaryModifyLogServiceImpl extends BaseServiceImpl<Long, TeacherSalaryModifyLog>  implements TeacherSalaryModifyLogService {
	
	@Autowired
	private TeacherSalaryModifyLogDao teacherSalaryModifyLogDao;
	@Autowired
	private CourseScheduleTeacherSalaryDao courseScheduleTeacherSalaryDao;

	@Override
	public BaseDAO<Long, TeacherSalaryModifyLog> getDAO() {
		return teacherSalaryModifyLogDao;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public Object add(TeacherSalaryModifyLog modifyLog) {
		//获取之前的课酬信息
		CourseScheduleTeacherSalary salary = courseScheduleTeacherSalaryDao.queryByCourseScheduleIdAndUserId(modifyLog.getCourseScheduleId(), modifyLog.getTeacherId());
		courseScheduleTeacherSalaryDao.updateSalary(modifyLog);
		//修改教师课酬
		modifyLog.setPreExpectSalary(salary.getActualSalary());
		modifyLog.setPreReduceSalary(salary.getReduceSalary());
		return teacherSalaryModifyLogDao.insert(modifyLog);
	}
}