@RequestMapping ("/tree") @DoLog (cncontent = "Permission tree initialization", value =false)//@Permission (name = "Login.tree") PublicString Tree (httpservletrequest request, httpservletresponse response, Ztreecomm Ztree)throwsException {Try { //1, access to the information of the landing personSysuser CurrentUser =Getloginuser (Request); //2. Get the list of permissions based on the ID, get the parent permission list (Limit=roleid) when the ID is emptyList<ztreecomm> tree =Sysuserservice.initauthoritytree (Ztree, CurrentUser); //3. Setting the parent nodeList<ztreecomm> Votree =NewArraylist<ztreecomm>(); for(inti = 0; I < tree.size (); i++) {Ztreecomm Ztree=(Ztreecomm) tree.get (i); intTotal =sysuserservice.isparent (Ztree); Ztree.setisparent ( Total! = 0?Constants.IS_TRUE:Constants.IS_FALSE); Votree.add (Ztree); } //4, List sort. Collections.sort (Votree,NewComparator<ztreecomm>() { Public intCompare (Ztreecomm arg0, Ztreecomm arg1) {returnArg0.getsortno (). CompareTo (Arg1.getsortno ()); } }); return This. Ajax (response, Votree); } Catch(Exception e) { This. Logexception (e); return This. Ajax (Response, "System exception: [" + e.getmessage () + "] Please contact your administrator! "); } }
@Override PublicList<ztreecomm> Initauthoritytree (Ztreecomm ztree, Sysuser sysuser)throwsException {//1. Get the role stringList<sysrole> Sysroles =Sysuser.getsysroles (); String Roleid= ""; if(Collectionhelp.isnotbank (sysroles)) { for(Object obj:sysroles) {sysrole role=(sysrole) obj; if(Constants.STATUS_ACTIVE.equals (Role.getstatus ())) {Roleid= Role.getroleid () + "," +Roleid; }}} ztree.setdiyparams (Roleid); //because Ztree does not have a Roleid property, the empty property of Ztree is used//2, according to Ztree, access to access informationList<ztreecomm> dataList =NewArraylist<ztreecomm>(); if(Stringutils.isempty (Ztree.getid ())) {//ID is empty, initial load, query root node. Where parent_dept_id is nullDataList = sqlsessiontemplate.selectlist (Securitymgrconstants.ztree_common_mapper_namespace + ". GetAuthorityRoot", Ztree); } Else { //The ID is not empty, and the child node is queried for the drop-down. where parent_dept_id =idDataList = sqlsessiontemplate.selectlist (Securitymgrconstants.ztree_common_mapper_namespace + ". GetAuthorityById", Ztree); } returndataList; }
Gets all the roles of the user and puts the role ID into the string and into the custom attribute in the Ztreecomm class Diyparams
Ztreecomm should be the corresponding sys_authority table, but there is no field in the table corresponding to Roleid, so the entity class stores roleid as strings in Ztree
Next determine whether the root node,//ID is empty, initial load, query root node,//ID is not empty, drop-down, query child node
<!--- < id = "Getauthorityroot" Resultmap= "Authoritytreeresultmap" parametertype= "Ztreecomm"> SELECT * from Sys_authority where authority_id in ( SELECT authority_id from sys_role_authority where INST R (#{diyparams},role_id) >0 ) and parent_id is NULL and authority_type= ' 2 ' </ Select >
Authority_type Permission Type: 1: normal permission 2: Menu 3: report
When you get a collection of permissions, determine what the parent node is for each permission
for (int i = 0; i < tree.size (); i++) { = (ztreecomm) tree.get (i); int total = sysuserservice.isparent (ztree); ! = 0? Constants.IS_TRUE:Constants.IS_FALSE); Votree.add (Ztree); }
<!--- < id = "Isparent" Resulttype = "integer" parametertype= "Ztreecomm"> Select COUNT (* ) from Sys_authority WHERE parent_id=#{id} and Authority_type= ' 2 ' </Select >
and assign values to each Ztree isparent into the new set.
To sort a new collection
// 4, List sort. New comparator<ztreecomm>() { publicint Compare ( Ztreecomm arg0, Ztreecomm arg1) { return arg0.getsortno (). CompareTo (Arg1.getsortno ()); } });
Java Framework Initialization Menu tree