package com.eactive.eai.rms.data.entity.onl.logger;

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

import com.eactive.eai.data.RollingTable;
import com.eactive.eai.data.entity.onl.logger.SubMessageLog;
import com.eactive.eai.data.entity.onl.logger.SubMessageLogId;
import com.eactive.eai.rms.common.util.CommonUtil;

@Service
@Transactional
public class SubMessageLogServiceImpl implements SubMessageLogService {

	private SubMessageLogRepository subMessageLogRepository;

	private ApplicationContext applicationContext;

	@Autowired
	public SubMessageLogServiceImpl(SubMessageLogRepository subMessageLogRepository,
			ApplicationContext applicationContext) {
		this.subMessageLogRepository = subMessageLogRepository;
		this.applicationContext = applicationContext;
	}

	@Override
	public SubMessageLog getById(String date, SubMessageLogId subMessageLogId) {

		long time = CommonUtil.getCalendar(date).getTimeInMillis();
		SubMessageLog subMessageLog = (SubMessageLog) applicationContext
				.getBean(RollingTable.class, SubMessageLog.class, time);

		return subMessageLogRepository.getById(subMessageLog.getClass(), subMessageLogId);
	}

}
