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);
}
}
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());
}
}
}
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;
}
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;
}
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;
}
Aggregations