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

📄 leafpriv.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.oa.netdisk;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 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 netdisk_dir_priv where dir_code=? order by type, name";    }    public void setQueryLoad() {        QUERY_LOAD =                "select dir_code,name,type,see,append,del,modify,examine from netdisk_dir_priv where id=?";    }    public void setQueryDel() {        QUERY_DEL = "delete from netdisk_dir_priv where id=?";    }    public void setQuerySave() {        QUERY_SAVE =                "update netdisk_dir_priv set see=?,append=?,del=?,modify=?,examine=? where id=?";    }    public void setQueryAdd() {        QUERY_ADD =                "insert into netdisk_dir_priv (name,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 (username==null)            username = "";                if (username.equals(UserDb.ADMIN))            return true;        UserDb user = new UserDb();        UserGroupDb[] groups = null;        if (username != null)            user = user.getUserDb(username);        if (user.isLoaded())            groups = user.getGroups();        Leaf lf = new Leaf();        lf = lf.getLeaf(dirCode);        return canUserDo(lf, user, groups, user.getRoles(), this.PRIV_SEE);    }        public boolean canUserDo(Leaf leaf, UserDb user, UserGroupDb[] groups, RoleDb[] roles, int privType) {                if (leaf.getRootCode().equals(user.getName()))            return true;        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) {                logger.info("canUserDo:name=" + lp.getName() + " privType=" + privType);                                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++) {                            logger.info("canUserDo:group[i].desc=" + groups[i].getDesc());                            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 {                 logger.info("privType=" + privType);                logger.info("canUserDo:userName=" + lp.getName());                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;                    }                    break;                }            }        }        return false;    }    public boolean canUserDo(String username, int privType) {        logger.info("canUserDo:privType=" + privType);        if (username==null)            return false;        if (username.equals(UserDb.ADMIN))            return true;                Leaf lf = new Leaf();        lf = lf.getLeaf(dirCode);        if (lf==null)            return false;        if (lf.getRootCode().equals(username))            return true;        logger.info("canUserDo: lf.rootCode=" + lf.getRootCode());        UserDb user = new UserDb();        user = user.getUserDb(username);

⌨️ 快捷键说明

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