| | |
| | | private static final AtomicLong sequence = new AtomicLong(0); |
| | | private static String lastTimestamp = ""; |
| | | |
| | | |
| | | //全局用户实时坐在部门 |
| | | public static Map<String, String> contextUserDept = new HashMap<>(); |
| | | |
| | |
| | | */ |
| | | public static Map<String, String> contextSnCompanyIdMap = new HashMap<>(); |
| | | |
| | | |
| | | /** |
| | | * 生成顺序ID:年月日时分秒毫秒(17位) + 序列号(4位) = 21位 |
| | | */ |
| | | public static String generateId() { |
| | | String pattern = "yyyyMMddHHmmssSSS"; |
| | | return generateId(null, pattern); |
| | | } |
| | | |
| | | /** |
| | | * 生成单据编码, (格式: yyyyMMddHHmmss + 4位随机数) |
| | | * @param prefix |
| | | * @return |
| | | */ |
| | | public static String generateOrderId(String prefix) { |
| | | String pattern = "yyyyMMddHHmmss"; |
| | | return generateId(prefix, pattern); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @return |
| | | */ |
| | | public static String generateId() { |
| | | String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")); |
| | | private static String generateId(String prefix, String pattern) { |
| | | if (null == pattern) pattern = "yyyyMMddHHmmss"; |
| | | String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern(pattern)); |
| | | long seq; |
| | | synchronized (ContextUtil.class) { |
| | | if (currentTimestamp.equals(lastTimestamp)) { |
| | |
| | | } else { |
| | | sequence.set(0); |
| | | seq = 0; |
| | | |
| | | lastTimestamp = currentTimestamp; |
| | | } |
| | | } |
| | | return String.format("%s%04d", currentTimestamp, seq); |
| | | |
| | | if (null == prefix) return String.format("%s%04d", currentTimestamp, seq); |
| | | return prefix + "_" + String.format("%s%04d", currentTimestamp, seq); |
| | | } |
| | | |
| | | |
| | | public static String UUID() { |
| | | return UUID.randomUUID().toString().replaceAll("-", ""); |
| | |
| | | public static String getCompanyId() { |
| | | |
| | | SysUser user = ShiroUtils.getSysUser(); |
| | | if(null != user) return user.getCompanyId(); |
| | | if (null != user) return user.getCompanyId(); |
| | | return FrameworkConfig.getCompanyId(); |
| | | } |
| | | |
| | |
| | | Integer index5 = 100001; |
| | | Integer index = 0; |
| | | String orderId = "001"; |
| | | if(StringUtils.isNotEmpty(oldOrderId)){ |
| | | if (StringUtils.isNotEmpty(oldOrderId)) { |
| | | index = Integer.valueOf(oldOrderId); |
| | | } |
| | | if(3 == num){ |
| | | if (3 == num) { |
| | | orderId = ((index3 + index) + "").substring(1); |
| | | } |
| | | if(4 == num){ |
| | | if (4 == num) { |
| | | orderId = ((index4 + index) + "").substring(1); |
| | | } |
| | | if(5 == num){ |
| | | if (5 == num) { |
| | | orderId = ((index5 + index) + "").substring(1); |
| | | } |
| | | return orderId; |