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

import com.csc.library.utilities.MyLog;
import com.csc.library.utilities.ReadFile;

import java.util.StringTokenizer;
import java.util.Vector;

import com.csc.library.databean.Mtime0;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialEnvironment;
import com.csc.library.session.InitialInquiry;
import com.csc.library.session.InitialRecord;
import com.csc.library.timeattendance.SwipeData;
import com.csc.library.timeattendance.WorkingShift;
import com.csc.library.utilities.CscCalendar;

/*
 * class 㹡èѺ÷ӧҹѺٴѵâͧѡҹ
 * NOT USED 2008/09/01
 */
public class ParisTimeProcess extends ProcessTimeBase {
	
	DbRecord empRec = null;
	CscCalendar cs1 = null;
	CscCalendar cs2 = null;
	
	public Vector getProcessList() {
		Vector v = new Vector();
		try {
			this.setParamData();
			if (!this.getParamValue("filterProcess").equals("")) {
				DbInquiry inq = new InitialInquiry(this.upf).getDbInquiry();
				inq.setParam(this.data);
				inq.setSchemaName(this.upf.getSchemaName());
				inq.initMyTable("Memployee", this.getParamValue("filterProcess"), "employeeid");
				inq.setColumn("employeeid, time0, runno, bossid, bu1, bu2, bu3, bu4, bu5, companyid, status, startdate, resigndate");			
				inq.setFatchAll(true);
				inq.refresh();
				while (inq.next()) {
					v.addElement(inq.getCurrentDbRecord().getString("employeeid"));
				}
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
		return v;
	}
	
	public void process() throws Exception {		
		this.setParamData();
		/*CscCalendar cs1 = new CscCalendar(this.getParamValue("startDate"));
		cs1.decDate();
		CscCalendar cs2 = new CscCalendar(this.getParamValue("endDate"));
		cs2.incDate();*/
		
		/*
		 * ҡק͹ӡèѺѹ  startDate  endDate  today
		 * зӡ new CscCalendar() ѹ ͹仨Ѻѹ
		 */
		if (this.getParamValue("startDate").equalsIgnoreCase("today") || this.getParamValue("endDate").equalsIgnoreCase("today")) {
			CscCalendar c1 = new CscCalendar();
			this.data.put("startDate", c1.getDDMMYYYY());
			this.data.put("endDate", c1.getDDMMYYYY());
		}
		
		this.cs1 = new CscCalendar(this.getParamValue("startDate"));        
        this.cs2 = new CscCalendar(this.getParamValue("endDate"));
        try {
        	this.cs1.setCSCTime(Float.parseFloat(this.getParamValue("startTime")));
        	this.cs2.setCSCTime(Float.parseFloat(this.getParamValue("endTime")));
        } catch (Exception e) {
        	this.cs1.setCSCTime(0.00f);
        	this.cs2.setCSCTime(0.00f);
        }
        
		Vector vt = this.processList;
		
		if (vt==null) {
			vt = new Vector();
			String condition = "";
			if (this.data.containsKey("conditionfile")) { //ҡյҹ condition ҡӹdzҡ file зӡҹҡ path ˹
				InitialEnvironment en = new InitialEnvironment("GLOBAL");
				String xmlPath = en.getValue("import-dir");
				ReadFile rf = new ReadFile(xmlPath + "condition/" + (String) this.data.get("conditionfile"));
				condition = rf.readLine();
				rf.closeFile();
			} else {
				condition = (String)this.data.get("processlist");
			}
			
			StringTokenizer str = new StringTokenizer(condition,"#");
			while (str.hasMoreTokens()) {
				vt.add(str.nextToken());
			}			
			this.upf.set("companyid", (String) this.data.get("companyid"));
			this.upf.setSchemaName((String) this.data.get("schemaname"));
			this.upf.setDbName((String) this.data.get("dbname"));
			this.upf.set("appname", (String) this.data.get("appname"));
			this.upf.set("lang", (String) this.data.get("lang"));
		}
		
		String errorResult = "";
		String errorProcess = "";
		for (int i=0;i<vt.size() && !this.isCancle();i++) {
			String id = (String) vt.elementAt(i);
			try {
				//ӡûżšèѺ  Ф  processlist ˹
				if (this.empRec == null) {
					this.empRec = new InitialRecord(this.upf).getDbRecord("MEMPLOYEE");
				} 
				this.empRec.clearField();
				this.empRec.set("employeeid", (String) vt.elementAt(i));
				this.empRec.set("companyid", (String) this.upf.get("companyid"));
				this.empRec.search();
				
				Mtime0 timeRec = this.getTimeRecord(this.empRec.getString("time0"));	//ҵҧ÷ӧҹͧѡҹ		 
				if (timeRec != null) {
					timeRec.setEmpRec(this.empRec);
					// ӡҧἹ÷ӧҹͧ  ҵǧҷ˹ ͹èѺ
					WorkingShift ws = timeRec.genWorkingShift(new CscCalendar(this.cs1.getTimestamp()), new CscCalendar(this.cs2.getTimestamp()));
					
					this.upf.set("empRecord",this.empRec.getString("employeeid"));
					if (this.getParamValue("cmdValue").equalsIgnoreCase("paris")) {
						this.parisTimeProcess(ws, this.empRec); //ӡèѺ÷ӧҹѺҡ÷ӧҹ
					}
				} else {
					errorResult += id+",";
				}
			} catch (Exception e ) {	
				errorProcess += id+",";
			}
			this.alive("Process EmployeeID : "+id+" ["+i+" of "+vt.size()+"]");
		}
		this.setMessage("Successful of PairTimeProcess : "+vt.size());
		this.setFullMessage("Successful of PairTimeProcess : "+vt.size()+"\n"+
				"Error Case : Not Find WorkingTime! Please Check time0, startdate, resigndate In MEMPLOYEE !!!"+ "\n" +
				"Result Error : "+errorResult+"\n"+
				"Error Process : "+errorProcess);
	}
	
	private void parisTimeProcess(WorkingShift ws, DbRecord empRec) {
		try {
			if (!ws.isEmpty()) {
				CscCalendar csStart = new CscCalendar(this.getParamValue("startDate"));
				csStart.decDate();
				CscCalendar csEnd = new CscCalendar(this.getParamValue("endDate"));
				csEnd.incDate();

				ws.setUProfile(this.upf);
				ws.setEmployeeid(empRec.getString("employeeid"));
				ws.setEmpTimeCode(empRec.getString("time0"));
				ws.adjust();
				ws.createLink();

				SwipeData SD = new SwipeData(); //new Class() 红šŧҢͧѡҹ
				SD.setUProfile(this.upf);
				SD.loadData(empRec.getString("employeeid"), csStart, csEnd); //֧ҡٴѵâͧѡҹ͡ҵǧѹ˹
				ws.genTimeZone();
				ws.setSwipeTrans(SD);
				ws.findTime(new CscCalendar(this.getParamValue("startDate") + " 00:00:00.000000000"),
						new CscCalendar(this.getParamValue("endDate") + " 23:59:00.000000000")); //ӡèѺ			
				SD.updateData(); //ӡúѹ֡èѺŧ ttimereserve ҡ͡÷ӧҹѺٴѵ
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}
}