From c7c90b74d723ab08069d40b6b1fadddb2deeeb7e Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期二, 09 九月 2025 16:28:13 +0800
Subject: [PATCH] 河南统一去ORGID
---
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java
index 5444f25..2bf520f 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/HospitalFilterInterceptor.java
@@ -3,22 +3,28 @@
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.StringUtils;
-import jdk.nashorn.internal.objects.annotations.Where;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
+
@Component
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class HospitalFilterInterceptor implements Interceptor {
+
+ @Value("${spring.profiles.active}")
+ private String active;
@Override
public Object intercept(Invocation invocation) throws Throwable {
@@ -38,6 +44,13 @@
// 鑾峰彇鍘熷 SQL
String originalSql = (String) metaObject.getValue("delegate.boundSql.sql");
+ //娌冲崡鐨勭壒娈婅姹傦紝涓嶈orgid
+ if (active.equals("hn")) {
+ String s = removeOrgIdCondition(originalSql);
+ // 灏嗕慨鏀瑰悗鐨� SQL 鍐欏洖
+ metaObject.setValue("delegate.boundSql.sql", s);
+ return invocation.proceed();
+ }
// 鑾峰彇褰撳墠 orgid
String orgid = null;
@@ -63,6 +76,46 @@
return invocation.proceed();
}
+ private String removeOrgIdCondition(String sql) {
+ // 杞崲涓哄皬鍐欎究浜庡尮閰嶏紝浣嗕繚鐣欏師濮嬪ぇ灏忓啓
+ String lowerSql = sql.toLowerCase();
+
+ // 鏌ユ壘 WHERE 瀛愬彞鐨勪綅缃�
+ int whereIndex = lowerSql.indexOf("where");
+ if (whereIndex == -1) {
+ return sql; // 娌℃湁 WHERE 瀛愬彞
+ }
+
+ // 鎻愬彇 WHERE 涔嬪悗鐨勯儴鍒�
+ String whereClause = sql.substring(whereIndex + 5);
+ String beforeWhere = sql.substring(0, whereIndex);
+
+ // 浣跨敤姝e垯琛ㄨ揪寮忓垎鍓叉潯浠�
+ String[] conditions = whereClause.split("(?i)\\s+(AND|OR)\\s+");
+
+ // 杩囨护鎺夊寘鍚� orgid 鐨勬潯浠�
+ List<String> filteredConditions = new ArrayList<>();
+ for (String condition : conditions) {
+ if (!containsOrgId(condition)) {
+ filteredConditions.add(condition.trim());
+ }
+ }
+
+ // 閲嶆柊鏋勫缓 SQL
+ if (filteredConditions.isEmpty()) {
+ return beforeWhere.trim();
+ } else {
+ String newWhereClause = String.join(" AND ", filteredConditions);
+ return beforeWhere + "WHERE " + newWhereClause;
+ }
+ }
+
+ private boolean containsOrgId(String condition) {
+ // 妫�鏌ユ潯浠舵槸鍚﹀寘鍚� orgid锛堣�冭檻鍒悕锛�
+ return condition.toLowerCase().matches(".*\\b(\\w+\\.)?orgid\\s*[=<>].*");
+ }
+
+
/**
* 淇敼 SQL锛屾敞鍏� orgid 鏉′欢
*
--
Gitblit v1.9.3