⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leafpriv.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.oa.flow;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.person.UserDb;import com.redmoon.oa.pvg.*;public class LeafPriv extends ObjectDbA {    private String dirCode = "", name = "";    int id, see = 1, append = 0, del = 0, modify = 0;    public static final int TYPE_USERGROUP = 0;    public static final int TYPE_USER = 1;    public static final int TYPE_ROLE = 2;    public static final int PRIV_SEE = 0;    public static final int PRIV_APPEND = 1;    public static final int PRIV_MODIFY = 2;    public static final int PRIV_DEL = 3;    public static final int PRIV_EXAMINE = 4;    public LeafPriv(int id) {        this.id = id;        load();        init();    }    public LeafPriv() {        init();    }    public LeafPriv(String dirCode) {        this.dirCode = dirCode;        init();    }    public void init() {        super.init();    }    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }        public Vector getRolesOfLeafPriv(String leafCode) {        ResultSet rs = null;        Conn conn = new Conn(connname);        Vector result = new Vector();        PreparedStatement ps = null;        RoleMgr rm = new RoleMgr();        try {            String sql = "select name from flow_dir_priv where dir_code=? and priv_type=?";            ps = conn.prepareStatement(sql);            ps.setString(1, leafCode);            ps.setInt(2, this.TYPE_ROLE);            rs = ps.executeQuery();            if (rs == null) {                return null;            } else {                while (rs.next()) {                    result.addElement(rm.getRoleDb(rs.getString(1)));                }            }        } catch (Exception e) {            logger.error("getRolesOfLeafPriv: " + e.getMessage());        } finally {                        if (conn != null) {                conn.close();                conn = null;            }        }        return result;    }    public String getTypeDesc() {        if (type==this.TYPE_USER)            return "用户";        else if (type==this.TYPE_USERGROUP)            return "用户组";        else if (type==this.TYPE_ROLE)            return "角色";        else            return "";    }    public void setQueryList() {        QUERY_LIST =                "select id from flow_dir_priv where dir_code=? order by priv_type desc, name";    }    public void setQueryLoad() {        QUERY_LOAD =                "select dir_code,name,priv_type,see,append,del,modify,examine from flow_dir_priv where id=?";    }    public void setQueryDel() {        QUERY_DEL = "delete from flow_dir_priv where id=?";    }    public void setQuerySave() {        QUERY_SAVE =                "update flow_dir_priv set see=?,append=?,del=?,modify=?,examine=? where id=?";    }    public void setQueryAdd() {        QUERY_ADD =                "insert into flow_dir_priv (name,priv_type,see,append,del,modify,examine,dir_code) values (?,?,?,?,?,?,?,?)";    }    public void load() {        ResultSet rs = null;        Conn conn = new Conn(connname);        PreparedStatement ps = null;        try {            ps = conn.prepareStatement(QUERY_LOAD);            ps.setInt(1, id);            rs = conn.executePreQuery();            if (rs != null && rs.next()) {                dirCode = rs.getString(1);                name = rs.getString(2);                type = rs.getInt(3);                see = rs.getInt(4);                append = rs.getInt(5);                del = rs.getInt(6);                modify = rs.getInt(7);                examine = rs.getInt(8);                loaded = true;            }        } catch (Exception e) {            logger.error("load: " + e.getMessage());        } finally {                        if (conn != null) {                conn.close();                conn = null;            }        }    }    public String getDirCode() {        return dirCode;    }    public void setDirCode(String code) {        this.dirCode = code;    }    public String getName() {        return name;    }    public void setType(int t) {        this.type = t;    }    public void setName(String n) {        this.name = n;    }    public int getType() {        return type;    }    public boolean isLoaded() {        return loaded;    }    public String toString() {        return "LeafPriv is " + dirCode + ":" + name;    }    private int type = 0;    public synchronized boolean save() {        RMConn conn = new RMConn(connname);        int r = 0;        try {            PreparedStatement ps = conn.prepareStatement(QUERY_SAVE);            ps.setInt(1, see);            ps.setInt(2, append);            ps.setInt(3, del);            ps.setInt(4, modify);            ps.setInt(5, examine);            ps.setInt(6, id);            r = conn.executePreUpdate();        } catch (SQLException e) {            logger.error("修改出错!");        }        return r == 1 ? true : false;    }    public boolean canUserSee(String username) {                if (dirCode.equals(Leaf.CODE_ROOT))            return true;        if (username==null)            username = "";                if (username.equals(UserDb.ADMIN))            return true;        return canUserDo(username, this.PRIV_SEE);    }        public boolean canUserDo(Leaf leaf, UserDb user, UserGroupDb[] groups, RoleDb[] roles, int privType) {        LeafPriv leafPriv = new LeafPriv(leaf.getCode());                Vector r = leafPriv.list();        Iterator ir = r.iterator();        while (ir.hasNext()) {                        LeafPriv lp = (LeafPriv) ir.next();                        if (lp.getType() == lp.TYPE_USERGROUP) {                                if (lp.getName().equals(UserGroupDb.EVERYONE)) {                    if (privType==this.PRIV_APPEND) {                        if (lp.getAppend() == 1)                            return true;                    }                    else if (privType==this.PRIV_DEL) {                        if (lp.getDel() == 1)                            return true;                    }                    else if (privType==this.PRIV_MODIFY) {                        if (lp.getModify()==1)                            return true;                    }                    else if (privType==this.PRIV_SEE) {                        if (lp.getSee()==1)                            return true;                    }                    else if (privType==this.PRIV_EXAMINE) {                        if (lp.getExamine()==1)                            return true;                    }                } else {                    if (groups != null) {                        int len = groups.length;                                                for (int i = 0; i < len; i++) {                            if (groups[i].getCode().equals(lp.getName())) {                                if (privType == this.PRIV_APPEND) {                                    if (lp.getAppend() == 1)                                        return true;                                } else if (privType == this.PRIV_DEL) {                                    if (lp.getDel() == 1)                                        return true;                                } else if (privType == this.PRIV_MODIFY) {                                    if (lp.getModify() == 1)                                        return true;                                } else if (privType == this.PRIV_SEE) {                                    if (lp.getSee() == 1)                                        return true;                                }                                else if (privType == this.PRIV_EXAMINE) {                                    if (lp.getExamine() == 1)                                        return true;                                }                                break;                            }                        }                    }                }            }            else if (lp.getType()==lp.TYPE_ROLE) {                if (roles!=null) {                                                int len = roles.length;                        for (int i = 0; i < len; i++) {                            if (roles[i].getCode().equals(lp.getName())) {                                if (privType == this.PRIV_APPEND) {                                    if (lp.getAppend() == 1)                                        return true;                                } else if (privType == this.PRIV_DEL) {                                    if (lp.getDel() == 1)                                        return true;                                } else if (privType == this.PRIV_MODIFY) {                                    if (lp.getModify() == 1)                                        return true;                                } else if (privType == this.PRIV_SEE) {                                    if (lp.getSee() == 1)                                        return true;                                }                                else if (privType == this.PRIV_EXAMINE) {                                    if (lp.getExamine() == 1)                                        return true;                                }                                break;                            }                        }                }            }            else if (lp.getType()==lp.TYPE_USER) {                 if (lp.getName().equals(user.getName())) {                    if (privType == this.PRIV_APPEND) {                        if (lp.getAppend() == 1)                            return true;                    } else if (privType == this.PRIV_DEL) {                        if (lp.getDel() == 1)                            return true;                    } else if (privType == this.PRIV_MODIFY) {                        if (lp.getModify() == 1)                            return true;                    } else if (privType == this.PRIV_SEE) {                        if (lp.getSee() == 1)                            return true;                    } else if (privType == this.PRIV_EXAMINE) {                        if (lp.getExamine() == 1)                            return true;                    }                }            }        }        return false;    }    public boolean canUserDo(String username, int privType) {        if (username==null)            return false;        if (username.equals(UserDb.ADMIN))            return true;        UserDb user = new UserDb();        user = user.getUserDb(username);                String[] privs = user.getPrivs();        if (privs!=null) {            int len = privs.length;            for (int i=0; i<len; i++) {                                if (privs[i].equals(PrivDb.PRIV_ADMIN))                    return true;            }        }        UserGroupDb[] groups = user.getGroups();        RoleDb[] roles = user.getRoles();                        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -