Search in sources :

Example 11 with FetchCase

use of app.hongs.db.util.FetchCase in project HongsCORE by ihongs.

the class Model method allow.

/**
 * 递归提取字段
 * @param table 顶层模型库表
 * @param assoc 当前关联库表
 * @param ac    当前下级关联
 * @param pc    当前层级参数
 * @param caze  当前查询用例
 * @param tn    当前表名
 * @param qn    层级名称
 * @param pn    相对层级
 * @param al    字段集合, 结构: {参数: [字段, 别名, 查询用例]}
 */
private void allow(Table table, Table assoc, Map ac, Map pc, FetchCase caze, String tn, String qn, String pn, Map al) {
    String tx, ax, az;
    tx = "`" + tn + "`.";
    if (null == qn) {
        qn = "";
        ax = "";
    } else if ("".equals(qn)) {
        qn = tn;
        ax = qn + ".";
    } else {
        qn = qn + "." + tn;
        ax = qn + ".";
    }
    if (null == pn) {
        pn = "";
        az = "";
    } else if ("".equals(pn)) {
        pn = tn;
        az = pn + ".";
    } else {
        pn = pn + "." + tn;
        az = pn + ".";
    }
    if (pc != null && pc.containsKey("fields")) {
        al.put(az + "*", new Object[] { null, null, caze });
    } else
        try {
            Map fs = assoc.getFields();
            for (Object n : fs.keySet()) {
                String f = (String) n;
                String k = f;
                String l = f;
                // 字段完整名
                f = tx + "`" + f + "`";
                // 字段别名
                l = az + /**/
                l;
                // 外部键
                k = ax + /**/
                k;
                al.put(k, new Object[] { f, l, caze });
            }
        } catch (HongsException e) {
            throw e.toExpedient();
        }
    if (ac == null || ac.isEmpty()) {
        return;
    }
    Iterator it = ac.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry et = (Map.Entry) it.next();
        Map tc = (Map) et.getValue();
        String jn = (String) tc.get("join");
        // 不是 JOIN 的重置 pn, 层级名随之改变
        if (!"INNER".equals(jn) && !"LEFT".equals(jn) && !"RIGHT".equals(jn) && !"FULL".equals(jn)) {
            jn = null;
        } else {
            jn = pn;
        }
        tn = (String) et.getKey();
        ac = (Map) tc.get("assocs");
        pc = (Map) tc.get("params");
        // 获取真实的表名, 构建关联表实例
        String rn;
        rn = (String) tc.get("tableName");
        if (rn == null || "".equals(rn)) {
            rn = (String) tc.get("name");
        }
        FetchCase caxe;
        try {
            assoc = table.db.getTable(rn);
            caxe = caze.gotJoin(tn);
        } catch (HongsException e) {
            throw e.toExpedient();
        }
        if (null == assoc) {
            throw new HongsExpedient.Common("Can not get table '" + rn + "' in DB '" + table.db.name + "'");
        }
        allow(table, assoc, ac, pc, caxe, tn, qn, jn, al);
    }
}
Also used : FetchCase(app.hongs.db.util.FetchCase) HongsException(app.hongs.HongsException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with FetchCase

use of app.hongs.db.util.FetchCase in project HongsCORE by ihongs.

the class RoleSet method imports.

@Override
protected void imports() throws HongsException {
    roles = new HashSet();
    DB db;
    Table tb;
    Table td;
    FetchCase fc;
    List<Map> rz;
    db = DB.getInstance("master");
    // ** 查询用户权限 **/
    tb = db.getTable("user_role");
    fc = new FetchCase().from(tb.tableName, tb.name).select(tb.name + ".role").filter(tb.name + ".user_id = ?", userId);
    rz = db.fetchMore(fc);
    for (Map rm : rz) {
        roles.add((String) rm.get("role"));
    }
    // ** 查询部门权限 **/
    tb = db.getTable("dept_role");
    td = db.getTable("user_dept");
    fc = new FetchCase().from(tb.tableName, tb.name).select(tb.name + ".role");
    fc.join(td.tableName, td.name).on(td.name + ".dept_id = " + tb.name + ".dept_id").filter(td.name + ".user_id = ?", userId);
    rz = db.fetchMore(fc);
    for (Map rm : rz) {
        roles.add((String) rm.get("role"));
    }
    // ** 当前保存时间 **/
    rtime = (int) (System.currentTimeMillis() / 1000);
}
Also used : Table(app.hongs.db.Table) FetchCase(app.hongs.db.util.FetchCase) Map(java.util.Map) DB(app.hongs.db.DB) HashSet(java.util.HashSet)

Example 13 with FetchCase

use of app.hongs.db.util.FetchCase in project HongsCORE by ihongs.

the class DeptAction method isUnique.

@Action("unique")
public void isUnique(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    FetchCase fc = model.fetchCase();
    fc.setOption("INCLUDE_REMOVED", Synt.declare(rd.get("include-removed"), false));
    boolean rv = model.unique(rd, fc);
    helper.reply(null, rv ? 1 : 0);
}
Also used : FetchCase(app.hongs.db.util.FetchCase) HashMap(java.util.HashMap) NaviMap(app.hongs.action.NaviMap) Map(java.util.Map) RoleMap(app.hongs.serv.auth.RoleMap) Action(app.hongs.action.anno.Action)

Example 14 with FetchCase

use of app.hongs.db.util.FetchCase in project HongsCORE by ihongs.

the class UserAction method doDelete.

@Action("delete")
@CommitSuccess
public void doDelete(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    FetchCase fc = model.fetchCase();
    fc.setOption("INCLUDE_REMOVED", Synt.declare(rd.get("include-removed"), false));
    // 不能删除自己和超级管理员
    Set rs = Synt.asSet(rd.get(model.table.primaryKey));
    if (rs != null) {
        if (rs.contains(helper.getSessibute(Cnst.UID_SES))) {
            helper.fault("不能删除当前登录用户");
            return;
        }
        if (rs.contains(Cnst.ADM_UID)) {
            helper.fault("不能删除超级管理账号");
            return;
        }
    }
    int rn = model.delete(rd, fc);
    CoreLocale ln = CoreLocale.getInstance().clone();
    ln.load("master");
    String ms = ln.translate("core.delete.user.success", Integer.toString(rn));
    helper.reply(ms, rn);
}
Also used : CoreLocale(app.hongs.CoreLocale) FetchCase(app.hongs.db.util.FetchCase) Set(java.util.Set) HashMap(java.util.HashMap) NaviMap(app.hongs.action.NaviMap) Map(java.util.Map) RoleMap(app.hongs.serv.auth.RoleMap) Action(app.hongs.action.anno.Action) CommitSuccess(app.hongs.action.anno.CommitSuccess)

Example 15 with FetchCase

use of app.hongs.db.util.FetchCase in project HongsCORE by ihongs.

the class UserAction method isUnique.

@Action("unique")
public void isUnique(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    FetchCase fc = model.fetchCase();
    fc.setOption("INCLUDE_REMOVED", Synt.declare(rd.get("include-removed"), false));
    boolean rv = model.unique(rd, fc);
    helper.reply(null, rv ? 1 : 0);
}
Also used : FetchCase(app.hongs.db.util.FetchCase) HashMap(java.util.HashMap) NaviMap(app.hongs.action.NaviMap) Map(java.util.Map) RoleMap(app.hongs.serv.auth.RoleMap) Action(app.hongs.action.anno.Action)

Aggregations

FetchCase (app.hongs.db.util.FetchCase)17 Map (java.util.Map)14 Action (app.hongs.action.anno.Action)8 HashMap (java.util.HashMap)8 NaviMap (app.hongs.action.NaviMap)5 RoleMap (app.hongs.serv.auth.RoleMap)5 Table (app.hongs.db.Table)4 HashSet (java.util.HashSet)4 HongsException (app.hongs.HongsException)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 DB (app.hongs.db.DB)2 IAction (app.hongs.dh.IAction)2 Collection (java.util.Collection)2 CoreLocale (app.hongs.CoreLocale)1 CommitSuccess (app.hongs.action.anno.CommitSuccess)1 Verify (app.hongs.action.anno.Verify)1 RoleSet (app.hongs.serv.auth.RoleSet)1 Iterator (java.util.Iterator)1