package com.chinacreator.video.validate;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Component;

import com.chinacreator.video.exception.BussinessException;

@Component
public class TimetampValidate {

	public void validate(String timetamp) throws Exception {
		if(StringUtils.isEmpty(timetamp)) {
			throw new BussinessException("10001", "timestamp不能为空");
		}
		long localTimestamp = (System.currentTimeMillis())/1000;
		try {
			if((localTimestamp - NumberUtils.toLong(timetamp)) >300 || (localTimestamp - NumberUtils.toLong(timetamp)) <-300) {
				throw new BussinessException("10002", "timestamp已失效");
			}
		} catch (Exception e) {
			if(e instanceof BussinessException) {
				throw e;
			}else {
				throw new BussinessException("10002", "timestamp已失效");
			}
		}
	}
}
