MoveTleave_SummaryToHistory.java 4.95 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
package com.csc.library.process;

import java.util.Vector;

import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialInquiry;
import com.csc.library.session.InitialRecord;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.MyLog;

public class MoveTleave_SummaryToHistory extends ProcessTimeBase{
	private DbInquiry inq = null;
	private String startMethodTime =""; 
	private String endSaveTime ="";
	
  public Vector getProcessList() {
		Vector v = new Vector();
		v.add("move2hisList1");
		return v;
  }//end getProcessList
  
  public void process() throws Exception {	
	//start method
	CscCalendar performanceTime1=new CscCalendar(); 
	this.startMethodTime ="start method at: "+ performanceTime1.getDDMMYYHHMMSS();
	String strWhereClause =" 1=1 ";
	
	Vector move2hisList1= this.processList;
	  
	  for (int i=0;i<move2hisList1.size() && !this.isCancle();i++) {
		
			this.setParamData();
			CscCalendar stDate = new CscCalendar(this.getParamValue("startDate"));
			CscCalendar endDate = new CscCalendar(this.getParamValue("endDate"));
		   	
			
			strWhereClause += " and dateid >='" + stDate.getYYYYMMDD() +"'" ;
			strWhereClause += " and dateid <='" + endDate.getYYYYMMDD() +"'" ;
	
			if(!this.getParamData("employeeBetween").equals("")&&this.getParamData("employeeBetween")!=null){
				strWhereClause += " and (" + this.getParamData("employeeBetween");	
			}//end if 
			
			if(!this.getParamData("employeeSelect").equals("")&&this.getParamData("employeeSelect")!=null){
				if(!this.getParamData("employeeBetween").equals("")&&this.getParamData("employeeBetween")!=null){
					strWhereClause += " OR employeeid in(" + this.getWhereClause(this.getParamData("employeeSelect")) +"))" ;
				}else{
					strWhereClause += " and employeeid in(" + this.getWhereClause(this.getParamData("employeeSelect")) +")" ;
				}//end if 
			}else{
				strWhereClause += ")";
			}//end if 
			
			if(!this.getParamData("positionSelect").equals("")&&this.getParamData("positionSelect")!=null){
				strWhereClause += " and emp_position in(" + this.getWhereClause(this.getParamData("positionSelect")) +")" ;
			}//end if 
			
			if(!this.getParamData("bu1Select").equals("")&&this.getParamData("bu1Select")!=null){
				strWhereClause += " and bu1 in(" + this.getWhereClause(this.getParamData("bu1Select")) +")" ;
			}//end if 
			
			if(!this.getParamData("bu2Select").equals("")&&this.getParamData("bu2Select")!=null){
				strWhereClause += " and bu2 in(" + this.getWhereClause(this.getParamData("bu2Select")) +")" ;
			}//end if 
			
			if(!this.getParamData("bu3Select").equals("")&&this.getParamData("bu3Select")!=null){
				strWhereClause += " and bu3 in(" + this.getWhereClause(this.getParamData("bu3Select")) +")" ;
			}//end if 
			
			if(!this.getParamData("bu4Select").equals("")&&this.getParamData("bu4Select")!=null){
				strWhereClause += " and bu4 in(" + this.getWhereClause(this.getParamData("bu4Select")) +")" ;
			}//end if 
			
			if(!this.getParamData("salatypeSelect").equals("")&&this.getParamData("salatypeSelect")!=null){
				strWhereClause += " and salatype in(" + this.getWhereClause(this.getParamData("salatypeSelect")) +")" ;
			}//end if 
		 	
	  }//end for
	  
	  	this.move2History(strWhereClause);
		CscCalendar performanceTime4=new CscCalendar(); 
	 	this.endSaveTime ="end save to DB at: "+ performanceTime4.getDDMMYYHHMMSS();
	
	 	System.out.print("MoveTleave_SummaryToHistory Time List:"+"\n"+
	 			 startMethodTime +"\n"+
	 			 endSaveTime + "\n");
		//=========== debug =========
	 	
		this.setFullMessage("Successful of MoveTleave_SummaryToHistory : "+move2hisList1.size());
	}//end process
	
	private String getWhereClause(String strValue){
		String[] valueList = strValue.split(",");
		String whereclauseRtn ="";
		for (int i1 =0;i1<valueList.length;i1++){
			if(whereclauseRtn.equals("")){
				whereclauseRtn = "\'"+valueList[i1]+"\'";
			}else{
				whereclauseRtn +=   ","+"\'"+valueList[i1]+ "\'";
			}//end if 
		}//end for 
		return whereclauseRtn;
	}//end getWhereClause
	
	private void move2History(String strWhereClause) {
		String sourceTable = "tleave_summary";
		String backupTable = "tleave_summary_history";
		try {
			if (this.inq == null){
				this.inq = new InitialInquiry(this.upf).getDbInquiry();
				this.inq.setParam(this.data);
				this.inq.setSchemaName(this.upf.getSchemaName());
				this.inq.initMyTable(sourceTable, strWhereClause , "");
				this.inq.setColumn("*");
			}
			
			DbRecord recHis = new InitialRecord(this.upf).getDbRecord(backupTable);
			recHis.setColumn("*");
			
			this.inq.refresh();
			while (this.inq.next()) {
				DbRecord rec =  this.inq.getCurrentDbRecord().cloneRecord(true);
				recHis.setData(rec);
				recHis.save();
				
			 	rec.delete(); 	 
			}//end while
		} catch (Exception e) {
			MyLog.error(this, e);			
		}//end try
	}//end moveHistory
	
}//end class