From 9e20b9fb77a41cb5b4a6eb6213fc51cab1f0bb91 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期五, 23 八月 2024 18:00:25 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/VciBaseUtil.java |  107 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/VciBaseUtil.java b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/VciBaseUtil.java
index 913d390..b13d963 100644
--- a/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/VciBaseUtil.java
+++ b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/VciBaseUtil.java
@@ -1,8 +1,12 @@
 package com.vci.starter.web.util;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Snowflake;
+import cn.hutool.core.util.IdUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.vci.common.exception.VciExceptionTool;
+import com.vci.corba.common.PLException;
 import com.vci.starter.web.annotation.Id;
 import com.vci.starter.web.annotation.VciBtmType;
 import com.vci.starter.web.annotation.VciLinkType;
@@ -48,6 +52,23 @@
 public class VciBaseUtil {
 
     /**
+     * 鑾峰彇寮傚父淇℃伅,鍥犱负鎶涘嚭鐨勫紓甯镐笉鍚岋紝鑾峰彇閿欒淇℃伅鐨勬柟寮忓瓨鍦ㄥ樊寮傛墍浠ユ棤娉曠粺涓�鑾峰彇
+     * 鍚庣画鏈夊叾浠栧紓甯搁渶瑕佽幏鍙栵紝鑷娣诲姞澶勭悊閫昏緫锛�
+     * @param e
+     * @return
+     */
+    public static String getExceptionMessage(Throwable e){
+        String exceptionStr = VciExceptionTool.getExceptionStr(e);
+        if(exceptionStr.contains("VciBaseException")){
+            return e.getMessage();
+        }else if(exceptionStr.contains("PLException")){
+            return Arrays.stream(((PLException) e).messages).collect(Collectors.joining("\n"));
+        }else {
+            return e.getMessage();
+        }
+    }
+
+    /**
      * 鏃ュ織瀵硅薄
      */
     private static Logger log = LoggerFactory.getLogger(VciBaseUtil.class);
@@ -59,6 +80,19 @@
      */
     public static String getPk() {
         return UUID.randomUUID().toString();
+    }
+
+    /**
+     * 闆姳ID
+     * @return
+     */
+    public static String getSnowflakePk() {
+        return String.valueOf(getSnowflakePk(1,1));
+    }
+
+    public static  Long getSnowflakePk(long workerId,long dataCenterId){
+        Snowflake snowflake = IdUtil.getSnowflake(workerId,dataCenterId);
+        return snowflake.nextId();
     }
 
     /**
@@ -253,6 +287,28 @@
     }
 
     /**
+     * 鍘婚櫎鏈�鍓嶉潰鐨剆piltFilter锛屽幓闄ゅ悗闈㈢殑spiltFilter
+     * @param s 瀛楃涓�
+     * @param spiltFilter,鍒嗛殧绗�
+     * @return 鍘婚櫎鏈熬閫楀彿
+     */
+    public static String removeComma(String s,String spiltFilter){
+        if(s == null || s.trim().length() == 0) {
+            return s;
+        }
+        else{
+            if(s.startsWith(spiltFilter)) {
+                s = s.substring(spiltFilter.length(), s.length());
+            }
+            if(s.endsWith(spiltFilter)) {
+                s = s.substring(0, s.length() - spiltFilter.length());
+            }
+            return s;
+        }
+    }
+
+
+    /**
      * 涓簊ql涓娇鐢╥n鏃讹紝鎻愪緵杞崲锛屾敞鎰廼n閲岀殑鍊间笉鑳借秴杩�1000
      * @param s 瀛楃涓�
      * @return 杩斿洖sql璇彞
@@ -438,6 +494,21 @@
             charMap.put(String.valueOf(c), (!charMap.containsKey(String.valueOf(c))? 1 : charMap.get(String.valueOf(c)) + 1));
         }
         return charMap.get(String.valueOf(findC));
+    }
+
+    /**
+     * 甯﹂�楀彿鐨勫瓧绗︿覆杞负list
+     * @param s 瀛楃涓�
+     * @return 瀛楃涓插垪琛�
+     */
+    public static List<String> str2List(String s,String spilter){
+        if (isNull(s)) {
+            return null;
+        } else {
+            List<String> l = new ArrayList<String>();
+            Collections.addAll(l,removeComma(s,spilter).split(spilter));
+            return l;
+        }
     }
 
     /**
@@ -1210,7 +1281,7 @@
      * @return 浼氳瘽瀵硅薄
      */
     public static SessionInfo getCurrentUserSessionInfoNotException() {
-        return WebThreadLocalUtil.getCurrentUserSessionInfoInThread().get();
+        return WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
     }
 
     /**
@@ -1218,7 +1289,7 @@
      * @param sessionInfo 鐢ㄦ埛瀵硅薄
      */
     public static void setCurrentUserSessionInfo(SessionInfo sessionInfo){
-        WebThreadLocalUtil.getCurrentUserSessionInfoInThread().set(sessionInfo);
+        WebThreadLocalUtil.setCurrentUserSessionInfoInThread(sessionInfo);
     }
 
     /**
@@ -1226,7 +1297,7 @@
      * @return true琛ㄧず鏌ヨ
      */
     public static boolean isQueryTotal(){
-        String needQueryTotal = WebThreadLocalUtil.getNeedQueryTotalInThread().get();
+        String needQueryTotal = WebThreadLocalUtil.getNeedQueryTotalInThread();
         if("false".equalsIgnoreCase(needQueryTotal)){
             return false;
         }else{
@@ -1299,6 +1370,25 @@
         }
     }
 
+
+    /**
+     * 鏁扮粍杞崲涓篠tring
+     * @param array 鏁扮粍瀵硅薄
+     * @param spiltFiter 鍒嗛殧绗�
+     * @return 閫楀彿閾炬帴鐨勫瓧绗︿覆
+     */
+    public static String array2String(String[] array,String spiltFiter) {
+        if(null == array || array.length == 0) {
+            return "";
+        } else{
+            String ss = "";
+            for(String s : array){
+                ss += s + spiltFiter;
+                //1.8鍙互
+            }
+            return removeComma(ss,spiltFiter);
+        }
+    }
     /**
      * 鏁扮粍杞崲涓篠tring
      * @param array 鏁扮粍瀵硅薄
@@ -1929,4 +2019,15 @@
         }
         return new String(c);
     }
+
+    /**
+     * 灏唖tring闆嗗悎杞负stirng鏁扮粍
+     * @param strCollection string闆嗗悎
+     * @return string鏁扮粍
+     */
+    public static String[] collection2StrArr(Collection<String> strCollection){
+        String[] strArr = new String[strCollection.size()];
+        strCollection.toArray(strArr);
+        return strArr;
+    }
 }

--
Gitblit v1.9.3