Dailyattendance_ot.java 9.26 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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
package com.csc.library.databean;

import com.csc.library.utilities.MyLog;
import java.text.DecimalFormat;
import java.util.Iterator;

import com.csc.library.database.MyHashMap;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.InitialInquiry;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.MyTreeMap;

public class Dailyattendance_ot extends Memployee {
	
	MyTreeMap hm_ta = new MyTreeMap(); //红ѹӧҹ
	MyTreeMap hm_value = new MyTreeMap(); 
	CscCalendar csStart = new CscCalendar();
	CscCalendar csEnd = new CscCalendar();
	MyHashMap hm_hol = new MyHashMap(); //红ѹشġ
	
	/*
	 * ҧ field Ѻ Hash 
	 *  getString դ ʴ "" ᷹͡
	 */
	private void initialColumn() {		
		for (int i=1; i<=40; i++) {
			for (int j=1; j<=11; j++) {
				this.hm_value.put("col"+i+"_"+j,"");
			}
			for (int k=5; k<=10; k++) {
				this.hm_value.put("col"+i+"_"+k+"h","");
			}
		}
	}	
	
	/*
	 *  param ҡ˹ҨѹͧҢš÷ӧҹ
	 * ˹ҨѺ Month  Year
	 */
	private void setCalendar() {
		MyLog.debug(this, "CODEID==="+this.param.get("CODEID"));
		MyLog.debug(this, "MONTH==="+this.param.get("MONTH"));
		MyLog.debug(this, "YEAR==="+this.param.get("YEAR"));					
		 
		this.csStart = new CscCalendar((String)this.param.get("YEAR")+"-"
			+(String)this.param.get("MONTH")+"-01");
		this.csEnd = new CscCalendar((String)this.param.get("YEAR")+"-"
				+(String)this.param.get("MONTH")+"-"+csStart.getDayInMonth());
	}
	
	/*
	 * 纤ҵҧ ͧ÷ӧҹ 1 record ŧ MyHashMap
	 * ͹㹵͹ save 
	 */
	private MyHashMap getEmpData(Simttime_current12 rec) {
		MyHashMap prop = new MyHashMap();
		try {			
			prop.put("dateid",rec.getString("dateid"));
			prop.put("m_tm_bg",rec.getString("m_tm_bg"));
			prop.put("m_tm_en",rec.getString("m_tm_en"));
			prop.put("time0id",rec.getString("time0id"));
			prop.put("tr_type",rec.getString("ty_type"));
			prop.put("eventgrp",rec.getString("eventgrp"));
			prop.put("lt",rec.getString("lt"));
			prop.put("col01",rec.getString("col01"));
			prop.put("col02",rec.getString("col02"));
			prop.put("col03",rec.getString("col03"));
			prop.put("col04",rec.getString("col04"));
			prop.put("data01",rec.getString("data01"));
			prop.put("data02",rec.getString("data02"));
			prop.put("data03",rec.getString("data03"));
			prop.put("data04",rec.getString("data04"));
			prop.put("dataEtc",rec.getString("dataEtc"));
		} catch (Exception e) {
			MyLog.error(this, e);
		}			
		return prop;
	}
	
	/*
	 * 红š÷ӧҹ/ ŧ MyHashMap hm_ta
	 * ͹硡Ѻѹ͹͡ çѺš÷ӧҹ
	 */
	private void initialEmpWorkingTime() {
		try {				
			String sql="employeeid='"+this.getString("employeeid")+"' and " +
					"(dateid between '"+this.csStart.getYYYYMMDD()+"' and '"+this.csEnd.getYYYYMMDD()+"')";
			DbInquiry inq = new InitialInquiry(this.userPro).getDbInquiry();
			inq.setParam(this.param);
			inq.setSchemaName(this.userPro.getSchemaName());
			inq.initMyTable("ttime_current1", sql, "");
			inq.setColumn("*");
			inq.refresh();
			int i=1;
			String tmp="";
			while (inq.next()) {
				MyTreeMap tr;
				Simttime_current12 rec = (Simttime_current12) inq.getCurrentDbRecord();
				CscCalendar csc = new CscCalendar(rec.getString("dateid"));
				if (csc.getYYYYMMDD().equals(tmp)) {
					tr = (MyTreeMap) this.hm_ta.get(csc.getYYYYMMDD());					
				} else {
					i=1;
					tr = new MyTreeMap();
				}								
				tr.put(String.valueOf(i), this.getEmpData(rec));
				this.hm_ta.put(csc.getYYYYMMDD(), tr);
				i++;
				tmp = csc.getYYYYMMDD();
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}		
	}
	
	/*
	 * Ӣš÷ӧҹ hm_ta ѹ͡Ҩҡ˹Ҩ
	 * ҡѹçѹ put š÷ӧҹŧ hm_value
	 * ҡçѹ put ѹŧ hm_value
	 */
	private void mapWorkingData() {
		DecimalFormat df = new DecimalFormat();
		CscCalendar dateStart = new CscCalendar(this.csStart.getYYYYMMDD());
		CscCalendar dateEnd = new CscCalendar(this.csEnd.getYYYYMMDD());
		int i=1;
		while (dateStart.beforeEqualsDate(dateEnd)) {
			if (this.hm_ta.containsKey(dateStart.getYYYYMMDD())) {			
				 /* 
				 * բš÷ӧҹ put š÷ӧҹ͡
				 * ŧ MyHashMap hm_value
				 */
				
				MyTreeMap tr = (MyTreeMap) this.hm_ta.get(dateStart.getYYYYMMDD());
				Iterator it = tr.keySet().iterator();
				while (it.hasNext()) {
					String code = (String) it.next();					
					try {
						MyHashMap hRec = (MyHashMap) tr.get(code);
						this.hm_value.put("col"+i+"_1", dateStart.getDDMMYYYY());
						this.hm_value.put("col"+i+"_2", hRec.getString("time0id"));
						if (hRec.getString("m_tm_bg").equals(hRec.getString("m_tm_en"))) {
							this.hm_value.put("col"+i+"_3", "");
							this.hm_value.put("col"+i+"_4", "");
						} else if (hRec.getString("tr_type").indexOf("A")>-1) {
							this.hm_value.put("col"+i+"_3", df.format(hRec.getDouble("c_tm_bg")));
							this.hm_value.put("col"+i+"_4", df.format(hRec.getDouble("c_tm_en")));
						} else {
							this.hm_value.put("col"+i+"_3", df.format(hRec.getDouble("m_tm_bg")));
							this.hm_value.put("col"+i+"_4", df.format(hRec.getDouble("m_tm_en")));
						}
						this.hm_value.put("col"+i+"_5", hRec.getString("lt"));
						this.hm_value.put("col"+i+"_6", hRec.getString("data01"));
						this.hm_value.put("col"+i+"_7" ,hRec.getString("data02"));
						this.hm_value.put("col"+i+"_8", hRec.getString("data03"));
						this.hm_value.put("col"+i+"_9", hRec.getString("data04"));
						this.hm_value.put("col"+i+"_10", hRec.getString("dataEtc"));					
						this.hm_value.put("col"+i+"_11", this.chkDayType(dateStart.getYYYYMMDD(), dateStart.getCSCDOW())); //ͧѹ
						/*
						 * col 5h-10h put  column ŧ 
						 */
						this.hm_value.put("col"+i+"_5h", "");
						this.hm_value.put("col"+i+"_6h", hRec.getString("col01"));
						this.hm_value.put("col"+i+"_7h" ,hRec.getString("col02"));
						this.hm_value.put("col"+i+"_8h", hRec.getString("col03"));
						this.hm_value.put("col"+i+"_9h", hRec.getString("col04"));
						this.hm_value.put("col"+i+"_10h", "");		
						
					} catch (Exception e) {
						MyLog.error(this, e);
					}			
					i++;
				}				
			} else {
				/*
				 * բš÷ӧҹ put ѹ
				 * ŧ MyHashMap hm_value
				 * ǹͧ  "" 
				 */
				MyLog.debug(this, "::: NOT MAP ::: "+dateStart.getDDMMYYYY());
				this.hm_value.put("col"+i+"_1", dateStart.getDDMMYYYY());
				this.hm_value.put("col"+i+"_11", this.chkDayType(dateStart.getYYYYMMDD(), dateStart.getCSCDOW())); //ͧѹ
				i++;
			}			
			dateStart.incDate();
		}
	}

	/*
	 * չӧҹѹ
	 * I = ѹشġ
	 * * = ѹش -
	 * Y = ѹӧҹ
	 */
	private String chkDayType(String date ,int type) {		
		if (this.hm_hol.containsKey(date)) {
			return "I";
		} else if (type==6 || type==7) {
			return "*";
		} 
		return "";		
	}
	
	/*
	 * ŴѹشġͧФ MyHashMap
	 * ͹ѹӧҹѹشġ
	 */
	private void setHoliday() {		
		try {
			DbInquiry inqChild = new InitialInquiry(this.userPro).getDbInquiry();
			inqChild.setParam(this.param);
			inqChild.setSchemaName(this.userPro.getSchemaName());						
			inqChild.initMyTable("Mholiday1", "", "");
			inqChild.setColumn("holidayid, hdate");
			
			DbInquiry inq = new InitialInquiry(this.userPro).getDbInquiry();
			inq.setParam(this.param);
			inq.setSchemaName(this.userPro.getSchemaName());						
			inq.initMyTable("Mtime0", "time0id='"+this.getString("time0")+"'", "");
			inq.setColumn("time0id, companyid, holidaycode");
			inq.putChild(inqChild);
			inq.refresh();
			if (inq.next()) {
				DbInquiry child = (DbInquiry) inq.getChild("Mholiday1");
				do {
					CscCalendar cs = new CscCalendar(inqChild.getCurrentDbRecord().getString("hdate"));
					this.hm_hol.put(cs.getYYYYMMDD(), cs.getYYYYMMDD());					
				} while (child.next());				
			}
		} catch(Exception e) {
			MyLog.error(this, e);
		}		
	}
	
	public void postInqNext() {		
		if (this.foundData) {
			super.postInqNext();	
			this.initialColumn();
			this.setCalendar();
			this.setHoliday();			
			this.initialEmpWorkingTime();
			this.mapWorkingData();
			MyLog.debug(this, this.hm_ta.toString());
			MyLog.debug(this, this.hm_value.toString());			
		}		
	}
	
	public String getString(String fieldName) {
		if (fieldName.indexOf("$") >= 0) {
			return this.getStringHash(fieldName);
		} else if (this.hm_value.containsKey(fieldName)) {
			return this.hm_value.get(fieldName).toString();
		} else return super.getString(fieldName);
	}

	private String getStringHash(String fieldName) {
		if (fieldName.indexOf("$") >= 0) {
			String fname = fieldName.substring(0, fieldName.indexOf("$"));
			String lname = fieldName.substring(fieldName.indexOf("$") + 1, fieldName.length());
			if (this.hm_value.containsKey(lname)) {				
				return (String) this.hm_value.get(lname);
			} else return super.getString(fieldName);
		} else return super.getString(fieldName);		
	}
}