|
@@ -106,7 +106,7 @@ public class UserService {
|
106
|
106
|
"WHERE t.app_id = z.app_id and t.r_id = z.id and z.status =1 \n" +
|
107
|
107
|
" and t.app_id ={0} and t.u_id ={1}";
|
108
|
108
|
|
109
|
|
- List<Map> roles = queryService.select(strSQL,appid,user.get("id"));
|
|
109
|
+ List<Map> roles = queryService.select(strSQL,appid,user.get("id").toString());
|
110
|
110
|
user.put("roles",roles);
|
111
|
111
|
|
112
|
112
|
//菜单
|
|
@@ -121,17 +121,18 @@ public class UserService {
|
121
|
121
|
|
122
|
122
|
|
123
|
123
|
// 后台判断权限
|
124
|
|
- strSQL = "SELECT a.*,b.id m_id\n" +
|
125
|
|
- "FROM k_role_priv t,k_module_priv z,k_module_priv_detail a,k_module b\n" +
|
126
|
|
- "WHERE t.r_id in({0}) and t.m_code = z.m_code and t.p_code = z.code\n" +
|
127
|
|
- " and a.code = z.code and b.code = z.m_code ";
|
|
124
|
+// strSQL = "select a.name\n" +
|
|
125
|
+// "from k_role_priv t,k_module_priv z,k_module_priv_detail a\n" +
|
|
126
|
+// "where t.r_id in({0})\n" +
|
|
127
|
+// " and t.p_code = z.code and a.code = z.code\n" +
|
|
128
|
+// " and a.type = 3";
|
|
129
|
+//
|
|
130
|
+// List<Map> list = queryService.select(strSQL,strRoles);
|
|
131
|
+//
|
|
132
|
+// List<Map> privs = new ArrayList<>();
|
|
133
|
+ UserPriv userPriv = new UserPriv(strRoles);
|
128
|
134
|
|
129
|
|
-
|
130
|
|
- List<Map> list = queryService.select(strSQL,strRoles);
|
131
|
|
-
|
132
|
|
- List<Map> privs = listPriv(list);
|
133
|
|
-
|
134
|
|
- user.put("privs",privs);
|
|
135
|
+ user.put("privs",userPriv.getPrivs());
|
135
|
136
|
|
136
|
137
|
|
137
|
138
|
// 用于在前端判断权限
|
|
@@ -145,18 +146,18 @@ public class UserService {
|
145
|
146
|
}
|
146
|
147
|
|
147
|
148
|
|
148
|
|
- private List<Map> listPriv(List<Map> list){
|
149
|
|
- List<Map> result = new ArrayList<Map>();
|
150
|
|
- for(int i = 0;i < list.size(); i ++){
|
151
|
|
- Map item = list.get(i);
|
152
|
|
- result.add(item);
|
153
|
|
- if(item.get("type").toString().equals("3")){
|
154
|
|
- result.addAll(getModuleDefaultPriv(item.get("name").toString()));
|
155
|
|
-
|
156
|
|
- }
|
157
|
|
- }
|
158
|
|
- return result;
|
159
|
|
- }
|
|
149
|
+// private List<Map> listPriv(List<Map> list){
|
|
150
|
+// List<Map> result = new ArrayList<Map>();
|
|
151
|
+// for(int i = 0;i < list.size(); i ++){
|
|
152
|
+// Map item = list.get(i);
|
|
153
|
+// result.add(item);
|
|
154
|
+// if(item.get("type").toString().equals("3")){
|
|
155
|
+// result.addAll(getModuleDefaultPriv(item.get("name").toString()));
|
|
156
|
+//
|
|
157
|
+// }
|
|
158
|
+// }
|
|
159
|
+// return result;
|
|
160
|
+// }
|
160
|
161
|
|
161
|
162
|
|
162
|
163
|
/**
|
|
@@ -164,14 +165,14 @@ public class UserService {
|
164
|
165
|
* @param moduleName
|
165
|
166
|
* @return
|
166
|
167
|
*/
|
167
|
|
- private List<Map> getModuleDefaultPriv(String moduleName){
|
168
|
|
- String strSQL = "SELECT z.*,b.id m_id\n" +
|
169
|
|
- "FROM k_module_priv t,k_module_priv_detail z,k_module b\n" +
|
170
|
|
- "WHERE t.m_code= '{0}' AND t.code = t.m_code\n" +
|
171
|
|
- " and z.code = t.code and b.code = t.m_code";
|
172
|
|
- List<Map> list = queryService.select(strSQL,moduleName);
|
173
|
|
- return listPriv(list);
|
174
|
|
- }
|
|
168
|
+// private List<Map> getModuleDefaultPriv(String moduleName){
|
|
169
|
+// String strSQL = "SELECT z.*,b.id m_id\n" +
|
|
170
|
+// "FROM k_module_priv t,k_module_priv_detail z,k_module b\n" +
|
|
171
|
+// "WHERE t.m_code= '{0}' AND t.code = t.m_code\n" +
|
|
172
|
+// " and z.code = t.code and b.code = t.m_code";
|
|
173
|
+// List<Map> list = queryService.select(strSQL,moduleName);
|
|
174
|
+// return listPriv(list);
|
|
175
|
+// }
|
175
|
176
|
|
176
|
177
|
|
177
|
178
|
/**
|
|
@@ -200,4 +201,89 @@ public class UserService {
|
200
|
201
|
|
201
|
202
|
}
|
202
|
203
|
|
|
204
|
+
|
|
205
|
+ class UserPriv {
|
|
206
|
+ private String roleIds;
|
|
207
|
+
|
|
208
|
+ //已经加载的模块
|
|
209
|
+ private List<String> moduleCache = new ArrayList<>() ;
|
|
210
|
+
|
|
211
|
+ private List<Map> privs = new ArrayList<>();
|
|
212
|
+
|
|
213
|
+ public UserPriv(String roleIds ){
|
|
214
|
+ this.roleIds = roleIds;
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ public List<Map> getPrivs(){
|
|
218
|
+ String strSQL = "select a.*\n" +
|
|
219
|
+ "from k_role_priv t,k_module_priv z,k_module_priv_detail a\n" +
|
|
220
|
+ "where t.r_id in({0})\n" +
|
|
221
|
+ " and t.p_code = z.code and a.code = z.code\n" +
|
|
222
|
+ " and a.type = 3";
|
|
223
|
+
|
|
224
|
+ List<Map> list = queryService.select(strSQL,roleIds);
|
|
225
|
+ load(list);
|
|
226
|
+ return privs;
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ //加载模块默认权限
|
|
230
|
+ private void loadModule(String module) {
|
|
231
|
+ if(moduleCache.contains(module))
|
|
232
|
+ return;
|
|
233
|
+
|
|
234
|
+ moduleCache.add(module);
|
|
235
|
+
|
|
236
|
+ String strSQL = "select z.*\n" +
|
|
237
|
+ "from k_module_priv t,k_module_priv_detail z\n" +
|
|
238
|
+ "where t.m_code='{0}' and t.code = z.code\n" +
|
|
239
|
+ " and t.code = t.m_code";
|
|
240
|
+ List<Map> list = queryService.select(strSQL,module);
|
|
241
|
+ load(list);
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ private void load(List<Map> list){
|
|
245
|
+ for(Map map : list) {
|
|
246
|
+ String type = map.get("type").toString();
|
|
247
|
+ String name = map.get("name").toString();
|
|
248
|
+
|
|
249
|
+ if(type.equals("3")){ //模块信息
|
|
250
|
+ loadModule(name);
|
|
251
|
+ }
|
|
252
|
+ else if(type.equals("6")) { // appi
|
|
253
|
+ loadApi(name);
|
|
254
|
+ }
|
|
255
|
+ else if(type.equals("7")) { // api group
|
|
256
|
+ loadApiGroup(name);
|
|
257
|
+ }
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ /**
|
|
262
|
+ * 加载api分组
|
|
263
|
+ * @param groupId
|
|
264
|
+ */
|
|
265
|
+ private void loadApiGroup(String groupId) {
|
|
266
|
+ String strSQL = "select code,name from k_api where g_id={0}";
|
|
267
|
+ List<Map> list = queryService.select(strSQL,groupId);
|
|
268
|
+ privs = ListUtil.merge(privs,list);
|
|
269
|
+
|
|
270
|
+ // 下级分类
|
|
271
|
+ strSQL = "select id from k_api_group where p_id={0}";
|
|
272
|
+ list = queryService.select(strSQL,groupId);
|
|
273
|
+ for(Map map : list) {
|
|
274
|
+ loadApiGroup(map.get("id").toString());
|
|
275
|
+ }
|
|
276
|
+ }
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+ //加载API
|
|
280
|
+ private void loadApi(String apiId) {
|
|
281
|
+ String strSQL = "select code,method from k_api where id={0}";
|
|
282
|
+ List<Map> list = queryService.select(strSQL,apiId);
|
|
283
|
+
|
|
284
|
+ privs = ListUtil.merge(privs,list);
|
|
285
|
+ }
|
|
286
|
+
|
|
287
|
+ }
|
|
288
|
+
|
203
|
289
|
}
|