📄 leaf.java
字号:
Vector vt = new Vector(); getAllChild(vt, this); int childcount = vt.size(); Iterator ir = vt.iterator(); while (ir.hasNext()) { Leaf childlf = (Leaf)ir.next(); int layer = parentLayer + 1 + 1; String pcode = childlf.getParentCode(); while (!pcode.equals(code)) { layer ++; Leaf lfp = getLeaf(pcode); pcode = lfp.getParentCode(); } childlf.setLayer(layer); childlf.update(); } Leaf oldParentLeaf = getLeaf(oldParentCode); oldParentLeaf.setChildCount(oldParentLeaf.getChildCount() - 1); oldParentLeaf.update(); Leaf newParentLeaf = getLeaf(newParentCode); newParentLeaf.setChildCount(newParentLeaf.getChildCount() + 1); newParentLeaf.update(); } } catch (Exception e) { logger.error("update: " + e.getMessage()); } } catch (SQLException e) { logger.error("update: " + e.getMessage()); } boolean re = r == 1 ? true : false; if (re) { removeFromCache(code); } return re; } public boolean AddChild(Leaf childleaf) throws ErrMsgException { int childorders = child_count + 1; String updatesql = ""; String insertsql = "insert into flow_directory (code,name,parent_code,description,orders,root_code,child_count,layer,type,add_date,formCode,dept) values ("; insertsql += StrUtil.sqlstr(childleaf.getCode()) + "," + StrUtil.sqlstr(childleaf.getName()) + "," + StrUtil.sqlstr(code) + "," + StrUtil.sqlstr(childleaf.getDescription()) + "," + childorders + "," + StrUtil.sqlstr(root_code) + ",0," + (layer+1) + "," + childleaf.getType() + ",NOW()" + "," + StrUtil.sqlstr(childleaf.getFormCode()) + "," + StrUtil.sqlstr(childleaf.getDept()) + ")"; if (!SecurityUtil.isValidSql(insertsql)) throw new ErrMsgException("请勿输入非法字符如;号等!"); Conn conn = new Conn(connname); try { updatesql = "Update flow_directory set child_count=child_count+1" + " where code=" + StrUtil.sqlstr(code); conn.beginTrans(); conn.executeUpdate(insertsql); conn.executeUpdate(updatesql); removeFromCache(code); conn.commit(); } catch (SQLException e) { conn.rollback(); logger.error("AddChild: " + e.getMessage()); return false; } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public void removeFromCache(String code) { try { rmCache.remove(code, dirCache); LeafChildrenCacheMgr.remove(code); } catch (Exception e) { logger.error("removeFromCache: " + e.getMessage()); } } public void removeAllFromCache() { try { rmCache.invalidateGroup(dirCache); LeafChildrenCacheMgr.removeAll(); } catch (Exception e) { logger.error("removeAllFromCache: " + e.getMessage()); } } public Leaf getLeaf(String code) { Leaf leaf = null; try { leaf = (Leaf) rmCache.getFromGroup(code, dirCache); } catch (Exception e) { logger.error("getLeaf1: " + e.getMessage()); } if (leaf == null) { leaf = new Leaf(code); if (leaf != null) { if (!leaf.isLoaded()) leaf = null; else { try { rmCache.putInGroup(code, dirCache, leaf); } catch (Exception e) { logger.error("getLeaf2: " + e.getMessage()); } } } } else { leaf.renew(); } return leaf; } public Vector getLeavesUseForm(String formCode) { Vector v = new Vector(); ResultSet rs = null; String sql = "select code from flow_directory where formCode=?"; Conn conn = new Conn(connname); try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, formCode); rs = conn.executePreQuery(); if (rs != null && rs.next()) { String mycode = rs.getString(1); v.addElement(getLeaf(mycode)); } } catch (SQLException e) { logger.error("getLeavesUseForm: " + e.getMessage()); e.printStackTrace(); } finally { if (conn != null) { conn.close(); conn = null; } } return v; } public boolean delsingle(Leaf leaf) { if (leaf.getType() == TYPE_LIST) { WorkflowDb wd = new WorkflowDb(); wd.delWorkflowDbOfType(leaf.getCode()); WorkflowPredefineDb wpd = new WorkflowPredefineDb(); wpd.delWorkflowPredefineDbOfType(leaf.getCode()); } JobUnitDb jud = new JobUnitDb(); jud.delJobOfWorkflow(leaf.getCode()); Conn conn = new Conn(connname); try { conn.beginTrans(); String sql = "delete from flow_directory where code=" + StrUtil.sqlstr(leaf.getCode()); boolean r = conn.executeUpdate(sql) == 1 ? true : false; sql = "update flow_directory set orders=orders-1 where parent_code=" + StrUtil.sqlstr(leaf.getParentCode()) + " and orders>" + leaf.getOrders(); conn.executeUpdate(sql); sql = "update flow_directory set child_count=child_count-1 where code=" + StrUtil.sqlstr(leaf.getParentCode()); conn.executeUpdate(sql); conn.commit(); } catch (SQLException e) { conn.rollback(); logger.error("delsingle: " + e.getMessage()); return false; } finally { removeAllFromCache(); if (conn != null) { conn.close(); conn = null; } } return true; } public synchronized void del(Leaf leaf) { delsingle(leaf); Iterator children = leaf.getChildren().iterator(); while (children.hasNext()) { Leaf lf = (Leaf) children.next(); del(lf); } } public Leaf getBrother(String direction) { String sql; RMConn rmconn = new RMConn(connname); Leaf bleaf = null; try { if (direction.equals("down")) { sql = "select code from flow_directory where parent_code=" + StrUtil.sqlstr(parent_code) + " and orders=" + (orders + 1); } else { sql = "select code from flow_directory where parent_code=" + StrUtil.sqlstr(parent_code) + " and orders=" + (orders - 1); } ResultIterator ri = rmconn.executeQuery(sql); if (ri != null && ri.hasNext()) { ResultRecord rr = (ResultRecord) ri.next(); bleaf = getLeaf(rr.getString(1)); } } catch (SQLException e) { logger.error("getBrother: " + e.getMessage()); } return bleaf; } public boolean move(String direction) { String sql = ""; boolean isexist = false; Leaf bleaf = getBrother(direction); if (bleaf != null) { isexist = true; } if (isexist) { Conn conn = new Conn(connname); try { conn.beginTrans(); if (direction.equals("down")) { sql = "update flow_directory set orders=orders+1" + " where code=" + StrUtil.sqlstr(code); conn.executeUpdate(sql); sql = "update flow_directory set orders=orders-1" + " where code=" + StrUtil.sqlstr(bleaf.getCode()); conn.executeUpdate(sql); } if (direction.equals("up")) { sql = "update flow_directory set orders=orders-1" + " where code=" + StrUtil.sqlstr(code); conn.executeUpdate(sql); sql = "update flow_directory set orders=orders+1" + " where code=" + StrUtil.sqlstr(bleaf.getCode()); conn.executeUpdate(sql); } conn.commit(); removeFromCache(code); removeFromCache(bleaf.getCode()); } catch (Exception e) { conn.rollback(); logger.error("move: " + e.getMessage()); return false; } finally { if (conn != null) { conn.close(); conn = null; } } } return true; } public Leaf getLeafByFormCode(String formCode) { String sql = "select code from flow_directory where formCode=?"; ResultSet rs = null; Leaf lf = null; Conn conn = new Conn(connname); try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, formCode); rs = conn.executePreQuery(); if (rs != null && rs.next()) { lf = getLeaf(rs.getString(1)); } } catch (SQLException e) { logger.error("getLeafByFormCode: " + e.getMessage()); e.printStackTrace(); } finally { if (conn != null) { conn.close(); conn = null; } } return lf; } public void setOrders(int orders) { this.orders = orders; } public void setPluginCode(String pluginCode) { this.pluginCode = pluginCode; } public void setFormCode(String formCode) { this.formCode = formCode; } public void setDept(String dept) { this.dept = dept; } public void setChildCount(int childCount) { this.child_count = childCount; } private int templateId = -1; private boolean loaded = false; private String pluginCode; private String formCode; private String dept; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -