From 096296cd7485c5583c8194d88cca700e3c4d84a0 Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期一, 01 十二月 2025 16:50:42 +0800
Subject: [PATCH] 调整基础配置信息查询方式,取消jpa
---
fzzy-igdss-core/src/main/java/com/fzzy/igds/utils/ContextUtil.java | 280 +++++++++++++++++++++++--------------------------------
1 files changed, 117 insertions(+), 163 deletions(-)
diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/utils/ContextUtil.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/utils/ContextUtil.java
index b4f16db..c23c9e4 100644
--- a/fzzy-igdss-core/src/main/java/com/fzzy/igds/utils/ContextUtil.java
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/utils/ContextUtil.java
@@ -1,14 +1,16 @@
-package com.fzzy.eoms.utils;
+package com.fzzy.igds.utils;
-import com.fzzy.igds.data.ConfigData;
+import com.ruoyi.common.config.FrameworkConfig;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
-import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.common.utils.StringUtils;
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;
/**
* 绯荤粺鍏敤鏂规硶
@@ -17,203 +19,155 @@
*/
public class ContextUtil {
- public static Map<String, Boolean> l = new HashMap<>();
+ private static final AtomicLong sequence = new AtomicLong(0);
+ private static String lastTimestamp = "";
+
+
//鍏ㄥ眬鐢ㄦ埛瀹炴椂鍧愬湪閮ㄩ棬
public static Map<String, String> contextUserDept = new HashMap<>();
+
/**
- * 鍏ㄥ眬鍛戒护ID
+ * 鍏ㄥ眬鐢ㄤ簬瀛樻斁SN涓庣粍缁囩紪鐮佺殑鍏崇郴锛屼緥濡傚垎鏈篠N鍜岀粍缁囩紪鐮佸叧绯�
*/
- public static Map<String, Integer> contextOrderId = new HashMap<>();
+ public static Map<String, String> contextSnCompanyIdMap = new HashMap<>();
+
/**
- * UUID鐢熸垚瑙勫垯
- *
- * @return
+ * 鐢熸垚椤哄簭ID锛氬勾鏈堟棩鏃跺垎绉掓绉�(17浣�) + 搴忓垪鍙�(4浣�) = 21浣�
*/
- public static String getUUID() {
- return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
- }
-
- public static String getBusinessID() {
- return DateFormatUtils.format(new Date(), "yyyyMMdd") + String.format("%04d", RandomUtils.nextInt(0, 10000));
- }
-
- public static String getCurTimeMillis() {
- return System.currentTimeMillis() + "";
- }
-
- public static String getTimeId() {
- return DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
- }
-
- public static String getTimeId(int start, int end) {
- return DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + RandomUtils.nextInt(start, end);
- }
-
-
- /**
- * 鑾峰彇褰撳墠骞翠唤
- *
- * @return
- */
- public static String getYear() {
- return DateFormatUtils.format(new Date(), "yyyyMM");
+ public static String generateId() {
+ String pattern = "yyyyMMddHHmmssSSS";
+ return generateId(null, pattern);
}
/**
- * 鐢熸垚璧勪骇缂栫爜ID
- * @return
- */
- public static String createAssetId() {
- return "NO" + randomChar(4) + getYear() + randomNum(6);
- }
-
-
- /**
- * 鐢熸垚涓氬姟ID
+ * 鐢熸垚鍗曟嵁缂栫爜锛� (鏍煎紡: yyyyMMddHHmmss + 4浣嶉殢鏈烘暟)
* @param prefix
* @return
*/
- public static String getBizId(String prefix) {
- if (prefix == null) prefix = "ID";
- return prefix + getTimeId() + randomNum(4);
+ public static String generateOrderId(String prefix) {
+ String pattern = "yyyyMMddHHmmss";
+ return generateId(prefix, pattern);
}
-
/**
- * 闅忔満鐢熸垚澶у啓瀛楁瘝
*
- * @param length 闀垮害
- * @return
- */
- public static String randomChar(int length) {
- Random random = new Random();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < length; i++) {
- char randomLetter = (char) (random.nextInt(26) + 'A'); // 65-90
- sb.append(randomLetter);
- }
- return sb.toString();
- }
-
- /**
- * 闅忔満鐢熸垚鏁板瓧
- * @param length
- * @return
- */
- public static String randomNum(int length) {
- Random random = new Random();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < length; i++) {
- int digit = random.nextInt(10); // 鐢熸垚0-9鐨勯殢鏈烘暟
- sb.append(digit);
- }
- return sb.toString();
- }
-
-
- public static String getDefaultBatchId() {
- return DateFormatUtils.format(new Date(), "yyyyMMddHHmm");
- }
-
- /**
- * 鏍规嵁褰撳墠鐧婚檰浜鸿幏鍙栫粍缁囩紪鍙凤紝濡傛灉娌℃湁鐧婚檰浜鸿幏鍙栫郴缁熼粯璁ょ殑缁勭粐缂栧彿
*
* @return
+ */
+ 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)) {
+ seq = sequence.incrementAndGet();
+ } else {
+ sequence.set(0);
+ seq = 0;
+ lastTimestamp = currentTimestamp;
+ }
+ }
+
+ 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("-", "");
+ }
+
+
+ /**
+ * 榛樿鑾峰彇鐧诲綍浜烘墍鍦ㄧ粍缁囷紝濡傛灉鏈櫥褰曞垯鑾峰彇绯荤粺榛樿缁勭粐
+ * @return 缁勭粐ID
*/
public static String getCompanyId() {
- return ShiroUtils.getLoginUserCompanyId();
- }
- /**
- * 鑾峰彇绯荤粺榛樿鐨�=companyId
- *
- * @return
- */
- public static String getDefaultCompanyId() {
SysUser user = ShiroUtils.getSysUser();
- if (null != user) {
+ if (null != user) return user.getCompanyId();
+ return FrameworkConfig.getCompanyId();
+ }
+
+ public static String getLoginUserName() {
+ SysUser user = ShiroUtils.getSysUser();
+ return null == user ? "绯荤粺" : user.getUserName();
+ }
+
+ public static SysUser getLoginUser() {
+ return ShiroUtils.getSysUser();
+ }
+
+ public static String subDeptId(SysUser user) {
+ if (null == user) {
+ user = getLoginUser();
+ }
+
+ if (null == user) {
+ return getCompanyId() + "001";
+ }
+
+ //浠庡叏灞�鑾峰彇锛屽鏋滄湁鍒欏彇鍏ㄥ眬鐨勯粯璁わ紝濡傛灉娌℃湁鍒欏彇鑷繁鎵�灞�
+ if (null != contextUserDept.get(user.getLoginName())) {
+ return contextUserDept.get(user.getLoginName());
+ }
+
+ if (null == user.getDeptId()) {
return user.getCompanyId();
- } else {
- ConfigData configData = SpringUtils.getBean(ConfigData.class);
- return configData.getDefaultCompanyId();
}
+ return user.getDeptId().toString();
}
+ public static void updateSubDept(String userId, String deptId) {
+ if (null == deptId) return;
+ contextUserDept.put(userId, deptId);
+ }
/**
- * 鏈�楂樼殑缂栫爜涓猴細缁勭粐缂栫爜锛岀劧鍚庨�愮骇寰�涓嬶紝濡傦細5013,5013_001,5013_002,5013_001_001
- *
- * @param companyId 蹇呴』
- * @param parentId 鍙┖
- * @param endId 鍙┖
- * @param format 蹇呴』 涓変綅浼�1000锛屽洓浣嶄紶10000
+ * 鑾峰彇椤哄簭鍙�
+ * @param oldOrderId 鍘熸湁椤哄簭鍙�
+ * @param num 浣嶆暟
* @return
*/
- public static String getNextId(String companyId, String parentId,
- String endId, int format) {
- if (parentId == null) {
- return companyId;
+ public static String getOrderId(String oldOrderId, Integer num) {
+ Integer index3 = 1001;
+ Integer index4 = 10001;
+ Integer index5 = 100001;
+ Integer index = 0;
+ String orderId = "001";
+ if (StringUtils.isNotEmpty(oldOrderId)) {
+ index = Integer.valueOf(oldOrderId);
}
- try {
- int endNum = 0;
- if (StringUtils.isNotEmpty(endId)) {
- endNum = Integer.valueOf(endId.substring(endId.length() - 3));
- }
- String endStr = ("" + (endNum + format + 1)).substring(1);
-
- if (parentId.equals(companyId)) {
- return companyId + "_" + endStr;
- }
- parentId = parentId.substring(parentId.lastIndexOf("_") + 1);
- return companyId + "_" + parentId + "_" + endStr;
-
- } catch (Exception e) {
- e.printStackTrace();
- return null;
+ if (3 == num) {
+ orderId = ((index3 + index) + "").substring(1);
}
+ if (4 == num) {
+ orderId = ((index4 + index) + "").substring(1);
+ }
+ if (5 == num) {
+ orderId = ((index5 + index) + "").substring(1);
+ }
+ return orderId;
}
/**
- * 鑾峰彇浠撳簱缂栫爜 鏍煎紡锛�
+ * 瀛樻斁SN涓庢墍灞炵粍缁囩殑鍏崇郴
*
- * @param deptId 5102_001_001 5102_001_002
- * 蹇呴』 鍒嗗簱缂栫爜
- * @param endId 蹇呴』 鏈�鍚庣殑浠撳簱缂栫爜
- * @param format 蹇呴』 涓変綅浼�1000锛屽洓浣嶄紶10000锛岄粯璁ら兘浼�1000
+ * @param sn
+ * @param companyId
+ */
+ public static void addSerCompany(String sn, String companyId) {
+ contextSnCompanyIdMap.put(sn, companyId);
+ }
+
+ /**
+ * 閫氳繃SN鑾峰彇褰撳墠SN鎵�灞炵殑缁勭粐
+ *
+ * @param sn
* @return
*/
- public static String getNextDepotId(String deptId, String endId, int format) {
- try {
- int endNum = 0;
- if (StringUtils.isNotEmpty(endId)) {
- endNum = Integer.valueOf(endId.substring(endId.length() - 3));
- }
- String endStr = ("" + (endNum + format + 1)).substring(1);
-
- endStr = deptId.substring(deptId.indexOf("_") + 1) + "_" + endStr;
-
- return endStr.replaceAll("_", "");
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
+ public static String getCompanyIdBySn(String sn) {
+ return contextSnCompanyIdMap.get(sn);
}
-
-
- /**
- * 鑾峰彇鍒犻櫎娉ㄩ噴
- *
- * @author sgj
- * @date 2025/08/05
- * @param desc 鍒犻櫎鏂囨鎻忚堪
- */
- public static String getDeleteDesc(String desc) {
- if (StringUtils.isEmpty(desc)) {
- desc = "鍒犻櫎鏁版嵁";
- }
- return desc + "_" + ShiroUtils.getLoginName() + "_" + new Date();
- }
-
-
}
--
Gitblit v1.9.3