czt
2025-11-25 94a7d37ab2f5101233056fa530d1577f4d699bf9
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
package com.fzzy.igds.utils;
 
import com.ruoyi.common.config.FrameworkConfig;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
 
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
 
/**
 * 系统公用方法
 *
 * @author Andy
 */
public class ContextUtil {
 
    private static final AtomicLong sequence = new AtomicLong(0);
    private static String lastTimestamp = "";
 
    /**
     * 生成顺序ID:年月日时分秒毫秒(17位) + 序列号(4位) = 21位
     *
     * @return
     */
    public static String generateId() {
        String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
        long seq;
        synchronized (ContextUtil.class) {
            if (currentTimestamp.equals(lastTimestamp)) {
                seq = sequence.incrementAndGet();
            } else {
                sequence.set(0);
                seq = 0;
 
                lastTimestamp = currentTimestamp;
            }
        }
        return String.format("%s%04d", currentTimestamp, seq);
    }
 
    public static String UUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
 
 
    /**
     * 默认获取登录人所在组织,如果未登录则获取系统默认组织
     * @return 组织ID
     */
    public static String getCompanyId() {
 
        SysUser user = ShiroUtils.getSysUser();
        if(null != user) return user.getCompanyId();
        return FrameworkConfig.getCompanyId();
    }
 
    public static String getLoginUserName() {
      return  ShiroUtils.getUserName() ;
    }
}