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

import java.util.Date;

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

import com.ym.mec.biz.dal.dao.EmployeeInfoDao;
import com.ym.mec.biz.dal.dao.EmployeeVisitDao;
import com.ym.mec.biz.dal.entity.EmployeeInfo;
import com.ym.mec.biz.dal.entity.EmployeeVisit;
import com.ym.mec.biz.service.EmployeeVisitService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.service.impl.BaseServiceImpl;

@Service
public class EmployeeVisitServiceImpl extends BaseServiceImpl<Long, EmployeeVisit>  implements EmployeeVisitService {
	
	@Autowired
	private EmployeeVisitDao employeeVisitDao;
	
	@Autowired
	private EmployeeInfoDao employeeInfoDao; 

	@Override
	public BaseDAO<Long, EmployeeVisit> getDAO() {
		return employeeVisitDao;
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
	public long insert(EmployeeVisit bean) {
		
		EmployeeInfo employeeInfo = employeeInfoDao.get(bean.getEmployeeInfoId());
		if(employeeInfo == null){
			throw new BizException("用户信息查询失败");
		}
		
		employeeInfo.setNextVisitDate(bean.getNextVisitDate());
		employeeInfo.setUpdateTime(new Date());
		employeeInfoDao.update(employeeInfo);
		
		return super.insert(bean);
	}
	
}