workflowpredefinedb.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 504 行 · 第 1/2 页
JAVA
504 行
package com.redmoon.oa.flow;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.cloudwebsoft.framework.util.*;import com.redmoon.oa.db.*;import com.redmoon.oa.person.*;import com.redmoon.oa.pvg.*;public class WorkflowPredefineDb extends ObjectDb { private int id; public static final int TYPE_SYSTEM = 1; public static final int TYPE_USER = 0; public WorkflowPredefineDb() { init(); } public WorkflowPredefineDb(int id) { this.id = id; init(); load(); } public int getId() { return id; } public void initDB() { tableName = "flow_predefined"; primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT); objectCache = new WorkflowPredefineCache(this); isInitFromConfigDB = false; QUERY_CREATE = "insert into " + tableName + " (flowString,typeCode,title,return_back,IS_DEFAULT_FLOW,id,dir_code,examine) values (?,?,?,?,?,?,?,?)"; QUERY_SAVE = "update " + tableName + " set flowString=?,typeCode=?,title=?,return_back=?,IS_DEFAULT_FLOW=?,dir_code=?,examine=? where id=?"; QUERY_LIST = "select id from " + tableName; QUERY_DEL = "delete from " + tableName + " where id=?"; QUERY_LOAD = "select flowString,typeCode,title,return_back,IS_DEFAULT_FLOW,dir_code,examine from " + tableName + " where id=?"; } public WorkflowPredefineDb getWorkflowPredefineDb(int id) { return (WorkflowPredefineDb)getObjectDb(new Integer(id)); } public WorkflowPredefineDb getDefaultPredefineFlow(String typeCode) { ResultSet rs = null; PreparedStatement ps = null; String sql = "select id from " + tableName + " where typeCode=? and IS_DEFAULT_FLOW=1"; Conn conn = new Conn(connname); try { ps = conn.prepareStatement(sql); ps.setString(1, typeCode); rs = conn.executePreQuery(); if (rs != null && rs.next()) { int id = rs.getInt(1); return getWorkflowPredefineDb(id); } } catch (SQLException e) { logger.error("getDefaultFlow: " + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) {} rs = null; } if (ps != null) { try { ps.close(); } catch (SQLException e) {} ps = null; } if (conn!=null) { conn.close(); conn = null; } } return null; } public boolean create() throws ErrMsgException { boolean re = false; PreparedStatement ps = null; defaultFlow = getDefaultPredefineFlow(typeCode)==null; id = (int)SequenceManager.nextID(SequenceManager.OA_WORKFLOW_PREDEFINED); Conn conn = new Conn(connname); try { ps = conn.prepareStatement(QUERY_CREATE); ps.setString(1, flowString); ps.setString(2, typeCode); ps.setString(3, title); ps.setInt(4, returnBack?1:0); ps.setInt(5, defaultFlow?1:0); ps.setInt(6, id); ps.setString(7, dirCode); ps.setInt(8, examine); re = conn.executePreUpdate()==1?true:false; if (re) { WorkflowPredefineCache rc = new WorkflowPredefineCache(this); rc.refreshCreate(); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); throw new ErrMsgException("数据库操作失败!"); } finally { if (ps!=null) { try { ps.close(); } catch (Exception e) {} ps = null; } if (conn!=null) { conn.close(); conn = null; } } return re; } public int delWorkflowPredefineDbOfType(String typeCode) { Vector v = new Vector(); String sql = "select id from " + tableName + " where typeCode=?"; PreparedStatement pstmt = null; ResultSet rs = null; int i = 0; Conn conn = new Conn(connname); try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, typeCode); rs = conn.executePreQuery(); while (rs.next()) { WorkflowPredefineDb wd = getWorkflowPredefineDb(rs.getInt(1)); try { wd.del(); } catch (ErrMsgException e) { logger.error("delWorkflowPredefineDbOfType:" + e.getMessage()); } i++; } } catch (SQLException e) { logger.error("delWorkflowPredefineDbOfType:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return i; } public boolean del() throws ErrMsgException { boolean re = false; PreparedStatement ps = null; Conn conn = new Conn(connname); try { ps = conn.prepareStatement(QUERY_DEL); ps.setInt(1, id); re = conn.executePreUpdate() == 1 ? true : false; if (re) { WorkflowPredefineCache rc = new WorkflowPredefineCache(this); primaryKey.setValue(new Integer(id)); rc.refreshDel(primaryKey); } } catch (SQLException e) { logger.error("del: " + e.getMessage()); } finally { if (ps!=null) { try { ps.close(); } catch (Exception e) {} ps = null; } if (conn != null) { conn.close(); conn = null; } } return re; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new WorkflowPredefineDb(pk.getIntValue()); } public void load() { ResultSet rs = null; PreparedStatement ps = null; Conn conn = new Conn(connname); try { ps = conn.prepareStatement(QUERY_LOAD); ps.setInt(1, id); rs = conn.executePreQuery(); if (rs != null && rs.next()) { flowString = rs.getString(1); typeCode = rs.getString(2); title = rs.getString(3); returnBack = rs.getInt(4)==1; defaultFlow = rs.getInt(5)==1; dirCode = StrUtil.getNullString(rs.getString(6)); examine = rs.getInt(7); loaded = true; primaryKey.setValue(new Integer(id)); } } catch (SQLException e) { logger.error("load: " + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) {} rs = null; } if (ps != null) { try { ps.close(); } catch (SQLException e) {} ps = null; } if (conn!=null) { conn.close(); conn = null; } } } public boolean save() throws ErrMsgException { PreparedStatement ps = null; boolean re = false; if (defaultFlow) { WorkflowPredefineDb wpf = getDefaultPredefineFlow(typeCode); if (wpf != null && wpf.isLoaded() && wpf.getId()!=id) { wpf.setDefaultFlow(false); wpf.save(); } } Conn conn = new Conn(connname); try {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?