java 代码
- package com.qiny.leave;
- import java.util.Map;
- import com.opensymphony.module.propertyset.PropertySet;
- import com.opensymphony.workflow.FunctionProvider;
- import com.opensymphony.workflow.spi.WorkflowEntry;
- import com.qiny.dao.LeaveDAO;
- import org.apache.log4j.Logger;
- public class ApplyFunction implements FunctionProvider {
- private static Logger logger = (Logger) Logger.getInstance(ApplyFunction.class);
- public void execute(Map transientVars, Map args, PropertySet ps) {
- logger.info("execute ......");
- WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
- long wfid = entry.getId();
- int actionId = ((Integer) transientVars.get("actionId")).intValue();
- logger.info("execute actionId=" + actionId);
- String applicant = (String) transientVars.get("applicant");
- String reason = (String) transientVars.get("reason");
- int dayCount = ((Integer) transientVars.get("dayCount")).intValue();
- LeaveApply leaveApply = new LeaveApply(applicant, reason, dayCount);
- leaveApply.setWfid(wfid);
- LeaveDAO leaveDao = new LeaveDAO();
- leaveDao.addLeaveApply(leaveApply);
- ps.setInt("dayCount", dayCount);
- logger.info("execute leaveDao has added leaveApply!");
- }
- }
- package com.qiny.leave;
- import java.util.Map;
- import com.opensymphony.module.propertyset.PropertySet;
- import com.opensymphony.workflow.FunctionProvider;
- import com.opensymphony.workflow.spi.WorkflowEntry;
- import com.qiny.dao.LeaveDAO;
- import org.apache.log4j.Logger;
- public class ApproveFunction implements FunctionProvider {
- private static Logger logger = (Logger) Logger.getInstance(ApproveFunction.class);
- public void execute(Map transientVars, Map args, PropertySet ps) {
- logger.info("execute ......");
- WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
- long wfid = entry.getId();
- int actionId = ((Integer) transientVars.get("actionId")).intValue();
- logger.info("execute actionId=" + actionId);
- int applyID = ((Integer) transientVars.get("applyID")).intValue();
- String approver = (String) transientVars.get("approver");
- int opinion = ((Integer) transientVars.get("opinion")).intValue();
- LeaveApprove LeaveApprove = new LeaveApprove(applyID, approver, opinion);
- LeaveDAO leaveDao = new LeaveDAO();
- leaveDao.addLeaveApprove(LeaveApprove);
- ps.setInt("opinion", opinion);
- logger.info("execute leaveDao has added leaveApprove!");
- }
- }
- package com.qiny.leave;
- public class LeaveApply {
- private int applyID; //申请ID 主键
- private String applicant; //申请人
- private String reason; //原因
- private String applyTime; //申请时间,为简单起见用字符串表示
- private int dayCount; //申请天数,在某种业务逻辑下,用作流程判断
- private long wfid; //所属工作流实例id
- public LeaveApply(){
- }
- public LeaveApply(String applicant,String reason,int dayCount){
- this.applicant = applicant;
- this.reason = reason;
- this.dayCount = dayCount;
- }
- public int getApplyID() {
- return applyID;
- }
- public String getApplicant() {
- return applicant;
- }
- public String getReason() {
- return reason;
- }
- public String getApplyTime() {
- return applyTime;
- }
- public int getDayCount() {
- return dayCount;
- }
- public long getWfid() {
- return wfid;
- }
- public void setApplyID(int applyID) {
- this.applyID = applyID;
- }
- public void setApplicant(String applicant) {
- this.applicant = applicant;
- }
- public void setReason(String reason) {
- this.reason = reason;
- }
- public void setApplyTime(String applyTime) {
- this.applyTime = applyTime;
- }
- public void setDayCount(int dayCount) {
- this.dayCount = dayCount;
- }
- public void setWfid(long wfid) {
- this.wfid = wfid;
- }
- }
- package com.qiny.leave;
- public class LeaveApprove {
- private int applyID; //申请id
- private String approver; //批准人
- private String approveTime; //批准时间,简单起见用字符串表示
- private int opinion; //意见 1:批准; 2:拒绝
- public LeaveApprove(){
- }
- public LeaveApprove(int applyID,String approver,int opinion){
- this.applyID = applyID;
- this.approver = approver;
- this.opinion = opinion;
- }
- public String getOpinionString(){
- return opinion == 1 ? "批准" : "拒绝";
- }
- public int getApplyID() {
- return applyID;
- }
- public String getApprover() {
- return approver;
- }
- public String getApproveTime() {
- return approveTime;
- }
- public int getOpinion() {
- return opinion;
- }
- public void setApplyID(int applyID) {
- this.applyID = applyID;
- }
- public void setApprover(String approver) {
- this.approver = approver;
- }
- public void setApproveTime(String approveTime) {
- this.approveTime = approveTime;
- }
- public void setOpinion(int opinion) {
- this.opinion = opinion;
- }
- }
- package com.qiny.dao;
- import java.util.List;
- import java.util.ArrayList;
- import java.sql.Connection;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.sql.DataSource;
- import javax.naming.InitialContext;
- import javax.naming.NamingException;
- import com.qiny.leave.LeaveApply;
- import com.qiny.leave.LeaveApprove;
- public class LeaveDAO {
- protected static DataSource ds = null;
- public LeaveDAO() {
- if (ds == null) {
- try {
- InitialContext ic = new InitialContext();
- ds = (DataSource) ic.lookup("java:JSQLConnectDB_LeaveApply");
- } catch (NamingException ne) {
- throw new RuntimeException("NamingException while looking");
- }
- }
- }
- public void addLeaveApply(LeaveApply leaveApply) {
- try {
- String exeSql = ""
- + " INSERT INTO bus_leaveApply (applicant,reason,applyTime,dayCount,wfid)"
- + " VALUES ('" + leaveApply.getApplicant() + "','" + leaveApply.getReason()
- + " ',CONVERT(VARCHAR(20),GETDATE(),121 ),'" + leaveApply.getDayCount()
- + " '," + leaveApply.getWfid() + ")";
- Connection connection = ds.getConnection();
- Statement statement = connection.createStatement();
- statement.execute(exeSql);
- statement.close();
- connection.close();
- } catch (SQLException ex) {
- throw new RuntimeException("DAO addLeaveApply failed!\n" + ex.getMessage());
- }
- }
- public void addLeaveApprove(LeaveApprove leaveApproval) {
- try {
- String exeSql = ""
- + " INSERT INTO bus_leaveApprove (applyID,approver,approveTime,opinion)"
- + " VALUES ('" + leaveApproval.getApplyID() + "','" + leaveApproval.getApprover()
- + " ',CONVERT(VARCHAR(20),GETDATE(),121 )," + leaveApproval.getOpinion() + ")";
- Connection connection = ds.getConnection();
- Statement statement = connection.createStatement();
- statement.execute(exeSql);
- statement.close();
- connection.close();
- } catch (SQLException ex) {
- throw new RuntimeException("DAO addLeaveApprove failed!\n" + ex.getMessage());
- }
- }
- public LeaveApply getLeaveApply(long wfid) {
- LeaveApply leaveApply = new LeaveApply();
- try {
- String querySql = ""
- + " SELECT applyID,applicant,reason,applyTime,dayCount,wfid "
- + " FROM bus_leaveApply WHERE wfid=" + wfid;
- Connection connection = ds.getConnection();
- Statement statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(querySql);
- if (rs.next()) {
- leaveApply.setApplyID(rs.getInt("applyID"));
- leaveApply.setApplicant(rs.getString("applicant"));
- leaveApply.setReason(rs.getString("reason"));
- leaveApply.setApplyTime(rs.getString("applyTime"));
- leaveApply.setDayCount(rs.getInt("dayCount"));
- leaveApply.setWfid(rs.getLong("wfid"));
- }
- rs.close();
- statement.close();
- connection.close();
- } catch (SQLException ex) {
- throw new RuntimeException("DAO getLeaveApply failed!\n" + ex.getMessage());
- }
- return leaveApply;
- }
- public List getLeaveAprovals(int applyID) {
- List approvals = new ArrayList();
- try {
- String querySql = ""
- + " SELECT applyID,approver,approveTime,opinion "
- + " FROM bus_leaveApprove WHERE applyID=" + applyID;
- Connection connection = ds.getConnection();
- Statement statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(querySql);
- while (rs.next()) {
- LeaveApprove leaveApproval = new LeaveApprove();
- leaveApproval.setApplyID(rs.getInt("applyID"));
- leaveApproval.setApprover(rs.getString("approver"));
- leaveApproval.setApproveTime(rs.getString("approveTime"));
- leaveApproval.setOpinion(rs.getInt("opinion"));
- approvals.add(leaveApproval);
- }
- rs.close();
- statement.close();
- connection.close();
- } catch (SQLException ex) {
- throw new RuntimeException("DAO getLeaveAprovals failed!\n" + ex.getMessage());
- }
- return approvals;
- }
- }