workflow_linebean.java
来自「java开发的办公系统 1.系统管理 (地区管理,部门管理,菜单管理,用户管理」· Java 代码 · 共 520 行
JAVA
520 行
package com.vere.manager.workflow.bean; import java.sql.*; import java.util.*; import com.vere.db.*; import com.vere.manager.workflow.item.*; public class Workflow_lineBean { private ResultSet rs=null; private int keyId; private int totalRecord; private Access access = null; public Workflow_lineBean() { try { access=new Access(); } catch(Exception e) { System.out.println(e.toString()); } } /** * @author Administrator * @param 无 * @return ArrayList:Workflow_lineItem 对象的 ArrayList 数组 * @see 取出 workflow_line 表中的所有记录,每一条记录存储在一个 Workflow_lineItem 对象中 */ public List find(){ ArrayList list=new ArrayList(); try { String sql="select * from "+T.WORKFLOW_LINE; rs = executeQuery(sql); while(rs.next()){ Workflow_lineItem item=new Workflow_lineItem(); item.setId(rs.getString("id")); item.setWorkflow_id(rs.getString("workflow_id")); item.setSendstateid(rs.getString("sendstateid")); item.setReceiveid(rs.getString("receiveid")); item.setName(rs.getString("name")); list.add(item); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } public FlowLineList findByWorkFlow_id(String workflow_id){//通过workflow_id找到流转线 FlowLineList v=new FlowLineList(); try { String sql="select a.id as aid,a.workflow_id as aworkflow_id,a.name as aname,a.y as ay,a.width as awidth,a.x as ax,a.height as aheight,a.state_type as astate_type, "+ " b.id as bid,b.workflow_id as bworkflow_id,b.sendstateid as bsendstateid,b.receiveid as breceiveid,b.name as bname, "+ " c.id as cid,c.workflow_id as cworkflow_id,c.name as cname,c.y as cy,c.width as cwidth,c.x as cx,c.height as cheight,c.state_type as cstate_type "+ " from "+T.WORKFLOW_STATE+" as a, "+T.WORKFLOW_LINE+" as b ,"+T.WORKFLOW_STATE+" as c where a.id=b.sendstateid and b.receiveid=c.id and b.workflow_id="+workflow_id; rs = executeQuery(sql); while(rs.next()){ Workflow_lineItem item=new Workflow_lineItem(); item.setId(rs.getString("bid")); item.setWorkflow_id(rs.getString("bworkflow_id")); item.setSendstateid(rs.getString("bsendstateid")); item.setReceiveid(rs.getString("breceiveid")); item.setName(rs.getString("bname")); Workflow_stateItem sendItem=new Workflow_stateItem(); sendItem.setId(rs.getString("aid")); sendItem.setWorkflow_id(rs.getString("aworkflow_id")); sendItem.setName(rs.getString("aname")); sendItem.setY(rs.getString("ay")); sendItem.setWidth(rs.getString("awidth")); sendItem.setX(rs.getString("ax")); sendItem.setHeight(rs.getString("aheight")); sendItem.setState_type(rs.getString("astate_type")); item.setSendState(sendItem); Workflow_stateItem receiveItem=new Workflow_stateItem(); receiveItem.setId(rs.getString("cid")); receiveItem.setWorkflow_id(rs.getString("cworkflow_id")); receiveItem.setName(rs.getString("cname")); receiveItem.setY(rs.getString("cy")); receiveItem.setWidth(rs.getString("cwidth")); receiveItem.setX(rs.getString("cx")); receiveItem.setHeight(rs.getString("cheight")); receiveItem.setState_type(rs.getString("cstate_type")); item.setReceiveState(receiveItem); v.add(item); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return v; } /** * @author Administrator * @param 无 * @return ArrayList:Workflow_lineItem 对象的 ArrayList 数组 * @see 取出 workflow_line 表中的所有记录,每一条记录存储在一个 Workflow_lineItem 对象中 */ public List findByIds(String ids){ ArrayList list=new ArrayList(); try { String sql="select * from "+T.WORKFLOW_LINE+" where id in ("+ids+")"; rs = executeQuery(sql); while(rs.next()){ Workflow_lineItem item=new Workflow_lineItem(); item.setId(rs.getString("id")); item.setWorkflow_id(rs.getString("workflow_id")); item.setSendstateid(rs.getString("sendstateid")); item.setReceiveid(rs.getString("receiveid")); item.setName(rs.getString("name")); list.add(item); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } /** * @author Administrator * @param id: 当前要修改记录的id号 * @return Workflow_lineItem * @see 取出 workflow_line 表中的指定id号的一条记录存储在一个 Workflow_lineItem 对象中 */ public Workflow_lineItem find(String id){ try { String sql="select * from "+T.WORKFLOW_LINE+" where id="+id; rs = executeQuery(sql); Workflow_lineItem item=new Workflow_lineItem(); if(rs.next()){ item.setId(rs.getString("id")); item.setWorkflow_id(rs.getString("workflow_id")); item.setSendstateid(rs.getString("sendstateid")); item.setReceiveid(rs.getString("receiveid")); item.setName(rs.getString("name")); } return item; }catch(SQLException e){ System.out.print(e.toString()); return null; } finally{ DBclose(); } } /** * @author Administrator * @param aItem: 查询的数据对象,page: 翻页时的当前页,pageSize: 翻页的每页显示的记录条数 * @return ArrayList:Workflow_lineItem 对象的 ArrayList 数组 * @see 查出 workflow_line 表中的指定数据,页号,页大小的每一条记录存储在一个 Workflow_lineItem 对象中 */ public List find(Workflow_lineItem aItem,int page,int pageSize){ int nextPageSize=pageSize*(page-1); ArrayList list=new ArrayList(); try { boolean b=false; StringBuffer filter=new StringBuffer(); String fvalue=null; fvalue=aItem.getWorkflow_id(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" workflow_id ="+fvalue+" "); b=true; } fvalue=aItem.getSendstateid(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" sendstateid ="+fvalue+" "); b=true; } fvalue=aItem.getReceiveid(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" receiveid ="+fvalue+" "); b=true; } StringBuffer sql=new StringBuffer(); sql.append(" select top "+pageSize+" * from "+T.WORKFLOW_LINE+" where "); if(b) { sql.append(" "+filter.toString()+" and "); } sql.append(" (id not in (SELECT TOP "+Integer.toString(nextPageSize)+" id from "+T.WORKFLOW_LINE+" "); if(b) { sql.append(" where "+filter.toString()+" "); } sql.append(" order by id desc )) order by id desc "); rs = executeQuery(sql.toString()); while(rs.next()){ Workflow_lineItem item=new Workflow_lineItem(); item.setId(rs.getString("id")); item.setWorkflow_id(rs.getString("workflow_id")); item.setSendstateid(rs.getString("sendstateid")); item.setReceiveid(rs.getString("receiveid")); item.setName(rs.getString("name")); list.add(item); } String sql1="select count(*) as total from "+T.WORKFLOW_LINE; if(b) sql1+=" where "+filter.toString(); rs = executeQuery(sql1); if(rs.next()){ totalRecord=rs.getInt("total"); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } /** * @author Administrator * @param aItem: 查询的数据对象,page: 翻页时的当前页,pageSize: 翻页的每页显示的记录条数 * @return ArrayList:Workflow_lineItem 对象的 ArrayList 数组 * @see 查出 workflow_line 表中的指定数据,页号,页大小的每一条记录存储在一个 Workflow_lineItem 对象中 */ public List find(Workflow_lineItem aItem){ ArrayList list=new ArrayList(); try { boolean b=false; StringBuffer filter=new StringBuffer(); String fvalue=null; fvalue=aItem.getWorkflow_id(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" workflow_id ="+fvalue+" "); b=true; } fvalue=aItem.getSendstateid(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" sendstateid ="+fvalue+" "); b=true; } fvalue=aItem.getReceiveid(); if(fvalue!=null && fvalue.length()>0) { if(b) filter.append(" and"); filter.append(" receiveid ="+fvalue+" "); b=true; } StringBuffer sql=new StringBuffer(); sql.append(" select * from "+T.WORKFLOW_LINE+" "); if(b) { sql.append(" where "+filter.toString()+" "); } rs = executeQuery(sql.toString()); while(rs.next()){ Workflow_lineItem item=new Workflow_lineItem(); item.setId(rs.getString("id")); item.setWorkflow_id(rs.getString("workflow_id")); item.setSendstateid(rs.getString("sendstateid")); item.setReceiveid(rs.getString("receiveid")); item.setName(rs.getString("name")); list.add(item); } }catch(SQLException e){ System.out.print(e.toString()); } finally{ DBclose(); } return list; } /** * @author Administrator * @param 无 * @return KeyId:插入记录时当前记录的id号 * @see 获得插入记录时当前记录的id号 */ public int getKey(){ return keyId; } /** * @author Administrator * @param 无 * @return (totalRecord):插入记录时当前记录的id号 * @see 获得插入记录时当前记录的id号 */ public int getTotalRecord(){ return totalRecord; } /** * @author Administrator * @param item:要添加的数据对象Workflow_lineItem * @return boolean:是否添加成功,如果添加成功返回true,否则返回false * @see 添加一条记录 */ public boolean addItem(Workflow_lineItem item){ try{ String sql="insert into "+T.WORKFLOW_LINE+"("+ "workflow_id,"+ "sendstateid,"+ "name,"+ "receiveid)values("+ ""+item.getWorkflow_id()+","+ ""+item.getSendstateid()+","+ "'"+item.getName()+"',"+ ""+item.getReceiveid()+")"; return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param item:要添加的数据对象UsersItem * @return keyId:当前添加记录的id号 否则返回 0 * @see 添加一条记录 */ public int AddItemMaxId(Workflow_lineItem item){ try{ String sql="insert into "+T.WORKFLOW_LINE+"("+ "workflow_id,"+ "sendstateid,"+ "name,"+ "receiveid)values("+ ""+item.getWorkflow_id()+","+ ""+item.getSendstateid()+","+ "'"+item.getName()+"',"+ ""+item.getReceiveid()+")"; executeUpdate(sql); sql = "select max(id) as id from "+T.WORKFLOW_LINE; rs = executeQuery(sql); if (rs.next()) { keyId = rs.getInt("id"); return keyId; } else return 0; }catch(SQLException e){ System.out.println(e.toString()); return 0; } finally{ DBclose(); } } /** * @author Administrator * @param item:要修改的数据对象Workflow_lineItem * @return boolean:如果修改成功返回true,否则返回false * @see 修改一条记录 */ public boolean updateItem(Workflow_lineItem item){ try{ String sql="update "+T.WORKFLOW_LINE+" set "+ "workflow_id="+item.getWorkflow_id()+","+ "sendstateid="+item.getSendstateid()+","+ "name='"+item.getName()+"',"+ "receiveid="+item.getReceiveid()+" where id="+item.getId(); return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param item:要修改的数据对象Workflow_lineItem * @return boolean:如果修改成功返回true,否则返回false * @see 修改一条记录 */ public boolean updateItemFile(Workflow_lineItem item){ try{ String sql="update "+T.WORKFLOW_LINE+" set "+ "workflow_id="+item.getWorkflow_id()+","+ "sendstateid="+item.getSendstateid()+","+ "name='"+item.getName()+"',"+ "receiveid="+item.getReceiveid()+" where id="+item.getId(); return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param item:要删除的数据对象Workflow_lineItem * @return boolean:如果删除成功返回true,否则返回false * @see 删除一条记录 */ public boolean removeItem(String sendid,String receiveid){ try{ String sql="delete from "+T.WORKFLOW_LINE+" where sendstateid="+sendid+" and receiveid="+receiveid ; ; return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param ids:要删除的记录的ids数组 * @return boolean:如果删除成功返回true,否则返回false * @see 批量删除条记录 */ public boolean removeItems(String[] ids) { try{ String sql="delete from "+T.WORKFLOW_LINE+" where id in ("; String filter=""; for(int i=0;i<ids.length-1;i++){ filter+=ids[i]+","; } filter+=ids[ids.length-1]+")"; sql+=filter; return executeUpdate(sql); }catch(Exception e){ System.out.println(e.toString()); return false; } finally{ DBclose(); } } /** * @author Administrator * @param sql:要更新的sql 语句 * @return boolean:如果执行成功返回true,否则返回false * @see 执行更新一条sql 语句 */ public boolean executeUpdate(String sql){ try{ access.getConnection(); return access.executeUpdate(sql); } catch(Exception e){ System.out.println(e.toString()); return false; } } /** * @author Administrator * @param sql:要查询的sql 语句 * @return boolean:如果执行成功返回true,否则返回false * @see 执行查询一条sql 语句 */ public ResultSet executeQuery(String sql){ try { access.getConnection(); rs=access.executeQuery(sql); return rs; } catch(Exception e){ System.out.println(e.toString()); return null; } } /** * @author Administrator * @param 无 * @return 无 * @see 关闭数据库操作对象 */ public void DBclose(){ try { access.DBclose(rs); } catch(Exception e) { System.out.println(e.toString()); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?