From c70b92da60c0d00625da5fc2369b475e69e0b88e Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 22 八月 2024 11:36:41 +0800
Subject: [PATCH] 1、完善代码和application.yml配置文件,去掉不用的引入文件; 2、init-config.xml配置中增加属性 enable,相应解析类也增加了解析与判断; 3、凡是有Server的应用,加载资源方式改为用springboot的工具类加载; 4、通信协议相关的扫描注解功能实现改为采用reflections-0.10.2,以实现可以在jar包情况下能够扫描类(.class)注解。

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/IDLongGenerator.java |   46 +++++++++++++++++++++++++++++-----------------
 1 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/IDLongGenerator.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/IDLongGenerator.java
index be3dc2a..3b8a133 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/IDLongGenerator.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/IDLongGenerator.java
@@ -1,13 +1,17 @@
 package com.dy.common.util;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
 import java.util.Calendar;
 
+@Slf4j
 @Component
 public class IDLongGenerator {
 
-	private static final int yearLenght = 4 ;//4锛氬勾搴﹀彇鍥涗綅锛� 3锛氬勾搴﹀彇涓変綅锛� 2锛氬勾搴﹀彇涓や綅锛� 1锛氬勾搴﹀彇涓�浣嶏紝 0锛氬勾搴﹀彇0浣�
+	private static final Object synObj = new Object() ;
+
+	private static final int yearLength = 4 ;//4锛氬勾搴﹀彇鍥涗綅锛� 3锛氬勾搴﹀彇涓変綅锛� 2锛氬勾搴﹀彇涓や綅锛� 1锛氬勾搴﹀彇涓�浣嶏紝 0锛氬勾搴﹀彇0浣�
 
 	private static int add = 0 ;
 	private static final int chengShu = 1000 ;//1000锛氫笁浣嶈嚜澧為噺锛屽嵆涓�绉掗挓鍙骇鐢�10000涓狪D
@@ -24,11 +28,16 @@
 	}
 
 	/**
-	 *  23 10 28 09 14 40 00000
-	 * 闀垮害16鐨処D锛屽勾搴﹀彇涓や綅锛岄暱搴�18鐨処D锛屽勾搴﹀彇鍥涗綅锛�17浣嶆暟瀛楄秴鍑轰簡javascript鐨勮〃鏁拌寖鍥达紝javascript浼氳〃鏁颁笉姝g‘
+	 *  2023 10 28 09 14 40 00000
+	 * 闀垮害19鐨処D锛屽勾搴﹀彇涓や綅锛岄暱搴�18鐨処D锛屽勾搴﹀彇鍥涗綅锛�17浣嶆暟瀛楄秴鍑轰簡javascript鐨勮〃鏁拌寖鍥达紝javascript浼氳〃鏁颁笉姝g‘
 	 */
-    public synchronized Long generate(){
-    	return doGenerate() ;	
+    public Long generate(){
+    	synchronized (synObj){
+			//Long id = doGenerate() ;
+			//log.info("浜х敓ID = " + id);
+			//return id ;
+			return doGenerate() ;
+		}
     }
 	/**
 	 * 璁剧疆鍚庣紑锛屼笉鍚屽瓙绯荤粺璁剧疆涓嶅悓鐨勫悗缂�
@@ -96,7 +105,7 @@
 
     /**
      * 鎵ц鐢熸垚
-     * @return ID
+     * @return ID 20231218 104504 06900
      */
     private Long doGenerate(){
     	long id ;
@@ -105,17 +114,17 @@
     		//涓婃鐢熸垚ID 涓庢湰娆$敓鎴怚D 涓嶅湪鍚屼竴绉掑唴
     		last = now ;
     		add = 0 ;
-    		id = last * chengShu + add ++;
+    		id = last * chengShu + add++;
     	}else{
     		//涓婃鐢熸垚ID 涓庢湰娆$敓鎴怚D 鍦ㄥ悓涓�绉掑唴
     		if(add >= maxAdd){
     			//闄勫姞閲忓凡缁忕敤灏�
     			waitNextSecond(last) ;//绛夊埌涓嬩竴绉�
-    			id = last * chengShu + add ++ ;//杩斿洖涓婁竴绉掔敓鎴愮殑ID
+    			id = last * chengShu + add++ ;//杩斿洖涓婁竴绉掔敓鎴愮殑ID
 				add = 0 ;//闄勫姞閲忓綊闆讹紝涓轰笅涓�绉掑噯澶�
     		}else{
     			//闄勫姞閲忔湭鐢ㄥ敖
-    			id = last * chengShu + add ++ ;
+    			id = last * chengShu + add++ ;
     		}
     	}
     	return (id * 100) + suffix ;
@@ -229,28 +238,31 @@
 	 * @return 澶勭悊鍚庣殑骞村害
 	 */
 	private static int dealYear(int year){
-		if(yearLenght == 0){
+		if(yearLength == 0){
 			return 0 ;
-		}else if(yearLenght == 1){
+		}else if(yearLength == 1){
 			return year % 10 ;
-		}else if(yearLenght == 2){
+		}else if(yearLength == 2){
 			return year % 100 ;
-		}else if(yearLenght == 3){
+		}else if(yearLength == 3){
 			return year % 1000 ;
-		}else if(yearLenght == 4){
+		}else if(yearLength == 4){
 			return year ;
 		}else{
 			return year ;
 		}
 	}
-//
+
 //	public static void main(String[] args){
+//		Calendar cal = Calendar.getInstance();
+//		System.out.println(cal.get(Calendar.MONTH) + 1) ;
+//
 //		IDLongGenerator o = new IDLongGenerator() ;
-//		int total = 800 ;
-//		long start = System.currentTimeMillis() ;
+//		int total = 1 ;
 //		for(int i = 0 ; i < total ; i++){
 //			System.out.println(o.generate()) ;
 //		}
+//		long start = System.currentTimeMillis() ;
 //		long end = System.currentTimeMillis() ;
 //		System.out.println("浜х敓" + total + "ID鐢ㄦ椂" + (end - start) + "姣");
 //

--
Gitblit v1.8.0