gaodandan 7 年之前
父节点
当前提交
83c97388bd

+ 44 - 34
src/main/java/com/chinaitop/depot/DatePermissionInterceptor.java

@@ -60,9 +60,9 @@ public class DatePermissionInterceptor implements Interceptor {
60 60
 		final BoundSql boundSql = statementHandler.getBoundSql();
61 61
 		String bouString = boundSql.getSql();// 获取执行sql 
62 62
 		
63
-		//sql是查询的才进行权限过滤
64
-	    if(mappedStatement.getSqlCommandType().toString().equals("select".toUpperCase())) {
65
-	    
63
+		//sql是查询的才进行权限过滤且不过滤t_url_config表的数据
64
+	    if(mappedStatement.getSqlCommandType().toString().equals("select".toUpperCase()) && 
65
+	    		!bouString.contains("t_url_config")) {
66 66
 			//通过本地线程获取库id
67 67
 			Object threadLocalObj = DataPolicyEngine.get();
68 68
 			String orgId = null;
@@ -70,43 +70,53 @@ public class DatePermissionInterceptor implements Interceptor {
70 70
 				orgId = ObjectUtils.toString(threadLocalObj);
71 71
 			}
72 72
 			if(orgId!=null) {
73
-				//解析sql中的表名
74
-				Statement statement = CCJSqlParserUtil.parse(bouString);
75
-			    Select selectStatement = (Select)statement;
76
-			    TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
77
-			    List<String> result = tablesNamesFinder.getTableList(selectStatement);
78
-				
79
-				Set<String> tableNames = new HashSet<String>();// 定义需要替换的table信息列表
80
-				//获取业务表信息数据
81
-				List<String> tableList = (List<String>)redisUtil.lGetAll("tableList").get(0);
82
-				for(int i=0;i<result.size();i++) {
83
-					for (int j = 0; j < tableList.size(); j++) {// 处理查看sql中是否有业务表
84
-						if (result.get(i).equals(ObjectUtils.toString(tableList.get(j)))) {// 是否存在业务表
85
-							tableNames.add(result.get(i));
73
+				//机构单独查询时使用递归查询,可以查询机构下级机构
74
+				if("com.chinaitop.depot.system.mapper.OrgInfoMapper.selectByExample".equals(mappedStatement.getId())) {
75
+					bouString = bouString.replaceAll("org_info", "(SELECT * from org_info"
76
+							+ " WHERE FIND_IN_SET(org_id,getChildrenOrg("+orgId+"))) org_info ");
77
+				}else {
78
+					//解析sql中的表名
79
+					Statement statement = CCJSqlParserUtil.parse(bouString);
80
+					Select selectStatement = (Select)statement;
81
+					TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
82
+					List<String> result = tablesNamesFinder.getTableList(selectStatement);
83
+					
84
+					Set<String> tableNames = new HashSet<String>();// 定义需要替换的table信息列表
85
+					//获取业务表信息数据
86
+					List<String> tableList = (List<String>)redisUtil.lGetAll("tableList").get(0);
87
+					for(int i=0;i<result.size();i++) {
88
+						for (int j = 0; j < tableList.size(); j++) {// 处理查看sql中是否有业务表
89
+							if (result.get(i).equals(ObjectUtils.toString(tableList.get(j)))) {// 是否存在业务表
90
+								tableNames.add(result.get(i));
91
+							}
86 92
 						}
87 93
 					}
88
-				}
89
-				
90
-				if (tableNames != null && tableNames.size() > 0) {// sql中存在业务表进行sql拼接数据重新检索
91
-					if(result.size() >= 2) {//sql中存在2张及以上表
92
-						for (String table : tableNames) {// 进行业务表的数据权限替换
93
-							table += " ";//表名后面加空格,防止两个表名一部分相似,导致替换出错
94
-							bouString = bouString.replaceAll(table, "(SELECT * from " + table
95
-									+ " WHERE org_id = '"+orgId+"') ");
96
-						}
97
-					}else {//sql中是单表
98
-						for (String table : tableNames) {// 进行业务表的数据权限替换
99
-							table += " ";//表名后面加空格,防止两个表名一部分相似,导致替换出错
100
-							bouString = bouString.replaceAll(table, "(SELECT * from " + table
101
-									+ " WHERE org_id = '"+orgId+"') "+table+" ");
94
+					
95
+					if (tableNames != null && tableNames.size() > 0) {// sql中存在业务表进行sql拼接数据重新检索
96
+						if(result.size() >= 2) {//sql中存在2张及以上表
97
+							for (String table : tableNames) {// 进行业务表的数据权限替换
98
+								table += " ";//表名后面加空格,防止两个表名一部分相似,导致替换出错
99
+								bouString = bouString.replaceAll(table, "(SELECT * from " + table
100
+										+ " WHERE org_id = '"+orgId+"') ");
101
+							}
102
+						}else {//sql中是单表
103
+							for (String table : tableNames) {// 进行业务表的数据权限替换
104
+								if(bouString.contains(table+" ")) {//防止是单表查询,表后面没有空格的时候替换不了
105
+									table += " ";//表名后面加空格,防止两个表名一部分相似,导致替换出错
106
+								}
107
+								bouString = bouString.replaceAll(table, "(SELECT * from " + table
108
+										+ " WHERE org_id = '"+orgId+"') "+table+" ");
109
+								System.out.println(bouString+"---");
110
+							}
102 111
 						}
112
+						
113
+						/*bouString = bouString.replaceAll(table, "(SELECT b.* from " + table
114
+						+ " b,user_business u WHERE b.org_id = u.org_id AND u .user_id ='"+userId+"' AND u.business_type = '"+table+"') ");*/
115
+						
103 116
 					}
104
-					
105
-					/*bouString = bouString.replaceAll(table, "(SELECT b.* from " + table
106
-							+ " b,user_business u WHERE b.org_id = u.org_id AND u .user_id ='"+userId+"' AND u.business_type = '"+table+"') ");*/
107
-					
108 117
 				}
109 118
 				
119
+				
110 120
 				//metaStatementHandler.setValue("delegate.boundSql.sql", bouString);
111 121
 				
112 122
 				Field field = getField(boundSql, "sql");

+ 2 - 1
src/main/java/com/chinaitop/depot/device/mapper/StorageDevicecheckMapper.xml

@@ -352,7 +352,8 @@
352 352
             model,
353 353
             store_count,
354 354
             really_count,
355
-            reason
355
+            reason,
356
+            org_id
356 357
         FROM
357 358
           storage_devicecheck
358 359
         <if test="_parameter != null">

+ 2 - 2
src/main/java/com/chinaitop/depot/device/mapper/StorageDeviceinputMapper.xml

@@ -583,9 +583,9 @@
583 583
 
584 584
    <select id="getModelGetList" parameterType="java.util.Map" resultMap="BaseResultMap">
585 585
 
586
-   select <include refid="Base_Column_List" /> from storage_deviceinput where `status`=0 and device_name In (select enumId from basic_enum where  enumName=#{deviceName}) and 
586
+   select <include refid="Base_Column_List" /> from storage_deviceinput sd where `status`=0 and device_name In (select enumId from basic_enum where  enumName=#{deviceName}) and 
587 587
 
588
-   storage_rack IN (select id  from basic_equipment_equipment_pool where shelf_id=#{storageRack}) ;
588
+   storage_rack IN (select id  from basic_equipment_equipment_pool bee where shelf_id=#{storageRack}) ;
589 589
 
590 590
   </select>
591 591