ForceFinishWorkflow.java 5.51 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
package com.csc.library.process;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import com.csc.library.database.CscConnection;
import com.csc.library.database.StaticProperties;
import com.csc.library.utilities.MyLog;

public class ForceFinishWorkflow extends MyProcess {
	
	private CscConnection conn = null;
	private Statement stmt = null;
	private Statement stmt1 = null;
	private ResultSet rs = null;
	private String WF_ID = "8002";
	private boolean isToSave = true;
	
	Vector success = new Vector();
	Vector fail = new Vector();
	
	@Override
	public Vector getProcessList() {
		Vector temp = new Vector();
		try{
			conn = (CscConnection) StaticProperties.myConnection.getConnection(upf.get("dbname"));
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select doc_no,runno from workflow_data where wf_status = '1' and wf_id = '"+WF_ID+"'");

			while (rs.next()){
				temp.add(rs.getString("runno"));
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}finally{
			try {
				rs.close();
				if(stmt!=null){
					stmt.close();
				}		
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}//end try
		return temp;
	}
	
	@Override
	public void process() throws Exception {
		if(upf==null){
			upf = this.getUProfile();
		}//end if 
		
		Vector item = this.getProcessList();
		
		for(int i=0; i < item.size(); i++ ){
			String runno = (String)item.get(i);
			updateActor(runno);
			if(isToSave){
				updateStep(runno);
				updateWFIncident(runno);
				updateWF(runno);
				
				success.add(runno);
			}else{
				fail.add(runno);
			}
			System.out.println("Process progress [" + i + "/" +item.size()+ "]");
		}
		System.out.println("!! success !!");
		for(int j=0; j < success.size(); j++){
			System.out.print((String)item.get(j)+":");
		}
		System.out.println("!! fail !!");
		for(int j=0; j < fail.size(); j++){
			System.out.print((String)item.get(j)+":");
		}
		
	}
	
	private void updateActor(String runno){
		try {
			conn = (CscConnection) StaticProperties.myConnection.getConnection(upf.get("dbname"));
			stmt = conn.createStatement();
			stmt1 = conn.createStatement();
			rs = stmt.executeQuery("select top 1 * from ACTOR_INCIDENT where WF_ID = '"+WF_ID+"' and WF_SEQ_NO = '" +runno+ "' order by STEP_ID desc;");

			while (rs.next()){
				if(rs.getString("status").equals("3")){
					isToSave = false;
					System.out.println("!!!!This workflow status is not in approve state!!!!!" + rs.getString("runno"));					
				}else{
					isToSave = true;
					stmt1.executeUpdate("update actor_incident set step_id = '6',completion_time = start_time,status = '2' where step_id = '"+rs.getString("step_id")+"' and step_seq_no = '"+rs.getString("step_seq_no")+"' and wf_id = '"+WF_ID+"' and wf_seq_no = '"+runno+"'");
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}finally{
			try {
				rs.close();
				if(stmt!=null){
					stmt.close();
				}	
				if(stmt1!=null){
					stmt1.close();
				}
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}//end try
	}
	
	private void updateWFIncident(String runno){
		try {
			conn = (CscConnection) StaticProperties.myConnection.getConnection(upf.get("dbname"));
			stmt = conn.createStatement();
			stmt1 = conn.createStatement();
			rs = stmt.executeQuery("select top 1 * from WORKFLOW_INCIDENT where WF_ID = '"+WF_ID+"' and WF_SEQ_NO = '" +runno+ "'");

			while (rs.next()){
				stmt1.executeUpdate("update workflow_incident set completion_time = start_time,status = '1' where wf_id = '"+WF_ID+"' and wf_seq_no = '"+runno+"'");
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}finally{
			try {
				rs.close();
				if(stmt!=null){
					stmt.close();
				}	
				if(stmt1!=null){
					stmt1.close();
				}
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}//end try
	}
	
	private void updateStep(String runno){
		try {
			conn = (CscConnection) StaticProperties.myConnection.getConnection(upf.get("dbname"));
			stmt = conn.createStatement();
			stmt1 = conn.createStatement();
			rs = stmt.executeQuery("select top 1 * from STEP_INCIDENT where WF_ID = '"+WF_ID+"' and WF_SEQ_NO = '" +runno+ "' order by STEP_ID desc;");

			while (rs.next()){
				stmt1.executeUpdate("update step_incident set step_id = '6',completion_time = start_time,status = '1' where step_id = '"+rs.getString("step_id")+"' and step_seq_no = '"+rs.getString("step_seq_no")+"' and wf_id = '"+WF_ID+"' and wf_seq_no = '"+runno+"'");
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}finally{
			try {
				rs.close();
				if(stmt!=null){
					stmt.close();
				}	
				if(stmt1!=null){
					stmt1.close();
				}
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}//end try
	}
	
	private void updateWF(String runno){
		try {
			conn = (CscConnection) StaticProperties.myConnection.getConnection(upf.get("dbname"));
			stmt1 = conn.createStatement();
			stmt1.executeUpdate("update workflow_data set completion_time = start_time,wf_status = '4',TRANSFER='0' where wf_id = '"+WF_ID+"' and runno = '"+runno+"'");
		}catch(Exception e){
			MyLog.error(this,e);
		}finally{
			try {
				rs.close();
				if(stmt!=null){
					stmt.close();
				}	
				if(stmt1!=null){
					stmt1.close();
				}
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		}//end try
	}
	
}