SystemController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:8k
- import groovy.xml.MarkupBuilder
- import java.text.SimpleDateFormat
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- class SystemController {
- def dataSource
- def index = {
- if(AuthUtil.getPower(session)>=1){
- redirect(action: left, params: params)
- }
- }
- def allowedMethods = [delete: ['GET', 'POST'], save: ['GET', 'POST'], update: 'POST', search: ['GET', 'POST']]
- def showmain = {
- def role = AuthUtil.getRole(session)
- if (role) {
- render(view: 'index'
- )
- }
- else
- {
- redirect(uri: '/error.gsp')
- }
- }
- def top = {
- def role = AuthUtil.getRole(session)
- //StringMap.parseStringToMap(StringMap.parseMapToString())
- List allRealUrls = new java.util.ArrayList() // 从系统获得的所有url
- List newUrls = new java.util.ArrayList() // requestMap与系统获得url比较后的url
- List newUrls0
- def te = grailsApplication.controllerClasses
- te.each {elem ->
- String[] uris = elem.getURIs()
- uris.each {elem1 ->
- if (elem1.endsWith("**")) {
- allRealUrls.add(elem1.substring(1, elem1.indexOf('*') - 1))
- }
- }
- }
- //println 'all:'+allRealUrls
- if (role) {
- def requestmap = Requestmap.findAllByConfigAttributeLike('%' + role + ',%')
- def urls = requestmap.collect {elem -> //从requestMap中获得的urls
- elem.url.substring(1, elem.url.indexOf('*') - 1)
- }
- urls.each {ele ->
- allRealUrls.each {elem1 ->
- if (ele.compareToIgnoreCase(elem1) == 0) {
- newUrls.add(elem1)
- }
- }
- }
- println 'List newUrls befor :'+newUrls
- newUrls0 = ChangeUrl.removeUrl(newUrls)
- println 'List newUrls0 after:'+newUrls0
- def allUrls2 =new ArrayList();
- // 【】内要小写
- allUrls2 =ChangeUrl.groupUrl(newUrls0).sort().reverse()
- println 'current :'+allUrls2
- render(view: 'top', model: [allUrls2: allUrls2 ])
- }
- }
- /*
- def left = {
- def role = AuthUtil.getRole(session)
- //StringMap.parseStringToMap(StringMap.parseMapToString())
- List allRealUrls = new java.util.ArrayList() // 从系统获得的所有url
- List newUrls = new java.util.ArrayList() // requestMap与系统获得url比较后的url
- List newUrls0
- def te = grailsApplication.controllerClasses
- te.each {elem ->
- //println elem.propertyName
- String[] uris = elem.getURIs()
- uris.each {elem1 ->
- if (elem1.endsWith("**")) {
- allRealUrls.add(elem1.substring(1, elem1.indexOf('*') - 1))
- }
- }
- }
- //println 'all:'+allRealUrls
- if (role) {
- def requestmap = Requestmap.findAllByConfigAttributeLike('%' + role + ',%')
- def urls = requestmap.collect {elem -> //从requestMap中获得的urls
- elem.url.substring(1, elem.url.indexOf('*') - 1)
- }
- urls.each {ele ->
- allRealUrls.each {elem1 ->
- if (ele.compareToIgnoreCase(elem1) == 0) {
- newUrls.add(elem1)
- }
- }
- }
- println 'List newUrls befor :'+newUrls
- newUrls0 = ChangeUrl.removeUrl(newUrls)
- println 'List newUrls0 after:'+newUrls0
- def allUrls =new ArrayList();
- // 【】内要小写
- allUrls =ChangeUrl.groupUrl(newUrls0).sort().reverse()
- render(view: 'left', model: [allUrls: allUrls ])
- } else {
-
- redirect(uri: '/error.gsp')
- }
- }*/
- def left = {
- //[ "data": writer.toString(), personList: Person.list( params )]
- //[ "data": writer.toString(), personList: System_menu.list( params )]
- ArrayList itemlist = getChildren("");
- List TreeFolder=new ArrayList();
- for(int i = 0 ; i < itemlist.size(); i++)
- {
- String s= renderTreeViewAjax((System_menu)itemlist.getAt(i));
- //println 'ddfdf'+s
- TreeFolder.add(s);
- }
- [ treefolderList: TreeFolder]
- }
- def sayHello = {
- response.setContentType("text/html;charset=GB2312");
- PrintWriter out= response.getWriter();
- String parentID = params.parentID;
- println 'hhh'+parentID;
- //StringBuffer outputContenter = new StringBuffer();
- if (parentID!=null&&!parentID.equals(""))
- {
- //res.setContentType("text/html;charset=GB2312");
- ArrayList itemlist = getChildren(parentID);
- println 'ddfdf'+itemlist.size()
- String s;
- //PrintWriter out= res.getWriter();
- for(int i = 0 ; i < itemlist.size(); i++)
- {
- s= renderTreeViewAjax((System_menu)itemlist.getAt(i));
- println s;
- out.println(s);
- }
- }
- out.close();
- render " [${new Date()}] Hello, ${params.parentID} "
- //render " [${new Date()}] Hello, ${params.id} "
- /*
- render outputContenter.toString()
- //render " [${new Date()}] Hello, ${params.id} "
- */
- }
- public String renderTreeViewAjax(System_menu htfl) {
- StringBuffer content = new StringBuffer();
- String ID=htfl.getId();
- String NAME=htfl.getName();
- String FLAG='true';
- //htfl.getActiveStatus();
- content.append("<li id='"+ID+"'>");
- if (canExpand(ID))
- {
- String submitURL="http://localhost:8080/CI/system/sayHello?parentID="+ID;
- // String submitURL="http://localhost:8080/CI/?parentID="+ID;
- content.append("<img src="/CI/images/plus.gif" onClick="getSubTree('"+ID+"','"+submitURL+"')">");
- //content.append("<a href="/CI/system/sayHello/1" onclick="new Ajax.Updater('hello','/CI/system/sayHello/1',{asynchronous:true,evalScripts:true});return false;"><img src="/CI/images/plus.gif"></a>");
- //content.append("<a href="/CI/system/sayHello/1" onclick="new Ajax.Updater('hello','/CI/system/sayHello/1',{asynchronous:true,evalScripts:true});return false;">dsfss</a>");
- }
- else
- {
- content.append("<img src="/CI/images/blank.gif">");
- }
- println 'd';
- //content.append("<img src="/CI/images/folder.gif"><a href="javascript:ShowDetail('"+ID+"','"+NAME+"','"+FLAG+"')"");
- //content.append(">"+NAME+"</a>");
- content.append("<img src="/CI/images/folder.gif"><a target='mainFrame' href='/CI/system_menu/show?id="+ID+"'");
- content.append(">"+NAME+"</a>");
- content.append("</li>");
- println 'e';
- return content.toString();
- }
- public List getChildren(String categoryId){
- def results = null
- if (categoryId!=null&&!categoryId.equals(""))
- results= System_menu.findAll("from System_menu where parent_id="+categoryId);
- else
- results= System_menu.findAll("from System_menu where id=1 ");
- return results
- }
- public boolean canExpand(String categoryId) {
- String nCount="0";
- nCount=System_menu.executeQuery("select count(*) from System_menu where parent_ID = " + Integer.parseInt(categoryId ))[0]
- //String ss= "select id from system_menu where parent_ID=" + Integer.parseInt(categoryId );
- if(nCount=="0")
- return false;
- else
- return true;
- }
- def mainFrame = {
-
- }
- }