package com.ssj.service.course.service.impl;

import com.ssj.bean.course.domain.CourseScanHis;
import com.ssj.dao.course.dao.ICourseScanDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.course.service.ICourseScanHisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class CourseScanHisServiceImpl extends BaseServiceImpl<CourseScanHis, String> implements ICourseScanHisService {

	@Autowired
	private ICourseScanDao dao;
	
	@Override
	public PagingAndSortingRepository<CourseScanHis, String> getDao() {
		
		return dao;
	}

	@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public CourseScanHis getSessionHis(String sessionId) {
		
		return dao.getSessionHis(sessionId,1);
	}

	@Override
	public void saveCourseScanHis(String sessionId, String userId) {
		CourseScanHis  his=dao.getSessionHis(sessionId);
		if(his ==null){
			his =new CourseScanHis();
			his.setSessionId(sessionId);
		}
		his.setState(1);
		his.setUserId(userId);
		his.setCreateTime(new Date());
		this.save(his);
	}

	
}
