GetUIDAndCode.java 1.78 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.findLatestStationId();
//				sectionId = sectionRepository.findLatestSectionId();
//				carParkId = carParkRepository.carParkMaxId();
//			}
//		}, 1000 * 30);
	}
	public synchronized long getLineId() {
		return lineRepository.selectMaxIdToLineCode() + 1;
	}
	public synchronized long getStationId() {
		return stationRepository.findLatestStationId() + 1;
	}
	public synchronized long getSectionId() {
		return sectionRepository.findLatestSectionId() + 1;
	}
	public synchronized long getCarParkId() {
		return carParkRepository.carParkMaxId() + 1;
	}
}