Search in sources :

Example 21 with Table

use of io.github.ihongs.db.Table in project HongsCORE by ihongs.

the class Form method insertAuthRole.

protected void insertAuthRole(String id) throws HongsException {
    ActionHelper helper = Core.getInstance(ActionHelper.class);
    String uid = (String) helper.getSessibute(Cnst.UID_SES);
    String tan;
    // 写入权限
    tan = (String) table.getParams().get("role.table");
    if (tan != null) {
        Table tab = db.getTable(tan);
        tab.insert(Synt.mapOf("user_id", uid, "role", centra + "/" + id + "/search"));
        tab.insert(Synt.mapOf("user_id", uid, "role", centra + "/" + id + "/create"));
        tab.insert(Synt.mapOf("user_id", uid, "role", centra + "/" + id + "/update"));
        tab.insert(Synt.mapOf("user_id", uid, "role", centra + "/" + id + "/delete"));
        tab.insert(Synt.mapOf("user_id", uid, "role", centra + "/" + id + "/revert"));
    }
    // 更新缓存(通过改变权限更新时间)
    tan = (String) table.getParams().get("user.table");
    if (tan != null) {
        Table tab = db.getTable(tan);
        tab.update(Synt.mapOf("rtime", System.currentTimeMillis() / 1000), "`id` = ?", uid);
    }
}
Also used : Table(io.github.ihongs.db.Table) ActionHelper(io.github.ihongs.action.ActionHelper)

Example 22 with Table

use of io.github.ihongs.db.Table in project HongsCORE by ihongs.

the class AssocMore method deleteMore.

/**
 * 关联删除
 *
 * @param table  主表
 * @param assocs 关联配置
 * @param ids    要删除的外键
 * @throws io.github.ihongs.HongsException
 */
public static void deleteMore(Table table, Map assocs, Object... ids) throws HongsException {
    if (assocs == null || assocs.isEmpty())
        return;
    Iterator it = assocs.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        Map config = (Map) entry.getValue();
        String type = (String) config.get("type");
        String name = (String) config.get("name");
        String tableName = (String) config.get("tableName");
        String foreignKey = (String) config.get("foreignKey");
        if (!type.equals("HAS_ONE") && !type.equals("HAS_MANY") && !type.equals("HAS_MORE")) {
            continue;
        }
        if (tableName == null || tableName.length() == 0) {
            tableName = name;
        }
        // 获取下级的下级的ID
        Table tbl = table.db.getTable(tableName);
        List idx = null;
        if (tbl.primaryKey != null && tbl.primaryKey.length() != 0) {
            List<Map> lst = tbl.fetchMore(new FetchCase().select("`" + tbl.primaryKey + "`").filter("`" + foreignKey + "`=?", ids));
            idx = new ArrayList();
            for (Map row : lst) {
                idx.add(row.get(tbl.primaryKey));
            }
        }
        // 下级伪删除同样有效
        tbl.remove("`" + foreignKey + "`=?", ids);
        // 递归删除下级的下级
        if (idx != null && !idx.isEmpty()) {
            deleteMore(tbl, tbl.getAssocs(), idx.toArray());
        }
    }
}
Also used : Table(io.github.ihongs.db.Table) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with Table

use of io.github.ihongs.db.Table in project HongsCORE by ihongs.

the class Data method cut.

/**
 * 删除记录
 *
 * 注意:
 * 用于终止当前节点,
 * 仅供内部持续补充.
 *
 * @param id
 * @param rd
 * @param ctime
 * @return 有更新为 1, 无更新为 0
 * @throws HongsException
 */
public int cut(String id, Map rd, long ctime) throws HongsException {
    delDoc(id);
    Table table = getTable();
    if (table == null) {
        return 1;
    }
    // String   uid   = getUserId();
    String fid = getFormId();
    Object[] param = new String[] { id, fid, "0" };
    String where = "`id`=? AND `form_id`=? AND `etime`=?";
    Map nd = table.fetchCase().filter(where, param).select("ctime,state,data,name").getOne();
    if (nd.isEmpty() || Synt.declare(nd.get("state"), 0) == 0) {
        // 删除是幂等的可重复调用
        return 0;
    }
    /* 没有新增, 不必限时
        if (Synt.declare(nd.get("ctime"), 0L ) >= ctime) {
            throw new HongsException(400, "Wait 1 second to del '"+id+"' in "+getDbName())
                .setLocalizedContent("matrix.wait.one.second")
                .setLocalizedContext("matrix");
        } */
    nd.put("state", 0);
    // 操作备注和终端代码
    if (rd.containsKey("memo")) {
        nd.put("memo", getText(rd, "memo"));
    }
    if (rd.containsKey("meno")) {
        nd.put("meno", getText(rd, "meno"));
    }
    table.update(nd, where, param);
    return 1;
}
Also used : Table(io.github.ihongs.db.Table) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 24 with Table

use of io.github.ihongs.db.Table in project HongsCORE by ihongs.

the class AuthKit method getUserDepts.

/**
 * 获取用户所在的分组
 * @param uid
 * @return
 * @throws HongsException
 */
public static Set getUserDepts(String uid) throws HongsException {
    Table rel = DB.getInstance("master").getTable("dept_user");
    List<Map> lst = rel.fetchCase().filter("user_id = ?", uid).select("dept_id").getAll();
    Set set = new HashSet();
    for (Map row : lst) {
        set.add(row.get("dept_id"));
    }
    return set;
}
Also used : Table(io.github.ihongs.db.Table) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 25 with Table

use of io.github.ihongs.db.Table in project HongsCORE by ihongs.

the class AuthKit method getDeptRoles.

/**
 * 获取分组拥有的权限
 * @param gid
 * @return
 * @throws HongsException
 */
public static Set getDeptRoles(String gid) throws HongsException {
    Table rel = DB.getInstance("master").getTable("dept_role");
    List<Map> lst = rel.fetchCase().filter("dept_id = ?", gid).select("role").getAll();
    Set set = new HashSet();
    for (Map row : lst) {
        set.add(row.get("role"));
    }
    return set;
}
Also used : Table(io.github.ihongs.db.Table) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Table (io.github.ihongs.db.Table)29 Map (java.util.Map)26 HashMap (java.util.HashMap)22 HongsException (io.github.ihongs.HongsException)12 HashSet (java.util.HashSet)11 Set (java.util.Set)11 DB (io.github.ihongs.db.DB)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)5 TreeSet (java.util.TreeSet)5 ActionHelper (io.github.ihongs.action.ActionHelper)4 ArrayList (java.util.ArrayList)4 Document (org.apache.lucene.document.Document)4 FetchCase (io.github.ihongs.db.util.FetchCase)3 Iterator (java.util.Iterator)3 Action (io.github.ihongs.action.anno.Action)2 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)2 Verify (io.github.ihongs.action.anno.Verify)2 Loop (io.github.ihongs.db.link.Loop)2 Dept (io.github.ihongs.serv.master.Dept)2