cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
package cn.ksource.web.controller.business.pages.xtgl;
 
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
 
import cn.ksource.beans.AC_ROLE;
import cn.ksource.beans.AC_ROLE_GROUP;
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.page.PageInfo;
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.ParamsMapUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.core.web.SysInfo;
import cn.ksource.core.web.WebUtil;
import cn.ksource.web.facade.JsglFacade;
/**
 * 角色权限--角色管理控制器
 * @note:
 * @version
 * @author sxj
 * @date June 28, 2016 10:35:44 AM
 */
@Controller
@RequestMapping("/business/pages/xtgl/jsgl")
public class JsglController {
    
    @Autowired
    private JsglFacade jsglFacade;
    
    
    @Resource(name="baseDao")
    private BaseDao baseDao;
    
 
    @RequestMapping("jsList.html")
    public ModelAndView jsList(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view = new ModelAndView("business/pages/xtgl/jsgl/jsList");
        return view;
    }
    
    @RequestMapping("jsData.html")
    public ModelAndView jsData(HttpServletRequest request,PageInfo pageInfo){
        ModelAndView view = new ModelAndView("business/pages/xtgl/jsgl/jsData");
        //定义参数Map
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        PageInfo info = jsglFacade.jsData(pageInfo,params);
        view.addObject("info", info);
        return view;
    }
    
    /**
     * 查询角色管理列表数量
     */
    @RequestMapping("jsCount.html")
    public void jsCount(HttpServletRequest request,HttpServletResponse response) {
        //定义参数Map
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        int count = jsglFacade.jsCount(params);
        WebUtil.write(response, String.valueOf(count));
    }
    
    @RequestMapping("del.html")
    public void onDelRole(HttpServletRequest request,HttpServletResponse response){
        String roleid = request.getParameter("id");
        int result = jsglFacade.deleteRole(roleid);
        WebUtil.write(response, result + "");
    }
    
    @RequestMapping("addJs.html")
    public ModelAndView onAddJsLoad(HttpServletRequest request,HttpServletResponse response){
        
        String id = request.getParameter("id");
        if (StringUtils.isBlank(id)) {
            Map map = new HashMap();
            
            return new ModelAndView("/business/pages/xtgl/jsgl/addJs","info",map);
        } else {   
            Map map = new AC_ROLE(id).getBeanMapById();
            return new ModelAndView("/business/pages/xtgl/jsgl/addJs","info",map);
        }
    }
    
    @RequestMapping("addJsSubmit.html")
    public ModelAndView onAddJsSubmit(AC_ROLE role,HttpServletRequest request,HttpServletResponse response){
        role.setType(1);
        
        role.insertOrUpdate();
        
        /*return WebUtil.goSysInfoPage(request,"操作成功!",
                "window.top.closeDialog(0);window.top.reloadDataGrid('dg',{});",
                SysInfo.Success);*/
 
        return WebUtil.sysInfoPage(request, "操作成功!",
                "window.top.hideDialog('0');window.top.query();",
                SysInfo.Success,"");
        
    }
    
    @RequestMapping("qxInRole.html")
    public ModelAndView onQxListLoad(HttpServletRequest request,HttpServletResponse response){
        String sql = "SELECT ID,GNMC,TYPE,SXH,SMALL_IMAGE,SJBH FROM GG_XTGN ORDER BY TYPE ASC,SXH ASC";
        
        String roleid = request.getParameter("id");
        Map roleMap = new HashMap();
        if (StringUtils.isNotBlank(roleid)) {
         List<Map>    roleQxList = baseDao.queryForList("SELECT GNBH FROM AC_ROLE_QX WHERE JSBH =:jsbh",new SqlParameter("jsbh",roleid));
         for (Map map2 : roleQxList) {
            roleMap.put(map2.get("GNBH"), "");
         }
        }
        
        List<Map> xtgnList = baseDao.queryForList(sql, new SqlParameter());
        
        List<Map> resultList = new LinkedList<Map>();
        
        Map<String, Map> yjgnCache = new HashMap<String, Map>();
        Map<String, Map> ejgnCache = new HashMap<String, Map>();
        Map<String, Map> sjgnCache = new HashMap<String, Map>();
        
        for (Map map : xtgnList) {
            
            if (roleMap.containsKey(map.get("ID"))) {
                map.put("CHECKED", true);
            }
            
            //一级功能
            if (map.get("TYPE").toString().equalsIgnoreCase("1")) {
                yjgnCache.put(map.get("ID").toString(), map);
                List<Map> ejgnList = new LinkedList<Map>();
                map.put("GNLIST", ejgnList);
                resultList.add(map);
                continue;
            }
            if (map.get("TYPE").toString().equalsIgnoreCase("2")) {
                Map yjgnMap = yjgnCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)yjgnMap.get("GNLIST");
                map.put("GNLIST", new LinkedList<Map>());
                list.add(map);
                
                ejgnCache.put(map.get("ID").toString(), map);
                continue;
            }
            if (map.get("TYPE").toString().equalsIgnoreCase("3")) {
                Map ejgnMap = ejgnCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)ejgnMap.get("GNLIST");
                map.put("GNLIST", new LinkedList<Map>());
                list.add(map);
                sjgnCache.put(map.get("ID").toString(), map);
                continue;
            }
            if (map.get("TYPE").toString().equalsIgnoreCase("4")) {
                Map sjgnMap = sjgnCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)sjgnMap.get("GNLIST");
                list.add(map);
            }
        }
        return new ModelAndView("/business/pages/xtgl/jsgl/qxInRole","menuList",resultList);
    }
    
    @RequestMapping("qxInRoleSubmit.html")
    public ModelAndView onQxListSubmit(HttpServletRequest request,HttpServletResponse response){
        String[] yjgnbhs = request.getParameterValues("yjgn");
        String[] ejgnbhs = request.getParameterValues("ejgn");
        String[] sjgnbhs = request.getParameterValues("sjgn");
        String[] sijgnbhs = request.getParameterValues("sijgn");
        String roleid = request.getParameter("roleid");
        jsglFacade.onQxInRoleSubmit(yjgnbhs, ejgnbhs, sjgnbhs, sijgnbhs, roleid);
        return WebUtil.sysInfoPage(request, "操作成功!",
                "window.top.hideDialog('0');",
                SysInfo.Success,"");
    }
    
    @RequestMapping("userJsList.html")
    public ModelAndView user_in_jsList(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view = new ModelAndView("/business/pages/xtgl/jsgl/userJsList");
        //当前登录加盟商所有用户,包括加盟商
        String userSql = "select ID,ZSXM,SSBMBH,LOGINNAME from gg_user where zt=1  order by bmpx asc";
        Map param = new HashMap();
        List<Map> allUserList = baseDao.queryForList(userSql,param);
        
        //角色下所有人员
        String roleid = request.getParameter("id");
        
        Map roleMap = new HashMap();
        if (StringUtils.isNotBlank(roleid)) {
         List<Map>    roleQxList = baseDao.queryForList("select YHBH from AC_USER_REF_ROLE where jsbh =:jsbh",new SqlParameter("jsbh",roleid));
         for (Map map2 : roleQxList) {
            roleMap.put(map2.get("YHBH"), "");
         }
        }
        
        //如果人员在角色中,则增加CHECKED属性
        for (Map map3 : allUserList) {
            if (roleMap.containsKey(map3.get("ID"))) {
                map3.put("CHECKED", true);
            }
        }
        
        Map resultMap = new HashMap();
        resultMap.put("PARTNERLIST", allUserList); 
        
        view.addObject("data", resultMap);
        //所有部门
        String sql = "SELECT * FROM GG_ZZJG WHERE ZT=1 ORDER BY CENGJ ASC,SXH ASC";
        List<Map> bmList = baseDao.queryForList(sql, new SqlParameter());
        List<Map> resultList = new LinkedList<Map>();
        
        Map<String, Map> yjgnCache = new HashMap<String, Map>();
        Map<String, Map> ejgnCache = new HashMap<String, Map>();
        Map<String, Map> sjgnCache = new HashMap<String, Map>();
        
        for (Map map : bmList) {
            String level = map.get("CENGJ").toString();
            String id = map.get("ID").toString();
            
            //一级树
            if (level.equalsIgnoreCase("1")) {
                yjgnCache.put(id, map);
                List<Map> ejgnList = new LinkedList<Map>();
                map.put("ejTree", ejgnList);
                resultList.add(map);
                continue;
            }
            //二级树
            if (level.equalsIgnoreCase("2")) {
                String pId = map.get("SJBH").toString();
                if(yjgnCache.containsKey(pId)) {
                    Map yjgnMap = yjgnCache.get(pId);
                    List<Map> list = (List<Map>)yjgnMap.get("ejTree");
                    map.put("sjTree", new LinkedList<Map>());
                    list.add(map);
                    
                    ejgnCache.put(id, map);
                }
                continue;
            }
            //三级树
            if (level.equalsIgnoreCase("3")) {
                if(null!=map.get("SJBH")){
                    String pId = map.get("SJBH").toString();
                    if(ejgnCache.containsKey(pId)) {
                        Map ejgnMap = ejgnCache.get(map.get("SJBH").toString());
                        List<Map> list = (List<Map>)ejgnMap.get("sjTree");
                        map.put("fjTree", new LinkedList<Map>());
                        list.add(map);
                        sjgnCache.put(id, map);
                    }
                }
            }
        }
        view.addObject("ZZJGList", resultList);
        return view;
    }
    
    @RequestMapping("userJsListSubmit.html")
    public ModelAndView user_in_jsListSubmit(HttpServletRequest request,HttpServletResponse response){
        String roleid = request.getParameter("roleid");
        String[] userids = request.getParameterValues("userid");
        jsglFacade.onUserInRoleSubmit(userids, roleid);
        /*return WebUtil.goSysInfoPage(request,"人员配置成功!","window.top.closeDialog(0);",
                SysInfo.Success);*/
        return WebUtil.sysInfoPage(request, "操作成功!",
                "window.top.hideDialog('0');",
                SysInfo.Success,"");
    }
    
    /*@RequestMapping("user_in_jsList.html")
    public ModelAndView user_in_jsList(HttpServletRequest request,HttpServletResponse response){
        
        //所有用户
        String userSql = "SELECT ID,ZSXM,SSBMBH FROM GG_USER WHERE ZT=1 ORDER BY BMPX ASC";
        List<Map> allUserList = baseDao.queryForList(userSql);
        
        //角色下所有人员
        String roleid = request.getParameter("id");
        
        Map roleMap = new HashMap();
        if (StringUtils.isNotBlank(roleid)) {
         List<Map>    roleQxList = baseDao.queryForList("SELECT YHBH FROM AC_USER_REF_ROLE WHERE JSBH =:jsbh",new SqlParameter("jsbh",roleid));
         for (Map map2 : roleQxList) {
            roleMap.put(map2.get("YHBH"), "");
         }
        }
        
        
        //如果人员在角色中,则增加CHECKED属性
        for (Map map3 : allUserList) {
            if (roleMap.containsKey(map3.get("ID"))) {
                map3.put("CHECKED", true);
            }
        }
        
        
        //所有部门
        String sql = "SELECT * FROM GG_ZZJG WHERE ZT=1 ORDER BY CENGJ ASC,SXH ASC";
        List<Map> bmList = baseDao.queryForList(sql, new SqlParameter());
        
        List<Map> resultList = new LinkedList<Map>();
        
        Map<String, Map> yjbmCache = new HashMap<String, Map>();
        Map<String, Map> ejbmCache = new HashMap<String, Map>();
        Map<String, Map> sjbmCache = new HashMap<String, Map>();
        
        for (Map map : bmList) {
            
            List<Map> userList = new LinkedList<Map>();
            map.put("USERLIST", userList);
            for (Map userMap : allUserList) {
                if (userMap.get("SSBMBH").toString().equalsIgnoreCase(map.get("ID").toString())) {
                    userList.add(userMap);   
                }
            }
            
            //一级功能
            if (map.get("CENGJ").toString().equalsIgnoreCase("1")) {
                yjbmCache.put(map.get("ID").toString(), map);
                List<Map> ejbmList = new LinkedList<Map>();
                map.put("BMLIST", ejbmList);
                resultList.add(map);
                continue;
            }
            if (map.get("CENGJ").toString().equalsIgnoreCase("2")) {
                Map yjbmMap = yjbmCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)yjbmMap.get("BMLIST");
                map.put("BMLIST", new LinkedList<Map>());
                list.add(map);
                
                ejbmCache.put(map.get("ID").toString(), map);
                continue;
            }
            if (map.get("CENGJ").toString().equalsIgnoreCase("3")) {
                Map ejbmMap = ejbmCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)ejbmMap.get("BMLIST");
                map.put("BMLIST", new LinkedList<Map>());
                list.add(map);
                sjbmCache.put(map.get("ID").toString(), map);
                continue;
            }
            if (map.get("CENGJ").toString().equalsIgnoreCase("4")) {
                Map sjbmMap = sjbmCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)sjbmMap.get("BMLIST");
                list.add(map);
            }
        }
        
        Map resultMap = new HashMap();
        resultMap.put("BMLIST", resultList);   
        return new ModelAndView("/business/pages/xtgl/jsgl/user_in_jsList","data",resultMap);
    }
    
    @RequestMapping("user_in_jsListSubmit.html")
    public ModelAndView user_in_jsListSubmit(HttpServletRequest request,HttpServletResponse response){
        String roleid = request.getParameter("roleid");
        String[] userids = request.getParameterValues("userid");
        jsglFacade.onUserInRoleSubmit(userids, roleid);
        return WebUtil.goSysInfoPage(request,"操作成功!","",
                SysInfo.Success);
    }*/
    
    @RequestMapping(value="userInRole.html",method=RequestMethod.GET)
    public ModelAndView onUserInRoleLoad(HttpServletRequest request,HttpServletResponse response){
        //定义参数Map
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        String userid = request.getParameter("userid");
        
        ModelAndView view = new ModelAndView("/business/pages/xtgl/jsgl/userInRole");
        List<Map> list = jsglFacade.getUserInRoleList(userid);
        Map info = new HashMap();
        for (Map map : list) {
            info.put(map.get("JSBH"), "");
        }
        view.addObject("info",info);
        view.addObject("ROLE_LIST",jsglFacade.getRoleList(params));
        return view;
    }
    
    @RequestMapping(value="userInRole.html",method=RequestMethod.POST)
    public ModelAndView onUserInRolePost(HttpServletRequest request,HttpServletResponse response){
        
        String userid = request.getParameter("userid");
        String[] roleids = request.getParameterValues("roleid");
        String[] groupids = request.getParameterValues("groupid");
        
        jsglFacade.onUserInRoleSubmit(userid, roleids,groupids);
        
        /*return WebUtil.goSysInfoPage(request,"人员配置成功!","window.top.closeDialog(2);",
                SysInfo.Success);*/
        return WebUtil.sysInfoPage(request, "人员配置成功!",
                "window.top.hideDialog('user');",
                SysInfo.Success,"");
    }
    
    /**
     * 查询角色分组管理列表
     */
    @RequestMapping("roleGroupList.html")
    public ModelAndView roleGroupList(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view = new ModelAndView("business/pages/xtgl/jsgl/roleGroupList");
        return view;
    }
    
    /**
     * 查询角色分组管理列表数据
     */
    @RequestMapping("roleGroupData.html")
    public ModelAndView roleGroupData(HttpServletRequest request,PageInfo pageInfo){
        ModelAndView view = new ModelAndView("business/pages/xtgl/jsgl/roleGroupData");
        //定义参数Map
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        PageInfo info = jsglFacade.roleGroupData(pageInfo,params);
        view.addObject("info", info);
        return view;
    }
    
    /**
     * 查询角色分组管理列表数量
     */
    @RequestMapping("roleGroupCount.html")
    public void roleGroupCount(HttpServletRequest request,HttpServletResponse response) {
        //定义参数Map
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        int count = jsglFacade.roleGroupCount(params);
        WebUtil.write(response, String.valueOf(count));
    }
    
    @RequestMapping("addJsGroup.html")
    public ModelAndView addJsGroup(HttpServletRequest request,HttpServletResponse response){
        
        String id = request.getParameter("id");
        if (StringUtils.isBlank(id)) {
            Map map = new HashMap();
            
            return new ModelAndView("/business/pages/xtgl/jsgl/addJsGroup","info",map);
        } else {   
            Map map = new AC_ROLE_GROUP(id).getBeanMapById();
            return new ModelAndView("/business/pages/xtgl/jsgl/addJsGroup","info",map);
        }
    }
    
    @RequestMapping("addJsGroupSubmit.html")
    public ModelAndView addJsGroupSubmit(AC_ROLE_GROUP group,HttpServletRequest request,HttpServletResponse response){
        if(StringUtil.isEmpty(group.getId())){
            group.setState(1);
        }
        group.insertOrUpdate();
        
        return WebUtil.sysInfoPage(request, "操作成功!",
                "window.top.hideDialog('3');window.top.document.getElementById('dialogIframe0').contentWindow.query();",
                SysInfo.Success,"");
        
    }
    
    @RequestMapping("groupUser.html")
    public ModelAndView groupUser(HttpServletRequest request,HttpServletResponse response){
        
        String id = request.getParameter("id");
            
        List<Map> userList = jsglFacade.getGroupUser(id);
        return new ModelAndView("/business/pages/xtgl/jsgl/groupUser","info",userList);
    }
    
    @RequestMapping("groupuserSubmit.html")
    public ModelAndView groupuserSubmit(HttpServletRequest request,HttpServletResponse response){
        //定义参数Map
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        jsglFacade.updateGroupUser(params);
        
        return WebUtil.sysInfoPage(request, "操作成功!",
                "window.top.document.getElementById('dialogIframe0').contentWindow.query();window.top.hideDialog('3');",
                SysInfo.Success,"");
        
    }
    
    @RequestMapping("delGroup.html")
    public void delGroup(HttpServletRequest request,HttpServletResponse response){
        String groupId = request.getParameter("id");
        int result = jsglFacade.deleteGroup(groupId);
        WebUtil.write(response, ConvertUtil.obj2StrBlank(result));
    }
}