`
weiwu83
  • 浏览: 188759 次
  • 来自: ...
社区版块
存档分类
最新评论

基于开源工作流引擎OSWorkflow的业务系统实例——请假审批系统2

阅读更多
java 代码
  1. package com.qiny.leave;   
  2.   
  3. import java.util.Map;   
  4. import com.opensymphony.module.propertyset.PropertySet;   
  5. import com.opensymphony.workflow.FunctionProvider;   
  6. import com.opensymphony.workflow.spi.WorkflowEntry;   
  7.   
  8. import com.qiny.dao.LeaveDAO;   
  9. import org.apache.log4j.Logger;   
  10.   
  11. public class ApplyFunction implements FunctionProvider {   
  12.   
  13.   private static Logger logger = (Logger) Logger.getInstance(ApplyFunction.class);   
  14.   
  15.   public void execute(Map transientVars, Map args, PropertySet ps) {   
  16.     logger.info("execute ......");   
  17.     WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");   
  18.     long wfid = entry.getId();   
  19.     int actionId = ((Integer) transientVars.get("actionId")).intValue();   
  20.     logger.info("execute actionId=" + actionId);   
  21.     String applicant = (String) transientVars.get("applicant");   
  22.     String reason = (String) transientVars.get("reason");   
  23.     int dayCount = ((Integer) transientVars.get("dayCount")).intValue();   
  24.     LeaveApply leaveApply = new LeaveApply(applicant, reason, dayCount);   
  25.     leaveApply.setWfid(wfid);   
  26.     LeaveDAO leaveDao = new LeaveDAO();   
  27.     leaveDao.addLeaveApply(leaveApply);   
  28.     ps.setInt("dayCount", dayCount);   
  29.     logger.info("execute leaveDao has added leaveApply!");   
  30.   }   
  31. }   
  32.   
  33.   
  34.   
  35.   
  36. package com.qiny.leave;   
  37.   
  38. import java.util.Map;   
  39. import com.opensymphony.module.propertyset.PropertySet;   
  40. import com.opensymphony.workflow.FunctionProvider;   
  41. import com.opensymphony.workflow.spi.WorkflowEntry;   
  42.   
  43. import com.qiny.dao.LeaveDAO;   
  44. import org.apache.log4j.Logger;   
  45.   
  46. public class ApproveFunction implements FunctionProvider {   
  47.   
  48.   private static Logger logger = (Logger) Logger.getInstance(ApproveFunction.class);   
  49.   
  50.   public void execute(Map transientVars, Map args, PropertySet ps) {   
  51.     logger.info("execute ......");   
  52.     WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");   
  53.     long wfid = entry.getId();   
  54.     int actionId = ((Integer) transientVars.get("actionId")).intValue();   
  55.     logger.info("execute actionId=" + actionId);   
  56.     int applyID = ((Integer) transientVars.get("applyID")).intValue();   
  57.     String approver = (String) transientVars.get("approver");   
  58.     int opinion = ((Integer) transientVars.get("opinion")).intValue();   
  59.     LeaveApprove LeaveApprove = new LeaveApprove(applyID, approver, opinion);   
  60.     LeaveDAO leaveDao = new LeaveDAO();   
  61.     leaveDao.addLeaveApprove(LeaveApprove);   
  62.     ps.setInt("opinion", opinion);   
  63.     logger.info("execute leaveDao has added leaveApprove!");   
  64.   }   
  65. }   
  66.   
  67.   
  68. package com.qiny.leave;   
  69.   
  70. public class LeaveApply {   
  71.   
  72.   private int applyID; //申请ID 主键   
  73.   private String applicant; //申请人   
  74.   private String reason; //原因   
  75.   private String applyTime; //申请时间,为简单起见用字符串表示   
  76.   private int dayCount; //申请天数,在某种业务逻辑下,用作流程判断   
  77.   private long wfid; //所属工作流实例id   
  78.   
  79.   public LeaveApply(){   
  80.   }   
  81.   
  82.   public LeaveApply(String applicant,String reason,int dayCount){   
  83.     this.applicant = applicant;   
  84.     this.reason = reason;   
  85.     this.dayCount = dayCount;   
  86.   }   
  87.   
  88.   public int getApplyID() {   
  89.     return applyID;   
  90.   }   
  91.   
  92.   public String getApplicant() {   
  93.     return applicant;   
  94.   }   
  95.   
  96.   public String getReason() {   
  97.     return reason;   
  98.   }   
  99.   
  100.   public String getApplyTime() {   
  101.     return applyTime;   
  102.   }   
  103.   
  104.   public int getDayCount() {   
  105.     return dayCount;   
  106.   }   
  107.   
  108.   public long getWfid() {   
  109.     return wfid;   
  110.   }   
  111.   
  112.   public void setApplyID(int applyID) {   
  113.     this.applyID = applyID;   
  114.   }   
  115.   
  116.   public void setApplicant(String applicant) {   
  117.     this.applicant = applicant;   
  118.   }   
  119.   
  120.   public void setReason(String reason) {   
  121.     this.reason = reason;   
  122.   }   
  123.   
  124.   public void setApplyTime(String applyTime) {   
  125.     this.applyTime = applyTime;   
  126.   }   
  127.   
  128.   public void setDayCount(int dayCount) {   
  129.     this.dayCount = dayCount;   
  130.   }   
  131.   
  132.   public void setWfid(long wfid) {   
  133.     this.wfid = wfid;   
  134.   }   
  135.   
  136. }   
  137.   
  138.   
  139. package com.qiny.leave;   
  140.   
  141. public class LeaveApprove {   
  142.   
  143.   private int applyID;  //申请id   
  144.   private String approver;  //批准人   
  145.   private String approveTime;  //批准时间,简单起见用字符串表示   
  146.   private int opinion;  //意见 1:批准; 2:拒绝   
  147.   
  148.   public LeaveApprove(){   
  149.   }   
  150.   
  151.   public LeaveApprove(int applyID,String approver,int opinion){   
  152.     this.applyID = applyID;   
  153.     this.approver = approver;   
  154.     this.opinion = opinion;   
  155.   }   
  156.   
  157.   public String getOpinionString(){   
  158.     return opinion == 1 ? "批准" : "拒绝";   
  159.   }   
  160.   
  161.   public int getApplyID() {   
  162.     return applyID;   
  163.   }   
  164.   
  165.   public String getApprover() {   
  166.     return approver;   
  167.   }   
  168.   
  169.   public String getApproveTime() {   
  170.     return approveTime;   
  171.   }   
  172.   
  173.   public int getOpinion() {   
  174.     return opinion;   
  175.   }   
  176.   
  177.   public void setApplyID(int applyID) {   
  178.     this.applyID = applyID;   
  179.   }   
  180.   
  181.   public void setApprover(String approver) {   
  182.     this.approver = approver;   
  183.   }   
  184.   
  185.   public void setApproveTime(String approveTime) {   
  186.     this.approveTime = approveTime;   
  187.   }   
  188.   
  189.   public void setOpinion(int opinion) {   
  190.     this.opinion = opinion;   
  191.   }   
  192.   
  193.   
  194. }   
  195.   
  196.   
  197.   
  198.   
  199. package com.qiny.dao;   
  200.   
  201. import java.util.List;   
  202. import java.util.ArrayList;   
  203.   
  204. import java.sql.Connection;   
  205. import java.sql.Statement;   
  206. import java.sql.ResultSet;   
  207. import java.sql.SQLException;   
  208. import javax.sql.DataSource;   
  209.   
  210. import javax.naming.InitialContext;   
  211. import javax.naming.NamingException;   
  212.   
  213. import com.qiny.leave.LeaveApply;   
  214. import com.qiny.leave.LeaveApprove;   
  215.   
  216. public class LeaveDAO {   
  217.   
  218.   protected static DataSource ds = null;   
  219.   
  220.   public LeaveDAO() {   
  221.     if (ds == null) {   
  222.       try {   
  223.         InitialContext ic = new InitialContext();   
  224.         ds = (DataSource) ic.lookup("java:JSQLConnectDB_LeaveApply");   
  225.       } catch (NamingException ne) {   
  226.         throw new RuntimeException("NamingException while looking");   
  227.       }   
  228.     }   
  229.   }   
  230.   
  231.   public void addLeaveApply(LeaveApply leaveApply) {   
  232.     try {   
  233.       String exeSql = ""  
  234.           + " INSERT INTO bus_leaveApply (applicant,reason,applyTime,dayCount,wfid)"  
  235.           + " VALUES ('" + leaveApply.getApplicant() + "','" + leaveApply.getReason()   
  236.           + " ',CONVERT(VARCHAR(20),GETDATE(),121 ),'" + leaveApply.getDayCount()   
  237.           + " '," + leaveApply.getWfid() + ")";   
  238.       Connection connection = ds.getConnection();   
  239.       Statement statement = connection.createStatement();   
  240.       statement.execute(exeSql);   
  241.       statement.close();   
  242.       connection.close();   
  243.     } catch (SQLException ex) {   
  244.       throw new RuntimeException("DAO addLeaveApply failed!\n" + ex.getMessage());   
  245.     }   
  246.   }   
  247.   
  248.   public void addLeaveApprove(LeaveApprove leaveApproval) {   
  249.     try {   
  250.       String exeSql = ""  
  251.           + " INSERT INTO bus_leaveApprove (applyID,approver,approveTime,opinion)"  
  252.           + " VALUES ('" + leaveApproval.getApplyID() + "','" + leaveApproval.getApprover()   
  253.           + " ',CONVERT(VARCHAR(20),GETDATE(),121 )," + leaveApproval.getOpinion() + ")";   
  254.       Connection connection = ds.getConnection();   
  255.       Statement statement = connection.createStatement();   
  256.       statement.execute(exeSql);   
  257.       statement.close();   
  258.       connection.close();   
  259.     } catch (SQLException ex) {   
  260.       throw new RuntimeException("DAO addLeaveApprove failed!\n" + ex.getMessage());   
  261.     }   
  262.   }   
  263.   
  264.   public LeaveApply getLeaveApply(long wfid) {   
  265.     LeaveApply leaveApply = new LeaveApply();   
  266.     try {   
  267.       String querySql = ""  
  268.           + " SELECT applyID,applicant,reason,applyTime,dayCount,wfid "  
  269.           + " FROM bus_leaveApply WHERE wfid=" + wfid;   
  270.       Connection connection = ds.getConnection();   
  271.       Statement statement = connection.createStatement();   
  272.       ResultSet rs = statement.executeQuery(querySql);   
  273.       if (rs.next()) {   
  274.         leaveApply.setApplyID(rs.getInt("applyID"));   
  275.         leaveApply.setApplicant(rs.getString("applicant"));   
  276.         leaveApply.setReason(rs.getString("reason"));   
  277.         leaveApply.setApplyTime(rs.getString("applyTime"));   
  278.         leaveApply.setDayCount(rs.getInt("dayCount"));   
  279.         leaveApply.setWfid(rs.getLong("wfid"));   
  280.       }   
  281.       rs.close();   
  282.       statement.close();   
  283.       connection.close();   
  284.     } catch (SQLException ex) {   
  285.       throw new RuntimeException("DAO getLeaveApply failed!\n" + ex.getMessage());   
  286.     }   
  287.     return leaveApply;   
  288.   }   
  289.   
  290.   public List getLeaveAprovals(int applyID) {   
  291.     List approvals = new ArrayList();   
  292.     try {   
  293.       String querySql = ""  
  294.           + " SELECT applyID,approver,approveTime,opinion "  
  295.           + " FROM bus_leaveApprove WHERE applyID=" + applyID;   
  296.       Connection connection = ds.getConnection();   
  297.       Statement statement = connection.createStatement();   
  298.       ResultSet rs = statement.executeQuery(querySql);   
  299.       while (rs.next()) {   
  300.         LeaveApprove leaveApproval = new LeaveApprove();   
  301.         leaveApproval.setApplyID(rs.getInt("applyID"));   
  302.         leaveApproval.setApprover(rs.getString("approver"));   
  303.         leaveApproval.setApproveTime(rs.getString("approveTime"));   
  304.         leaveApproval.setOpinion(rs.getInt("opinion"));   
  305.         approvals.add(leaveApproval);   
  306.       }   
  307.       rs.close();   
  308.       statement.close();   
  309.       connection.close();   
  310.     } catch (SQLException ex) {   
  311.       throw new RuntimeException("DAO getLeaveAprovals failed!\n" + ex.getMessage());   
  312.     }   
  313.     return approvals;   
  314.   }   
  315.   
  316. }   
  317.   
分享到:
评论
1 楼 peantf 2008-06-06  
能不能给点详细的说明啊.都不怎么明白...... 

相关推荐

Global site tag (gtag.js) - Google Analytics