GetUIDAndCode.java 1.9 KB
package com.bsth.util;

import java.util.Timer;
import java.util.TimerTask;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bsth.repository.CarParkRepository;
import com.bsth.repository.LineRepository;
import com.bsth.repository.SectionRepository;
import com.bsth.repository.StationRepository;

/**
 * 
 * @ClassName: GetUIDAndCode(自定义ID)
 * 
 * @Description: TODO(自定义ID)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年4月28日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */
@Component
public class GetUIDAndCode  {
	
	@Autowired
	private  LineRepository lineRepository;
	
	@Autowired
	private StationRepository stationRepository;
	
	@Autowired
	private SectionRepository sectionRepository;
	
	@Autowired
	private CarParkRepository carParkRepository;
	
	/** 线路ID */
	private static long lineId = 0L;
	
	/** 站点ID */
	private static long stationId = 0L;
	
	/** 路段ID */
	private static long sectionId = 0L;
	
	/** 停车长ID*/
	private static long carParkId = 0L;
	
	public GetUIDAndCode() {
		
		new Timer().schedule(new TimerTask() {
			
			@Override
			public void run() {
			 
				lineId = lineRepository.selectMaxIdToLineCode();
				
				stationId = stationRepository.stationMaxId();
				
				sectionId = sectionRepository.sectionMaxId();
				
				carParkId = carParkRepository.carParkMaxId();
				
			}
		}, 1000 * 30);
		
	}
	
	public static synchronized long getLineId() {
		
		++lineId;
		
		return lineId;
		
	}
	
	public static synchronized long getStationId() {
		
		++stationId;
		
		return stationId;
	}
	
	public static synchronized long getSectionId() {
		
		++sectionId;
		
		return sectionId;
		
	}
	
	public static synchronized long getCarParkId() {
		
		++carParkId;
		
		return carParkId;
		
	}

}