田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
package com.vci.common.utility;
 
/**
 * <p>Title: </p>
 * <p>Description: has two methods, one is to get 36 length guid,
 * the other is to get 20 length guid.</p>
 */
public final class ObjectUtility {
    
    public static final String seperator = "";
 
    public ObjectUtility() {
        
    }
    
    /**
     * get a new guid which length is 36
     * 
     * @return string
     */
    public static String getNewObjectID36() {
        RandomGUID36 newGUID = new RandomGUID36();
        return newGUID.toString();
    }
    
    /**
     * get a new guid which length is 20
     * 
     * @param strToken
     * @return
     */
    public static String getNewObjectID20(String strToken) {
        RandomGUID20 random = new RandomGUID20();
        return random.getNewObjectID(strToken);
    }
    
    /**
     * 采用雪花算法创建ID
     * @return
     */
    public static long getSnowFlakeID() {
        return SnowFlake.nextId();
    }
    
    
    public static long getTimeMillis(Object value) {
        long times = 0;
        if (value == null)
            return times;
        
        if (value instanceof java.sql.Timestamp) {
            java.sql.Timestamp ts = (java.sql.Timestamp)value;
            times = ts.getTime();
        } else if (value instanceof java.sql.Timestamp) {
            java.sql.Date date = (java.sql.Date)value;
            times = date.getTime();
        } else {
            times = Long.valueOf(value.toString());
        }
        
        return times;
    }
    
}