📄 authority.java
字号:
package com.sinosoft.user;
import java.util.*;
import com.sinosoft.common.*;
public class Authority extends Object{
protected IndexMap propList;
protected HashSet Property;
private List strList = new ArrayList();
private boolean EOF = false;
private int COUNT;
public Authority(){
propList = new IndexMap();
Property = new HashSet();
//Property.add("UserID");
//Property.add("AuthorityID");
//Property.add("Flag");
Property.add("AuthorityID");
Property.add("AuthorityName");
Property.add("AuthorityParentID");
//Property.add("Note");
////////////用户与权限关联表//////////////
Property.add("UserID");
//Property.add("Flag"); //目前没用上 1 为用户 0为用户组
//Property.add("MakeDate");
}
//权限表初始化
public void init(String id){
DBAccess d = new DBAccess();
String sql = "SELECT * from Authority where AuthorityID=?";
this.propList = d.init(sql,id,this.Property);
}
public boolean delete(String id){
DBAccess DBA= new DBAccess();
String SQL = "DELETE from user_authority WHERE UserID = ?";
return DBA.executeDelete(SQL,id);
}
public boolean create(List list){
String SQL = "INSERT into user_authority (USERID,AUTHORITYID,FLAG) values(?,?,1)";
DBAccess d = new DBAccess();
return d.mulExecute(SQL.toString(), list);
}
public boolean multiCreate(String userID, String authorityIDs) {
this.delete(userID);
boolean flag = false;
if("".equals(authorityIDs)) {
return true;
}
List list = new ArrayList();
String[] strArr = authorityIDs.split(",");
for(int i = 0; i < strArr.length; i++) {
String[] temp = new String[2];
temp[0] = userID;
temp[1] = strArr[i];
list.add(temp);
}
flag = this.create(list);
return flag;
}
///////////////////////////////用户或用户组与权限关联表程序////////////////////////////////
//获得用户或用户组的权限
public String getAuthority(String userID){
List list = new ArrayList();
list.add(userID);
String SQL = "SELECT authorityID FROM user_authority WHERE userID= ?";
DBAccess DBA = new DBAccess();
List l = DBA.parseSQL(SQL.toString(),list);
StringBuffer stb = new StringBuffer("");
for(int i = 0; i < l.size(); i++) {
stb.append(l.get(i) + ",");
}
return stb.toString();
}
// 获得权限树 递归算法//根据USERID以及USERID所属的USERGROUP获得权限的并集
public String getUserOrUserGroupXML(String pid){
List result = new ArrayList();
String xmlStr = "";
DBAccess DBA = new DBAccess();
String authorityIDs = getAuthority(this.get("UserID"));
if (!("".equals(authorityIDs))){
List list = new ArrayList();
String sql = "SELECT AuthorityID,AuthorityName from authority where AuthorityParentID=?";
list.add(pid);
result = DBA.mulparseSQL(sql.toString(),list);
IndexMap hm = new IndexMap();
for(int i=0; i<result.size();i++){
hm = (IndexMap)result.get(i);
String id = (String)hm.get(0);
String name = (String)hm.get(1);
xmlStr += "<item id='" + id + "'";
if (("," + authorityIDs + ",").indexOf(("," + id + ","))>=0 && (authorityID(id).size() == 0)){ //判断如果有权限,并且是叶子节点时,被选中
xmlStr += " checked='1'";
}
xmlStr += " text='" + name + "'>\n";
xmlStr += getUserOrUserGroupXML(id);
xmlStr += "</item>\n";
}
}else{
//如果要是增加新的功能选项,请及时更新这个XML
xmlStr =
"<item id='1' text='产品管理'>" +
"<item id='47' text='畅游天下管理'>" +
"<item id='48' text='数据导入'></item>" +
"</item>" +
"<item id='2' text='产品管理'>" +
"<item id='3' text='新建产品'></item>" +
"<item id='4' text='产品查询'>" +
"<item id='40' text='产品查询'></item>" +
"<item id='29' text='编辑'></item>" +
"<item id='30' text='删除'></item>" +
"</item>" +
"</item>" +
"<item id='5' text='卡式保单激活'>" +
"<item id='6' text='新建卡式保单'></item>" +
"<item id='7' text='卡式保单查询'></item>" +
"</item>" +
"<item id='58' text='定点医院管理'>" +
"<item id='59' text='数据导入'></item>" +
"</item>" +
"</item>" +
"<item id='8' text='业务管理'>" +
"<item id='9' text='业务管理'>" +
"<item id='10' text='投保意向管理'>" +
"<item id='60' text='处理'></item>" +
"<item id='41' text='投保意向管理'></item>" +
"<item id='31' text='转办'></item>" +
"</item>" +
"<item id='11' text='投诉管理'>" +
"<item id='42' text='投诉管理'></item>" +
"<item id='32' text='删除'></item>" +
"<item id='33' text='转办'></item>" +
"<item id='51' text='受理'></item>" +
"<item id='52' text='结案'></item>" +
"</item>" +
"<item id='12' text='咨询留言管理'>" +
"<item id='53' text='处理'></item>" +
"<item id='49' text='删除'></item>" +
"<item id='43' text='咨询留言管理'></item>" +
"<item id='34' text='转办'></item>" +
"</item>" +
"</item>" +
"<item id='13' text='机构管理'>" +
"<item id='14' text='机构邮箱绑定'></item>" +
"</item>" +
"<item id='15' text='活动报名管理'>" +
"<item id='46' text='活动报名维护'>" +
"<item id='54' text='开放活动报名'></item>" +
"<item id='55' text='关闭活动报名'></item>" +
"<item id='56' text='删除活动报名'></item>" +
"</item>" +
"<item id='16' text='新建活动报名'></item>" +
"<item id='17' text='活动报名查询'>" +
"<item id='57' text='报名汇总表'></item>" +
"</item>" +
"</item>" +
"<item id='18' text='代理人管理'>" +
"<item id='19' text='新建代理人'></item>" +
"<item id='20' text='查询代理人'>" +
"<item id='44' text='查询代理人'></item>" +
"<item id='35' text='开通'></item>" +
"<item id='36' text='冻结'></item>" +
"<item id='37' text='优秀代理人开通'></item>" +
"<item id='38' text='优秀代理人开通'></item>" +
"</item>" +
"</item>" +
"</item>" +
"<item id='21' text='CMS管理'></item>" +
"<item id='22' text='系统管理'>" +
"<item id='23' text='用户权限管理'>" +
"<item id='24' text='权限管理'>" +
"<item id='45' text='权限管理'></item>" +
"<item id='39' text='个人直接授权'></item>" +
"</item>" +
"</item>" +
"<item id='25' text='系统管理'>" +
"<item id='50' text='用户日志'></item>" +
"<item id='26' text='系统日志'></item>" +
"</item>" +
"</item>";
}
return xmlStr;
}
public List authorityID(String parentID){
List list = new ArrayList();
list.add(parentID);
String SQL = "SELECT AuthorityID from authority where AuthorityParentID= ?";
DBAccess d = new DBAccess();
List l = d.parseSQL(SQL.toString(),list);
return l;
}
public void setUpdateValue(String name,Object value){
if(this.set(name,value)){
Object[] uValue = new Object[2];
uValue[0] = name;
uValue[1] = value;
strList.add(uValue);
}
}
public boolean set(String name, Object value){
if(Property.contains(name)){
propList.put(name,value);
return true;
}else
return false;
}
public String get(String name){
if (Property.contains(name)){
String value = (String)propList.get(name);
if(value != null && !value.equals(""))
return value;
else
return "";
}else
return "";
}
public int getCOUNT() {
return COUNT;
}
public void setCOUNT(int count) {
COUNT = count;
}
public boolean isEOF() {
return EOF;
}
public void setEOF(boolean eof) {
EOF = eof;
}
public void clear(){
propList.clear();
}
public static void main(String[] args){
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -