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 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 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 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 xtgnList = baseDao.queryForList(sql, new SqlParameter()); List resultList = new LinkedList(); Map yjgnCache = new HashMap(); Map ejgnCache = new HashMap(); Map sjgnCache = new HashMap(); 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 ejgnList = new LinkedList(); map.put("GNLIST", ejgnList); resultList.add(map); continue; } if (map.get("TYPE").toString().equalsIgnoreCase("2")) { Map yjgnMap = yjgnCache.get(map.get("SJBH").toString()); List list = (List)yjgnMap.get("GNLIST"); map.put("GNLIST", new LinkedList()); 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 list = (List)ejgnMap.get("GNLIST"); map.put("GNLIST", new LinkedList()); 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 list = (List)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 allUserList = baseDao.queryForList(userSql,param); //角色下所有人员 String roleid = request.getParameter("id"); Map roleMap = new HashMap(); if (StringUtils.isNotBlank(roleid)) { List 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 bmList = baseDao.queryForList(sql, new SqlParameter()); List resultList = new LinkedList(); Map yjgnCache = new HashMap(); Map ejgnCache = new HashMap(); Map sjgnCache = new HashMap(); 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 ejgnList = new LinkedList(); 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 list = (List)yjgnMap.get("ejTree"); map.put("sjTree", new LinkedList()); 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 list = (List)ejgnMap.get("sjTree"); map.put("fjTree", new LinkedList()); 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 allUserList = baseDao.queryForList(userSql); //角色下所有人员 String roleid = request.getParameter("id"); Map roleMap = new HashMap(); if (StringUtils.isNotBlank(roleid)) { List 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 bmList = baseDao.queryForList(sql, new SqlParameter()); List resultList = new LinkedList(); Map yjbmCache = new HashMap(); Map ejbmCache = new HashMap(); Map sjbmCache = new HashMap(); for (Map map : bmList) { List userList = new LinkedList(); 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 ejbmList = new LinkedList(); map.put("BMLIST", ejbmList); resultList.add(map); continue; } if (map.get("CENGJ").toString().equalsIgnoreCase("2")) { Map yjbmMap = yjbmCache.get(map.get("SJBH").toString()); List list = (List)yjbmMap.get("BMLIST"); map.put("BMLIST", new LinkedList()); 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 list = (List)ejbmMap.get("BMLIST"); map.put("BMLIST", new LinkedList()); 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 list = (List)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 params = ParamsMapUtil.getParameterMap(request); String userid = request.getParameter("userid"); ModelAndView view = new ModelAndView("/business/pages/xtgl/jsgl/userInRole"); List 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 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 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 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 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)); } }