GetUIDAndCode.java
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
}
}